What does a CI pipeline for Prometheus rules look like?
IntermediateProductionObservability as Code, Security & Vendor Choices
Answer
promtool check rules rules/*.yamlfor syntax (extract thespecfromPrometheusRuleobjects first, or lint withpint).promtool test rules tests/*.yamlwith unit tests that feed synthetic series and assert which alerts fire and with which labels.pint ci(Cloudflare) against a live Prometheus to catch rules referencing metrics that do not exist, missingrunbook_url, or rate over gauges.- Merge, then GitOps (Argo CD / Flux) applies the CRDs.
tests:
- interval: 1m
input_series:
- series: 'job:http_errors:ratio_rate5m{job="api"}'
values: '0.2x15'
alert_rule_test:
- eval_time: 10m
alertname: APIHighErrorRate
exp_alerts: [{ exp_labels: { severity: critical, job: api } }]
More on Observability as Code, Security & Vendor Choices
What does "observability as code" cover, and why insist on it?BeginnerHow do you manage Grafana with Terraform?IntermediateHow do you validate Alertmanager configuration in CI?BeginnerRaw dashboard JSON, Jsonnet/Grafonnet or the Grafana Foundation SDK: which do you pick?AdvancedWhat are monitoring mixins and how do you consume them?AdvancedHow do Grafana dashboards get loaded automatically in `kube-prometheus-stack`?Beginner