Commit f82a06c9 authored by Stan Hu's avatar Stan Hu

Merge branch 'rpereira2/allow-numbers-in-dashboard-query-key' into 'master'

Allow query/query_range keys to contain numbers

See merge request gitlab-org/gitlab!39530
parents 2a0a2127 540ab2b4
---
title: Allow query/query_range keys in metrics dashboard to contain numbers
merge_request: 39530
author:
type: changed
...@@ -89,8 +89,8 @@ is no longer used. ...@@ -89,8 +89,8 @@ is no longer used.
| `id` | string | no | Used for associating dashboard metrics with database records. Must be unique across dashboard configuration files. Required for [alerting](../alerts.md) (support not yet enabled, see [relevant issue](https://gitlab.com/gitlab-org/gitlab/-/issues/27980)). | | `id` | string | no | Used for associating dashboard metrics with database records. Must be unique across dashboard configuration files. Required for [alerting](../alerts.md) (support not yet enabled, see [relevant issue](https://gitlab.com/gitlab-org/gitlab/-/issues/27980)). |
| `unit` | string | yes | Defines the unit of the query's return data. | | `unit` | string | yes | Defines the unit of the query's return data. |
| `label` | string | no, but highly encouraged | Defines the legend-label for the query. Should be unique within the panel's metrics. Can contain time series labels as interpolated variables. | | `label` | string | no, but highly encouraged | Defines the legend-label for the query. Should be unique within the panel's metrics. Can contain time series labels as interpolated variables. |
| `query` | string | yes if `query_range` is not defined | Defines the Prometheus query to be used to populate the chart/panel. If defined, the `query` endpoint of the [Prometheus API](https://prometheus.io/docs/prometheus/latest/querying/api/) will be utilized. | | `query` | string/number | yes if `query_range` is not defined | Defines the Prometheus query to be used to populate the chart/panel. If defined, the `query` endpoint of the [Prometheus API](https://prometheus.io/docs/prometheus/latest/querying/api/) will be utilized. |
| `query_range` | string | yes if `query` is not defined | Defines the Prometheus query to be used to populate the chart/panel. If defined, the `query_range` endpoint of the [Prometheus API](https://prometheus.io/docs/prometheus/latest/querying/api/) will be utilized. | | `query_range` | string/number | yes if `query` is not defined | Defines the Prometheus query to be used to populate the chart/panel. If defined, the `query_range` endpoint of the [Prometheus API](https://prometheus.io/docs/prometheus/latest/querying/api/) will be utilized. |
| `step` | number | no, value is calculated if not defined | Defines query resolution step width in float number of seconds. Metrics on the same panel should use the same `step` value. | | `step` | number | no, value is calculated if not defined | Defines query resolution step width in float number of seconds. Metrics on the same panel should use the same `step` value. |
## Dynamic labels ## Dynamic labels
......
...@@ -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