docs: fleet alerts README and roll notes
README: the box's own sinks carry disk and engine_silent only; Slack URLs in CARLOS_ALERT_WEBHOOK; CARLOS_ALERT_DISK_ETA_HOURS (Theil-Sen trend, 2 h hold); CARLOS_ALERT_ENGINE_BEAT (refused for root); a Fleet alerts section for /fleet/alerts, the rules, connector kinds and how each is confirmed, limits, the token doors, the webhook body and signature, at-least-once delivery, and the seal key file with replica-only restores. Roll notes: dev first, the engine-beat host.env step after the console rolls, the quick Slack check, and the live witness on dennis-stenciling as a scoped proposal for Paul's go. Nothing in them has been run.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
README.md+194 −5docs/superpowers/notes/roll-fleet-alerts-1.md+252 −0
Intent
<task-notification> <task-id>a634b77cb82f351e3</task-id> <tool-use-id>toolu_01DaSPeAc4h6aPsA5BRHbLTX</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/6112a34e-476e-4b5e-8e07-f93a46fc6d50/tasks/a634b77cb82f351e3.output</output-file> <status>completed</status> <summary>Agent "Implement Task 10: /fleet/alerts pages" finished</summary> <note>A task-notification fires each time this agent stops with no live background children of its own. The user can send it another message and resume it, so the same task-id may notify more than once.</note> <result>- **Status:** DONE. All five R-35 fixes are in; covering tests and `go vet` pass. - **Commit:** `0d1c147f` console: alerts fix round 1 (door bodies capped, unsubscribed status, paused confirm, kept threshold, honest history note) - **What changed:** 1. The three public door POSTs now read at most 4 KiB of URL-encoded form before touching the token. A larger body gets 413, a multipart one 415, and nothing acts. 2. A connector turned off from its unsubscribe link shows "The recipient turned these alerts off on X. Send a test to turn them back on." A test that gets through turns it back on and clears that marker. 3. Confirming a connector that is turned off now says "Confirmed. Alerts to X are paused. An operator can turn them back on." 4. Saving a rule without a threshold keeps the stored one. 5. History reads 201 rows and shows 200, so the older-incidents note appears only when one is hidden. The two new strings are in the deck as "derived (R-35)". - **Tests:** - Five new tests, one per fix. Each fails when its fix is reverted and passes with it in place. - The covering run passes: the alert, door, operator, rail, perf, shots and route-census tests. - The record-write census passes (`NewServer` is unchanged), and all the alert claim probes still pass with the body cap. - **Concerns:** none new. - **Report:** fix report appended to `/home/paulca/amadan.net/carlos/platform/.claude/worktrees/design-fleet-alerts/.superpowers/sdd/2026-10-30-fleet-alerts-1-engine-connectors/task-10-report.md`</result> <usage><subagent_tokens>426825</subagent_tokens><tool_uses>11</tool_uses><duration_ms>499412</duration_ms></usage> </task-notification>
<task-notification> <task-id>ac216e6213f4ae3aa</task-id> <tool-use-id>toolu_01B3azKZT84vhiawMxScEvDx</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/6112a34e-476e-4b5e-8e07-f93a46fc6d50/tasks/ac216e6213f4ae3aa.output</output-file> <status>completed</status> <summary>Agent "Re-review Task 10 fix round 1" finished</summary> <note>A task-notification fires each time this agent stops with no live background children of its own. The user can send it another message and resume it, so the same task-id may notify more than once.</note> <result>**Finding Verdicts** 1. **Door POST body cap (4 KiB, `ParseForm`, never multipart, before the token is read)** — ADDRESSED. - `alertDoorForm` (alertpages.go:328-344) sets `MaxBytesReader` at 4<<10. It refuses a `multipart/` Content-Type with 415 before reading anything. It then calls `r.ParseForm()`, giving 413 for `*http.MaxBytesError` and 400 for any other error. - It is the first statement in `handleAlertConfirm` (:855), `handleAlertUnsubscribe` (:914) and `handleAlertSnooze` (:952). All three run before `ConfirmAlertConnectorByToken`, `UnsubscribeAlertConnector` and `UseAlertToken`. - Snooze reads `r.Form.Get("for")`, not `FormValue`, so a multipart body is never parsed. - `TestAlertDoorRefusesLargeOrMultipartBody` covers an 8 KiB snooze (413), an 8 KiB confirm (413) and a multipart snooze (415). It asserts nothing was snoozed and nothing confirmed, and that a short form still returns 200. - The unsubscribe door has no refusal test, but it uses the same helper in the same position. 2. **Unsubscribed status text, test lifts suspension and clears the marker, deck row "derived (R-35)"** — ADDRESSED. - `alertsView` loads `AlertUnsubscribes()` (alertpages.go:359). `alertConnectorRow` shows `conn.status.unsubscribed` for `Suspended && marker present` (:399), after the `NeedsReentry` case. - The copy matches the finding exactly (:47). Deck row is added with "derived (R-35)". - `ResumeAlertConnector` (alertstore.go:700-713) now runs the unsuspend and the marker delete in one transaction. - Its only caller is the successful-test path (alertnotify.go:917). - `TestFleetAlertsUnsubscribedStatus` checks the text, the absence of "Suspended since", the lifted suspension, the marker row count of 0, and that the text is gone afterwards. - The marker's time format is RFC3339 (written at alertstore.go:1218) and is parsed the same way. 3. **Confirm on a still-suspended connector** — ADDRESSED. - `handleAlertConfirm` picks `door.confirm.paused` when `c.Suspended` (alertpages.go:386-390). The `c` it uses comes from the confirm transaction's fresh read (alertstore.go:1180). - The wording matches the finding, and the deck row is "derived (R-35)". - `TestAlertDoorConfirmWhilePaused` asserts the paused text, the absence of "Alerts now go to", and a connector left confirmed and still suspended. 4. **Absent or empty threshold keeps the stored value** — ADDRESSED. - The handler reads `AlertRuleSettings` first (alertpages.go:663-668). For rules with bounds it preloads `st.Threshold = settings[rule].Threshold` (:683), and only a non-blank, valid value replaces it (:686-695). Box rules have no bounds entry, so they still store none. - `TestFleetAlertsRuleSaveKeepsThreshold` covers a missing field and a blank field. The blank case also checks that `Enabled` goes false while 30 is kept. 5. **History fetches 201, shows 200** — ADDRESSED. - `RecentAlertIncidents(..., alertHistoryLimit+1)`, `Full: len(ins) > alertHistoryLimit`, then `ins[:min(len(ins), alertHistoryLimit)]` (alertpages.go:714-718). - `TestFleetAlertsHistoryLimitOnlyWhenHidden` shows no note at exactly 200. At 201 it shows the note, 200 rows, and the oldest row hidden. **Extra checks you asked for** - **Legitimate door POSTs.** The door form is `<form method="post" action="{{.Action}}">`, and the snooze buttons send `name="for" value="1h"` (alert_door.html:16-17). A browser sends `application/x-www-form-urlencoded` with a body of about 7 bytes, far under 4 KiB. The token is in the path, so it is unaffected. - A plain snooze after the refusals returns 200 in the test. - A `for` supplied in the query string still works, because `r.Form` merges the query. A POST with no recognised Content-Type skips body parsing and succeeds as before. - **Cap before any token is read or spent.** Confirmed by the call order above. `registerRoute` wraps only `withReqMemoOnViews` and `withFrameClear`, and the alerts routes have no global middleware that parses the form first. The only `FormValue` calls in alertpages.go are on operator routes, using `PostFormValue` at :501, :662 and :686. - **Reported results.** The report names the covering tests and shows the RED-by-mutation output and the GREEN runs. Its `go test` lines are `ok`. I did not re-run them. ### New Breakage in the Fix Diff None. Minor note, not a defect: if an already-suspended (failure) connector is then unsubscribed, it shows the unsubscribed text, because the marker is set. That is the wording R-35 asks for. ### Out-of-Scope Observations None. ### Verdict **Fix round:** All findings addressed, no new Critical/Important breakage.</result> <usage><subagent_tokens>71076</subagent_tokens><tool_uses>12</tool_uses><duration_ms>64339</duration_ms></usage> </task-notification>
diff --git a/README.md b/README.md| index 46047c144..54149d8b3 100644 |
| --- a/README.md |
| +++ b/README.md |
| @@ -916,13 +916,29 @@ for the full design. |
| samples, one object per UTC hour, retained 48 hours. |
| - `metrics/boxes/<box>/days/<YYYY-MM-DD>.json` — hourly min/avg/max rollups, |
| kept forever (the capacity/trend history). |
| -- `alerts/boxes/<box>.json` — on-box alert state (fire/clear, hysteresis). |
| +- `alerts/boxes/<box>.json` — on-box alert state (fire/clear, hysteresis), |
| + written only when a rule changes. The console's alert engine reads it |
| + every minute (see [Fleet alerts](#fleet-alerts)). |
| + |
| +**Which rules a box sends itself.** The box's own sinks (the webhook and the |
| +SNS topic below) carry only the incident-level rules the console cannot see |
| +for itself: `disk` (the disk is full now) and `engine_silent` (the console's |
| +alert engine has stopped). Every other rule, the disk forecast, memory, |
| +CPU, mail relay lag and the location database among them, still goes into |
| +`alerts/boxes/<box>.json` with every fire and clear, and reaches people |
| +through the console's alert engine, grouped and with its noise rules. So the |
| +box's sinks are the backstop for when the console is down, not the main |
| +channel. |
| **Config surface** — read by the box agent from `/etc/carlos/host.env`: |
| -- `CARLOS_ALERT_WEBHOOK` — optional; the agent POSTs the alert JSON here on |
| - fire and on clear. Unset simply skips the webhook channel (keymail |
| - delivery and the console UI channel are unaffected). |
| +- `CARLOS_ALERT_WEBHOOK`: optional. The agent POSTs here when `disk` or |
| + `engine_silent` fires or clears. A Slack incoming-webhook URL (https on |
| + `hooks.slack.com`) gets Slack's own `{"text": ...}` body, carrying the |
| + same words as the email, because Slack refuses any other body. So |
| + pointing a box at a Slack channel is this one line. Any other URL gets the |
| + alert event as JSON. Redirects are not followed. Unset skips the webhook |
| + channel. |
| - `CARLOS_ALERT_SNS_TOPIC_ARN` — optional; the agent publishes each fire and |
| clear to this SNS topic as a plain-text email-sized message, signed with |
| the box's instance role (which needs `sns:Publish` on the topic). The |
| @@ -939,17 +955,45 @@ for the full design. |
| - With neither sink set, the box says so: the agent logs `NO SINK |
| CONFIGURED` at start, and the box's private status snapshot carries |
| `metrics.alerts` with both sinks false, which `carlos status --live` prints |
| - as `alerts=not-delivered`. |
| + as `alerts=not-delivered`. The console's alert engine raises the |
| + `alert_delivery_broken` warning for such a box. |
| - `CARLOS_ALERT_DISK_PCT` / `CARLOS_ALERT_MEM_PCT` / `CARLOS_ALERT_CPU_PCT` — |
| optional threshold overrides for the built-in disk / memory / host-CPU |
| rules, as percent integers 0-100 (e.g. `95`). Anything else is ignored |
| with a log line, and that rule keeps its built-in default. |
| +- `CARLOS_ALERT_DISK_ETA_HOURS`: optional, the disk forecast's threshold in |
| + hours (default 72). The agent keeps one disk reading a minute for 6 hours |
| + and takes the trend as the median of the slopes between every pair of |
| + readings, so a single burst of writes does not read as a trend. The |
| + `disk_eta` rule fires when the disk is on course to fill within this many |
| + hours and has stayed so for 2 hours. It clears when the course passes 1.5 |
| + times the threshold, or when the disk stops growing, so deleting files |
| + clears it. The forecast needs 2 hours of readings, so it says nothing for |
| + 2 hours after the agent starts. Any positive number of hours is accepted; |
| + anything else keeps 72. While the disk is growing, the box's heartbeat |
| + carries the forecast as `disk_full_eta_hours`. The variable is read when |
| + the agent starts. |
| +- `CARLOS_ALERT_ENGINE_BEAT`: set it only on the box that runs the console, |
| + to the beat file the console's alert engine rewrites after every pass: |
| + `alert-engine.beat` beside console.db, so `/data/console/alert-engine.beat` |
| + by default. When that file is more than 10 minutes old, or has not |
| + appeared within 10 minutes of the agent starting, the agent fires |
| + `engine_silent` through its own sinks. That is the one alert that still |
| + reaches someone when the console has stopped. The agent checks the file |
| + with lstat and never follows a symlink; a symlink, a directory or a time |
| + in the future counts as no beat. An agent running as root does not check |
| + it at all, because the file is the console's to write, and `carlos status |
| + --live` says `engine-beat=off (agent runs as root, so the backstop is |
| + off)`. A watching agent shows `engine-beat=on`. A relative path is refused |
| + the same way. Unset (every box but the console's) shows nothing. |
| **Console surfaces:** |
| - `GET /fleet/metrics` — operator-only dashboard: per-box needles and |
| 48-hour sparklines, a per-box per-unit table (ordered by CPU, busiest |
| first), and active alerts at the top. |
| +- `GET /fleet/alerts` and `/fleet/alerts/history`: operator-only, where |
| + fleet alerts go and what has fired (see [Fleet alerts](#fleet-alerts)). |
| - A "Resources" section on each app's own page — owner-facing, scoped to |
| that app's own instances only (current CPU and memory plus 48-hour |
| sparklines); never host-level totals or other tenants' units. |
| @@ -957,6 +1001,151 @@ for the full design. |
| The `days/` rollups are written from the first flush onward but nothing |
| renders them yet — they are the history a later trend view will read. |
| +## Fleet alerts |
| + |
| +The console runs an alert engine. Once a minute it reads every box's alert |
| +state and heartbeat, groups what is firing into incidents, and sends each |
| +incident to the connectors operators have set up on `/fleet/alerts`. It |
| +replaced the old alert watcher, which mailed every box alert to every |
| +operator one by one. The design is |
| +`docs/superpowers/specs/2026-10-30-fleet-alerts-and-traffic-design.md`. |
| + |
| +**One console runs it.** The engine runs on a console started without host |
| +claims, which is every console today: like every console worker, it assumes |
| +one console per deployment. A host-claim console does not start it and logs |
| +why. The operator dashboard lists the engine as the "Alert checks" job. Two |
| +problems show as a note on that job rather than a failure: a connector key |
| +that cannot be read (see below), and an operator no usable connector |
| +reaches. |
| + |
| +**Rules.** Each rule is one thing to watch across the fleet: |
| + |
| +| Rule | Evaluated on | Level | Default | |
| +|---|---|---|---| |
| +| `disk_eta`, disk full forecast | box | warning | full within 72 hours, held 2 hours (`CARLOS_ALERT_DISK_ETA_HOURS`) | |
| +| `disk`, disk full now | box | incident | 90 percent (`CARLOS_ALERT_DISK_PCT`) | |
| +| `mem`, `cpu` | box | warning | 90 and 95 percent (`CARLOS_ALERT_MEM_PCT`, `CARLOS_ALERT_CPU_PCT`) | |
| +| `lag`, mail relay lag | box | warning | 900 seconds, fixed | |
| +| `geoip`, location database | box | warning | fixed | |
| +| `engine_silent` | the console box's agent | incident | no beat for 10 minutes, fixed (`CARLOS_ALERT_ENGINE_BEAT`) | |
| +| `box_silent` | console | incident | no heartbeat for 15 minutes, editable from 5 to 1440 | |
| +| `service_down` | console | incident | a platform service the fleet summary reports down | |
| +| `cert_expiring` | console | warning | a served host's certificate expires within 14 days, editable from 1 to 60 | |
| +| `alert_delivery_broken` | console | warning | a box with no sink of its own (`alerts=not-delivered`) | |
| +| `seal_key` | console | incident | the connector key cannot be used, or a connector needs its URL again | |
| + |
| +Box rules keep their thresholds in each box's `host.env`; the page shows |
| +them read-only with the variable's name. Each rule is on or off. A rule |
| +that is off still records incidents in History but sends nothing. Each rule |
| +sends to every confirmed connector unless the operator ticks a subset, and |
| +the page shows how often it fired in the last 30 days and how often it |
| +cleared within 10 minutes, so a noisy rule is easy to spot. |
| + |
| +Something that stops being reported at all, such as a box silent for over a |
| +day or a service gone from the fleet summary, leaves its open incidents. An |
| +incident left with nothing in it closes as "no further reports" rather than |
| +"cleared". |
| + |
| +**Connectors** are where alerts go. Each kind is proved before it gets |
| +anything but its confirmation: |
| + |
| +- **Slack**: an incoming-webhook URL on `https://hooks.slack.com/`. The |
| + console posts a test message carrying a confirm link. Opening the link |
| + and pressing Confirm turns the connector on, which proves someone in the |
| + channel saw it. |
| +- **Email**: an address. The console sends a confirm link, valid for 7 |
| + days, and nothing else goes to the address until it is used. Email goes |
| + through Keymail first and SES after, like the console's other mail. |
| +- **Webhook**: an https URL on port 443. The console sends a signed test |
| + when it is added, and the connector is on once a test gets a 2xx answer. |
| + |
| +Every email and Slack alert carries an unsubscribe link that turns that |
| +connector off, and nothing else. |
| + |
| +Confirmation messages are limited to 5 an hour and 20 a day, and test sends |
| +to 10 an hour for each connector. Each operator also gets an email connector |
| +for their sign-in address, already confirmed, the first time the engine sees |
| +them as an operator. That happens once: an operator who deletes theirs keeps |
| +it deleted. Revoking an operator removes theirs and stops anything queued |
| +for it, and granting the role again seeds a new one. |
| + |
| +Slack and webhook URLs are secrets. The console seals them at rest and |
| +never shows them again: the page shows the host and the last four |
| +characters. Every send checks the URL again: https on port 443, Slack only |
| +on `hooks.slack.com`, and the address actually dialled may not be loopback, |
| +private, link-local, CGNAT (Tailscale's `100.64.0.0/10` among them) or a |
| +cloud metadata address. No proxy is used, redirects are not followed, at |
| +most 1 KiB of the answer is read, and a send gives up after 5 seconds. A |
| +failed send is recorded as a category (timeout, refused, TLS, status 500 |
| +and so on), never with its URL. |
| + |
| +A connector that fails is retried after 1 minute, then at doubling |
| +intervals up to 12 hours. One that has failed for 24 hours is suspended and |
| +the operators are told once. A test that gets through turns a suspended or |
| +unsubscribed connector back on. |
| + |
| +**Messages.** Every message says what is wrong, how long there is, and what |
| +to do, and links to the incident and to a snooze page (1 hour, 1 day or 1 |
| +week, for that rule on that box, service or host). The noise rules: |
| + |
| +- The first message waits until the incident is 5 minutes old and lists |
| + everything affected so far, so one rule firing on several boxes is one |
| + message. An |
| + incident that fires and clears inside those 5 minutes sends nothing. |
| +- A box (or service, or host) joining an open incident sends nothing until |
| + the incident is 30 |
| + minutes old, then at most one "now also" message an hour. |
| +- Nothing repeats while a condition holds, except one reminder a day for an |
| + incident open over 24 hours. A clear sends one message. |
| +- A rule that fires 3 times in an hour on one box becomes one open incident |
| + marked as flapping, until an hour passes with no firing. |
| + |
| +The links in messages go to `/alerts/confirm/<token>`, |
| +`/alerts/unsubscribe/<token>` and `/alerts/snooze/<token>`. The token is the |
| +only credential: 32 random bytes, stored hashed, good for one action on one |
| +connector or incident. Opening a link only shows a page with a button, and |
| +only pressing it acts, so a mail scanner that opens every link changes |
| +nothing. Snooze links last 30 days. |
| + |
| +**Webhook body.** JSON with `"v":1`: `delivery_id`, `scope`, `rule`, |
| +`level`, `kind` (fire, clear, update, reminder or verify), `subject`, |
| +`members`, `what`, `how_long`, `what_to_do`, `at`, `incident_url` and |
| +`snooze_url`. Each request carries `Carlos-Signature: t=<unix |
| +seconds>,ed25519=<base64>`, an Ed25519 signature over `carlos-alert`, a |
| +newline, `t`, a newline and the body. The label means a mail event can never |
| +pass as an alert. The public key is on `/fleet/alerts` and served as bare |
| +base64 text at `GET /alerts/signing-key`, so receivers outside CARLOS can |
| +check it. |
| + |
| +**Delivery is at least once.** Each incident change and the messages it |
| +queues are committed in one SQLite transaction, so a console that dies |
| +mid-pass loses nothing. A console that dies after a send but before |
| +recording it sends that one message again when it comes back. Webhook |
| +receivers drop the repeat by `delivery_id`; Slack and email can't, and a |
| +rare duplicate is the cost. |
| + |
| +**The connector key and restores.** The seal key is a 32-byte AES-256-GCM |
| +key in its own 0600 file beside console.db, `alert-connectors.key` |
| +(`/data/console/alert-connectors.key` by default). It is kept out of the |
| +database on purpose: console.db is replicated to the bucket, and a replica |
| +or backup alone must not reveal a Slack URL. So back the key file up |
| +separately. The console creates it on its first pass, and only when the |
| +path does not exist at all. After a restore from the replica alone, the |
| +console makes a fresh key, every Slack and webhook connector shows "Enter |
| +the URL again" and is skipped, and `seal_key` fires. Email connectors keep |
| +working, because addresses are not sealed. A key file that exists but |
| +cannot be read, or is the wrong size, is never replaced: Slack and webhook |
| +connectors are held, `seal_key` fires, and the "Alert checks" job says so |
| +on every pass. |
| + |
| +**When the engine took over** it read what the old watcher had already |
| +mailed, so a rule that was already firing was not announced a second time. |
| + |
| +**Not yet.** No SMS, and no account or app alerts: this is the operators' |
| +fleet scope only. The console's one-off pages (moves recovery, egress |
| +conflict, lifetimes, claim loss) still go through `alerting.Page`, which is |
| +armed only on host-claim consoles, as before. |
| + |
| ## App capabilities |
| A handful of apps need more from the platform than the `carlos-app@<host>` |
diff --git a/docs/superpowers/notes/roll-fleet-alerts-1.md b/docs/superpowers/notes/roll-fleet-alerts-1.md| new file mode 100644 |
| index 000000000..2030aa69f |
| --- /dev/null |
| +++ b/docs/superpowers/notes/roll-fleet-alerts-1.md |
| @@ -0,0 +1,252 @@ |
| +# Rolling fleet alerts plan 1 |
| + |
| +Branch `design-fleet-alerts`. Spec: |
| +`docs/superpowers/specs/2026-10-30-fleet-alerts-and-traffic-design.md`. Plan: |
| +`docs/superpowers/plans/2026-10-30-fleet-alerts-1-engine-connectors.md`. |
| + |
| +**Status: a proposal. None of it has been run.** The roll itself goes the |
| +usual release road. Each `host.env` change and the live witness below change |
| +real dev or flagship boxes, so each needs Paul's explicit go under AGENTS.md |
| +"Production infrastructure needs scoped approval". One go covers one whole |
| +section, cleanup included. |
| + |
| +## What changes when it rolls |
| + |
| +On the boxes (the `carlos` binary): |
| + |
| +- A new box rule, `disk_eta`, the disk full forecast. It needs 2 hours of |
| + readings, so every rolled box says nothing about it for 2 hours after its |
| + agent restarts. The heartbeat gains `disk_full_eta_hours` while the disk |
| + is growing. |
| +- **The box's own sinks carry only `disk` and `engine_silent`.** From the box |
| + roll on, memory, CPU, mail relay lag, location database and forecast |
| + transitions stop going to each box's `CARLOS_ALERT_WEBHOOK` and |
| + `CARLOS_ALERT_SNS_TOPIC_ARN`. On flagship, that means the SNS emails for |
| + those warnings stop. They still go into `alerts/boxes/<box>.json`, so the |
| + console still sees them (next point). |
| +- A Slack URL in `CARLOS_ALERT_WEBHOOK` now gets Slack's body. No box sets |
| + one today. |
| +- `carlos status --live` shows `engine-beat=on` or `engine-beat=off (...)` |
| + after `alerts=` on a box with `CARLOS_ALERT_ENGINE_BEAT` set, and nothing |
| + on the others. |
| + |
| +On the console: |
| + |
| +- The alert engine replaces the alert watcher. It runs every minute as the |
| + "Alert checks" job, only on a console without host claims (dev and |
| + flagship both qualify). |
| +- console.db gains the `alert_*` tables when the console starts. The |
| + engine's first pass imports what the old watcher already mailed |
| + (`alert_seen`), so a rule already firing is not announced again, and |
| + gives each operator an email connector for their sign-in address, already |
| + confirmed. |
| +- It creates the connector key `alert-connectors.key` (0600) beside |
| + console.db on its first pass, and writes `alert-engine.beat` there after |
| + every pass that commits. |
| +- The first `GET /fleet/alerts` creates the webhook signing key (a `keys` |
| + row, `alert-sign`). |
| +- Store requests: the same `alerts/boxes/` LIST and GETs a minute the |
| + watcher made, now conditional, plus conditional GETs of the heartbeats and |
| + `status/fleet.json` every 5th pass (about 288 a day for each box). No new |
| + objects. |
| + |
| +**There is no gap between the box roll and the console roll.** The old |
| +console watcher reads every rule in `alerts/boxes/<box>.json` and mails |
| +operators about each, `disk_eta` included, until the console rolls. Still, |
| +roll the console soon after its boxes: in between, flagship's warnings |
| +reach operators by the watcher's email only, not SNS. |
| + |
| +## Order |
| + |
| +Dev first, then flagship (memory `roll-order-dev-first`). Boxes before their |
| +console. |
| + |
| +1. Dev boxes: sophie-knitting (console box), leo-climbing, |
| + dennis-stenciling. |
| +2. Dev console. |
| +3. Dev checks (below), then the quick Slack check. |
| +4. `CARLOS_ALERT_ENGINE_BEAT` on the dev console box (below). |
| +5. The live witness, if Paul wants it before flagship (below). |
| +6. Flagship boxes, then the flagship console, then the same checks and the |
| + same `host.env` step on the flagship console box (i-092c0c1eea75723cb, |
| + eu-west-1, profile `keymail`). |
| + |
| +## Checks after each console roll |
| + |
| +1. `/fleet/alerts` loads for an operator. Every operator has an email |
| + connector marked "Added for <their address>" with status On. |
| +2. The operator dashboard's "Alert checks" job ran in the last minute, is |
| + not Failed, and has no note. A note "no usable alert connector reaches |
| + <address>" names an operator nothing reaches. |
| +3. On the console box: `ls -l <dir of CONSOLE_DB>/alert-connectors.key` |
| + shows a 32-byte 0600 file, and `stat -c %y <dir>/alert-engine.beat` |
| + moves forward every minute. The directory is |
| + `/data/console` unless the console unit sets `CONSOLE_DB`. |
| +4. Back up `alert-connectors.key` off the box. It is not in the Litestream |
| + replica, by design. Without it, a restore from the replica makes every |
| + Slack and webhook connector need its URL entered again. Where it lives |
| + (1Password beside the secrets key, say) is Paul's call. |
| +5. Nothing new in the journal: `journalctl -u console --since -10min | grep |
| + 'alert engine'` shows no repeating error. (Use the console's real unit |
| + name; on dev it is `console.service`.) |
| + |
| +## `CARLOS_ALERT_ENGINE_BEAT` on each console box |
| + |
| +Set `CARLOS_ALERT_ENGINE_BEAT=/data/console/alert-engine.beat` in |
| +`/etc/carlos/host.env` on the box that runs the console (dev: sophie-knitting, |
| +i-05498eada6f0afd23; flagship: i-092c0c1eea75723cb), and restart the agent. |
| +If the console unit sets `CONSOLE_DB`, use `alert-engine.beat` in that |
| +directory instead. |
| + |
| +Do it **after** the console has rolled and the beat file exists. An agent |
| +watching a beat that never appears fires `engine_silent` through the box's |
| +own sinks 10 minutes after it starts, which on flagship is a real SNS email. |
| + |
| +Before setting it, check the agent's user can see the file. The agent runs |
| +as `carlos` (carlos-edge.service), and only needs to stat it: |
| + |
| + runuser -u carlos -- stat -c '%U %a %y' /data/console/alert-engine.beat |
| + |
| +If that fails with "Permission denied", do not set the variable: the agent |
| +would read the beat as missing and page. Report it instead; the console's |
| +directory permissions need a decision first. |
| + |
| +Then: |
| + |
| + cp -p /etc/carlos/host.env /etc/carlos/host.env.bak-$(date +%Y%m%d)-enginebeat |
| + echo 'CARLOS_ALERT_ENGINE_BEAT=/data/console/alert-engine.beat' >> /etc/carlos/host.env |
| + systemctl restart carlos-edge |
| + |
| +The restart is the same edge restart a platform roll makes. Check: `carlos |
| +status --live` shows `engine-beat=on` for the console box, and no |
| +`engine_silent` fires in the next 15 minutes. `engine-beat=off (agent runs |
| +as root, so the backstop is off)` would mean the agent runs as root, which no |
| +box does today. |
| + |
| +Optionally, after this, point a box's `CARLOS_ALERT_WEBHOOK` at a Slack |
| +incoming webhook so `disk` and `engine_silent` reach Slack too. That is one |
| +more `host.env` line and agent restart per box, and its own go. |
| + |
| +## Quick check: the Slack test message (dev) |
| + |
| +Scope for the go: the dev console (platform.dev.carlosframework.com, dev |
| +account 640012953448, eu-west-1). One Slack incoming webhook that Paul |
| +creates in a channel of his choice. No AWS change. |
| + |
| +1. On `/fleet/alerts`, add a Slack connector named, say, `dev alerts` with |
| + that URL. |
| +2. The page says a test message with a confirm link went to Slack. The |
| + message arrives in the channel within a few seconds. |
| +3. Open the link. The page shows a Confirm button and does nothing else. |
| + Press it: "Confirmed. Alerts now go to dev alerts." The connector shows On. |
| +4. Press "Send test". A second message arrives. |
| + |
| +This proves the dialler, the seal, the Slack body and the token door. It |
| +leaves a connector that gets every dev fleet alert, which the witness below |
| +needs. Cleanup, if Paul wants it gone: delete the connector on the page, and |
| +the webhook in Slack. |
| + |
| +## Live witness: the disk forecast end to end (dev, needs Paul's go) |
| + |
| +**Purpose.** Watch a real forecast travel from a box's disk to Slack and back: |
| +the trend fit, the 2 hour hold, the box's alert object, the engine's 5 |
| +minute group window, and the clear. |
| + |
| +**Scope.** |
| + |
| +- Account and region: dev, 640012953448, eu-west-2. |
| +- Box: dennis-stenciling (carlos-dev-uk, i-009d593f451cfd562), profile |
| + `kass`, reached as root over SSM. It is the dev box with the least |
| + traffic. First check `/fleet/metrics` on the dev console lists it as |
| + reporting; if dennis is gone or silent, stop and ask rather than switch |
| + boxes. |
| +- Changes on that box only: |
| + - a scratch file `/data/tmp/fleet-alerts-witness`, growing 50 MiB every |
| + 10 minutes, capped at 2 GiB; |
| + - a transient systemd timer and service, `fleet-alerts-witness`, made with |
| + `systemd-run` (nothing written to `/etc/systemd`); |
| + - one line in `/etc/carlos/host.env`: |
| + `CARLOS_ALERT_DISK_ETA_HOURS=100000`, so any growth at all counts as on |
| + course to fill; |
| + - two restarts of `carlos-edge`, one to start and one to clean up. |
| +- Messages: one Slack message to the dev connector on fire and one on |
| + clear. Each operator's email connector on the dev console gets the same |
| + two emails. |
| +- Traffic effects: two edge restarts on dennis, each the same as a platform |
| + roll's. dennis carried the least traffic of the dev boxes when last |
| + looked at (the far side of the `assetcheck` test app). |
| +- Cost: about 1.3 GB written to the box's EBS volume and deleted again, a |
| + little CPU for `/dev/urandom`. No new bucket objects: the box's alert |
| + object is written twice (fire, clear), as for any alert. |
| +- Duration: about 6 hours 10 minutes. |
| + |
| +**Before starting.** On dennis, as root: |
| + |
| + df -B1 --output=avail,pcent /data # need 5 GiB free or more, and use under 80% |
| + test -e /data/tmp && echo exists || echo absent # write this down |
| + grep -n '^CARLOS_ALERT_DISK_ETA_HOURS=' /etc/carlos/host.env # expect nothing |
| + systemctl is-active carlos-edge |
| + |
| +The 80% bound keeps the 2 GiB cap well away from the `disk` rule's 90%. If |
| +`CARLOS_ALERT_DISK_ETA_HOURS` is already set, stop and ask. |
| + |
| +**Start (T0).** On dennis, as root, in one go so the agent's restart and the |
| +first write are within a minute of each other: |
| + |
| + cp -p /etc/carlos/host.env /etc/carlos/host.env.bak-fleet-alerts-witness |
| + echo 'CARLOS_ALERT_DISK_ETA_HOURS=100000' >> /etc/carlos/host.env |
| + mkdir -p /data/tmp |
| + systemctl restart carlos-edge |
| + systemd-run --unit=fleet-alerts-witness --on-active=1s --on-unit-active=10min \ |
| + /bin/sh -c 'f=/data/tmp/fleet-alerts-witness; s=$(stat -c %s "$f" 2>/dev/null || echo 0); if [ "$s" -lt 2147483648 ]; then head -c 52428800 /dev/urandom >>"$f"; fi' |
| + |
| +`--on-active=1s` makes the first write at once; `--on-unit-active` alone |
| +would never start, because the service has never run. Random bytes, not |
| +zeros, so a compressing filesystem still counts them. |
| + |
| +**What to expect.** The restart empties the agent's in-memory readings, so |
| +every reading after T0 is part of the growth: |
| + |
| +| When | What | |
| +|---|---| |
| +| T0 to T0+2h | Nothing. The forecast needs 2 hours of readings. | |
| +| T0+2h | The forecast reads growing. `disk_full_eta_hours` appears in dennis's heartbeat (within 5 minutes). The 2 hour hold starts. | |
| +| T0+4h | `disk_eta` fires on the box and its alert object is written. The box's own sinks do not page: it is a warning. | |
| +| T0+4h, within a minute | The engine opens the incident. `/fleet/alerts/history` shows it open. | |
| +| about T0+4h05m | One Slack message: the disk full forecast warning for dennis-stenciling, with the incident and snooze links. Allow up to T0+4h08m for the engine's minute passes. | |
| + |
| +If nothing arrives by T0+4h20m: read `alerts/boxes/dennis-stenciling.json` |
| +for `disk_eta`, the "Alert checks" job on the dashboard, and the console |
| +journal, before changing anything. |
| + |
| +**Cleanup (T1, after the Slack message).** On dennis, as root: |
| + |
| + systemctl stop fleet-alerts-witness.timer fleet-alerts-witness.service |
| + rm -f /data/tmp/fleet-alerts-witness |
| + rmdir /data/tmp # only if the "before" check said absent |
| + sed -i '/^CARLOS_ALERT_DISK_ETA_HOURS=100000$/d' /etc/carlos/host.env |
| + diff /etc/carlos/host.env.bak-fleet-alerts-witness /etc/carlos/host.env && rm /etc/carlos/host.env.bak-fleet-alerts-witness |
| + systemctl restart carlos-edge |
| + |
| +Removing the one line, rather than copying the backup back, keeps any other |
| +edit made to `host.env` in the meantime. If `diff` shows a difference, keep |
| +the backup and report it. |
| + |
| +**Then expect a clear about 2 hours later** (T1+2h, Slack within 2 minutes |
| +after). The restart empties the readings again, `disk_eta` stays firing |
| +across it (its state is saved in `/data/monitor/alerts.json`), and the first |
| +verdict, 2 hours on, sees no growth and clears it. One Slack message says it |
| +cleared; History shows the incident closed. If the box's ordinary growth |
| +reads as a trend instead, the threshold is back at 72 hours and the clear |
| +comes when the forecast passes 108 hours, which a box with ordinary log |
| +growth does on that first verdict. |
| + |
| +**Verification after cleanup.** `systemctl status fleet-alerts-witness.timer` |
| +says the unit is not found; `/data/tmp/fleet-alerts-witness` does not exist; |
| +`host.env` matches the "before" state; `carlos status --live` shows dennis |
| +reporting on the current release; and History shows exactly one disk |
| +forecast incident for dennis, opened and cleared. |
| + |
| +**Abort at any time** with the cleanup block. Before T0+4h nothing has been |
| +sent. After the fire, the clear follows about 2 hours after the cleanup as |
| +above. |