Class: PrometheusMetricsFinder

Inherits:
Object
  • Object
show all
Defined in:
app/finders/prometheus_metrics_finder.rb

Constant Summary collapse

ACCEPTED_PARAMS =
[
  :project,
  :group,
  :title,
  :y_label,
  :identifier,
  :id,
  :common,
  :ordered
].freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ PrometheusMetricsFinder

Returns a new instance of PrometheusMetricsFinder.


24
25
26
# File 'app/finders/prometheus_metrics_finder.rb', line 24

def initialize(params = {})
  @params = params.slice(*ACCEPTED_PARAMS)
end

Class Method Details

.indexesObject

Cautiously preferring a memoized class method over a constant so that the DB connection is accessed after the class is loaded.


17
18
19
20
21
22
# File 'app/finders/prometheus_metrics_finder.rb', line 17

def self.indexes
  @indexes ||= PrometheusMetric
    .connection
    .indexes(:prometheus_metrics)
    .map { |index| index.columns.map(&:to_sym) }
end

Instance Method Details

#executePrometheusMetric, PrometheusMetric::ActiveRecord_Relation

Returns:


29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'app/finders/prometheus_metrics_finder.rb', line 29

def execute
  validate_params!

  metrics = by_project(::PrometheusMetric.all)
  metrics = by_group(metrics)
  metrics = by_title(metrics)
  metrics = by_y_label(metrics)
  metrics = by_common(metrics)
  metrics = by_ordered(metrics)
  metrics = by_identifier(metrics)
  metrics = by_id(metrics)

  metrics
end