feat(alerts): an acknowledgement is on the record, with who made it (#5463)
CI / lint (push) Successful in 3s
CI / integration (push) Successful in 1m7s
CI / unit (push) Successful in 1m27s
CI / publish (push) Successful in 1m8s

#5463 "Acknowledgements on record: an event and who did it", step 1 of
milestone 499 "Alerts you can trust". The live walk in #5461 found that
acknowledging changed only the alert's current state: once it resolved,
nothing said who had acknowledged it or when.

- alert_events.actor_id (migration 0040): the person behind a transition.
- Acknowledging writes a firing → acknowledged event by the acknowledger.
- A rule edit, disable or enable that resets an alert carries its actor
  (web and MCP alike).
- The history page notes "acknowledged by X" and "rule disabled by X"; MCP
  get_alert_history returns `by`.
- One usernames() helper in alerts.service, used by the active list, the
  history page and the MCP tools.
- docs/core/alerting.md: the state diagram no longer shows an acknowledged
  alert re-firing, and says what an event records.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-09 08:19:48 -04:00
co-authored by Claude Opus 5.5
parent b3a5bbfeff
commit 734d313a54
9 changed files with 133 additions and 48 deletions
+14 -1
View File
@@ -16,7 +16,7 @@ RULE = SimpleNamespace(metric_name="cpu_pct", operator=AlertOperator(">"), thres
def _event(**kw):
base = dict(transitioned_at=datetime(2026, 10, 6, tzinfo=timezone.utc), from_state="inactive",
to_state="firing", metric_value=97.5, note=None, email_sent=None, email_error=None,
webhook_sent=None, webhook_error=None, ansible_run_id=None)
webhook_sent=None, webhook_error=None, ansible_run_id=None, actor_id=None)
return SimpleNamespace(**{**base, **kw})
@@ -48,3 +48,16 @@ def test_only_attempted_deliveries_are_listed():
row = _history_row(_event(email_sent=True, webhook_sent=True), RULE)
assert [(label, sent) for label, sent, _ in row["deliveries"]] == [("email", True), ("webhook", True)]
assert _history_row(_event(), RULE)["deliveries"] == []
def test_a_transition_a_person_made_says_who():
"""#5463: an acknowledgement, and a rule change that reset the alert,
name the person; one whose account is gone still reads as a person's."""
names = {"u1": "bob"}
ack = _event(from_state="firing", to_state="acknowledged", metric_value=None, actor_id="u1")
assert _history_row(ack, RULE, names)["notes"] == ["acknowledged by bob"]
off = _event(from_state="firing", to_state="resolved", note="rule disabled", actor_id="u1")
assert _history_row(off, RULE, names)["notes"] == ["rule disabled by bob"]
gone = _event(from_state="firing", to_state="acknowledged", actor_id="u9")
assert _history_row(gone, RULE, names)["notes"] == ["acknowledged by a deleted user"]
assert _history_row(_event(note="rule enabled"), RULE, names)["notes"] == ["rule enabled"]