How do you test alerting rules before they reach production?
IntermediateProductionAlerting Strategy, SLOs & Runbooks
Answer
Unit-test them with promtool:
# tests.yaml
rule_files: [rules.yaml]
evaluation_interval: 1m
tests:
- interval: 1m
input_series:
- series: 'http_requests_total{job="api",code="500"}'
values: '0+10x30'
- series: 'http_requests_total{job="api",code="200"}'
values: '0+100x30'
alert_rule_test:
- eval_time: 20m
alertname: ApiHighErrorRate
exp_alerts:
- exp_labels: { severity: page, job: api }
Run promtool check rules rules.yaml and promtool test rules tests.yaml in CI, plus pint for style checks. Then deploy new rules with severity: ticket for a week before promoting to page.
More on Alerting Strategy, SLOs & Runbooks
What is the single most important rule for deciding whether an alert should page a human?BeginnerWhat severity levels do you define, and where does each one go?BeginnerWhy do mature teams alert on SLO burn rate instead of raw error rate thresholds?IntermediateIn a multi-window burn-rate alert, what is the short window for?AdvancedHow do you generate SLO alert rules without hand-writing dozens of burn-rate expressions?IntermediateHow do you pick an SLO target for a service that has never had one?Beginner