Slos error budgets google sre

From CraftOS-dev/craftbot-agent-bundles · View interactive version

Slos error budgets google sre is an AI agent skill from the GitHub repository CraftOS-dev/craftbot-agent-bundles. Source: https://sre.google/workbook/implementing-slos/ · https://sloth.dev/ · https://github.com/pyrra-dev/pyrra

How to use this skill

Skill file

<!--

Source: https://sre.google/workbook/implementing-slos/ · https://sloth.dev/ · https://github.com/pyrra-dev/pyrra

Authored: June 2026 for the devops-engineer agent bundle.

-->

SLOs + Error Budgets (Google SRE)

Define service-level objectives (SLOs), generate Prometheus recording +

alerting rules via Sloth or Pyrra, set up multi-window

multi-burn-rate alerts, and use error budgets to govern release pace.

Follows the Google SRE Workbook framework.

When to use

budget-based alerting.

Skip when: service has <100 req/day (statistical SLOs are noisy); the system

is an experiment or alpha (no SLO commitment).

Setup

brew install slok/repo/sloth                                  # Sloth (SLO generator)
# OR via Docker
docker pull ghcr.io/slok/sloth:v0.11.0

# Pyrra (K8s-native SLO operator)
kubectl apply -f https://github.com/pyrra-dev/pyrra/releases/latest/download/manifests.yaml

# Nobl9 — managed alternative (paid)
brew install nobl9/tools/sloctl
sloctl config add-context prod

No API key needed for Sloth/Pyrra; both run against Prometheus + AlertManager.

Common recipes

Recipe 1 — Define an SLI (the measurable signal)

The SLI must be from the user's perspective. For an HTTP API:

Avoid "CPU is below 80%" — that's not what users feel.

Recipe 2 — Sloth spec (single SLO)

# slos/api.yaml
version: prometheus/v1
service: api
labels:
  team: platform
slos:
  - name: requests-availability
    objective: 99.9       # over 30d (default time window)
    description: "99.9% of requests succeed (non-5xx)"
    sli:
      events:
        error_query: |
          sum(rate(http_requests_total{service="api",status=~"5.."}[{{.window}}]))
        total_query: |
          sum(rate(http_requests_total{service="api"}[{{.window}}]))
    alerting:
      name: ApiHighErrorRate
      labels: { team: platform }
      annotations:
        summary: "API error rate burning SLO budget"
        runbook_url: "https://github.com/myorg/runbooks/api/availability.md"
      page_alert:
        labels: { severity: critical }
      ticket_alert:
        labels: { severity: warning }
sloth generate -i slos/api.yaml -o prometheus-rules/api.yaml
sloth validate -i slos/api.yaml
kubectl apply -f prometheus-rules/api.yaml -n monitoring

Sloth emits recording rules for SLI + budget + burn rate, plus

alerting rules for multi-window multi-burn-rate.

Recipe 3 — Multi-window multi-burn-rate (the Google pattern)

| Burn rate | Long window | Short window | Page/Ticket |

|---|---|---|---|

| 14.4× | 1h | 5m | Page |

| 6× | 6h | 30m | Page |

| 3× | 24h | 2h | Ticket |

| 1× | 72h | 6h | Ticket |

A page fires only when BOTH the long and short windows confirm — kills

false positives from blips. Sloth/Pyrra generate this automatically.

Math: burn rate = (actual_error_rate / (1 - SLO)) — i.e. how many "SLOs

worth" of budget is consumed per hour. At 14.4×, you burn 30 days of budget

in ~2 hours.

Recipe 4 — Latency SLI (histogram_quantile)

slos:
  - name: requests-latency-p99
    objective: 99
    description: "99% of requests under 200ms"
    sli:
      events:
        error_query: |
          sum(rate(http_request_duration_seconds_bucket{service="api",le="0.2"}[{{.window}}]))
        total_query: |
          sum(rate(http_request_duration_seconds_count{service="api"}[{{.window}}]))
        # NOTE: error_query is "good events" here; Sloth handles the inversion

Pattern: rate(*_bucket{le="THRESHOLD"}) counts requests faster than the

threshold; divide by total. SLI = "fraction fast enough".

Recipe 5 — Pyrra (K8s-native SLO CRD)

apiVersion: pyrra.dev/v1alpha1
kind: ServiceLevelObjective
metadata: { name: api-availability, namespace: prod }
spec:
  target: "99.9"
  window: 28d
  description: "99.9% of API requests succeed"
  indicator:
    ratio:
      errors:
        metric: http_requests_total{service="api",status=~"5.."}
      total:
        metric: http_requests_total{service="api"}
  alerting:
    name: ApiAvailability
    labels: { team: platform }
kubectl apply -f api-slo.yaml
kubectl get servicelevelobjective -n prod
# Pyrra reconciles → PrometheusRules created automatically

Pyrra has a UI: kubectl port-forward -n pyrra svc/pyrra-api-frontend 9099:9099.

Recipe 6 — Recording rules (efficient SLI)

Without recording rules, every alert evaluation re-runs the SLI query. With

them, the SLI is cached. Sloth/Pyrra generate these.

groups:
  - name: api.slos
    rules:
      - record: slo:sli_error:rate5m
        expr: |
          sum(rate(http_requests_total{service="api",status=~"5.."}[5m]))
          /
          sum(rate(http_requests_total{service="api"}[5m]))
        labels: { service: api, slo: requests-availability }
      - record: slo:error_budget:remaining
        expr: |
          1 - (slo:sli_error:rate30d / 0.001)    # 0.001 = (1 - 0.999) for 99.9%
        labels: { service: api, slo: requests-availability }

