Lesson 6 : Alert Management Control Plane
Lesson 6 : Alert Management Control Plane
What We Are Building
InfraWatch Alerts — a production alert management console modeled after PagerDuty and Datadog:
Rule engine — Threshold, anomaly, and expression-based rules with templates
Evaluation pipeline — Sustained breach detection, deduplication, suppression windows
Lifecycle processing — Severity scoring, escalation policies, auto-resolution
Query plane — Search, statistics, bulk operations, CSV/JSON export
Operator console — Dark-theme dashboard with live WebSocket updates
Notification routing — Channel delivery with circuit-breaker protection
Core Concept: Signal vs Noise
Every monitoring platform ingests thousands of metric points per minute. The hard problem is not detection — it is deciding which signals deserve human attention. Datadog and PagerDuty solve this with pending timers (avoid flapping), fingerprint deduplication (one alert per root cause), and suppression windows (maintenance silence).
The non-obvious insight: alert state is a first-class entity, not a side effect of rule evaluation. A rule fires; an alert instance is born with its own lifecycle. Operators acknowledge, escalate, and resolve alerts — not rules.
Where This Fits
Alerts sit between completed metric pipelines and human response. They assume metrics arrive reliably and workers can evaluate rules on schedule.
Component Architecture
Ingest — Agents POST metric samples; each sample triggers rule evaluation.
Evaluator — Compares values against thresholds or Z-score anomaly models.
Processor — Manages pending→firing transitions, severity scoring, history audit.
Query API — Powers search, statistics, and export for the operator console.
WebSocket — Pushes state changes to the dashboard without polling.
Control & Data Flow
Metric arrives → stored in PostgreSQL → evaluator checks all enabled rules → suppression filter → dedup fingerprint → create or update alert instance → pending timer → firing → notification router → WebSocket broadcast → dashboard card refresh.
Step-by-step path your code follows:
Agent or simulator POSTs a sample to
/api/v1/metrics/ingest.Sample lands in the
metric_samplestable.The evaluation engine loads every enabled rule.
The suppression service checks maintenance windows and regex patterns.
The evaluator compares the value against a threshold or Z-score anomaly model.
An alert instance is created or updated — pending becomes firing after
for_duration_seconds.The notification router logs delivery; WebSocket pushes the update.
Dashboard stats cards and the alert table refresh.
Alert Lifecycle
States: OK → Pending → Firing → Acknowledged → Resolved, with a Suppressed branch during maintenance windows. Pending requires sustained breach (for_duration_seconds) before firing — the same pattern Prometheus for: clauses use.
Real-World Context
PagerDuty routes firing alerts through escalation policies with time-delayed notifications.
Datadog monitors use evaluation windows to prevent alert storms from brief spikes.
Grafana alert rules separate rule definition from alert instance management.
Your console implements all three patterns in one self-contained stack.
Design Notes
These choices show up directly in the code you will run:
Pending before firing — Rules use
for_duration_secondsso a one-second CPU spike does not wake anyone at 3 a.m.Fingerprint dedup — A SHA-256 fingerprint per rule and metric stops duplicate alert rows from flooding the table.
DB-first state — Every transition is written to
alert_state_historyso you can audit what happened and when.Same-origin WebSocket — The frontend connects to
ws://<host>/ws/alerts; Vite and nginx proxy it correctly in both local and Docker modes.Self-contained project — Clone
infrawatch-alerts/alone. Everything you need is inside that folder.No API keys in source — Database credentials are local Docker defaults for development. Set
SECRET_KEYin.envbefore production.
Project Layout
Success Criteria
After completing this lesson you should be able to:
Keep going with the full lesson
The rest of this lesson — plus its implementation guide, runnable scripts and source code — is included with the course or an All Access plan. Create a free account to start the free lessons in every course.
Already a member? Sign in