Skip to content
Tech Atlas, home
Search
Esc
  • All roadmapsBrowse every learning path
  • ExploreFind a technology area
  • ProjectsGuided projects and builds
  • My AtlasYour learning dashboard
Lesson 4 of 6 · Concept · 25 min · revision 2

SLOs, black-box probes and alerts worth waking up for

Define an SLI, an SLO and an error budget for a user-facing service, measure availability from outside with a black-box probe, and write multi-window, multi-burn-rate alerts that page on user impact, tested with promtool and routed with Alertmanager.

Contentsand lesson path

What you will learn

  • Define SLIs and SLOs with an error budget, and write burn-rate alerts that page on user impact rather than on internal causes.

01. Why it matters

Most teams start with alerts on whatever is easy to measure: CPU above 90%, a pod restarted, one 5xx response. Within a month the on-call phone rings at night for things that did not hurt anyone, people learn to ignore it, and the one page that matters is lost in the noise. Every page should be urgent, actionable and about something users can feel.

Service level objectives give you that filter. You write down what good service means as a number, measure it the way users experience it, and alert only when that number is being spent fast enough to miss the target. The same number also settles arguments about risk: while there is budget left you can ship; when it is gone, reliability work comes first.

02. SLIs, SLOs and the error budget

  • A service level indicator (SLI) is a measurement of good service, best written as a ratio: good events divided by valid events. For ask-api, candidates are availability (requests answered without a 5xx), latency (requests answered within 2 s, a sensible bar for an endpoint that waits on a model) and even quality (answers that cite at least one source).
  • A service level objective (SLO) is a target for an SLI over a window, such as 99.5% over a rolling 30 days. Rolling windows match how users remember an outage better than calendar months do.
  • The error budget is what the SLO allows to go wrong: 100% minus the target, here 0.5% of events. With one event a minute, that is about 216 bad minutes in 30 days, or 3.6 hours of total outage.

Why not aim for 100%? The networks and devices between users and your service fail far more often than that, so, as the Google SRE book puts it, a user cannot tell 99.999% from 100%, or 99.99% from 99.999% on a 99% reliable phone. Every extra nine costs far more than the last, and a service can rarely be more reliable than what it depends on. ask-api calls a hosted model; unless you add fallbacks such as a second provider or cached answers, your SLO cannot be stricter than the provider's real reliability.

Measure as close to the user as you can. Server-side metrics, the white-box view from lessons 2 and 3, only count requests that reached your process: requests lost to an expired certificate, a broken load balancer, a DNS error or a crashed pod never appear in them. That is why the SLO for this skill's project is measured by a probe from outside.

An SLO written down for ask-api
service:   ask-api
SLI:       share of synthetic POST /ask probes, sent from outside every 30 s,
           that get HTTP 200 with an "answer" field within 10 s
SLO:       99.5% over a rolling 30 days
budget:    0.5% of probes  =  about 432 of 86,400  =  about 3.6 hours of outage
policy:    budget spent -> freeze risky launches, fix reliability first

03. Measure availability from outside with a probe

A black-box probe sends real requests to the service the way a user would, through public DNS, TLS and the load balancer, and records whether they succeeded. With Prometheus, the usual tool is the blackbox exporter: Prometheus scrapes its /probe endpoint, passing the target URL and a module name; the exporter makes the request and answers with metrics such as probe_success (1 or 0) and probe_duration_seconds. Managed uptime checks from cloud providers do the same job.

The module below probes the endpoint users actually call, POST /ask, and counts a response as success only if it is a 200 whose body contains an answer. A 200 from a health endpoint would prove only that the process is up, not that answering works.

YAML · blackbox.yml (blackbox exporter v0.29)
modules:
  ask_answers:
    prober: http
    timeout: 10s
    http:
      method: POST
      headers:
        Content-Type: application/json
      body: '{"question": "synthetic probe: when are refunds paid?"}'
      valid_status_codes: [200]
      fail_if_body_not_matches_regexp: ['"answer"']
