Pidoku

Archive

This learning material is in the archive. It is not currently maintained and has not been updated with the latest information, so tool versions, prices and dates may be out of date.

Burn-Rate Alerting

Module 2 Lesson 2.d 1h Difficulty 4/5

Prerequisites 2.b, 2.c

The idea in one minute#

Do not page when the error rate crosses some threshold. Page when the error budget is being spent fast enough to matter. The speed of spending is the burn rate: the observed error ratio divided by the ratio the SLO allows. Burn rate 1 spends exactly the whole budget over the SLO window; burn rate 14.4 spends a 30-day budget in about two days.

The standard recipe — multiwindow, multi-burn-rate alerts from the Google SRE workbook — pages when a high burn rate is seen over both a long window (so a two-minute blip does not page) and a short window (so the alert stops soon after the problem does). Two page-level rules catch fast and medium burns; a ticket-level rule catches slow leaks.

An analogy#

A fuel gauge with a trip computer. You do not want an alarm every time you accelerate hard (a blip). You do want one when, at the current consumption, you will run dry before the next station — and you want it to stop beeping once you ease off.

A picture#

flowchart TB
  M[":prometheus: <b>Error ratio</b><br/><small>recorded over 5m, 30m, 1h, 6h, 3d</small>"] --> F{"1h AND 5m<br/>burn > 14.4?"}
  M --> S{"6h AND 30m<br/>burn > 6?"}
  M --> T{"3d AND 6h<br/>burn > 1?"}
  F -->|"2% of budget in 1 h"| P1[":pagerduty: <b>Page</b><br/><small>fast burn</small>"]
  S -->|"5% of budget in 6 h"| P2[":pagerduty: <b>Page</b><br/><small>medium burn</small>"]
  T -->|"10% of budget in 3 days"| TK[":jira: <b>Ticket</b><br/><small>slow leak</small>"]
  class M memory
  class F,S,T queue
  class P1,P2 warn
  class TK io

How it really works#

Burn rate#

error budget (ratio)   = 1 − SLO                     99.9% → 0.001
burn rate              = error ratio over window ÷ (1 − SLO)
time to exhaust budget = SLO window ÷ burn rate
budget consumed        = burn rate × alert window ÷ SLO window
Burn rateA 30-day budget is gone inBudget used in 1 h
130 days0.14%
215 days0.28%
65 days0.83%
14.450 hours2%
3620 hours5%
1000 (100% errors at 99.9%)43 minutesall of it

Why simpler alerts fail#

The workbook walks through the options and their trade-offs. The four properties to judge an alert by are precision (pages are real), recall (real problems page), detection time and reset time (how long it keeps firing after the fix).

AlertProblem
Error ratio over 10 min > SLO budget (0.1%)Pages on blips that use a tiny fraction of budget. Poor precision.
Error ratio over 30 days > budgetAccurate, but detects a major outage hours late and stays firing for 30 days.
Burn rate > 14.4 over 1 hGood precision, but stays firing for up to an hour after recovery; misses slow burns.
Multiple burn rates, long window eachCatches fast and slow, but long reset times.
Multiple burn rates, each with a long and a short windowGood precision and recall, fast reset. The recommended default.

The short window — about 1/12 of the long one — is the trick: the long window decides whether it is serious; the short window confirms it is still happening, so the alert clears within minutes of recovery.

For a 99.9% SLO over 30 days (the workbook’s starting point):

SeverityLong windowShort windowBurn rateBudget used when it fires
Page1 h5 min14.42%
Page6 h30 min65%
Ticket3 days6 h110%

These are starting values. Low-traffic services, very tight SLOs and services with long recovery need adjustment (see below).

In Prometheus#

First, recording rules that compute the error ratio at each window (so alert evaluation is cheap):

YAML
groups:
  - name: checkout-slo-recordings
    rules:
      - record: slo:checkout_errors:ratio_rate5m
        expr: |
          sum(rate(http_requests_total{job="checkout", code=~"5..|429"}[5m]))
          /
          sum(rate(http_requests_total{job="checkout"}[5m]))
      # …the same expression again for 30m, 1h, 6h and 3d:
      - record: slo:checkout_errors:ratio_rate30m
        expr: sum(rate(http_requests_total{job="checkout", code=~"5..|429"}[30m])) / sum(rate(http_requests_total{job="checkout"}[30m]))
      - record: slo:checkout_errors:ratio_rate1h
        expr: sum(rate(http_requests_total{job="checkout", code=~"5..|429"}[1h])) / sum(rate(http_requests_total{job="checkout"}[1h]))
      - record: slo:checkout_errors:ratio_rate6h
        expr: sum(rate(http_requests_total{job="checkout", code=~"5..|429"}[6h])) / sum(rate(http_requests_total{job="checkout"}[6h]))
      - record: slo:checkout_errors:ratio_rate3d
        expr: sum(rate(http_requests_total{job="checkout", code=~"5..|429"}[3d])) / sum(rate(http_requests_total{job="checkout"}[3d]))

