TExcelTAD
Home › Site Reliability Engineering: SLOs, Incidents & Chaos › Mini Project: SLOs, Alerts & a Postmortem

Mini Project: SLOs, Alerts & a Postmortem

In this project you take one service through the whole SRE loop from this course: define its SLOs, turn them into tested burn-rate alerts, run a simulated outage against them, and write the postmortem. The result is a small repository you could show in an interview: an SLO document, Prometheus rules with unit tests, a simulation and a postmortem.

The service is linkly, a URL shortener: GET /{code} answers with a 302 redirect to the long URL, backed by a database and a cache. It's the application of the DevOps Capstone, so you can reuse this work there.

The plan

Step Deliverable Lessons
1 SLO document for the redirect journey Choosing SLIs, Setting SLOs, Writing an SLO Document
2 error budget policy Error Budget Policies
3 recording rules, burn-rate alerts and promtool tests SLO Recording Rules, Burn-Rate Alert Rules, Latency SLOs
4 Alertmanager routing with a routing test Routing Pages & Tickets
5 a simulated outage and its numbers Multi-Window Alerts
6 runbook and postmortem Runbooks, Blameless Postmortems

Suggested layout:

text
linkly-sre/
├── README.md                 what is here and how to run the tests
├── slo/
│   ├── linkly-slo.md         the SLO document
│   ├── error-budget-policy.md
│   ├── linkly-rules.yml      recording rules + burn-rate alerts (generated)
│   ├── linkly-test.yml       promtool tests
│   └── generate.sh           writes the rule file
├── alertmanager/
│   └── alertmanager.yml      + a routing test in CI
├── sim/outage.py             the outage simulation
├── runbooks/linkly-error-budget-burn.md
└── postmortems/2026-xx-xx-db-failover.md

Step 1–2: SLOs and policy

Decide and write down, using the templates:

  • availability: good = response not 5xx; valid = every GET /{code} except probes and load tests (are 404s for unknown codes valid? argue it in the rationale);
  • latency: good = answered within 300 ms (put a histogram bucket at 0.3);
  • targets: the reference solution uses 99.9% availability and 99% latency over 28 days. Justify yours;
  • the error budget policy: what stops when the budget is gone, and who decides exceptions.

Step 3: rules and tests

Generate the rules for both SLIs from one loop, so adding a third SLI is one line, and test them on a scenario: three days of normal traffic, then a database failover that fails about 30% of redirects for 6 minutes, followed by two hours in which 15% of redirects are slower than 300 ms while the cache refills. The reference session (run it, then change the scenario and the assertions to your own):

bash · try it yourself
mkdir -p slo && cd slo
# recording rules: one bad-event ratio per SLI and window
{
  echo "groups:"
  echo "  - name: linkly-slo"
  echo "    rules:"
  for w in 5m 30m 1h 2h 6h 1d 3d; do
    cat <<YML
      - record: slo:availability_errors:ratio_rate$w
        expr: |
          sum(rate(http_requests_total{job="linkly",code=~"5.."}[$w]))
          / sum(rate(http_requests_total{job="linkly"}[$w]))
      - record: slo:latency_slow:ratio_rate$w
        expr: |
          1 - sum(rate(http_request_duration_seconds_bucket{job="linkly",le="0.3"}[$w]))
          / sum(rate(http_request_duration_seconds_count{job="linkly"}[$w]))
YML
  done
} > linkly-rules.yml
# alerts: the same four burn-rate conditions for both SLIs
alert() {  # name, recorded metric, error budget, severity, then pairs of "long short burn"
  local name=$1 m=$2 b=$3 sev=$4; shift 4
  local expr="" sep=""
  for spec in "$@"; do
    set -- $spec
    expr="$expr$sep(slo:${m}:ratio_rate$1 > $3 * $b and slo:${m}:ratio_rate$2 > $3 * $b)"
    sep=" or "
  done
  printf '      - alert: %s\n        expr: %s\n        labels: {severity: %s, slo: %s}\n' "$name" "$expr" "$sev" "$m"
}
# appended to the same group, so they always read this evaluation's recorded ratios
{
  for sli in "availability_errors 0.001" "latency_slow 0.01"; do
    set -- $sli
    alert LinklyErrorBudgetBurn "$1" "$2" page   "1h 5m 14.4" "6h 30m 6"
    alert LinklyErrorBudgetBurn "$1" "$2" ticket "1d 2h 3"    "3d 6h 1"
  done
} >> linkly-rules.yml
promtool check rules linkly-rules.yml
cat > linkly-test.yml <<'YML'
rule_files: [linkly-rules.yml]
evaluation_interval: 1m
tests:
  - name: database failover, then slow redirects for 2 hours
    interval: 1m
    input_series:
      - series: 'http_requests_total{job="linkly",code="302"}'
        values: '0+2999x4800'
      - series: 'http_requests_total{job="linkly",code="503"}'
        values: '0+1x4320 5520+1200x5 11521+1x473'
      - series: 'http_request_duration_seconds_bucket{job="linkly",le="0.3"}'
        values: '0+2985x4326 12915660+2550x119 13222095+2985x353'
      - series: 'http_request_duration_seconds_count{job="linkly"}'
        values: '0+3000x4800'
    alert_rule_test:
      - eval_time: 3d2m
        alertname: LinklyErrorBudgetBurn
        exp_alerts: []
      - eval_time: 3d3m                  # 3 minutes into the failover
        alertname: LinklyErrorBudgetBurn
        exp_alerts:
          - exp_labels: {severity: page, slo: availability_errors}
      - eval_time: 3d35m                 # the 30-minute window has cleared
        alertname: LinklyErrorBudgetBurn
        exp_alerts: []
      - eval_time: 3d1h2m
        alertname: LinklyErrorBudgetBurn
        exp_alerts: []
      - eval_time: 3d1h3m                # the slow-redirect burn (about 15x) fills the 1-hour window
        alertname: LinklyErrorBudgetBurn
        exp_alerts:
          - exp_labels: {severity: page, slo: latency_slow}
      - eval_time: 3d2h7m                # one minute after the latency recovers
        alertname: LinklyErrorBudgetBurn
        exp_alerts: []
YML
promtool test rules linkly-test.yml
Checking linkly-rules.yml
  SUCCESS: 18 rules found

  SUCCESS

The availability page fires 3 minutes into the failover and has resolved half an hour later; the latency page fires about an hour into the slow period (its burn rate, about 15, only just exceeds 14.4, so the 1-hour window has to fill up first) and resolves within a minute of the recovery. Add tests of your own: a slow burn that opens a ticket and never pages, a short blip that does nothing, and the no-traffic case.

Step 4: routing

Write alertmanager.yml with page and ticket routes and an inhibit rule, check it with amtool check-config, and add amtool config routes test --verify.receivers=… assertions for "page goes to the pager" and "ticket never pages" to CI.

Step 5: simulate the outage

promtool proves the rules fire; a simulation tells the story in numbers for the postmortem: when each alert fired and resolved, and how much of each budget the incident consumed. The model replays the same scenario minute by minute with plain averages over each window:

python · try it yourself
# minute-by-minute model of the scenario: 3,000 requests a minute
REQ = 3000
START = 0                                       # minute 0 = 3d0m in the promtool test
def minute(m):
    errors = 1200 if 0 < m <= 6 else 1          # database failover: about 30% errors for 6 minutes
    slow = 450 if 6 < m <= 126 else 15          # then 15% of redirects slower than 300 ms for 2 hours
    return errors, slow

SLOS = {"availability": (0, 0.001), "latency": (1, 0.01)}     # index into minute(), error budget
RULES = [("page", 60, 5, 14.4), ("page", 360, 30, 6), ("ticket", 1440, 120, 3), ("ticket", 4320, 360, 1)]
HISTORY = 4320                                 # three days of normal traffic before minute 0
series = [minute(m) for m in range(-HISTORY, 300)]
prefix = [[0], [0]]                            # running totals of errors and slow requests
for e, s in series:
    prefix[0].append(prefix[0][-1] + e)
    prefix[1].append(prefix[1][-1] + s)

def burn(i, window, idx, budget):              # mean burn rate over the last `window` minutes ending at i
    lo = max(0, i - window + 1)
    bad = prefix[idx][i + 1] - prefix[idx][lo]
    return bad / (REQ * (i + 1 - lo)) / budget

for slo, (idx, budget) in SLOS.items():
    firing, events = None, []
    for i in range(HISTORY - 10, len(series)):
        sev = next((s for s, lw, sw, b in RULES
                    if burn(i, lw, idx, budget) > b and burn(i, sw, idx, budget) > b), None)
        if sev != firing:
            events.append(f"{sev or 'resolved'} at +{i - HISTORY}m")
            firing = sev
    bad_extra = sum(s[idx] for s in series[HISTORY:]) - len(series[HISTORY:]) * (1 if idx == 0 else 15)
    window_budget = budget * REQ * 60 * 24 * 28
    print(f"{slo:<12} {', '.join(events):<40} extra bad events {bad_extra:>6}  "
          f"= {bad_extra / window_budget:.1%} of the 28-day budget")
availability page at +3m, resolved at +36m            extra bad events   7194  = 5.9% of the 28-day budget
latency      page at +64m, resolved at +127m          extra bad events  52200  = 4.3% of the 28-day budget

The simulation agrees with promtool to within a minute or so (Prometheus's rate() extrapolates at the window edges; plain averages don't). Together, the two incidents used about 6% of the availability budget and 4% of the latency budget: noticeable, not a policy trigger. Try a bigger scenario: how long a full outage exhausts the availability budget, or how slow a burn can be before it neither pages nor tickets.

Step 6: runbook and postmortem

  • Write the runbook for LinklyErrorBudgetBurn with the queries that tell availability from latency and the database from the cache.
  • Write the postmortem for the simulated incident with the template from Blameless Postmortems: summary, impact (use the simulation's numbers), a timeline (invent plausible human events: page acknowledged, IC declared, failover confirmed, cache warm-up identified), contributing factors, and at least three action items of different types (prevent, detect, mitigate). One natural action item: the latency page fired an hour late because a burn rate of 15 barely crosses 14.4; would a cache warm-up procedure, or the 6-hour rule, have helped?

Checklist

  • SLO document with rationale, exclusions, budget and alerting sections
  • error budget policy signed off (by a friend playing product owner, if need be)
  • promtool check rules and promtool test rules pass, with tests for fast burn, slow burn, blip, recovery
  • amtool check-config and routing tests pass
  • simulation reproduces the alert times within a few minutes
  • runbook linked from the alert's runbook_url annotation
  • blameless postmortem with owned, dated action items
  • all of it runs in CI on every change (CI/CD)

Test yourself

Why did the latency page fire about an hour into the slow period rather than within minutes?

  1. The latency rules are broken
  2. The burn rate (about 15) barely exceeds 14.4, so the 1-hour window needed almost an hour of slow requests to cross it
  3. Latency alerts always take an hour
  4. The ticket inhibited the page

Why combine promtool tests with a separate simulation?

  1. promtool can't test alerts
  2. promtool proves the real rules fire as expected; the simulation gives the budget numbers and timeline for the postmortem and makes what-if scenarios cheap
  3. Simulations replace tests
  4. To slow down CI