Commit 21d7d707 authored by Ryan Cobb's avatar Ryan Cobb Committed by Thong Kuah

Add path to edit custom metrics

This adds a path to edit custom metrics in prometheus dashboard
response. It also adds a boolean to indicate if a panel group contains
custom metrics.
parent f378b397
......@@ -11,6 +11,7 @@ module Metrics
SEQUENCE = [
STAGES::CommonMetricsInserter,
STAGES::ProjectMetricsInserter,
STAGES::ProjectMetricsDetailsInserter,
STAGES::EndpointInserter,
STAGES::Sorter
].freeze
......
---
title: Adds path to edit custom metrics in dashboard response
merge_request: 24645
author:
type: added
# frozen_string_literal: true
module Gitlab
module Metrics
module Dashboard
module Stages
class ProjectMetricsDetailsInserter < BaseStage
def transform!
dashboard[:panel_groups].each do |panel_group|
next unless panel_group
has_custom_metrics = custom_group_titles.include?(panel_group[:group])
panel_group[:has_custom_metrics] = has_custom_metrics
panel_group[:panels].each do |panel|
next unless panel
panel[:metrics].each do |metric|
next unless metric
metric[:edit_path] = has_custom_metrics ? edit_path(metric) : nil
end
end
end
end
private
def custom_group_titles
@custom_group_titles ||= PrometheusMetricEnums.custom_group_details.values.map { |group_details| group_details[:group_title] }
end
def edit_path(metric)
Gitlab::Routing.url_helpers.edit_project_prometheus_metric_path(project, metric[:metric_id])
end
end
end
end
end
end
......@@ -16,7 +16,8 @@
"label": { "type": "string" },
"track": { "type": "string" },
"prometheus_endpoint_path": { "type": "string" },
"metric_id": { "type": "number" }
"metric_id": { "type": "number" },
"edit_path": { "type": ["string", "null"] }
},
"additionalProperties": false
}
......@@ -10,7 +10,8 @@
"panels": {
"type": "array",
"items": { "$ref": "panels.json" }
}
},
"has_custom_metrics": { "type": "boolean" }
},
"additionalProperties": false
}
......@@ -12,6 +12,7 @@ describe Gitlab::Metrics::Dashboard::Processor do
[
Gitlab::Metrics::Dashboard::Stages::CommonMetricsInserter,
Gitlab::Metrics::Dashboard::Stages::ProjectMetricsInserter,
Gitlab::Metrics::Dashboard::Stages::ProjectMetricsDetailsInserter,
Gitlab::Metrics::Dashboard::Stages::EndpointInserter,
Gitlab::Metrics::Dashboard::Stages::Sorter
]
......@@ -25,6 +26,10 @@ describe Gitlab::Metrics::Dashboard::Processor do
end
end
it 'includes boolean to indicate if panel group has custom metrics' do
expect(dashboard[:panel_groups]).to all(include( { has_custom_metrics: boolean } ))
end
context 'when the dashboard is not present' do
let(:dashboard_yml) { nil }
......@@ -145,7 +150,8 @@ describe Gitlab::Metrics::Dashboard::Processor do
unit: metric.unit,
label: metric.legend,
metric_id: metric.id,
prometheus_endpoint_path: prometheus_path(metric.query)
prometheus_endpoint_path: prometheus_path(metric.query),
edit_path: edit_metric_path(metric)
}
end
......@@ -165,4 +171,11 @@ describe Gitlab::Metrics::Dashboard::Processor do
identifier: metric
)
end
def edit_metric_path(metric)
Gitlab::Routing.url_helpers.edit_project_prometheus_metric_path(
project,
metric.id
)
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment