1. Alerting on symptoms #
What bothers the user, not every possible cause.
Symptoms and causes #
| Alert on a cause | Alert on a symptom |
|---|---|
| CPU at 90% | p99 latency above target |
| A pod restarts | 5xx error rate above 2% |
| Disk at 80% | Disk full in less than 4h (prediction) |
An alert must be actionable: if nobody has anything to do when receiving it, it is a dashboard indicator, not an alert. Every useless alert leads to alert fatigue: teams end up ignoring the real ones too.
- alert: DiskWillFillIn4Hours
expr: predict_linear(node_filesystem_avail_bytes{fstype!="tmpfs"}[6h], 4*3600) < 0
for: 30m
labels: { severity: warning }
annotations:
summary: "Le disque {{ $labels.mountpoint }} de {{ $labels.instance }} sera plein dans 4 h" 2. Labels and annotations #
What routing and humans need.
Conventions #
| Element | Usage | Example |
|---|---|---|
severity | Urgency: critical (wakes people up), warning (business hours), info | critical |
team | Recipient team, used by routing | payments |
summary | One sentence readable on a phone | Payment API: 8% errors |
description | Details, values | {{ $value | humanizePercentage }} |
runbook_url | Diagnosis and resolution procedure | wiki link |
dashboard_url | Context dashboard | Grafana link |
Common mistake: Never put a changing value ({{ $value }}) in labels: each new value would create a new alert. Values go in annotations.3. Testing your rules #
promtool test rules.
Unit tests #
promtool replays simulated series and checks which alerts fire, when and with which labels:
# tests.yml
rule_files: [rules.yml]
evaluation_interval: 1m
tests:
- interval: 1m
input_series:
- series: 'up{job="api", instance="api-1"}'
values: '1 1 0 0 0 0 0 0'
alert_rule_test:
- eval_time: 4m # 2 min de panne : encore pending
alertname: InstanceDown
exp_alerts: []
- eval_time: 8m # 6 min de panne : firing
alertname: InstanceDown
exp_alerts:
- exp_labels: { severity: critical, team: plateforme, job: api, instance: api-1 }
exp_annotations:
summary: "api-1 ne répond plus"
runbook_url: https://wiki.example.org/runbooks/instance-downpromtool check rules rules.yml
promtool test rules tests.ymlGood practice: Add these two commands to the CI of the rules repository: a rule that never fires is as dangerous as a broken rule.
