Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

grafana-builder: add support for native/classic stat panel query #1285

Merged
merged 1 commit into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading