Beacon incident system

How Beacon turns a failing check into an alert, an incident, chat messages and phone calls. This page is for the review of the state machine refactor. It shows each state machine, the rules that keep the noise low for the on-call engineers, and the results of the failure tests.

Context

Beacon is the incident manager of Frappe Cloud V2. It runs checks on each region every minute. A check is a ClickHouse query or an HTTP or TLS probe. Each row that a check returns is a problem on one resource, such as a host or a proxy.

The engineers work mostly on two screens: the alert and the incident. When the phone rings at 3 am, the engineer must see at once what is broken, where, and how bad it is. Beacon must also not send messages that nobody needs, because people stop reading a noisy channel.

The refactor had three goals:

Beacon is not in production yet. So the refactor has no data patches and no code for old setups.

Size before and after

Code lines count Python, JavaScript, Vue, CSS, HTML and SQL in the app, without built files.

PointCode linesDocTypes
Before the refactor8,92522
After the refactor8,49418
Change−431 (−4.8%)−4

Four DocTypes are gone:

The line count went down less than the DocType count. Most of the lines that were removed went back in as clearer messages and as the checks that stop duplicate messages.

The objects

Each box is a record type. An arrow shows which record makes or owns the next one.

RecordWhat it is
ResourceOne thing that Beacon checks: a host, a VM, a proxy, a region. A Resource Source lists them. A failed fetch never removes a resource.
Alert RuleOne check. A file in the repository of the team that owns the component defines it. The rule title must say what is wrong.
AlertOne problem on one resource, from its start to its end. Beacon writes it only when its state changes.
IncidentThe record that people work on. It holds the alerts of one cause, the updates, the call state and the postmortem. A Maintenance is an incident of another type.
NotificationOne chat post, email or call. Beacon writes it in the same transaction as the change that caused it, and a job sends it after the commit.

One outage, start to end

Example: a host in Mumbai stops answering. Its VMs stop too.

  1. The rule returns a row for host h12. Beacon makes a Pending alert. One bad minute is not an outage, so nobody hears about it yet.
  2. The row is still there after pending_for. The alert goes to Firing.
  3. The coordinator looks for an open incident that covers h12, or a parent of it. There is none, so it makes a new Internal incident in Triggered.
  4. The incident is High. Beacon posts to chat, emails each active responder and calls the first responder.
  5. The VM alerts on h12 fire next. The incident covers h12 and everything under it, so they join it. Beacon posts one chat message with all the alerts that joined. It does not make a new incident or a new call for each VM.
  6. The engineer answers the call. The answer acknowledges the incident. The calls stop.
  7. The host comes back. Every alert recovers. The incident was made by Beacon and is still Internal, so Beacon resolves it. A person must resolve a public incident.

Alert states

An alert has three states. A Resolved alert never fires again. A new problem on the same resource makes a new alert.

Incident states

An incident is open from Triggered to Monitoring. Only an action changes its status. The status field is read-only in Desk.

Maintenance

While a maintenance is In Progress, and for 10 minutes after it ends, Beacon suppresses the alerts in its scope. The 10 minutes let rebooted hosts come back.

Escalation states

The escalation is the call state of one incident. It is separate from the incident status, because a person can update an incident while Beacon still calls.

SeverityChatEmailCallNext responder after
CriticalYesYesYes2 minutes
HighYesYesYes5 minutes
MediumYesNoNo-
LowYesNoNo-
A High or Critical incident calls until a person acknowledges it. There is no limit on rounds. After the last responder, Beacon waits the repeat time (15 minutes) and starts a new round from the first responder. The old setting max_rounds is gone.

Notification states

A Notification is one chat post, email or call. Beacon writes it as Queued in the same transaction as the change that caused it. A job sends it after the commit. So a rolled-back change never sends a message, and no remote call runs while a database lock is held.

Noise rules

Each rule below removes messages that the engineer does not need, and keeps the ones that need an action.

EventWhat Beacon sends
Low or Medium incidentChat only. No email, no call.
Alerts join an open incidentOne chat message for each incident in each coordinator run, with a table of up to 5 alerts. Not one message for each alert.
Alert on a child resourceCalls wait 90 seconds, so the incident of the parent can take the alert first.
Escalation stepA call and, once for each responder in each round, an email. No Activity log entry for each step.
A call or email failsOne chat message for each incident and channel in an hour, with a link to the notification.
A rule query breaksOne chat message when it breaks and one when it works again. Nothing while it stays broken.
All alerts recover on an incident that a person must closeOne chat message, one time.
Empty postmortemOne reminder at 3 days and one at 7 days after the resolve.
A resource list would remove many resourcesOne chat message when Beacon holds the removal for review. Not one each fetch.

How a message reads

Titles are <rule title> on <resource>, or in <region> for a region-level rule. The incident name in chat links to the incident. Chat messages use Markdown tables. Text that people read never uses the word "page". Example chat message for a new incident:

🟠 High incident INC-00031 in Mumbai
Host down on h12
ResourceValueDetail
h12312no report for 312 s (limit 120 s)

The example uses made-up names and numbers.

Failure tests

The tests ran on a development site, with a separate disabled test region, a fake ClickHouse client and a fake message channel. No real chat post, email or call went out.

9 scenarios, 56 checks. All passed. The test deleted every record that it made.

#What went wrongWhat Beacon didResult
1The rule query fails two times, then works.The Firing alert stayed Firing. Beacon wrote one Error Log on the first failure and none on the second. The next good run resolved the alert once.Pass
2Another connection holds the incident row lock for 2 seconds.The action waited 1.8 seconds, then wrote one update. No duplicate row.Pass
3The job for a notification is lost.A row Queued for 2 minutes was queued again. A row Queued for 2 hours became Failed. No other row changed.Pass
4A call is answered after its incident was merged.The answer acknowledged the incident that it was merged into. When that incident was already closed, the call became Answered and acknowledged nothing.Pass
5An alert recovers and fails again inside resolve_after.One alert, one incident and one chat message. The clean timer stopped.Pass
6The region cannot be read.No alert resolved and no incident closed. The coordinator stopped with the error, and the new alert stayed without an incident until the next good run.Pass
7A person resolves an incident while its alert fires.Beacon refused it without a silence. With a 1-hour silence, the incident resolved, the alert stayed Firing and silenced, and the next run made no new incident.Pass
8The same problem comes back after a resolve.A new incident opened, both inside and after 30 minutes. A resolved Public incident stayed Resolved and Public.Pass
9Nobody acknowledges a High incident.After 3 full rounds with 2 responders, the escalation was still Calling: 6 calls and 6 emails, one email for each responder in each round. Acknowledge stopped it.Pass

Limits: the tests call the Beacon classes directly in one process, with a fake ClickHouse client and fake responders. They do not test the real Twilio, email or chat providers, or the timing of the scheduler.

Rule titles

An engineer reads the rule title first. Titles such as "Atlas silent" or "Object storage health" did not say what was wrong. Each producer repository now has a draft pull request with clearer titles, a one-line description and details that name the limit.

Old titleNew title
Atlas silentAtlas stopped reporting
BMC problemsHost BMC reports a fault
Object storage healthObject storage cluster is unhealthy
Central errorsCentral throws unhandled errors
Telemetry volume grewTelemetry volume more than doubled

Example detail before: no host sync for 312 s. After: no host sync for 312 s (limit 120 s). No query logic, threshold, severity or alert key changed. Every changed query parses in ClickHouse.

Merge these after the refactor is deployed. The refactor adds the -- description: header, and an older Beacon stops the sync of a source with an unknown header.

What is left