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:
@@ -432,19 +432,22 @@ async def _evaluate_rule(
|
||||
return notifications
|
||||
|
||||
|
||||
async def reset_rule_state(session: AsyncSession, rule: AlertRule, note: str) -> None:
|
||||
async def reset_rule_state(session: AsyncSession, rule: AlertRule, note: str,
|
||||
actor_id: str | None = None) -> None:
|
||||
"""Put a rule's alert back to inactive because the rule itself changed
|
||||
(what it watches, its threshold, or it was disabled or re-enabled), and
|
||||
start its silence watch over. An alert that was
|
||||
firing or acknowledged gets a resolved event carrying `note`; nobody is
|
||||
notified, since nothing about the watched resource changed."""
|
||||
firing or acknowledged gets a resolved event carrying `note` and the
|
||||
person who changed the rule (`actor_id`); nobody is notified, since
|
||||
nothing about the watched resource changed."""
|
||||
state = (await session.execute(
|
||||
select(AlertState).where(AlertState.rule_id == rule.id))).scalar_one_or_none()
|
||||
if state is None:
|
||||
return
|
||||
now = datetime.now(timezone.utc)
|
||||
if state.state in (AlertStateEnum.firing, AlertStateEnum.acknowledged):
|
||||
_add_event(session, rule.id, state.state.value, "resolved", None, now, note=note)
|
||||
_add_event(session, rule.id, state.state.value, "resolved", None, now, note=note,
|
||||
actor_id=actor_id)
|
||||
# The watch starts over now: silence is measured from here, against the
|
||||
# cadence of whatever the rule watches from now on.
|
||||
state.last_transition_at = now
|
||||
@@ -466,6 +469,7 @@ def _add_event(
|
||||
value: float | None,
|
||||
now: datetime,
|
||||
note: str | None = None,
|
||||
actor_id: str | None = None,
|
||||
) -> str:
|
||||
"""Add an AlertEvent row and return its ID."""
|
||||
event_id = str(uuid.uuid4())
|
||||
@@ -477,6 +481,7 @@ def _add_event(
|
||||
metric_value=value,
|
||||
transitioned_at=now,
|
||||
note=note,
|
||||
actor_id=actor_id,
|
||||
)
|
||||
session.add(event)
|
||||
return event_id
|
||||
|
||||
Reference in New Issue
Block a user