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
# We need to remove any newlines since our UrlBlocker does not allow
# multiline URLs.
query.squish
query.to_s.squish
end
end
end
......
......@@ -9,8 +9,8 @@
},
"unit": { "type": "string" },
"label": { "type": "string" },
"query": { "type": "string" },
"query_range": { "type": "string" },
"query": { "type": ["string", "number"] },
"query_range": { "type": ["string", "number"] },
"step": { "type": "number" }
}
}
......@@ -48,7 +48,7 @@ panel_groups:
y_label: "y_label"
metrics:
- id: metric_a2
query_range: 'query'
query_range: 2000
label: Legend Label
unit: unit
- title: "Super Chart A1"
......
......@@ -10,8 +10,8 @@
],
"properties": {
"id": { "type": "string" },
"query_range": { "type": "string" },
"query": { "type": "string" },
"query_range": { "type": ["string", "number"] },
"query": { "type": ["string", "number"] },
"unit": { "type": "string" },
"label": { "type": "string" },
"track": { "type": "string" },
......
......@@ -27,9 +27,17 @@ RSpec.describe Gitlab::Metrics::Dashboard::Stages::MetricEndpointInserter do
transform!
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
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
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