Skip to content

Commit

Permalink
grafana-builder: add support for native/classic stat panel query
Browse files Browse the repository at this point in the history
Seamlessly allow using statPanel with classic/native queries.

Signed-off-by: György Krajcsovits <[email protected]>
  • Loading branch information
krajorama committed Jul 17, 2024
1 parent 2a87a25 commit ff1b5ec
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
12 changes: 10 additions & 2 deletions grafana-builder/grafana.libsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -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):: {
Expand Down
2 changes: 2 additions & 0 deletions mixin-utils/utils.libsonnet
Original file line number Diff line number Diff line change
@@ -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.
Expand Down

0 comments on commit ff1b5ec

Please sign in to comment.