Skip to content

Commit

Permalink
Merge pull request #49 from benclapp/custom-alert-annotations
Browse files Browse the repository at this point in the history
Add optional alertLabels and alertAnnotations
  • Loading branch information
metalmatze committed Jun 11, 2021
2 parents 56f86bf + eaff717 commit ba86443
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 16 deletions.
6 changes: 4 additions & 2 deletions examples/http-request-errors.yaml
@@ -1,5 +1,6 @@
alerts:
- expr: |
- annotations: {}
expr: |
(
sum(rate(promhttp_metric_handler_requests_total{namespace="default",job="fooapp",code=~"5.."}[5m]))
/
Expand All @@ -11,7 +12,8 @@ alerts:
job: fooapp
namespace: default
severity: warning
- expr: |
- annotations: {}
expr: |
(
sum(rate(promhttp_metric_handler_requests_total{namespace="default",job="fooapp",code=~"5.."}[5m]))
/
Expand Down
6 changes: 4 additions & 2 deletions examples/http-request-latency.yaml
@@ -1,12 +1,14 @@
alerts:
- expr: |
- annotations: {}
expr: |
prometheus_http_request_duration_seconds:histogram_quantile > 0.500
for: 5m
labels:
job: fooapp
namespace: default
severity: warning
- expr: |
- annotations: {}
expr: |
prometheus_http_request_duration_seconds:histogram_quantile > 1.000
for: 5m
labels:
Expand Down
6 changes: 4 additions & 2 deletions slo-libsonnet/error-burn.libsonnet
Expand Up @@ -5,6 +5,8 @@ local errors = import 'errors.libsonnet';
local slo = {
alertName: 'ErrorBudgetBurn',
alertMessage: 'High error budget burn for %s (current value: {{ $value }})' % [std.strReplace(std.join(',', self.selectors), '"', '')],
alertLabels: {},
alertAnnotations: {},
metric: error 'must set metric for error burn',
recordingrule: '%s:burnrate%%s' % self.metric, // double %% at the end as we template again further on
selectors: [],
Expand Down Expand Up @@ -65,10 +67,10 @@ local errors = import 'errors.libsonnet';
},
labels: labels {
severity: w.severity,
},
} + slo.alertLabels,
annotations: {
message: slo.alertMessage,
},
} + slo.alertAnnotations,
'for': '%(for)s' % w,
}
for w in slo.windows
Expand Down
6 changes: 4 additions & 2 deletions slo-libsonnet/errorlatency-burn.libsonnet
Expand Up @@ -5,6 +5,8 @@ local util = import '_util.libsonnet';
local slo = {
alertName: 'ErrorBudgetBurn',
alertMessage: 'App is burning too much error budget',
alertLabels: {},
alertAnnotations: {},
metric: error 'must set metric for error burn', // This has to be a histogram metric without _bucket or _count
recordingrule: '%s:burnrate%%s' % self.metric, // double %% at the end as we template again further on
selectors: error 'must set selectors for error burn',
Expand Down Expand Up @@ -71,10 +73,10 @@ local util = import '_util.libsonnet';
],
labels: labels {
severity: w.severity,
},
} + slo.alertLabels,
annotations: {
message: slo.alertMessage,
},
} + slo.alertAnnotations,
'for': '%(for)s' % w,
}
for w in slo.windows
Expand Down
5 changes: 4 additions & 1 deletion slo-libsonnet/errors.libsonnet
Expand Up @@ -4,6 +4,8 @@ local util = import '_util.libsonnet';
errors(param):: {
local slo = {
metric: error 'must set metric for errors',
alertLabels: {},
alertAnnotations: {},
selectors: [],
errorSelectors: ['code=~"5.."'],
rate: '5m',
Expand All @@ -30,7 +32,8 @@ local util = import '_util.libsonnet';
'for': '5m',
labels: labels {
severity: severity.name,
},
} + slo.alertLabels,
annotations: slo.alertAnnotations,
}
for severity in [
{ name: 'warning', percent: slo.warning },
Expand Down
11 changes: 6 additions & 5 deletions slo-libsonnet/latency-burn.libsonnet
Expand Up @@ -10,7 +10,8 @@ local util = import '_util.libsonnet';
// bucket. As recording rules rely on it.
latencyTarget: error 'must set latencyTarget latency burn',
latencyBudget: error 'must set latencyBudget latency burn',
labels: [],
alertLabels: {},
alertAnnotations: {},
codeSelector: 'code',
notErrorSelector: '%s!~"5.."' % slo.codeSelector,
} + param,
Expand Down Expand Up @@ -81,10 +82,10 @@ local util = import '_util.libsonnet';
],
labels: util.selectorsToLabels(rulesSelectors) {
severity: 'critical',
},
} + slo.alertLabels,
annotations: {
message: 'High requests latency budget burn for %s (current value: {{ $value }})' % [std.strReplace(std.join(',', rulesSelectors), '"', '')],
},
} + slo.alertAnnotations,
},
{
alert: slo.alertName,
Expand Down Expand Up @@ -116,10 +117,10 @@ local util = import '_util.libsonnet';
],
labels: util.selectorsToLabels(rulesSelectors) {
severity: 'warning',
},
} + slo.alertLabels,
annotations: {
message: 'High requests latency budget burn for %s (current value: {{ $value }})' % [std.strReplace(std.join(',', rulesSelectors), '"', '')],
},
} + slo.alertAnnotations,
},
],

Expand Down
8 changes: 6 additions & 2 deletions slo-libsonnet/latency.libsonnet
Expand Up @@ -4,6 +4,8 @@ local util = import '_util.libsonnet';
latency(param):: {
local slo = {
metric: error 'must set metric for latency',
alertLabels: {},
alertAnnotations: {},
selectors: error 'must set selectors for latency',
quantile: error 'must set quantile for latency',
labels: [],
Expand Down Expand Up @@ -37,7 +39,8 @@ local util = import '_util.libsonnet';
'for': '5m',
labels: labels {
severity: 'warning',
},
} + slo.alertLabels,
annotations: slo.alertAnnotations,
},

alertCritical: {
Expand All @@ -47,7 +50,8 @@ local util = import '_util.libsonnet';
'for': '5m',
labels: labels {
severity: 'critical',
},
} + slo.alertLabels,
annotations: slo.alertAnnotations,
},

grafana: {
Expand Down

0 comments on commit ba86443

Please sign in to comment.