Class: PrometheusMetric

Inherits:
ApplicationRecord show all
Includes:
EachBatch
Defined in:
app/models/prometheus_metric.rb

Constant Summary

Constants inherited from ApplicationRecord

ApplicationRecord::MAX_PLUCK

Constants included from ResetOnUnionError

ResetOnUnionError::MAX_RESET_PERIOD

Instance Method Summary collapse

Methods inherited from ApplicationRecord

cached_column_list, #create_or_load_association, declarative_enum, default_select_columns, id_in, id_not_in, iid_in, pluck_primary_key, primary_key_in, #readable_by?, safe_ensure_unique, safe_find_or_create_by, safe_find_or_create_by!, #to_ability_name, underscore, where_exists, where_not_exists, with_fast_read_statement_timeout, without_order

Methods included from SensitiveSerializableHash

#serializable_hash

Instance Method Details

#group_titleObject



35
36
37
# File 'app/models/prometheus_metric.rb', line 35

def group_title
  group_details(group).fetch(:group_title)
end

#priorityObject



31
32
33
# File 'app/models/prometheus_metric.rb', line 31

def priority
  group_details(group).fetch(:priority)
end

#queriesObject



51
52
53
54
55
56
57
58
59
60
# File 'app/models/prometheus_metric.rb', line 51

def queries
  [
    {
      query_range: query,
      unit: unit,
      label: legend,
      series: query_series
    }.compact
  ]
end

#query_seriesObject



62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'app/models/prometheus_metric.rb', line 62

def query_series
  case legend
  when 'Status Code'
    [{
      label: 'status_code',
      when: [
        { value: '2xx', color: 'green' },
        { value: '4xx', color: 'orange' },
        { value: '5xx', color: 'red' }
      ]
    }]
  end
end

#required_metricsObject



39
40
41
# File 'app/models/prometheus_metric.rb', line 39

def required_metrics
  group_details(group).fetch(:required_metrics, []).map(&:to_s)
end

#to_metric_hashObject



47
48
49
# File 'app/models/prometheus_metric.rb', line 47

def to_metric_hash
  queries.first.merge(metric_id: id)
end

#to_query_metricObject



43
44
45
# File 'app/models/prometheus_metric.rb', line 43

def to_query_metric
  Gitlab::Prometheus::Metric.new(id: id, title: title, required_metrics: required_metrics, weight: 0, y_label: y_label, queries: queries)
end