Prometheus Rule Unit Testing with promtool Prompt
Generate promtool unit test files (test_rules.yml) that assert alert firing, recording-rule output, and label propagation for Prometheus rule groups in CI.
- Target user
- SREs and platform engineers running Prometheus who gate rule changes through CI
- Difficulty
- Intermediate
- Tools
- Claude, ChatGPT
The prompt
You are a senior observability engineer who writes promtool unit tests so that alert and recording rules are verified in CI before they ever reach production Prometheus. I will provide: - The rule group file (alerting and/or recording rules) - The scrape/evaluation interval the rules run at - The scenarios I want covered (e.g. "fires after 5m of high error rate", "does not fire on a single spike") Your job: 1. **Map each rule** — list every alert and recording rule, its expression, `for:` duration, and the labels/annotations it should emit. 2. **Design input series** — build the `input_series` blocks using the `values` expanded-notation (e.g. `0+10x5`) that recreate each scenario, aligning sample timing to the eval interval. 3. **Write firing assertions** — produce `alert_rule_test` entries with the correct `eval_time` (accounting for the `for:` duration) and `exp_alerts` including labels and annotations. 4. **Write recording assertions** — produce `promql_expr_test` entries asserting the recording rule output value and label set at chosen eval times. 5. **Add negative cases** — include scenarios that must NOT fire (single spikes, recovery) to catch over-sensitive thresholds. 6. **Wire the runner** — give the exact `promtool test rules test_rules.yml` invocation and a minimal CI step. 7. **Self-check** — note any rule whose behavior cannot be tested from the inputs given and what extra series are needed. Output as: a complete ```yaml``` test file ready for `promtool test rules`, followed by the run command and a short list of scenarios covered vs. not covered. If a `for:` duration or eval interval is ambiguous, default to caution: state the assumption inline and choose eval_times that make the firing boundary explicit rather than guessing.
Run this prompt with AI
Test it, get an AI-improved version, or compare models — live in the Prompt Workspace. No copy-paste.
Related prompts
-
Prometheus Meta-Monitoring & Self-SLO Design Prompt
Build the monitoring-of-the-monitoring layer: alerts and SLOs that tell you when Prometheus itself is unhealthy — scrapes lagging, rules failing, WAL growing, or the whole instance dead — so your blind spots do not become silent outages.
-
Prometheus Config Reload Validation with promtool Prompt
Validate Prometheus and rule config changes with promtool check before a hot reload, and design a safe reload pipeline that fails closed on bad config.
-
PromQL absent_over_time Gap Detection Prompt
Design absent()/absent_over_time() expressions that detect missing metrics, scrape gaps, and label-scoped absence without false-firing during restarts or expected idle periods.
-
Prometheus Staleness & Stale Markers Prompt
Understand and debug Prometheus staleness handling — stale markers, the 5-minute lookback, disappearing targets, and how staleness interacts with alert rules and absent().
More Prometheus & Monitoring prompts & error guides
Browse every Prometheus & Monitoring prompt and troubleshooting guide in one place.
Reading prompts? Get all 500 in one free PDF
500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.
- 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
- Instant PDF download — yours free, forever
- Plus one practical AI-workflow email a week (no spam)
Single opt-in · unsubscribe anytime · no spam.