feat(api): idempotent incident creation via dedup_key#321
Open
juanjogarciatorres43 wants to merge 1 commit into
Open
feat(api): idempotent incident creation via dedup_key#321juanjogarciatorres43 wants to merge 1 commit into
juanjogarciatorres43 wants to merge 1 commit into
Conversation
Add server-side de-duplication for incident creation so automated sources (e.g. the Datadog->IMPACT auto-raise mechanism) can safely retry/redeliver without opening duplicate incidents. - Incident.dedup_key: optional idempotency key (NULL for manual incidents). - Partial unique constraint: at most one OPEN incident (status <= Mitigated) per dedup_key. NULL keys never collide; once an incident reaches Post-mortem/Closed the key is freed, so a later recurrence opens a new one. - API: POST /incidents accepts an optional dedup_key (write-only). On conflict the existing open incident is returned with HTTP 200 (instead of 201), and the Slack channel workflow is NOT re-triggered. Manual creation paths are unaffected (no dedup_key -> NULL -> no constraint).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds server-side de-duplication for incident creation:
POST /api/v2/firefighter/incidentsnow accepts an optionaldedup_key, and at most one open incident can exist per key. Automated sources can safely retry/re-deliver without opening duplicate incidents.This is the IMPACT half of QC-159 (Datadog → IMPACT auto-raise; ADR-0110). It is independently mergeable and fully backward-compatible — manual creation paths (Slack/web) send no
dedup_key(NULL) and are unaffected.Why
The Datadog→IMPACT mechanism re-delivers and the source monitors flap heavily, so without dedup each alert would open a new P3 (and a new Slack channel). Doing dedup at the source of truth (the incident store) is atomic, correct across the incident lifecycle, and reusable by every future adopter — strictly better than a per-receiver dedup store.
How
Incident.dedup_key— optionalCharField(NULL for manual incidents).UNIQUE(dedup_key) WHERE dedup_key IS NOT NULL AND _status <= Mitigated (40).dedup_key; on conflict it returns the existing open incident with HTTP 200 (instead of 201) and does not re-trigger the Slack channel workflow.Tests
Notes for review (Pulse)
0034adds a partial unique index onincidents_incident(small table → normal build is fine; switch toCREATE UNIQUE INDEX CONCURRENTLYif a zero-lock build is preferred)._status <= 40(Mitigated) — a recurrence during Post-mortem opens a new incident (intended).except IntegrityErroris broad but only swallowed when a matching open incident exists; otherwise re-raised.