2018-11-19 21:01:13 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-06-06 10:07:33 -04:00
|
|
|
module Gitlab
|
|
|
|
module Prometheus
|
|
|
|
class MetricGroup
|
2017-06-16 08:23:33 -04:00
|
|
|
include ActiveModel::Model
|
2017-05-10 05:25:30 -04:00
|
|
|
|
2017-06-16 08:23:33 -04:00
|
|
|
attr_accessor :name, :priority, :metrics
|
2018-08-31 12:53:50 -04:00
|
|
|
|
2017-06-16 08:23:33 -04:00
|
|
|
validates :name, :priority, :metrics, presence: true
|
2017-05-10 05:25:30 -04:00
|
|
|
|
2018-02-23 12:58:40 -05:00
|
|
|
def self.common_metrics
|
2019-11-15 07:06:12 -05:00
|
|
|
all_groups = ::PrometheusMetricsFinder.new(common: true).execute
|
|
|
|
.group_by(&:group_title)
|
|
|
|
.map do |name, metrics|
|
|
|
|
MetricGroup.new(
|
|
|
|
name: name,
|
|
|
|
priority: metrics.map(&:priority).max,
|
|
|
|
metrics: metrics.map(&:to_query_metric)
|
|
|
|
)
|
|
|
|
end
|
2018-12-21 06:11:58 -05:00
|
|
|
|
|
|
|
all_groups.sort_by(&:priority).reverse
|
2017-06-06 10:07:33 -04:00
|
|
|
end
|
2018-02-23 12:58:40 -05:00
|
|
|
|
|
|
|
# EE only
|
|
|
|
def self.for_project(_)
|
|
|
|
common_metrics
|
|
|
|
end
|
2017-05-10 05:25:30 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2020-04-28 05:09:34 -04:00
|
|
|
|
2021-05-11 17:10:21 -04:00
|
|
|
Gitlab::Prometheus::MetricGroup.prepend_mod_with('Gitlab::Prometheus::MetricGroup')
|