Then the alerts:

YAML
groups:
  - name: checkout-slo-alerts
    rules:
      - alert: CheckoutErrorBudgetBurnFast
        expr: |
          (slo:checkout_errors:ratio_rate1h > (14.4 * 0.001)
            and slo:checkout_errors:ratio_rate5m > (14.4 * 0.001))
          or
          (slo:checkout_errors:ratio_rate6h > (6 * 0.001)
            and slo:checkout_errors:ratio_rate30m > (6 * 0.001))
        labels:
          severity: page
          service: checkout
        annotations:
          summary: "Checkout is burning its error budget fast"
          description: "Error ratio {{ $value | humanizePercentage }}; at this rate the 30-day budget is gone in under 5 days."
          runbook_url: "https://runbooks.example.com/checkout/error-budget-burn"
          dashboard: "https://grafana.example.com/d/checkout-slo"

      - alert: CheckoutErrorBudgetBurnSlow
        expr: |
          slo:checkout_errors:ratio_rate3d > (1 * 0.001)
            and slo:checkout_errors:ratio_rate6h > (1 * 0.001)
        labels:
          severity: ticket
          service: checkout
        annotations:
          summary: "Checkout is slowly spending more than its error budget"
          runbook_url: "https://runbooks.example.com/checkout/error-budget-burn"

No for: clause is needed — the long window already provides the persistence. Tools like Sloth and Pyrra (2.e) generate all of this from a ten-line SLO definition.

A latency SLO uses the same structure: the “bad” count is requests above the threshold, i.e. total minus the histogram bucket at the threshold:

1 - ( sum(rate(http_request_duration_seconds_bucket{job="checkout", le="1"}[1h]))
      / sum(rate(http_request_duration_seconds_count{job="checkout"}[1h])) )

Adjusting the recipe#

  • Low traffic. With 10 requests an hour, one failure is a 10% error ratio and a burn rate of 100. Options: generate synthetic traffic (3.b), combine small services into one SLO, use time-slice SLIs, or require a minimum number of failed requests in the window (and sum(increase(...errors[1h])) > 5).
  • Very tight SLOs (99.99%+). 100% errors burns at 10,000×; even the 5-minute window is slow relative to a 4-minute monthly budget. Recovery must be automatic; the alert is a notification.
  • Long recovery. If mitigating takes an hour, a 2%-in-1-h page fires too late to save the budget. Lower the burn thresholds.
  • 28-day windows. Scale the numbers: 14.4 corresponds to 2% of a 30-day budget per hour; for 28 days, 2% per hour is a burn of 13.44. Most teams keep 14.4 and 6 regardless.

A worked example#

Checkout, 99.9% SLO over 30 days. Four scenarios:

ScenarioWhat happensWhat you want
Blip30% errors for 2 minutes (a pod restart)No page
Bad deploy5% errors until rolled back after 40 minutesPage within minutes
Degradation0.8% errors (burn 8) for 10 hoursPage within an hour or two
Slow leak0.15% errors (burn 1.5) for daysA ticket, not a page

The program below simulates each minute of each scenario and evaluates three strategies: a naive threshold, a single 1-hour burn-rate alert, and the multiwindow rules above. It prints when each alert first fires and how long it keeps firing after the problem stops.

Code#

Go
// burnrate.go — simulate error-ratio scenarios and compare alerting strategies.
package main

import "fmt"

const (
	slo    = 0.999
	budget = 1 - slo
	minute = 1
	hour   = 60 * minute
	day    = 24 * hour
)

// ratio returns the mean error ratio over the last w minutes ending at t (constant traffic).
func ratio(prefix []float64, t, w int) float64 {
	start := t - w + 1
	if start < 0 {
		start = 0
	}
	return (prefix[t+1] - prefix[start]) / float64(t-start+1)
}

type rule struct {
	long, short int
	burn        float64
}

type strategy struct {
	name  string
	fires func(p []float64, t int) bool
}

func multi(rules ...rule) func([]float64, int) bool {
	return func(p []float64, t int) bool {
		for _, r := range rules {
			if ratio(p, t, r.long) > r.burn*budget && ratio(p, t, r.short) > r.burn*budget {
				return true
			}
		}
		return false
	}
}

