Skip to content

fix(prometheus): map pending alerts to the pending status - #6897

Open
RishavTiwari25 wants to merge 1 commit into
keephq:mainfrom
RishavTiwari25:fix/prometheus-pending-status
Open

RishavTiwari25 wants to merge 1 commit into
keephq:mainfrom
RishavTiwari25:fix/prometheus-pending-status

Conversation

@RishavTiwari25

Copy link
Copy Markdown

Problem

When Keep pulls alerts from Prometheus (PrometheusProvider._get_alerts, which reads GET /api/v1/alerts), every alert comes back as firing, including the ones Prometheus reports as "state": "pending".

A pending alert is one whose rule matches but has not lasted for the rule's for: duration yet. Prometheus itself does not notify on it. In Keep it shows up as firing right away, so workflows and notifications that trigger on firing alerts can run for a condition that may clear before it ever fires.

Cause: _format_alert maps the state through STATUS_MAP, which only has firing and resolved. Anything else, pending included, falls back to AlertStatus.FIRING.

The Grafana and VictoriaMetrics providers already map "pending" to AlertStatus.PENDING, so Prometheus was the odd one out.

Fix

Add "pending": AlertStatus.PENDING to PrometheusProvider.STATUS_MAP. Alertmanager webhooks only send firing and resolved, so the push path does not change.

Tests

New tests/providers/prometheus_provider/test_prometheus_format_alert.py, which feeds _format_alert the data object from /api/v1/alerts:

  • test_pending_alert_is_not_reported_as_firing fails on main (status is firing) and passes with the fix.
  • test_firing_alert_stays_firing checks that firing alerts are unchanged.

pytest tests/providers/prometheus_provider tests/providers/grafana_provider gives 19 passed. ruff check (0.11.4, the pinned version) and ruff format --check are clean. I also tried tests/deduplication/test_deduplications.py locally on Windows, but it fails the same way with and without this change (it needs the full app environment), so I couldn't use it as a check.

Prometheus' /api/v1/alerts returns alerts that are still inside their
'for:' window with state 'pending'. STATUS_MAP had no entry for it, so
they fell back to FIRING. Grafana and VictoriaMetrics already map
'pending' to AlertStatus.PENDING.
@github-actions

Copy link
Copy Markdown
Contributor

No linked issues found. Please add the corresponding issues in the pull request description.
Use GitHub automation to close the issue when a PR is merged

@CLAassistant

CLAassistant commented Oct 26, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@RishavTiwari25

Copy link
Copy Markdown
Author

The only failing check is the linked-issue one: I could not find an existing issue for this bug. Happy to open one if you prefer, or the no-issue label would skip the check.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants