1local utils = import '../utils.libsonnet';
2
3{
4  sloLatency(title, description, selector, dimensions, quantile, warning, critical)::
5    local aggregatedLabels = std.split(dimensions, ',');
6    local dimensionsTemplate = std.join(' ', ['{{%s}}' % std.stripChars(label, ' ') for label in aggregatedLabels]);
7
8    $.panel(title, description) +
9    $.queryPanel(
10      'histogram_quantile(%.2f, sum by (%s) (rate(%s[$interval])))' % [quantile, utils.joinLabels(aggregatedLabels + ['le']), selector],
11      dimensionsTemplate + ' P' + quantile * 100
12    ) +
13    {
14      yaxes: $.yaxes('s'),
15      thresholds+: [
16        {
17          value: warning,
18          colorMode: 'warning',
19          op: 'gt',
20          fill: true,
21          line: true,
22          yaxis: 'left',
23        },
24        {
25          value: critical,
26          colorMode: 'critical',
27          op: 'gt',
28          fill: true,
29          line: true,
30          yaxis: 'left',
31        },
32      ],
33    },
34}
35