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
- Size before and after
- The objects
- One outage, start to end
- Alert states
- Incident states
- Escalation states
- Notification states
- Noise rules
- Failure tests
- Rule titles
- What is left
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:
- Put each state change in one place. Each record with a lifecycle has one
StateMachinethat lists the allowed moves. Every other move is refused with a clear message. - Make the code smaller and simpler, with fewer DocTypes and the same features.
- Make every chat message, email and call easy to read, and send fewer of them.
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.
| Point | Code lines | DocTypes |
|---|---|---|
| Before the refactor | 8,925 | 22 |
| After the refactor | 8,494 | 18 |
| Change | −431 (−4.8%) | −4 |
Four DocTypes are gone:
- Service. An SLO Burn alert rule is now the service. It holds the public title, the SLO target and the burn alert in one record.
- Service Day. Daily uptime is now calculated from the minute rows when someone reads it.
- Incident Action Item. Action items are now a checklist in the RCA text:
[ ] Title - @assignee - issue link. - Notification Outbox. The Notification record now writes, sends and records each message itself.
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.
| Record | What it is |
|---|---|
| Resource | One 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 Rule | One check. A file in the repository of the team that owns the component defines it. The rule title must say what is wrong. |
| Alert | One problem on one resource, from its start to its end. Beacon writes it only when its state changes. |
| Incident | The 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. |
| Notification | One 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.
- 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.
- The row is still there after
pending_for. The alert goes to Firing. - 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.
- The incident is High. Beacon posts to chat, emails each active responder and calls the first responder.
- 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.
- The engineer answers the call. The answer acknowledges the incident. The calls stop.
- 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.
- A query error or an unreachable region changes no state. A failing check never resolves an alert, because a broken check is not a recovered host.
- A removed resource, or a resource that is no longer checked, resolves its alert as Resource Removed.
- A Firing alert only goes up in severity. It keeps the row that made it worse.
- An alert can be silenced for a known problem. A silenced alert keeps its state and stays visible, but it joins no incident and makes no call.
Incident states
An incident is open from Triggered to Monitoring. Only an action changes its status. The status field is read-only in Desk.
- Auto resolve. When all alerts recover, Beacon resolves an Internal incident that it made. For an incident that a person made, or one that is Unlisted or Public, Beacon posts to chat one time that a person must resolve it.
- Resolve while alerts fire. Beacon refuses it, unless the person silences those alerts for some hours. Then the incident closes and the alerts stay open and silenced.
- Reopen. Only staff can reopen, in the 7 days after the resolve. A reopen makes no calls. Beacon itself never reopens an incident. A new problem after a resolve makes a new incident.
- Public. Beacon never publishes an incident. A person decides what customers see.
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.
| Severity | Chat | Call | Next responder after | |
|---|---|---|---|---|
| Critical | Yes | Yes | Yes | 2 minutes |
| High | Yes | Yes | Yes | 5 minutes |
| Medium | Yes | No | No | - |
| Low | Yes | No | No | - |
max_rounds is gone.- Why wait 90 seconds. When the resource has a parent, such as a VM on a host, the host alert usually comes a little later. The wait lets an incident on the host take the VM alert, so the engineer gets one call for the host and not one for each VM.
- Pause. "Calls and emails paused" in Beacon Settings stops all calls and emails, for example after a database restore. The escalations continue when the pause ends.
- No active responder. The escalation stops and Beacon posts to chat: "Calls stopped. No responder is active. Contact the team directly."
- Answered call. Twilio tells Beacon that the call was answered. The answer acknowledges the incident as the person who was called. If the incident was merged, the answer follows the merge to the open incident.
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.
- Sent once. The job claims the row first (Queued to Sending). A second job for the same row sends nothing.
- Lost job. Each minute, Beacon queues again each row that is Queued for more than 1 minute. A row that is Queued for 1 hour becomes Failed.
- Stopped job. A row that stays in Sending means that the job stopped during the provider call. Beacon does not send it again, because the provider may already have it.
- Stale call. A queued call for an incident that closed, or whose escalation stopped, is Cancelled and never rings.
- Email. Sent means that Frappe accepted the email into its Email Queue. Frappe records a later delivery error on the Email Queue row.
Noise rules
Each rule below removes messages that the engineer does not need, and keeps the ones that need an action.
| Event | What Beacon sends |
|---|---|
| Low or Medium incident | Chat only. No email, no call. |
| Alerts join an open incident | One 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 resource | Calls wait 90 seconds, so the incident of the parent can take the alert first. |
| Escalation step | A call and, once for each responder in each round, an email. No Activity log entry for each step. |
| A call or email fails | One chat message for each incident and channel in an hour, with a link to the notification. |
| A rule query breaks | One 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 close | One chat message, one time. |
| Empty postmortem | One reminder at 3 days and one at 7 days after the resolve. |
| A resource list would remove many resources | One 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 | ||
| Resource | Value | Detail |
|---|---|---|
| h12 | 312 | no 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 wrong | What Beacon did | Result |
|---|---|---|---|
| 1 | The 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 |
| 2 | Another connection holds the incident row lock for 2 seconds. | The action waited 1.8 seconds, then wrote one update. No duplicate row. | Pass |
| 3 | The 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 |
| 4 | A 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 |
| 5 | An alert recovers and fails again inside resolve_after. | One alert, one incident and one chat message. The clean timer stopped. | Pass |
| 6 | The 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 |
| 7 | A 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 |
| 8 | The 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 |
| 9 | Nobody 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 title | New title |
|---|---|
| Atlas silent | Atlas stopped reporting |
| BMC problems | Host BMC reports a fault |
| Object storage health | Object storage cluster is unhealthy |
| Central errors | Central throws unhandled errors |
| Telemetry volume grew | Telemetry 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
- Local services. The service rules on the development site are from the old format. The definition files in the producer repositories must be synced again after the rule pull requests merge.
- Alert Rule form. The service fields on the Alert Rule form need a layout review with a mockup.
- No active responder. The escalation stops when no responder is active. A question for review: should Beacon keep trying, so that calls start when someone is added?
- Smaller code. The code is 4.8% smaller. More cuts need design decisions, for example fewer fields on the incident form.