aboutsummaryrefslogtreecommitdiffstats
path: root/dashboards/panels.py
diff options
context:
space:
mode:
Diffstat (limited to 'dashboards/panels.py')
-rw-r--r--dashboards/panels.py13
1 files changed, 12 insertions, 1 deletions
diff --git a/dashboards/panels.py b/dashboards/panels.py
index faa60f7..919cb3c 100644
--- a/dashboards/panels.py
+++ b/dashboards/panels.py
@@ -237,6 +237,12 @@ def row(title, y, collapsed=False, children=None, repeat=None):
return r
+# Which editor tab Grafana opens the variable on. Only the UI reads this: at query time
+# PrometheusVariableSupport.query() takes the `query` string and hands it straight to
+# PrometheusMetricFindQuery, which re-parses it. Derive it so the two cannot disagree.
+QRY_TYPES = {"label_names(": 0, "label_values(": 1, "metrics(": 2, "query_result(": 3}
+
+
def query_var(name, query, label=None, multi=True, include_all=True, all_value=".*",
current_all=True, hide=0, regex=None):
"""A Prometheus-backed template variable.
@@ -244,13 +250,18 @@ def query_var(name, query, label=None, multi=True, include_all=True, all_value="
`regex` filters and rewrites the returned strings. Named capture groups `value` and
`text` split one string into what queries substitute and what the UI shows -- nest
them (`(?<text>(?<value>\\S+) .*)`) to show a superset of what you select on.
+
+ `label_values(...)` resolves against /api/v1/label/<l>/values over the *dashboard's
+ time range*, so it lists every value seen in that window, not the ones that exist
+ now. `query_result(...)` is an instant query at the range's end instead. Prefer it
+ whenever a stale option would be actively wrong rather than merely extra.
"""
v = {
"name": name,
"label": label or name,
"type": "query",
"datasource": DS,
- "query": {"qryType": 1, "query": query,
+ "query": {"qryType": QRY_TYPES.get(query.split("(")[0] + "(", 4), "query": query,
"refId": "PrometheusVariableQueryEditor-VariableQuery"},
"refresh": 1,
"includeAll": include_all,