[ Bug]: Grafana alert that resolves inside a still-firing group stays firing in Keep
Describe the bug
Grafana sends one webhook per alert group. The top-level status stays firing while any alert in the group is firing, and each entry in alerts[] carries its own status.
GrafanaProvider._format_alert (keep/providers/grafana_provider/grafana_provider.py:410-412, main @ fe5c8964) maps every alert from the top-level status:
status = GrafanaProvider.STATUS_MAP.get(event.get("status"), AlertStatus.FIRING)So an alert that resolves while another alert in its group is still firing is stored as firing. Workflows and incidents never see the resolution. Grouped notifications are Grafana's default (grouped by alertname), so this affects most Grafana users. The line dates from #727.
To Reproduce
- Create a Grafana alert rule with two series, or two instances in one notification group.
- Let one instance resolve while the other keeps firing. Grafana sends
status: firingwithalerts: [{status: firing, ...}, {status: resolved, ...}]. - In Keep, the resolved instance is still firing.
Failing tests (red on main, green with the fix), in tests/providers/grafana_provider/test_grafana_v12_webhook.py::TestGroupedNotificationStatus:
test_each_alert_keeps_its_own_status(formatter). On main:{'d5fdbbe0a0a940c1': 'firing'} != 'resolved'.test_resolved_alert_in_firing_group_is_stored_resolved, end to end throughprocess_eventandget_last_alerts(sqlite). On main the stored status isfiring.test_group_status_is_used_when_alert_has_nonecovers the fallback.
Expected behavior
Each alert uses its own status and falls back to the group status only when it has none.
Additional context
A fix with a regression test is ready: alert.get("status") or event.get("status"), on breken-ai/keep fix/grafana-per-alert-status. tests/providers + tests/test_provider_factory.py: 72 passed, and ruff is clean. The PR will follow once the CLA is signed (same account as #6805).
Prepared with AI assistance (Claude) from the breken-ai account.
Source: keephq/keep