Skip to content

Commit 5cf8359

Browse files
authored
grafana-builder: add support for native/classic stat panel query (#1285)
Seamlessly allow using statPanel with classic/native queries. Signed-off-by: György Krajcsovits <[email protected]>
1 parent 2a87a25 commit 5cf8359

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

grafana-builder/grafana.libsonnet

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -332,17 +332,25 @@ local utils = import 'mixin-utils/utils.libsonnet';
332332
},
333333

334334
statPanel(query, format='percentunit'):: {
335+
local isNativeClassic = utils.isNativeClassicQuery(query),
335336
type: 'singlestat',
336337
thresholds: '70,80',
337338
format: format,
338339
targets: [
339340
{
340-
expr: query,
341+
expr: if isNativeClassic then utils.showClassicHistogramQuery(query) else query,
342+
format: 'time_series',
343+
instant: true,
344+
refId: if isNativeClassic then 'A_classic' else 'A',
345+
},
346+
] + if isNativeClassic then [
347+
{
348+
expr: utils.showNativeHistogramQuery(query),
341349
format: 'time_series',
342350
instant: true,
343351
refId: 'A',
344352
},
345-
],
353+
] else [],
346354
},
347355

348356
tablePanel(queries, labelStyles):: {

mixin-utils/utils.libsonnet

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
local g = import 'grafana-builder/grafana.libsonnet';
22

33
{
4+
isNativeClassicQuery(query):: if std.isObject(query) then std.objectHas(query, 'native') && std.objectHas(query, 'classic') else false,
5+
46
// The ncHistogramQuantile (native classic histogram quantile) function is
57
// used to calculate histogram quantiles from native histograms or classic
68
// histograms. Metric name should be provided without _bucket suffix.

0 commit comments

Comments
 (0)