func main() {
	const length = 5 * day
	const startAt = 4 * day // let the long windows fill with clean data first

	type scenario struct {
		name     string
		duration int
		errRatio float64
	}
	scenarios := []scenario{
		{"blip: 30% for 2 min", 2 * minute, 0.3},
		{"bad deploy: 5% for 40 min", 40 * minute, 0.05},
		{"degradation: 0.8% for 10 h", 10 * hour, 0.008},
		{"slow leak: 0.15% for 3 d", 3 * day, 0.0015},
	}

	strategies := []strategy{
		{"naive: 10m ratio > 0.1%", func(p []float64, t int) bool { return ratio(p, t, 10*minute) > budget }},
		{"burn 14.4 over 1h only", multi(rule{hour, hour, 14.4})},
		{"multiwindow pages", multi(rule{hour, 5 * minute, 14.4}, rule{6 * hour, 30 * minute, 6})},
		{"multiwindow ticket", multi(rule{3 * day, 6 * hour, 1})},
	}

	for _, sc := range scenarios {
		start := startAt
		if sc.duration > day { // a long leak starts earlier so the 3-day window sees it
			start = length - sc.duration - 2*hour
		}
		series := make([]float64, length)
		for t := range series {
			series[t] = 0.0002 // background errors, burn rate 0.2
			if t >= start && t < start+sc.duration {
				series[t] = sc.errRatio
			}
		}
		prefix := make([]float64, length+1)
		for i, v := range series {
			prefix[i+1] = prefix[i] + v
		}
		used := 0.0
		for _, v := range series[start : start+sc.duration] {
			used += v
		}
		fmt.Printf("\n%s  (uses %.1f%% of a 30-day budget)\n", sc.name, 100*used/(budget*30*day))
		end := start + sc.duration
		for _, st := range strategies {
			first, last := -1, -1
			for t := start; t < length; t++ {
				if st.fires(prefix, t) {
					if first < 0 {
						first = t
					}
					last = t
				}
			}
			if first < 0 {
				fmt.Printf("  %-26s never fires\n", st.name)
				continue
			}
			reset := last - end + 1
			if reset < 0 {
				reset = 0
			}
			fmt.Printf("  %-26s fires after %5d min, keeps firing %4d min after recovery\n",
				st.name, first-start, reset)
		}
	}
}

What to look for in the output:

  • The naive alert pages on everything — the blip that used 1.4% of the budget, and the slow leak that deserved a ticket. On a real service it would page many times a week.
  • The 1-hour-only alert ignores the blip, but keeps firing for about 40 minutes after the bad deploy was rolled back, and never fires for the degradation.
  • The multiwindow pages ignore the blip, catch the bad deploy after about 17 minutes (when 2% of the budget is gone) and the degradation after about 4.5 hours (5% gone), and clear within a few minutes of recovery.
  • The slow leak only ever produces the ticket — which is what you want.

Detection time follows a formula: long window × burn threshold × (1 − SLO) ÷ error ratio. For the bad deploy: 60 min × 14.4 × 0.001 ÷ 0.05 ≈ 17 min. A total outage (100% errors) pages in under a minute.

note

A two-minute total outage uses 4.6% of a 30-day budget at 99.9%, so the fast-burn rule correctly pages for it. “Blip” here means a short, partial failure.

Remember this#

  • Burn rate = error ratio ÷ (1 − SLO). Alert on burn rate, not raw error ratio.
  • Default rules (99.9%, 30 days): page at 14.4× over 1 h and 5 min, page at 6× over 6 h and 30 min, ticket at 1× over 3 d and 6 h.
  • The long window gives precision; the short window gives fast reset.
  • Low-traffic services and very tight SLOs need adjusted rules or synthetic traffic.

Try it#

  1. Run burnrate.go. Change the bad deploy to 2% errors. Which rule catches it now, and how fast?
  2. Change the SLO to 99.99% (update slo). What happens to the blip?
  3. Write the recording rules and alerts for a latency SLO of “99% under 500 ms”.

Check yourself#

  1. At a 99.9% SLO, what error ratio corresponds to a burn rate of 14.4?
  2. Why does a single long window give a long reset time?
  3. What is the short window for, and why is it about 1/12 of the long one?
  4. Name two ways to make burn-rate alerts work for a service with 50 requests an hour.

Sources#

↑↓ navigate↵ openesc close

100% drag to pan · scroll or pinch to zoom · double-click to zoom in