Skip to content

fix: deduplicate repeated Alertmanager and Grafana notifications (#124) - #147

Merged
OkiriGabriel merged 1 commit into
mainfrom
fix/alert-dedupe-124
Oct 29, 2026
Merged

OkiriGabriel merged 1 commit into
mainfrom
fix/alert-dedupe-124

Conversation

@OkiriGabriel

Copy link
Copy Markdown
Collaborator

Description

Fixes #124.

Alertmanager and Grafana re-send a still-firing alert every group_interval / repeat_interval (4h by default), after restarts, and once per HA replica. Every delivery became a new incident: a fresh diagnosis (LLM cost), another Slack approval, possibly another PagerDuty page, and with AUTO_APPLY=true, the fix applied again (another rollback or restart).

New services/alert_dedupe.py:

{"status": "duplicate", "incident_ids": [], "duplicate_of": ["INC-20261029100000-a1b2c3"]}

Response shape is backwards compatible: first deliveries still return {"status": "queued", "incident_ids": [...]}.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • Documentation update

Testing

  • New tests/test_alert_dedupe.py (21 tests):
    • both endpoints: repeat is duplicate and enqueued once under the claimed ID; new startsAt gives a new incident; mixed batch reports new and duplicate; orgs deduplicated separately; window 0 disables; resolved alerts ignored
    • identity: fingerprint wins over labels; label order irrelevant without a fingerprint; startsAt is part of identity
    • claim: only the first wins; expired marker allows a new incident and becomes the new marker; custom window; invalid window falls back to the default; markers stay outside queue/
    • retention removes old markers and keeps recent ones
  • New tests/conftest.py: each test gets fresh dedupe storage (several existing tests post the same alert payload).
  • Full suite: 964 passed, 4 skipped. Flake8 critical: 0. Bandit -ll clean. mkdocs build --strict plus link check: 0 errors.

Docs

.env.example (ALERT_DEDUPE_WINDOW_SEC), docs/API_REFERENCE.md (repeat-notification behaviour and response), docs/GRAFANA_PROMETHEUS.md (troubleshooting row).

🤖 Generated with Claude Code

Both re-send a still-firing alert every group_interval/repeat_interval,
after restarts and from each HA replica, and every delivery became a new
incident that re-ran diagnosis and could re-apply the fix (#124).

Before enqueueing, each firing alert atomically claims a marker keyed on
org + fingerprint (or sorted labels) + startsAt (put_json_if_absent), and
the incident is then queued under the claimed id, so concurrent
deliveries cannot both get through. Repeats within
ALERT_DEDUPE_WINDOW_SEC (default 3600, 0 disables) are returned as
duplicate_of the original incident, with status "duplicate" when nothing
new was queued. A new startsAt is a new incident. Markers live under
alert_dedupe/, off the queue poll path, and are expired by retention.

Fixes #124

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@OkiriGabriel
OkiriGabriel merged commit 138f144 into main Oct 29, 2026
12 checks passed
@OkiriGabriel
OkiriGabriel deleted the fix/alert-dedupe-124 branch November 26, 2026 10:13
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.

[BUG] Repeated Alertmanager/Grafana notifications create duplicate incidents and can re-apply fixes

1 participant