Prometheus rate() returns negative during sub-scrape restarts
Writing Prometheus alerting or dashboard queries with rate() or irate() over a counter metric.
Prometheus counters reset to 0 on process restart, and rate() detects this by looking for a drop between consecutive samples and treating it as a reset. But if the restart completes within a single scrape interval (15s default), Prometheus sees the POST-restart value against the PRE-restart value from its last scrape — no drop is ever observed, and rate() produces a momentarily NEGATIVE value. Downstream alerting that assumes rate ≥ 0 flaps. Fix: wrap rate expressions in clamp_min(rate(...), 0).
Any Prometheus alert on rate() should be wrapped in clamp_min(..., 0). Sub-scrape-interval restarts are the scenario — don't assume they're rare in containerized environments.