From ff1b5ecec58d6cef3c56626770684f091c9772f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gy=C3=B6rgy=20Krajcsovits?= Date: Wed, 17 Jul 2024 13:22:26 +0200 Subject: [PATCH] grafana-builder: add support for native/classic stat panel query MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Seamlessly allow using statPanel with classic/native queries. Signed-off-by: György Krajcsovits --- grafana-builder/grafana.libsonnet | 12 ++++++++++-- mixin-utils/utils.libsonnet | 2 ++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/grafana-builder/grafana.libsonnet b/grafana-builder/grafana.libsonnet index 435575803..9b4740a7c 100644 --- a/grafana-builder/grafana.libsonnet +++ b/grafana-builder/grafana.libsonnet @@ -332,17 +332,25 @@ local utils = import 'mixin-utils/utils.libsonnet'; }, statPanel(query, format='percentunit'):: { + local isNativeClassic = utils.isNativeClassicQuery(query), type: 'singlestat', thresholds: '70,80', format: format, targets: [ { - expr: query, + expr: if isNativeClassic then utils.showClassicHistogramQuery(query) else query, + format: 'time_series', + instant: true, + refId: if isNativeClassic then 'A_classic' else 'A', + }, + ] + if isNativeClassic then [ + { + expr: utils.showNativeHistogramQuery(query), format: 'time_series', instant: true, refId: 'A', }, - ], + ] else [], }, tablePanel(queries, labelStyles):: { diff --git a/mixin-utils/utils.libsonnet b/mixin-utils/utils.libsonnet index ada9574b1..7190225ad 100644 --- a/mixin-utils/utils.libsonnet +++ b/mixin-utils/utils.libsonnet @@ -1,6 +1,8 @@ local g = import 'grafana-builder/grafana.libsonnet'; { + isNativeClassicQuery(query):: if std.isObject(query) then std.objectHas(query, 'native') && std.objectHas(query, 'classic') else false, + // The ncHistogramQuantile (native classic histogram quantile) function is // used to calculate histogram quantiles from native histograms or classic // histograms. Metric name should be provided without _bucket suffix.