YAML · the Prometheus scrape job that drives the probe
scrape_configs:
  - job_name: probe-ask
    scrape_interval: 30s
    metrics_path: /probe
    params:
      module: [ask_answers]
    static_configs:
      - targets: [https://ask.example.com/ask]   # the public URL users call
    relabel_configs:
      - source_labels: [__address__]     # the URL becomes ?target=...
        target_label: __param_target
      - source_labels: [__param_target]  # ...and the instance label
        target_label: instance
      - target_label: __address__        # while Prometheus scrapes the prober
        replacement: blackbox-exporter:9115
Part of one /probe response against a local ask-api (values vary)
probe_duration_seconds 0.170793697
probe_http_status_code 200
probe_success 1

The relabelling trick is worth reading slowly: Prometheus is told to scrape the exporter, while the URL in targets travels as a query parameter and becomes the instance label. Three practical rules:

  • Run the prober somewhere else: another region, another provider, or at least another network. A prober next to the service shares its failures and stays silent when users are cut off.
  • Mind the cost. Every probe of /ask makes a model call: one every 30 s is 2,880 calls a day. Keep the probe prompt tiny, tag probe traffic (a header or a dedicated API key) so it can be excluded from product analytics, and budget for it.
  • Know the blind spots. A probe sees one path from one place. It misses failures that hit only some users or some inputs, so keep the request-based error ratio from lesson 3 next to it as a second SLI.

04. Burn-rate alerts: page on how fast the budget is going

Two obvious alerts both fail. Error ratio above 0.5% for five minutes pages for blips that cost a sliver of the monthly budget. Budget exhausted fires when it is too late to protect the objective. What you want to know is how fast the budget is being spent.

Burn rate is the observed error ratio divided by the budget ratio. At burn rate 1 the budget runs out exactly at the end of the 30 days. At 14.4, a single hour spends 14.4 / 720 = 2% of the month's budget, and the whole budget is gone in 720 / 14.4 = 50 hours. The Google SRE workbook recommends combining several such alerts, each with a long window that proves the burn is significant and a short window, one twelfth as long, that proves it is still happening and lets the alert clear soon after a fix:

Multi-window, multi-burn-rate alerts for a 30-day SLO
severity  burn rate  long window  short window  budget spent when it fires
page      14.4       1 hour       5 minutes     2% of 30 days
page      6          6 hours      30 minutes    5% of 30 days
ticket    1          3 days       6 hours       10% of 30 days

threshold = burn rate x (1 - SLO);  for 99.5%: 14.4 x 0.005 = 0.072 (7.2% failing)

In PromQL, recording rules compute the share of failed probes over each window once, and each alert combines two of them with and, so both windows must be over the threshold at the same time. The last alert covers the case where the prober itself stops: without data, every burn alert stays silent.

YAML · slo_rules.yml
# SLO: 99.5% of probes of POST /ask succeed over 30 days (error budget 0.5%).
groups:
  - name: ask-availability-slo
    interval: 30s
    rules:
      # Share of failed probes over each window (0 = all good, 1 = all failed).
      - record: job:probe_errors:ratio_5m
        expr: 1 - avg_over_time(probe_success{job="probe-ask"}[5m])
      - record: job:probe_errors:ratio_30m
        expr: 1 - avg_over_time(probe_success{job="probe-ask"}[30m])
      - record: job:probe_errors:ratio_1h
        expr: 1 - avg_over_time(probe_success{job="probe-ask"}[1h])
      - record: job:probe_errors:ratio_6h
        expr: 1 - avg_over_time(probe_success{job="probe-ask"}[6h])
      - record: job:probe_errors:ratio_3d
        expr: 1 - avg_over_time(probe_success{job="probe-ask"}[3d])

      # Page: 2% of the 30-day budget gone in 1 hour (burn rate 14.4).
      - alert: AskAvailabilityFastBurn
        expr: |
          job:probe_errors:ratio_1h > (14.4 * 0.005)
          and
          job:probe_errors:ratio_5m > (14.4 * 0.005)
        labels:
          severity: page
        annotations:
          summary: "ask-api is failing probes fast enough to spend 2% of
            its monthly error budget per hour"
      # Page: 5% of the budget gone in 6 hours (burn rate 6).
      - alert: AskAvailabilityMediumBurn
        expr: |
          job:probe_errors:ratio_6h > (6 * 0.005)
          and
          job:probe_errors:ratio_30m > (6 * 0.005)
        labels:
          severity: page
      # Ticket: 10% of the budget gone in 3 days (burn rate 1).
      - alert: AskAvailabilitySlowBurn
        expr: |
          job:probe_errors:ratio_3d > (1 * 0.005)
          and
          job:probe_errors:ratio_6h > (1 * 0.005)
        labels:
          severity: ticket
      # With no probe data every burn alert stays silent, so alert on silence too.
      - alert: AskProbeDataMissing
        expr: absent_over_time(probe_success{job="probe-ask"}[10m])
        labels:
          severity: ticket

An alert you have never seen fire is a guess. promtool can replay a scripted outage against the rules: two hours of passing probes, then nothing but failures. After three minutes of outage the 1-hour window has only reached 5.8%, below the 7.2% threshold; four minutes in, 9 of the last 120 probes have failed (7.5%), both windows are over the threshold and the page fires.

YAML · slo_test.yml
rule_files: [slo_rules.yml]
evaluation_interval: 30s
tests:
  - interval: 30s
    input_series:
      # Two hours of passing probes, then every probe fails from minute 120.
      - series: 'probe_success{job="probe-ask"}'
        values: '1x239 0x29'
    alert_rule_test:
      - eval_time: 123m
        alertname: AskAvailabilityFastBurn
        exp_alerts: []     # 7 failed probes out of 120 in the last hour: 5.8%
      - eval_time: 124m
        alertname: AskAvailabilityFastBurn
        exp_alerts:        # 9 failed probes out of 120: 7.5%
          - exp_labels:
              severity: page
              job: probe-ask
            exp_annotations:
              summary: "ask-api is failing probes fast enough to spend 2% of
                its monthly error budget per hour"
Terminal · in the folder that holds both files
# promtool ships in the Prometheus release archive (Linux x86-64 shown here).
V=3.16.0; A=prometheus-$V.linux-amd64
curl -sSfLO "https://github.com/prometheus/prometheus/releases/download/v$V/$A.tar.gz"
tar xzf "$A.tar.gz"
"./$A/promtool" test rules slo_test.yml
# Or, with Docker:
# docker run --rm -v "$PWD":/w -w /w --entrypoint promtool \
#   prom/prometheus:v3.16.0 test rules slo_test.yml
Expected output
Processing test file: slo_test.yml
  SUCCESS

05. Symptoms page, causes inform

Notice what the paging rules do not mention: CPU, memory, pod restarts, queue depth, the model provider's status page. Those are causes. They matter for diagnosis and belong on dashboards or in low-priority tickets, but they make poor pages: a saturated CPU may hurt nobody, and the cause that takes you down next is usually one nobody wrote an alert for. Paging on the symptom, users failing to get answers, catches any cause that users can feel, including ones nobody predicted, as long as the SLI can see it (remember the probe's blind spots above).

