Class: Gitlab::Metrics::Dashboard::Transformers::Yml::V1::PrometheusMetrics
- Inherits:
-
Object
- Object
- Gitlab::Metrics::Dashboard::Transformers::Yml::V1::PrometheusMetrics
- Defined in:
- lib/gitlab/metrics/dashboard/transformers/yml/v1/prometheus_metrics.rb
Overview
Takes a JSON schema validated dashboard hash and maps it to PrometheusMetric model attributes
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(dashboard_hash, project: nil, dashboard_path: nil) ⇒ PrometheusMetrics
constructor
A new instance of PrometheusMetrics.
Constructor Details
#initialize(dashboard_hash, project: nil, dashboard_path: nil) ⇒ PrometheusMetrics
Returns a new instance of PrometheusMetrics.
12 13 14 15 16 17 18 |
# File 'lib/gitlab/metrics/dashboard/transformers/yml/v1/prometheus_metrics.rb', line 12 def initialize(dashboard_hash, project: nil, dashboard_path: nil) @dashboard_hash = dashboard_hash.with_indifferent_access @project = project @dashboard_path = dashboard_path @dashboard_hash.default_proc = -> (h, k) { raise Transformers::Errors::MissingAttribute, k.to_s } end |
Instance Method Details
#execute ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/gitlab/metrics/dashboard/transformers/yml/v1/prometheus_metrics.rb', line 20 def execute prometheus_metrics = [] dashboard_hash[:panel_groups].each do |panel_group| panel_group[:panels].each do |panel| panel[:metrics].each do |metric| prometheus_metrics << { project: project, title: panel[:title], y_label: panel[:y_label], query: metric[:query_range] || metric[:query], unit: metric[:unit], legend: metric[:label], identifier: metric[:id], group: Enums::PrometheusMetric.groups[:custom], common: false, dashboard_path: dashboard_path }.compact end end end prometheus_metrics end |