Interview Prep/Monitoring & Observability/Alerting Strategy, SLOs & Runbooks

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.

All Monitoring & Observability questions Roadmap: Monitoring & alerting

More on Alerting Strategy, SLOs & Runbooks