Alertmanager turns firing alerts into notifications. It routes them by label, so severity="page" reaches the on-call pager and ticket goes to the team's channel; it groups related alerts into one message; it inhibits alerts made redundant by another that is already firing; and it lets you silence alerts for planned maintenance, with an expiry time and a comment saying why.

YAML · alertmanager.yml (checked with amtool, Alertmanager v0.35)
route:
  receiver: team-chat               # anything not matched below
  group_by: [alertname, job]        # one notification per alert and service
  routes:
    - matchers: ['severity="page"']
      receiver: on-call-pager
    - matchers: ['severity="ticket"']
      receiver: team-chat
      repeat_interval: 24h
inhibit_rules:
  # While the fast-burn page fires, hold back the slower page for the same job.
  - source_matchers: ['alertname="AskAvailabilityFastBurn"']
    target_matchers: ['alertname="AskAvailabilityMediumBurn"']
    equal: [job]
receivers:
  - name: on-call-pager
    webhook_configs:
      - url: http://pager-bridge.internal:8080/alert     # placeholder endpoint
  - name: team-chat
    webhook_configs:
      - url: http://chat-bridge.internal:8080/alert      # placeholder endpoint

06. Check your understanding

Practice check · 3 questions

Budgets, windows and probes

Three questions about the alerting design in this lesson.

Q1. ask-api has an availability SLO of 99.5% over 30 days. Failures start and hold steady at a burn rate of 14.4. Roughly how long until the whole error budget is gone?
Q2. In the fast-burn page, what does the 5-minute window add to the 1-hour window?
Q3. Where should the black-box probe behind ask-api's availability SLO run?
Practice only: not graded, not saved, not evidence.

07. Apply it

For your skill project, write the reliability side of the service:

  • an SLO document like the one above, with an availability SLI measured by a probe from outside, and a budget policy your team would accept;
  • a blackbox exporter module that checks the response body, and a scrape job for it;
  • the burn-rate rules with thresholds for your target, plus a promtool test showing that a total outage pages within ten minutes and that a two-minute blip does not page at all;
  • an Alertmanager route that sends pages and tickets to different receivers (a webhook test receiver is enough), and a runbook link on every page.

08. Review prompt

Without looking back: for an SLO of 99.95% over 28 days, work out the error budget in minutes of total outage and the error-ratio threshold of a 14.4 burn-rate alert. Explain why each paging alert needs two windows, why the availability probe should run outside the system, and why CPU above 90% should not page. Then name three things Alertmanager does besides delivering a message.

References

Your progress

Reading state

Sign in to save that you finished reading this lesson.

Sign in to mark reading complete

Prove this skill

8 questions · about 6 minutes · scored automatically. Marking a lesson as read never demonstrates a skill.
Take the skill check