`promtool test rules` fails with `expected: ... got: nil` for an alert test
AdvancedTroubleshootingPromQL and recording rules
Answer
Likely causes → eval_time is earlier than the alert's for duration allows, input series intervals are wrong, or labels in exp_labels miss rule-added labels like severity.
Diagnose → Run the alert expression in the test file as a promql_expr_test to see raw output at eval_time.
Fix → Set eval_time past for (e.g. for: 5m → eval_time: 10m), use series notation like '0+10x20', and list every label including rule labels.
Prevent → Keep a test file per rule file and run it in CI.
More on PromQL and recording rules
A PromQL query in the UI returns `Empty query result` for a metric you can see on `/metrics`Beginner`rate(http_requests_total[1m])` returns nothing but `http_requests_total` has dataBeginner`rate()` applied to a gauge shows huge spikesBeginnerBinary operation fails: `many-to-many matching not allowed: matching labels must be unique on one side`Advanced`found duplicate series for the match group {pod="api-1"} on the right hand-side of the operation`IntermediateError ratio query returns no data during quiet hoursIntermediate