Class: PrometheusMetric

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

Instance Method Summary collapse

Methods inherited from ApplicationRecord

at_most, id_in, id_not_in, iid_in, pluck_primary_key, primary_key_in, safe_ensure_unique, safe_find_or_create_by, safe_find_or_create_by!, underscore, without_order

Instance Method Details

#group_titleObject


33
34
35
# File 'app/models/prometheus_metric.rb', line 33

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

#priorityObject


29
30
31
# File 'app/models/prometheus_metric.rb', line 29

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

#queriesObject


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

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

#query_seriesObject


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

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


37
38
39
# File 'app/models/prometheus_metric.rb', line 37

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

#to_metric_hashObject


45
46
47
# File 'app/models/prometheus_metric.rb', line 45

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

#to_query_metricObject


41
42
43
# File 'app/models/prometheus_metric.rb', line 41

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