Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

10.5 KB
Raw Blame

Alert lifecycle transitions lack a deterministic contract harness

Recorded: 2026-08-26 Origin: alerting audit (2026-08-26) finding 2 and docs/ALERT_ENGINE_EVOLUTION.md Phase 1.

Gap

The alert manager's transition semantics (hysteresis trigger/clear, sustained-for delays, severity derivation, confirmation counts) are implemented imperatively across per-family check paths and asserted only by per-unit tests. There is no deterministic, engine-independent statement of the lifecycle contract, so regressions in the frozen transition core keep shipping (#1682, #1683, #1553, #1693, #1724) and cross-family semantic drift is invisible.

Resolution

Phase 1 of docs/ALERT_ENGINE_EVOLUTION.md: a pure transition reducer (internal/alerts/reducer) that characterizes the manager's semantics family by family, plus a parity harness (reducer_parity_test.go in internal/alerts) that drives both engines through identical observation sequences and fails on any divergence. The reducer must characterize, not improve: divergences are reducer bugs unless investigation proves a manager defect, which is then fixed in the manager first.

First slice (2026-08-26): the metric-threshold family. The harness immediately caught a real manager defect: checkMetric hysteresis resolution removed alerts by the legacy <resourceID>-<metric> ID while canonical-identity alerts are stored under the canonical state key and the legacy ID carries no alias, so the removal silently no-oped — a resolved notification went out while the alert stayed active and re-resolved every poll (guest per-disk usage alerts were the remaining production caller; user-visible as the stale-alert class, e.g. #1580). Fixed at the caller with a focused regression test before the parity slice landed.

Second slice (2026-08-26): the confirmation (discrete-state) family — N-consecutive-match activation, single-observation recovery at the evaluator layer, spec-carried severity — characterized against evaluateCanonicalLifecycleAlert. The harness again surfaced a real defect: the confirmation maps persist only counts, so lifecyclePreviousState reconstructed pending runs dated at the current observation and activation stamped StartTime at the final confirming poll, understating outage start by the whole confirmation window (the manager had already fixed this once for unified incidents via unifiedIncidentFirstSeen but not for the generic lifecycle path). Fixed with lifecycleFirstMatched, mirroring that precedent, before the parity slice landed.

Third slice (2026-08-26): the recovery-confirmation gate — the poll-driven offline composition where offline polls reset the recovery counter and run the evaluator while healthy polls skip the evaluator and run clearResourceOfflineAlert (N consecutive healthy polls to resolve, default 3, storage 2; pending still clears on one healthy poll). The harness caught a defect in the slice-2 fix itself: callers that reset confirmation counts directly (bypassing the evaluator path) left a stale lifecycleFirstMatched entry that backdated the next run's alert to the previous run's first observation. Fixed by re-stamping whenever an observation starts a new run.

Fourth slice (2026-08-26): re-fire-within-retention start restoration — a resolve followed by a re-activation inside the recently-resolved retention (5 minutes) restores the original occurrence's StartTime and is treated as the same occurrence (EventRefired in the reducer; the manager reactivates without a new history entry); outside the window the re-fire is a fresh occurrence. First slice where parity passed with no manager defect found. Known un-characterized nuance, deliberately deferred: the manager's retention check mixes wall-clock now against evidence-stamped resolve times, which the reducer normalizes to ObservedAt throughout — that difference disappears at cutover.

Fifth slice (2026-08-26): the acknowledge lifecycle — ack marks a firing incident and its canonical record, survives per-tick alert rebuilds (preserveAlertState's existing branch) and short resolve/re-fire cycles (the restore branch), is removed by unacknowledge, and expires once the inactive record passes the one-hour cleanup TTL. The manager's restore has no age check of its own — expiry is cleanup's pruning — so the reducer draws the hour deterministically at restore time (AckRetention), and the parity expiry scenario exercises the manager's real Cleanup pass. Applies to both families (checkMetric shares preserveAlertState). Second consecutive slice with no manager defect found.

Sixth slice (2026-08-26): the intent gate — operator suppression (expected offline, muted, retired, active maintenance windows) and explicit grace policies hold ACTIVATION only, while confirmations keep counting; release activates with the run's first active observation as the alert start; an already-firing incident is never suppressed by intent. The manager accrues grace on monotonic process runtime while the reducer measures the signal clock — coincident under continuous operation, recorded as a nuance that disappears at cutover. Third consecutive parity slice with no manager defect; the operator scenarios' StartTime parity additionally exercises the lifecycleFirstMatched fix in composition. Deferred: the backup-offline deferral sub-policy (MaxDeferralSeconds / PostGraceSeconds).

Capstone (2026-08-26): the shadow-mode runtime feed. The reducer now runs continuously inside the live manager against the same production observations — the canonical lifecycle path (connectivity, powered-state, discrete-state kinds), the poll-driven recovery paths, manual acknowledge/unacknowledge/clear, with persisted-alert seeding at enable — and every state disagreement is counted (Manager.ShadowDivergences) and recorded in the alert event log as a shadow_divergence event (rate-limited per key; the reducer resyncs to the manager after each report so one divergence yields one event, including divergences from unhooked mutations). Enabled by the monitoring bootstrap next to the event log. The divergence rate is the go/no-go evidence for each Phase 2 family cutover.

Backup-offline deferral (2026-08-26): characterized — deferral while the backup runs bounded by the max-deferral cap on total condition-active time, post-grace from the backup's end still bounded by the cap — with unit tests and parity against the real LoadIntentPolicies/IntentBackup composition. The shadow feed now models the deferral independently instead of echoing the manager's hold. Phase 1 characterization is complete: every discrete-family and metric-family behavior is pinned.

Phase 2 (2026-08-26/27): all four per-observation transition families cut over to the reducer core as authoritative state, one scoped commit each — match-spec lifecycle (ee35d178b successor chain), legacy checkMetric, canonical metric threshold, and the stateful family. Each cutover held the family's full test surface green and kept the parity harnesses as regression pins. The cutovers surfaced and fixed three production defects at the root: checkMetric resolving by legacy ID so canonical-keyed alerts never cleared (#1580 class), confirmation-run StartTime stamped at the final confirming poll instead of the first match, and powered-off grace measured on the wall clock after cutover (restored wall-clock immunity via monotonic RuntimeTick signals).

Legacy-map deletion (2026-08-27, 6eee5a164): the seven transition-state maps deleted from the manager per the plan's retirement list; cleanup-loop hygiene moved into the core (PruneStalePending on both cleanup paths, pending reaping for removed containers via PendingResourceIDs, healthy observations from HandleHostOnline/HandleDockerHostOnline). The test-seam conversion surfaced two more real gaps, fixed at the root: config-change auto-resolution never mirrored its forget into the core (a policy-disabled alert stayed firing in the core), and evaluateIntentNoLock created intent pending state without ResourceID/ResourceType/TrackingKey so per-resource clears could not match it.

Scoped out deliberately: the unified-incidents reconciler stays on its batch reconciliation model (rationale recorded in docs/ALERT_ENGINE_EVOLUTION.md, Phase 2 status).

Phase 3 (2026-08-27, 8827defb6): the declarative policy fold. effectiveAlertPolicyNoLock translates the persisted AlertConfig into the effective policy for one resource — type defaults, DisableAll switches, custom rules, identity-aware overrides — and every scattered DisableAll* read plus resolveResourceThresholds/getGuestThresholds now routes through it. Characterization tests (alert_policy_test.go) pinned the fold against the legacy resolution across the config matrix before call sites moved. UI migration deliberately deferred as demand-gated (no ledger signal for a rules-first editing surface); rationale in docs/ALERT_ENGINE_EVOLUTION.md.

The evolution plan's phases are complete: Phase 0 event log, Phase 1 characterized reducer + shadow feed, Phase 2 family cutovers + legacy map deletion, Phase 3 engine-side rule model. Open follow-ons recorded in the plan doc: event-log-as-sole-history-authority (retires the JSON snapshot file), the unified-incidents reconciler emitting reducer-shaped events at that boundary, and the demand-gated rules-first UI.

Post-plan hardening (2026-08-27): the lifecycle contract suite landed as a release gate (3049da030) — engine contracts for config-save silence, resolve-exactly-once, ack-halts-escalation, and suppressed recovery, plus grouped-rendering contracts proving every delivery surface names all N grouped alerts and that a cancelled-before-delivery firing holds its recovery. Building the suite surfaced that dispatch bookkeeping only runs when callbacks are installed (test-harness nuance, not a defect) and that acknowledgement by an alert's internal legacy ID does not resolve — the exported canonical ID is the working surface (evidence for alert-identity-config-migration).

The event log then became the history authority (871f2348b, 2dc2b7275, fbbdb929d): lifecycle events carry full alert snapshots, history is projected from the log with the JSON entries imported once and the files retired to *.imported, clears are append-only tombstones, and the reconciler and system-alert families now record fired events. Parity work surfaced and fixed one real defect: the JSON history never propagated acknowledgement onto its rows, so the History view showed acknowledged alerts as unacknowledged for their entire active life.

Registered follow-on: alert-identity-config-migration (the versioned migration of persisted override keys and ack records to canonical identity, after which the alias layers can be deleted).