From 2e3649cb6594192b5fd2f2654f084d9ca269566e Mon Sep 17 00:00:00 2001 From: Srinath Kotu Date: Tue, 2 Apr 2024 10:57:49 -0500 Subject: [PATCH 1/3] 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 91ca33f3..a0d40d0a 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 736173d404065e0784c3a3e5fb6a504db48fdd51 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/3] 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 a0d40d0a..2e1895ee 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 From 13e82ef995a141c0666d30ce6df6bfc5fa10899f Mon Sep 17 00:00:00 2001 From: Duologic Date: Tue, 28 May 2024 15:46:58 +0200 Subject: [PATCH 3/3] fix: generate docs --- custom/dashboard/variable.libsonnet | 5 +++-- docs/API/dashboard/variable.md | 12 ++++++++++++ .../custom/dashboard/variable.libsonnet | 9 +++++++++ gen/grafonnet-v11.0.0/docs/dashboard/variable.md | 12 ++++++++++++ 4 files changed, 36 insertions(+), 2 deletions(-) diff --git a/custom/dashboard/variable.libsonnet b/custom/dashboard/variable.libsonnet index 2e1895ee..b4ce4d38 100644 --- a/custom/dashboard/variable.libsonnet +++ b/custom/dashboard/variable.libsonnet @@ -259,14 +259,15 @@ local d = import 'github.com/jsonnet-libs/docsonnet/doc-util/main.libsonnet'; 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()`.', + 'Construct a Prometheus template variable using `query_result()`.', args=[ d.arg('query', d.T.string), ] ), withQueryResult(query): - var.withQuery('query_result(%s)' % `query),` + var.withQuery('query_result(%s)' % query), }, // Deliberately undocumented, use `refresh` below diff --git a/docs/API/dashboard/variable.md b/docs/API/dashboard/variable.md index d12cdd9c..e5114eaf 100644 --- a/docs/API/dashboard/variable.md +++ b/docs/API/dashboard/variable.md @@ -120,6 +120,7 @@ g.dashboard.new('my dashboard') * [`fn withValueOnly()`](#fn-querygeneraloptionsshowondashboardwithvalueonly) * [`obj queryTypes`](#obj-queryquerytypes) * [`fn withLabelValues(label, metric="")`](#fn-queryquerytypeswithlabelvalues) + * [`fn withQueryResult(query)`](#fn-queryquerytypeswithqueryresult) * [`obj refresh`](#obj-queryrefresh) * [`fn onLoad()`](#fn-queryrefreshonload) * [`fn onTime()`](#fn-queryrefreshontime) @@ -898,6 +899,17 @@ PARAMETERS: - default value: `""` Construct a Prometheus template variable using `label_values()`. +##### fn query.queryTypes.withQueryResult + +```jsonnet +query.queryTypes.withQueryResult(query) +``` + +PARAMETERS: + +* **query** (`string`) + +Construct a Prometheus template variable using `query_result()`. #### obj query.refresh diff --git a/gen/grafonnet-v11.0.0/custom/dashboard/variable.libsonnet b/gen/grafonnet-v11.0.0/custom/dashboard/variable.libsonnet index 91ca33f3..b4ce4d38 100644 --- a/gen/grafonnet-v11.0.0/custom/dashboard/variable.libsonnet +++ b/gen/grafonnet-v11.0.0/custom/dashboard/variable.libsonnet @@ -259,6 +259,15 @@ local d = import 'github.com/jsonnet-libs/docsonnet/doc-util/main.libsonnet'; 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 `query_result()`.', + args=[ + d.arg('query', d.T.string), + ] + ), + withQueryResult(query): + var.withQuery('query_result(%s)' % query), }, // Deliberately undocumented, use `refresh` below diff --git a/gen/grafonnet-v11.0.0/docs/dashboard/variable.md b/gen/grafonnet-v11.0.0/docs/dashboard/variable.md index d12cdd9c..e5114eaf 100644 --- a/gen/grafonnet-v11.0.0/docs/dashboard/variable.md +++ b/gen/grafonnet-v11.0.0/docs/dashboard/variable.md @@ -120,6 +120,7 @@ g.dashboard.new('my dashboard') * [`fn withValueOnly()`](#fn-querygeneraloptionsshowondashboardwithvalueonly) * [`obj queryTypes`](#obj-queryquerytypes) * [`fn withLabelValues(label, metric="")`](#fn-queryquerytypeswithlabelvalues) + * [`fn withQueryResult(query)`](#fn-queryquerytypeswithqueryresult) * [`obj refresh`](#obj-queryrefresh) * [`fn onLoad()`](#fn-queryrefreshonload) * [`fn onTime()`](#fn-queryrefreshontime) @@ -898,6 +899,17 @@ PARAMETERS: - default value: `""` Construct a Prometheus template variable using `label_values()`. +##### fn query.queryTypes.withQueryResult + +```jsonnet +query.queryTypes.withQueryResult(query) +``` + +PARAMETERS: + +* **query** (`string`) + +Construct a Prometheus template variable using `query_result()`. #### obj query.refresh