Commit ad3c212f authored by rpereira2's avatar rpereira2

Allow query/query_range key contain numbers

A number is a valid Prometheus query. Such queries are usually used
to display a threshold on a chart.
parent 7fa48bd7
---
title: Allow query/query_range keys in metrics dashboard to contain numbers
merge_request: 39530
author:
type: changed
...@@ -47,7 +47,7 @@ module Gitlab ...@@ -47,7 +47,7 @@ module Gitlab
# We need to remove any newlines since our UrlBlocker does not allow # We need to remove any newlines since our UrlBlocker does not allow
# multiline URLs. # multiline URLs.
query.squish query.to_s.squish
end end
end end
end end
......
...@@ -9,8 +9,8 @@ ...@@ -9,8 +9,8 @@
}, },
"unit": { "type": "string" }, "unit": { "type": "string" },
"label": { "type": "string" }, "label": { "type": "string" },
"query": { "type": "string" }, "query": { "type": ["string", "number"] },
"query_range": { "type": "string" }, "query_range": { "type": ["string", "number"] },
"step": { "type": "number" } "step": { "type": "number" }
} }
} }
...@@ -48,7 +48,7 @@ panel_groups: ...@@ -48,7 +48,7 @@ panel_groups:
y_label: "y_label" y_label: "y_label"
metrics: metrics:
- id: metric_a2 - id: metric_a2
query_range: 'query' query_range: 2000
label: Legend Label label: Legend Label
unit: unit unit: unit
- title: "Super Chart A1" - title: "Super Chart A1"
......
...@@ -10,8 +10,8 @@ ...@@ -10,8 +10,8 @@
], ],
"properties": { "properties": {
"id": { "type": "string" }, "id": { "type": "string" },
"query_range": { "type": "string" }, "query_range": { "type": ["string", "number"] },
"query": { "type": "string" }, "query": { "type": ["string", "number"] },
"unit": { "type": "string" }, "unit": { "type": "string" },
"label": { "type": "string" }, "label": { "type": "string" },
"track": { "type": "string" }, "track": { "type": "string" },
......
...@@ -27,9 +27,17 @@ RSpec.describe Gitlab::Metrics::Dashboard::Stages::MetricEndpointInserter do ...@@ -27,9 +27,17 @@ RSpec.describe Gitlab::Metrics::Dashboard::Stages::MetricEndpointInserter do
transform! transform!
expect(all_metrics).to satisfy_all do |metric| expect(all_metrics).to satisfy_all do |metric|
metric[:prometheus_endpoint_path] == prometheus_path(metric[:query_range].squish) metric[:prometheus_endpoint_path].present? && !metric[:prometheus_endpoint_path].include?("\n")
end end
end end
it 'works when query/query_range is a number' do
query = 2000
transform!
expect(all_metrics[1][:prometheus_endpoint_path]).to eq(prometheus_path(query))
end
end end
private private
......
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