Workflow: Alerts That Ask for an Action
An Alert Is a Request to Act
Before an alert exists, it must answer four questions:
| Question | A good alert | What fails the test |
|---|---|---|
| What is wrong for users? | “develop: backend users are failing - 20% of requests in the last 5m” | “goroutines > 10000” - internal, says nothing about users |
| What should I do? | the first check, in the alert: “the backend’s error logs and the last change” | no description, or a link to a dead page |
| How urgent? | critical - act now; warning - plan a fix | everything critical, so nothing is |
| Who? | routed by environment: production to the production receiver | a receiver with no integration |
What fails the test does not become an alert. It goes on a dashboard, where it helps explain a problem someone is already looking at - memory, goroutines, the scrape status of each target.
The other half of the rule: when nothing is wrong, nothing fires. On the platform at rest only the Watchdog fires - on purpose, as a heartbeat. Every other alert that fires at rest is either a real problem or noise that must be removed.
Measure What Users Get
The backend’s error rate used to be computed over all its requests, in all three environments together:
- the kubelet’s probes (
/healthz,/readyz,/livez) and Prometheus’s scrapes (/metrics) succeed every few seconds - on a quiet cluster they are almost all the traffic, and they dilute a real failure; - a drill in
developmoved the “production” number, and healthy staging traffic could hide a failing production.
The platform now records the indicators on user requests only, per namespace:
Backend SLO rules
Show the SLO recording rules and burn-rate alerts
# Share of user requests that failed with a 5xx. "or vector(0)"-style padding is not used on
# purpose: with no 5xx series the ratio is absent, and so is the alert.
- record: backend:user_error_ratio:rate5m
expr: |
sum by (namespace) (rate(app_http_requests_total{job="backend",path!~"/healthz|/readyz|/livez|/metrics",status=~"5.."}[5m]))
/ backend:user_requests:rate5m
- record: backend:user_error_ratio:rate30m
expr: |
sum by (namespace) (rate(app_http_requests_total{job="backend",path!~"/healthz|/readyz|/livez|/metrics",status=~"5.."}[30m]))
/ backend:user_requests:rate30m
- record: backend:user_error_ratio:rate1h
expr: |
sum by (namespace) (rate(app_http_requests_total{job="backend",path!~"/healthz|/readyz|/livez|/metrics",status=~"5.."}[1h]))
/ backend:user_requests:rate1h
- record: backend:user_error_ratio:rate6h
expr: |
sum by (namespace) (rate(app_http_requests_total{job="backend",path!~"/healthz|/readyz|/livez|/metrics",status=~"5.."}[6h]))
/ backend:user_requests:rate6h
# p95 latency of user requests, per namespace.
- record: backend:user_latency_p95:rate5m
expr: |
histogram_quantile(0.95,
sum by (namespace, le) (rate(app_http_request_duration_seconds_bucket{job="backend",path!~"/healthz|/readyz|/livez|/metrics"}[5m])))
- name: backend.slo.alerts
interval: 30s
rules:
# Fast burn: at 14.4x the allowed rate the whole month's budget is gone in about two days.
# Act now: users are failing. Pages (critical).
- alert: BackendErrorBudgetBurnFast
expr: |
backend:user_error_ratio:rate5m > (14.4 * 0.005)
and backend:user_error_ratio:rate1h > (14.4 * 0.005)
and backend:user_requests:rate5m > 0.05
for: 2m
labels:
severity: critical
component: backend
slo: availability
annotations:
summary: "{{ $labels.namespace }}: backend users are failing - {{ $value | humanizePercentage }} of requests in the last 5m"
description: "More than 7.2% of user requests to the backend in {{ $labels.namespace }} fail with a 5xx, over the last hour and still in the last 5 minutes. First check: the backend's error logs and the last change - a promotion or a config change (Chapter 10)."
runbook_url: "https://safeops.work/members/chapter-11-observability/runbook-incident-debug/"
# Slow burn: at 6x the budget is gone in five days. Not urgent tonight - plan a fix (warning).
- alert: BackendErrorBudgetBurnSlow
expr: |
backend:user_error_ratio:rate30m > (6 * 0.005)
and backend:user_error_ratio:rate6h > (6 * 0.005)
and backend:user_requests:rate30m > 0.05
for: 15m
labels:
severity: warning
component: backend
slo: availability
annotations:
summary: "{{ $labels.namespace }}: backend error budget burning - {{ $value | humanizePercentage }} of requests over 30m"
description: "More than 3% of user requests to the backend in {{ $labels.namespace }} have failed over the last 6 hours. Not an outage: find the failing route in the backend logs and plan the fix before the budget is gone."
runbook_url: "https://safeops.work/members/chapter-11-observability/runbook-incident-debug/"
backend:user_requests:rate5m(and 30m, 1h, 6h) - user requests per second.backend:user_error_ratio:rate5m(and 30m, 1h, 6h) - the share of them that failed with a 5xx.backend:user_latency_p95:rate5m- the 95th percentile: the duration that about 95% of them stayed at or under.
The path label is the route pattern (/status/{code}), not the raw path - so the set of series stays bounded.
The Budget, and How Fast It Burns
The objective: 99.5% of user requests succeed - an error budget of 0.5%. Over thirty days that is three and a half hours of complete failure, or much longer of partial failure - if traffic is even. The budget counts requests, not minutes: an hour down at the daily peak spends far more of it than the same hour at night.
A threshold alert (“error rate above 5%”) fires on a busy minute and misses a slow leak. The platform alerts instead on how fast the budget burns - the method from Google’s SRE workbook:
| Alert | Burn rate | Windows (both must be over) | for | Severity |
|---|---|---|---|---|
BackendErrorBudgetBurnFast | 14.4x - the month’s budget gone in about two days | 1h and 5m above 7.2% | 2m | critical |
BackendErrorBudgetBurnSlow | 6x - gone in five days | 6h and 30m above 3% | 15m | warning |
- Two windows: the long one proves the problem is real, not a blip; the short one proves it is still happening - so the alert resolves soon after a fix. The fast alert clears about five minutes after recovery; the slow one, about thirty - for half an hour it reports a budget already spent, not one still burning.
- A traffic floor: at three requests a minute or fewer (
requests > 0.05/s), one failed request would be a third of everything. Below the floor the ratios do not page. - No traffic, no alert: with no requests the ratio is
NaN- and missing traffic is not a burning budget. An environment with no available backend replica is caught byBackendNoReadyPods; ready replicas that answer every request with a 5xx are caught byBackendErrorBudgetBurnFast- but only while there is traffic above the floor. - Honest limit: the objective is per thirty days, but Prometheus keeps seven. The burn-rate windows (up to six hours) fit; a thirty-day report of the objective needs longer storage.
When the Budget Is Spent
An alert says the budget is burning. Something else has to say what changes once it is gone - without that, the error budget is a number nobody acts on. The usual answer is a short written error budget policy, agreed before it is needed (one widely used shape: the example policy in Google’s SRE workbook). For this platform it would say:
- Who decides: the owner of the service - here, you; in a team, the on-call lead together with whoever owns the roadmap.
- What waits: feature changes to the environment whose budget is spent. Production’s budget stops production’s changes, not develop’s.
- What still goes: rollbacks, the fix for the cause, security fixes and changes that make it more reliable - each through a pull request, as always.
- When it resumes: when the error ratio over the window you can measure - seven days here - is back under 0.5%, and the cause has a postmortem (Chapter 15).
- Exceptions: written down, with a reason and an end date, by the person who decides.
Nothing in the platform enforces it - it is an agreement, kept where the team reads it.
What the Indicator Does Not See
backend:user_error_ratio counts 5xx only. A 4xx is the client’s mistake by HTTP’s definition, and usually it is: a wrong password (401), a name already taken (409). But 429 is the backend refusing on purpose - and a limit set too low turns real users away with 429 while the budget stays full and no alert fires. Not every 4xx belongs in the budget; know which ones would mean users failing, and look at them separately when they matter.
Two more blind spots: a slow answer is not a failed one (latency has its own alert, BackendLatencyHigh, below), and a request that never reaches the backend - the frontend or the ingress failing - is in none of the backend’s metrics. Zero 5xx does not prove the users’ path works; a check from the users’ side does.
The Backend’s Alerts
Backend alerts
Show the backend alerts
- alert: BackendLatencyHigh
expr: |
backend:user_latency_p95:rate5m > 1
and backend:user_requests:rate5m > 0.05
for: 10m
labels:
severity: warning
component: backend
annotations:
summary: "{{ $labels.namespace }}: backend p95 latency {{ $value | humanizeDuration }}"
description: "One in twenty user requests to the backend in {{ $labels.namespace }} takes longer than 1s, for 10 minutes. First check: the slow route in the latency panel by path, then its trace (the database span or an outbound call)."
runbook_url: "https://safeops.work/members/chapter-11-observability/runbook-incident-debug/"
- alert: BackendNearMemoryLimit
expr: |
max by (namespace, pod) (
container_memory_working_set_bytes{namespace=~"develop|staging|production",container="backend"}
/ on (namespace, pod, container)
kube_pod_container_resource_limits{resource="memory",container="backend"}
) > 0.9
for: 15m
labels:
severity: warning
component: backend
annotations:
summary: "{{ $labels.namespace }}/{{ $labels.pod }}: backend at {{ $value | humanizePercentage }} of its memory limit"
description: "The working set has stayed above 90% of the memory limit for 15 minutes; the next allocation may be OOMKilled. First check: does it level off (a size) or climb (a leak)? Chapter 08."
runbook_url: "https://safeops.work/members/chapter-11-observability/runbook-incident-debug/"
| Alert | Severity | Fires when | First check |
|---|---|---|---|
BackendErrorBudgetBurnFast | critical | users fail, fast (above) | the error logs and the last change - a promotion (Chapter 10) |
BackendErrorBudgetBurnSlow | warning | the budget burns slowly (above) | the failing route in the logs; plan the fix |
BackendNoReadyPods | critical | no backend replica available for 2 minutes | the pod status: CrashLoopBackOff, OOMKilled, ImagePullBackOff, Pending |
BackendLatencyHigh | warning | user p95 above 1 second for 10 minutes | the slow route, then its trace |
BackendNearMemoryLimit | warning | working set above 90% of the limit for 15 minutes | does it level off (a size) or climb (a leak)? - Chapter 08 |
Left to the default rules on purpose: a target Prometheus cannot scrape (TargetDown - lost telemetry is not a down service) and a pod that keeps restarting (KubePodCrashLooping - a single restart is not an incident). Removed from the defaults: the rules for etcd, the scheduler, the controller manager and kube-proxy, which neither kind nor k3s lets Prometheus scrape, and KubeHpaMaxedOut, which fires forever for every HPA whose minimum equals its maximum - as develop and staging run on purpose (Chapter 09).
One Incident, One Notification, the Right People
Alert routes
Show the Alertmanager routes
# Who hears about an alert - the same routes on kind and on the platform.
# production -> receiver "production" (the production channel)
# develop, staging -> receiver "nonprod" (the non-production channel)
# any other critical alert -> "production" (cluster-wide trouble: a node, storage, Flux)
# any other warning -> "nonprod"
# Watchdog and InfoInhibitor are left out: Watchdog is the heartbeat (watchdog-heartbeat.yaml),
# InfoInhibitor only mutes info-level alerts.
#
# Noise rules:
# - one notification per environment and alert name (group_by), re-sent every 4h in production and
# 12h elsewhere while it still fires - not on every evaluation;
# - a critical backend alert mutes the backend warnings of the same environment (inhibitRules): when
# users already fail (BackendErrorBudgetBurnFast) or nothing is ready (BackendNoReadyPods), a slow
# burn or a latency warning adds nothing - one incident, one notification.
#
# The receivers here have no integration: on kind the alerts are routed and grouped, and the
# Alertmanager API shows which receiver each group went to. The platform adds Slack to the same two
# receivers (../slack-receivers.yaml). Chapter 14 moves delivery to the Guardian.
---
apiVersion: monitoring.coreos.com/v1alpha1
kind: AlertmanagerConfig
metadata:
name: safeops-routing
labels:
alertmanagerconfig: safeops
spec:
route:
receiver: nonprod
matchers:
- name: alertname
value: Watchdog|InfoInhibitor
matchType: "!~"
groupBy: [namespace, alertname]
groupWait: 30s
groupInterval: 5m
repeatInterval: 12h
routes:
- receiver: production
matchers:
- name: namespace
value: production
matchType: "="
repeatInterval: 4h
- receiver: nonprod
matchers:
- name: namespace
value: develop|staging
matchType: "=~"
- receiver: production
matchers:
- name: severity
value: critical
matchType: "="
repeatInterval: 4h
inhibitRules:
- sourceMatch:
- name: severity
value: critical
matchType: "="
- name: component
value: backend
matchType: "="
targetMatch:
- name: severity
value: warning
matchType: "="
- name: component
value: backend
matchType: "="
equal: [namespace]
receivers:
- name: production
- name: nonprod
- Routes: alerts from
production, and any othercriticalalert (a node, storage, Flux) go to the receiverproduction; alerts fromdevelopandstaging, and any otherwarning, go tononprod. - Grouping: one notification per environment and alert name, repeated every four hours in production and twelve elsewhere while it still fires - not on every evaluation.
- Inhibition: while a critical backend alert fires in an environment, its backend warnings there are muted. When users already fail, “latency is high” adds nothing.
- Delivery: on the platform both receivers post to Slack - production and non-production channels - once the Slack webhooks are in their encrypted Secret (
alertmanager-slack); until then the alerts are routed and grouped but reach no one, and the platform’s README says so. On kind they have no integration: the Alertmanager API shows where each group went. From Chapter 14 on, a second route hands every alert exceptWatchdogandInfoInhibitorto the Guardian as well - next to these receivers, not instead of them. - The heartbeat:
Watchdogfires all the time; on the platform it pings Healthchecks.io every minute. When the pings stop - Prometheus, Alertmanager or the cluster down - Healthchecks.io alerts by e-mail, from outside. Silence of the alerting system is itself detected.
From the Symptom to the Line of Code: Traces and Logs
An alert says that users fail. A trace says where: one request, followed from the click in the browser, through the backend, to each database query - with the time each step took. A log line says what happened, and carries the same trace_id:
- the frontend creates a span for the user action and sends
traceparentwith the API call; - the backend continues the trace (
otelhttp), adds a span for each SQL query (otelpgx), and writestrace_idandspan_idon its log lines; - all three go to Uptrace (
service.versionandk8s.namespace.nameon every span) - one view from the click to the query.
Sampling is 100%: every request is kept. At this platform’s traffic that is right; a busy service samples (Uptrace suggests a few percent) and keeps every error.
On kind, traces are optional: set the Terraform variable uptrace_dsn with your own Uptrace project’s DSN and the backend and frontend export to it. Uptrace Cloud’s free plan is the easy way; Uptrace can also be self-hosted for free, with databases of its own (ClickHouse and PostgreSQL among them - Uptrace’s install guide lists them for your version; this course has not tested it). Without it, metrics, alerts and logs still work - the lab does them first.
Guardrails That Stop It
- The rules are in Git (review) - an alert is added, removed or loosened in a pull request.
- Silence at rest (checked) - a new alert that fires on an idle cluster is noise; the lab checks that only
Watchdogfires. - Routes in Git (review) - every alert has a destination by environment and severity.
- The heartbeat (platform) - the alerting system’s own silence pages someone from outside.
Safe Workflow (Step-by-Step)
- Before adding an alert, answer the four questions; if one has no answer, it is a dashboard panel.
- Measure users: user requests, per environment, not probes.
- Alert on the burn, with two windows and a traffic floor - not on single spikes.
- Route and group: environment and severity decide the receiver; a critical mutes its warnings.
- Prove the path with a test alert before you rely on it - and check that at rest nothing but the heartbeat fires.
- During an incident: the alert’s first check, then the trace, then the log line with the same
trace_id.
Instructions for Your AI Agent
The rules this chapter adds:
- Never add an alert that does not name an action, an urgency and a first check. Internal signals go on a dashboard.
Enforced by: review of the rules in Git; the lab’s silence-at-rest check (only
Watchdogfires on a healthy idle cluster). - Measure the backend on user requests per environment - never on all requests, never across environments.
Enforced by: the recording rules in
backend-slo-rules.yaml(review). - Never lower a threshold or remove the traffic floor to make an alert fire in a test - a test of the rule generates the condition; a test alert posted to Alertmanager tests only the routing and the receiver. Enforced by: instruction only.
- Never route an alert to a receiver nobody reads, and never silence a channel instead of removing the noise. Enforced by: the routes in Git (review).
This builds on: Version Promotion (Chapter 10) - after a promotion, these signals say whether it was good. This enables: Backup & Restore (Chapter 12) - the next failure is data, and the same alerting tells you about it.