feat(alerts): an acknowledgement is on the record, with who made it (#5463)
#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:
@@ -1,6 +1,7 @@
|
||||
"""Integration: alert state against real Postgres. An acknowledgement holds
|
||||
while the breach lasts, an alert clears after its OK run, and changing what a
|
||||
rule watches (or disabling it) resets its state with a note on the event."""
|
||||
while the breach lasts and is on the record with who made it (#5463), an alert
|
||||
clears after its OK run, and changing what a rule watches (or disabling it)
|
||||
resets its state with a note and the person on the event."""
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
@@ -44,7 +45,7 @@ def test_acknowledge_holds_clear_after_and_reset(app):
|
||||
metric_name="cpu_pct", operator=">", threshold=90,
|
||||
consecutive_failures_required=1, consecutive_ok_required=2)
|
||||
rule = await alert_svc.add_rule(s, fields, created_by=user.id)
|
||||
rule_id = rule.id
|
||||
rule_id, user_id = rule.id, user.id
|
||||
|
||||
async def sample(v):
|
||||
async with app.db_sessionmaker() as s:
|
||||
@@ -62,11 +63,18 @@ def test_acknowledge_holds_clear_after_and_reset(app):
|
||||
.order_by(AlertEvent.transitioned_at))).scalars().all()
|
||||
return [(e.from_state, e.to_state, e.note) for e in rows]
|
||||
|
||||
async def last_actor():
|
||||
async with app.db_sessionmaker() as s:
|
||||
return (await s.execute(select(AlertEvent.actor_id).where(
|
||||
AlertEvent.rule_id == rule_id).order_by(
|
||||
AlertEvent.transitioned_at.desc()).limit(1))).scalar_one()
|
||||
|
||||
await sample(95)
|
||||
assert (await state()).state == AlertStateEnum.firing
|
||||
async with app.db_sessionmaker() as s:
|
||||
async with s.begin():
|
||||
await alert_svc.acknowledge(s, rule_id, None)
|
||||
await alert_svc.acknowledge(s, rule_id, user_id)
|
||||
assert await last_actor() == user_id
|
||||
for _ in range(3):
|
||||
await sample(97) # still breached: the acknowledgement holds
|
||||
assert (await state()).state == AlertStateEnum.acknowledged
|
||||
@@ -75,7 +83,9 @@ def test_acknowledge_holds_clear_after_and_reset(app):
|
||||
await sample(10)
|
||||
st = await state()
|
||||
assert st.state == AlertStateEnum.inactive and st.acknowledged_at is None
|
||||
assert await events() == [("inactive", "firing", None), ("acknowledged", "resolved", None)]
|
||||
assert await events() == [("inactive", "firing", None), ("firing", "acknowledged", None),
|
||||
("acknowledged", "resolved", None)]
|
||||
assert await last_actor() is None # the readings resolved it, not a person
|
||||
|
||||
# Changing the threshold of a firing rule resets it, saying why.
|
||||
await sample(95)
|
||||
@@ -100,9 +110,10 @@ def test_acknowledge_holds_clear_after_and_reset(app):
|
||||
async with app.db_sessionmaker() as s:
|
||||
async with s.begin():
|
||||
r = await s.get(AlertRule, rule_id)
|
||||
await alert_svc.apply_rule_change(s, r, {}, enabled=False)
|
||||
await alert_svc.apply_rule_change(s, r, {}, enabled=False, actor_id=user_id)
|
||||
assert (await state()).state == AlertStateEnum.inactive
|
||||
assert (await events())[-1] == ("firing", "resolved", "rule disabled")
|
||||
assert await last_actor() == user_id
|
||||
|
||||
# Re-enabling starts the watch over: silence is measured from now.
|
||||
async with app.db_sessionmaker() as s:
|
||||
|
||||
Reference in New Issue
Block a user