From 36e6648c5b321ce536268a7c2911fe1efc652a57 Mon Sep 17 00:00:00 2001 From: Srinath Kotu Date: Tue, 2 Apr 2024 10:57:49 -0500 Subject: [PATCH 1/2] Expanding Query Types for creating "Query Result" dashboard variables --- custom/dashboard/variable.libsonnet | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/custom/dashboard/variable.libsonnet b/custom/dashboard/variable.libsonnet index d95565f5..eededd67 100644 --- a/custom/dashboard/variable.libsonnet +++ b/custom/dashboard/variable.libsonnet @@ -255,10 +255,18 @@ local d = import 'github.com/jsonnet-libs/docsonnet/doc-util/main.libsonnet'; d.arg('metric', d.T.string, default=''), ] ), + '#withQueryResult':: d.func.new( + 'Construct a Prometheus template variable using `label_values()`.', + args=[ + d.arg('query', d.T.string), + ] + ), withLabelValues(label, metric=''): if metric == '' then var.withQuery('label_values(%s)' % label) else var.withQuery('label_values(%s, %s)' % [metric, label]), + withQueryResult(query): + var.withQuery('query_result(%s)' % query), }, // Deliberately undocumented, use `refresh` below From 78f0c4a09db989e0d4c9ad730f49564b33c551ec Mon Sep 17 00:00:00 2001 From: srikotu <87999051+srikotu@users.noreply.github.com> Date: Mon, 13 May 2024 16:27:08 -0500 Subject: [PATCH 2/2] Update custom/dashboard/variable.libsonnet Co-authored-by: Jeroen Op 't Eynde --- custom/dashboard/variable.libsonnet | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/custom/dashboard/variable.libsonnet b/custom/dashboard/variable.libsonnet index eededd67..d71cd623 100644 --- a/custom/dashboard/variable.libsonnet +++ b/custom/dashboard/variable.libsonnet @@ -255,18 +255,18 @@ local d = import 'github.com/jsonnet-libs/docsonnet/doc-util/main.libsonnet'; d.arg('metric', d.T.string, default=''), ] ), + withLabelValues(label, metric=''): + if metric == '' + then var.withQuery('label_values(%s)' % label) + else var.withQuery('label_values(%s, %s)' % [metric, label]), '#withQueryResult':: d.func.new( 'Construct a Prometheus template variable using `label_values()`.', args=[ d.arg('query', d.T.string), ] ), - withLabelValues(label, metric=''): - if metric == '' - then var.withQuery('label_values(%s)' % label) - else var.withQuery('label_values(%s, %s)' % [metric, label]), withQueryResult(query): - var.withQuery('query_result(%s)' % query), + var.withQuery('query_result(%s)' % `query),` }, // Deliberately undocumented, use `refresh` below