Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
20 changes: 20 additions & 0 deletions mixin-utils/test/test_native-classic-histogram.libsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -238,3 +238,23 @@ test.new(std.thisFile)
}
)
)
+ test.case.new(
name='histogram count increase',
test=test.expect.eq(
actual=utils.ncHistogramCountIncrease('request_duration_seconds', 'cluster="cluster1", job="job1"'),
expected={
classic: 'increase(request_duration_seconds_count{cluster="cluster1", job="job1"}[$__rate_interval])',
native: 'histogram_count(increase(request_duration_seconds{cluster="cluster1", job="job1"}[$__rate_interval]))',
}
)
)
+ test.case.new(
name='histogram count increase with rate interval',
test=test.expect.eq(
actual=utils.ncHistogramCountIncrease('request_duration_seconds', 'cluster="cluster1", job="job1"', rate_interval='5m'),
expected={
classic: 'increase(request_duration_seconds_count{cluster="cluster1", job="job1"}[5m])',
native: 'histogram_count(increase(request_duration_seconds{cluster="cluster1", job="job1"}[5m]))',
}
)
)
23 changes: 23 additions & 0 deletions mixin-utils/utils.libsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,29 @@ local g = import 'grafana-builder/grafana.libsonnet';
},
},

// The ncHistogramCountIncrease (native classic histogram count rate) function is
// used to calculate the histogram increase of count from native histograms or
// classic histograms. Metric name should be provided without _count suffix.
ncHistogramCountIncrease(metric, selector, rate_interval='$__rate_interval')::
local rateOpen = 'increase(';
local rateClose = '[%s])' % rate_interval;
{
classic: '%(rateOpen)s%(metric)s_count{%(selector)s}%(rateClose)s' % {
metric: metric,
rateInterval: rate_interval,
rateOpen: rateOpen,
rateClose: rateClose,
selector: selector,
},
native: 'histogram_count(%(rateOpen)s%(metric)s{%(selector)s}%(rateClose)s)' % {
metric: metric,
rateInterval: rate_interval,
rateOpen: rateOpen,
rateClose: rateClose,
selector: selector,
},
},

// TODO(krajorama) Switch to histogram_avg function for native histograms later.
// ncHistogramAverageRate (native classic histogram average rate) function is
// used to calculate the histogram average rate from native histograms or
Expand Down
Loading