debian-mirror-gitlab/lib/gitlab/prometheus/metric_group.rb

34 lines
859 B
Ruby
Raw Normal View History

2019-02-15 15:39:39 +05:30
# frozen_string_literal: true
2017-09-10 17:25:29 +05:30
module Gitlab
module Prometheus
class MetricGroup
2019-12-04 20:38:33 +05:30
prepend_if_ee('EE::Gitlab::Prometheus::MetricGroup') # rubocop: disable Cop/InjectEnterpriseEditionModule
2017-09-10 17:25:29 +05:30
include ActiveModel::Model
attr_accessor :name, :priority, :metrics
2018-11-20 20:47:30 +05:30
2017-09-10 17:25:29 +05:30
validates :name, :priority, :metrics, presence: true
2018-03-27 19:54:05 +05:30
def self.common_metrics
2019-12-26 22:10:19 +05:30
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
2019-02-15 15:39:39 +05:30
all_groups.sort_by(&:priority).reverse
2017-09-10 17:25:29 +05:30
end
2018-03-27 19:54:05 +05:30
# EE only
def self.for_project(_)
common_metrics
end
2017-09-10 17:25:29 +05:30
end
end
end