Skip to content

Alert routes: post a firing alarm once until it really clears - #487

Merged
nambok merged 2 commits into
mainfrom
alert-repeat-setting
Nov 6, 2026
Merged

nambok merged 2 commits into
mainfrom
alert-repeat-setting

Conversation

@nambok

@nambok nambok commented Nov 6, 2026

Copy link
Copy Markdown
Collaborator

Summary

An alert route can now post an alarm that keeps firing once, instead of every time it fires (a CloudWatch alarm flapping between ALARM and OK posted on every swing). The setting is per route with per-alarm overrides; "every time" stays the default, so existing routes change nothing. Dashboard: CoderHelm/coderhelm#323 (pinned here).

Changes

  • Setting shape. Route attributes repeat (every_time | until_clear | daily, missing = every_time) and alarm_repeat, a map of exact CloudWatch alarm name to setting (max 200). The override is keyed by alarm name, the same exact-name match rules use (alarm_name), rather than hung on rules: rules exist to open a PR and need a repo, so notify-only routes (where flooding hurts most) would have nowhere to put it. Plain messages use the route's setting; custom notifications and EventBridge events, which never send a recovery, always post every time.
  • Episodes (common::alert_episodes): per team, route and alert fingerprint (the alarm ARN: account, region, name), ALERT_EPISODE#<hash>: open flag, first/last notified time, fire and reminder counts, first alert id. Every change is read, a pure step decision, then a put conditioned on the version read; a lost race re-reads and decides again, so two simultaneous deliveries post once.
  • Quiet window. An OK only starts clearing. CLEAR_QUIET_MIN_SECS = 30 min, or CLEAR_QUIET_PERIODS (2) x the alarm's own span (Trigger.Period x EvaluationPeriods from the SNS payload) when longer, capped at 6 h. 30 min is six 5-minute periods of calm: long enough to call a flapping alarm settled, short enough that the recovery is still news; slow alarms can't swing back sooner than their next evaluation, so they get two of their own spans. An ALARM inside the window is the same episode. After it, the episode ends, the recovery posts once (if post_recoveries), and the next ALARM posts at once (an ALARM arriving after the window but before the check also ends the old episode first).
  • Daily reminder. In daily mode, one reminder card per 24 h while open (the alarm's own card, line: still firing, since when, how many times), triggered by a repeat fire or by a scheduled check for alarms stuck in ALARM; none after a clear.
  • Later checks. New worker message alert_episode_check (contract + DLQ type list updated), chained 15-minute SQS delays on the ticket queue, like the tag sweep. No infra change.
  • Fix action. A held repeat (Plan::Hold) never reaches decide, so no second run; a new episode goes through decide unchanged, keeping the ALERTSEEN 6 h run dedupe. A failed run start drops the new episode so the SNS retry opens it again; a new episode deduped by ALERTSEEN still posts its card with a line saying no new run.
  • History. Every delivery is still recorded in ALERT_EVENT#; episode deliveries carry episode, episode_fires, suppressed. New outcomes suppressed, reminded, clearing (the OK's record becomes recovered/no_open_alert when the window closes). Deliveries count suppressed as ignored.
  • Open-alert helpers (close_open_alert, recovered_line, card_context) moved to common::alert_notify for the worker to share.
  • Docs: self-host integrations page.
  • selfhost/versions.json: dashboard pinned to the merge of AWS connections: trust the install's own account, release-pinned templates, and a live permissions check with a one-click update #323.

Verification

  • cargo fmt --all --check, cargo clippy --workspace --all-targets -- -D warnings: clean.
  • cargo test -p common -p gateway -p worker: all pass. New tests: flapping ALARM/OK/ALARM inside the window posts once; a real clear then a new ALARM posts again (and a duplicate or early check changes nothing); daily reminder once per 24 h while open (fire-driven and scheduled), none after clear or in until-clear mode; redeliveries count once; two concurrent deliveries post once (racing in-memory store); per-alarm override beats the route; routes without the field post every time; held repeats never start a run; failed start lets the retry reopen; request validation; quiet window bounds.
  • Not verified against live AWS: SNS delivery, DynamoDB conditional writes and the SQS delay chain were exercised only through unit tests and an in-memory store.

A route (and any CloudWatch alarm by name) can post every time (default,
and what routes saved before the setting do), once until it clears, or
once with a daily reminder. Each alert's episode is stored per route and
alarm ARN and changed only by version-conditioned writes, so concurrent
deliveries post once. An OK starts a quiet window (30 min, or two of the
alarm's evaluation spans, up to 6 h); an ALARM inside it is the same
episode. The worker checks the window and the daily reminder later through
chained SQS delays. Held repeats start no run and are recorded as
suppressed with their episode.
@nambok
nambok merged commit 23a163e into main Nov 6, 2026
10 checks passed
@nambok
nambok deleted the alert-repeat-setting branch November 6, 2026 14:22
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.

1 participant