Recipe 7 — Error budget policy (markdown sibling to code)

# Error Budget Policy — api service

**SLO:** 99.9% availability over rolling 30 days
**Budget:** 0.1% × 30d = ~43 minutes of downtime per month

## Policy

- **Budget > 50% remaining (healthy):** Ship features at normal pace.
- **Budget 20-50% remaining (watch):** Slow risky changes; add canaries.
- **Budget 0-20% remaining (depleted):** Freeze non-essential feature
  releases. Only reliability work + critical bug fixes.
- **Budget exhausted (negative):** Full release freeze. Postmortem
  required. SLO breach reported to leadership.

## Review

- Quarterly SLO review on the second Tuesday.
- Targets that page rarely → too generous; tighten.
- Targets that page constantly → too aggressive; loosen or change SLI.

Recipe 8 — Alert annotations

alerting:
  page_alert:
    annotations:
      summary: "API burning error budget at {{ .Labels.burn_rate }}x rate"
      description: |
        Service {{ .Labels.service }} is consuming error budget at
        {{ .Labels.burn_rate }}× the sustainable rate (target {{ .Labels.objective }}%).
      runbook_url: "https://github.com/myorg/runbooks/api/{{ .Labels.slo }}.md"
      dashboard_url: "https://grafana.myorg.com/d/api-slo"

runbook_url is mandatory — paging without a runbook is paging into the void.

Recipe 9 — Grafana SLO dashboard

# Current 30d budget remaining
slo:error_budget:remaining{service="api", slo="requests-availability"}

# Burn rate over time
slo:sli_error:rate1h / 0.001

# Time-to-exhaustion at current burn
((1 - slo:sli_error:rate30d / 0.001) * 30 * 24) / (slo:sli_error:rate1h / 0.001)

Grafana dashboard JSON example: https://grafana.com/grafana/dashboards/14348

Recipe 10 — Test the alert (fault injection)

# Inject errors via a feature flag or canary
kubectl set env deployment/api -n prod ERROR_INJECT_RATE=0.1

# Watch
kubectl logs -n monitoring -l app=alertmanager -f
# Expect 14.4× page after ~5min

Restore: kubectl set env deployment/api ERROR_INJECT_RATE=0 -n prod.

Recipe 11 — Validate Sloth spec in CI

# .github/workflows/slos.yml
- name: Validate SLO specs
  run: |
    for f in slos/*.yaml; do
      docker run --rm -v $PWD:/work -w /work ghcr.io/slok/sloth:v0.11.0 validate -i $f
    done
- name: Generate PrometheusRules
  run: docker run --rm -v $PWD:/work -w /work ghcr.io/slok/sloth:v0.11.0 generate -i slos/ -o prometheus-rules/
- name: Confirm rules differ
  run: git diff --exit-code prometheus-rules/

PR fails if generated rules are out of sync with the spec.

Recipe 12 — Nobl9 (managed alternative)

# slo-api.yaml — Nobl9 declarative
apiVersion: n9/v1alpha
kind: SLO
metadata: { name: api-availability, project: production }
spec:
  service: api
  budgetingMethod: Occurrences
  objectives:
    - target: 0.999
      timeSliceWindow: 30d
  indicator:
    metricSource: { name: prometheus, kind: Agent }
    rawMetric:
      query: "sum(rate(http_requests_total{service='api',status!~'5..'}[1m])) / sum(rate(http_requests_total{service='api'}[1m]))"
sloctl apply -f slo-api.yaml
sloctl get slos

Examples

Example 1 — First SLO for new API service

Goal: Define + ship "99.9% availability over 30d" SLO.

  1. Confirm metric exists: http_requests_total{service="api",status="..."}.
  2. Author Sloth spec (Recipe 2).
  3. sloth generate -i api.yaml -o rules.yaml.
  4. kubectl apply -f rules.yaml -n monitoring.
  5. Sanity check Prometheus:

slo:sli_error:rate5m{service="api"} should evaluate.

  1. Author runbook at runbooks/api/availability.md.
  2. Commit + PR; review with on-call.

Result: Multi-burn-rate alerts live; runbook linked from each alert.

Example 2 — Convert latency thresholds to a real SLO

Goal: Replace latency > 1s alert (noisy) with budget-based one.

  1. Identify percentile: "99% of requests under 200ms over 7d".
  2. Confirm histogram exists: http_request_duration_seconds_bucket{le="0.2"}.
  3. Sloth spec (Recipe 4) — latency SLO with objective: 99, time_window: 7d.
  4. Generate + apply rules.
  5. Compare alert volume in Alertmanager over 1 week: expect 80%+ noise drop.

Result: Pages only when budget is at sustained risk.

Edge cases / gotchas

"requests served successfully" is.

a 99% SLO have very different burn rates for the same error rate.

Prometheus retains 14d locally, use Mimir/Thanos remote_write.

SLI ratio NaN. Sloth handles via slo:sli_error:absent; verify.

per-instance SLO unless each is independently user-facing.

debounce.

fire once the budget is already spent.

policy must account for "shared fate" — Google SRE recommends a separate

"vendor incident" tag rather than counting against budget.

cost extra; useful as a redundancy SLI.

kubectl edit is overwritten.

SLOs nobody talks about become decoration.

Sources

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.