Skip to content

Commit

Permalink
mixin-utils: Parameterize interval for histogramRules (#806)
Browse files Browse the repository at this point in the history
When ingesting at 1 DPM the recording rules don't produce any data
because x[1m] would capture only a single data point. And a single
data point does not have any rate of increase or decrease, so
rate(x[1m]) produces no data.

Signed-off-by: Dimitar Dimitrov <[email protected]>
  • Loading branch information
dimitarvdimitrov authored Jun 16, 2022
1 parent 9e9d5cd commit 72c850d
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions mixin-utils/utils.libsonnet
Original file line number Diff line number Diff line change
@@ -1,36 +1,37 @@
local g = import 'grafana-builder/grafana.libsonnet';

{
histogramRules(metric, labels)::
histogramRules(metric, labels, interval='1m')::
local vars = {
metric: metric,
labels_underscore: std.join('_', labels),
labels_comma: std.join(', ', labels),
interval: interval,
};
[
{
record: '%(labels_underscore)s:%(metric)s:99quantile' % vars,
expr: 'histogram_quantile(0.99, sum(rate(%(metric)s_bucket[1m])) by (le, %(labels_comma)s))' % vars,
expr: 'histogram_quantile(0.99, sum(rate(%(metric)s_bucket[%(interval)s])) by (le, %(labels_comma)s))' % vars,
},
{
record: '%(labels_underscore)s:%(metric)s:50quantile' % vars,
expr: 'histogram_quantile(0.50, sum(rate(%(metric)s_bucket[1m])) by (le, %(labels_comma)s))' % vars,
expr: 'histogram_quantile(0.50, sum(rate(%(metric)s_bucket[%(interval)s])) by (le, %(labels_comma)s))' % vars,
},
{
record: '%(labels_underscore)s:%(metric)s:avg' % vars,
expr: 'sum(rate(%(metric)s_sum[1m])) by (%(labels_comma)s) / sum(rate(%(metric)s_count[1m])) by (%(labels_comma)s)' % vars,
expr: 'sum(rate(%(metric)s_sum[1m])) by (%(labels_comma)s) / sum(rate(%(metric)s_count[%(interval)s])) by (%(labels_comma)s)' % vars,
},
{
record: '%(labels_underscore)s:%(metric)s_bucket:sum_rate' % vars,
expr: 'sum(rate(%(metric)s_bucket[1m])) by (le, %(labels_comma)s)' % vars,
expr: 'sum(rate(%(metric)s_bucket[%(interval)s])) by (le, %(labels_comma)s)' % vars,
},
{
record: '%(labels_underscore)s:%(metric)s_sum:sum_rate' % vars,
expr: 'sum(rate(%(metric)s_sum[1m])) by (%(labels_comma)s)' % vars,
expr: 'sum(rate(%(metric)s_sum[%(interval)s])) by (%(labels_comma)s)' % vars,
},
{
record: '%(labels_underscore)s:%(metric)s_count:sum_rate' % vars,
expr: 'sum(rate(%(metric)s_count[1m])) by (%(labels_comma)s)' % vars,
expr: 'sum(rate(%(metric)s_count[%(interval)s])) by (%(labels_comma)s)' % vars,
},
],

Expand Down

0 comments on commit 72c850d

Please sign in to comment.