Class: Projects::Prometheus::AlertsFinder

Inherits:
Object
  • Object
show all
Defined in:
app/finders/projects/prometheus/alerts_finder.rb

Overview

Find Prometheus alerts by project, environment, id, or any combo thereof.

Optionally filter by metric.

Arguments:

params:
  project: Project | integer
  environment: Environment | integer
  metric: PrometheusMetric | integer

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ AlertsFinder

Returns a new instance of AlertsFinder.



16
17
18
19
20
21
22
23
# File 'app/finders/projects/prometheus/alerts_finder.rb', line 16

def initialize(params = {})
  unless params[:project] || params[:environment] || params[:id]
    raise ArgumentError,
      'Please provide one or more of the following params: :project, :environment, :id'
  end

  @params = params
end

Instance Method Details

#executeActiveRecord::Relation<PrometheusAlert>

Find all matching alerts

Returns:



28
29
30
31
32
33
34
# File 'app/finders/projects/prometheus/alerts_finder.rb', line 28

def execute
  relation = by_project(PrometheusAlert)
  relation = by_environment(relation)
  relation = by_metric(relation)
  relation = by_id(relation)
  ordered(relation)
end