TExcelTAD
Home › Site Reliability Engineering: SLOs, Incidents & Chaos › Toolkit: Sloth, Pyrra, OpenSLO, k6 & Incident Tools

Toolkit: Sloth, Pyrra, OpenSLO, k6 & Incident Tools

Writing burn-rate rules by hand, as in Burn-Rate Alert Rules, teaches how they work. In production most teams generate them, run load tests with a dedicated tool, and handle incidents in a dedicated product. This lesson is a field guide; none of these tools is in this course's image, so their sessions are samples. Check each project's documentation for the version you use.

How an SLO generator works

Every SLO generator does the same thing: read a short SLO spec, emit recording rules for each window and the multi-window, multi-burn-rate alerts. The session builds a tiny one (yq turns the YAML spec into JSON, about 20 lines of Python write the rules) and checks its output with promtool:

bash · try it yourself
cat > slo.yaml <<'YML'
service: checkout
objective: 99.9
errors: http_requests_total{job="checkout",code=~"5.."}
total: http_requests_total{job="checkout"}
YML
cat > slo-gen.py <<'PY'
import json, sys
spec = json.load(open(sys.argv[1]))
budget = round(1 - spec["objective"] / 100, 6)
windows = ["5m", "30m", "1h", "2h", "6h", "1d", "3d"]
alerts = {"page": [("1h", "5m", 14.4), ("6h", "30m", 6)], "ticket": [("1d", "2h", 3), ("3d", "6h", 1)]}
name = lambda w: f"slo:sli_error:ratio_rate{w}"
out = ["groups:", f"  - name: slo-{spec['service']}", "    rules:"]
for w in windows:
    out += [f"      - record: {name(w)}",
            f"        expr: sum(rate({spec['errors']}[{w}])) / sum(rate({spec['total']}[{w}]))",
            f"        labels: {{service: {spec['service']}}}"]
for severity, rules in alerts.items():
    expr = " or ".join(f"({name(l)} > {b} * {budget} and {name(s)} > {b} * {budget})" for l, s, b in rules)
    out += [f"      - alert: {spec['service'].capitalize()}ErrorBudgetBurn",
            f"        expr: {expr}",
            f"        labels: {{severity: {severity}}}"]
print("\n".join(out))
PY
yq -o=json slo.yaml > slo.json
python3 slo-gen.py slo.json > rules.yml
promtool check rules rules.yml
grep -c 'record:' rules.yml
grep 'alert:' -A1 rules.yml | grep 'expr' | head -1 | cut -c1-110
Checking rules.yml
  SUCCESS: 9 rules found

7
        expr: (slo:sli_error:ratio_rate1h > 14.4 * 0.001 and slo:sli_error:ratio_rate5m > 14.4 * 0.001) or (sl

Real generators add what this sketch leaves out: per-SLO labels on every rule, an error-budget-remaining rule, optimised long windows, metadata for dashboards, latency SLIs from histograms, and validation of the spec.

Sloth

Sloth generates Prometheus rules from a short SLO spec, as a CLI or a Kubernetes controller (there, the same content is a PrometheusServiceLevel resource with camelCase keys). A CLI spec (sample):

yaml
version: "prometheus/v1"
service: "checkout"
labels:
  team: payments
slos:
  - name: "requests-availability"
    objective: 99.9
    description: "Checkout requests succeed."
    sli:
      events:
        error_query: sum(rate(http_requests_total{job="checkout",code=~"5.."}[{{.window}}]))
        total_query: sum(rate(http_requests_total{job="checkout"}[{{.window}}]))
    alerting:
      name: CheckoutAvailabilityBurn
      annotations:
        runbook_url: https://runbooks.example.com/checkout/error-budget-burn
      page_alert:
        labels: {severity: page}
      ticket_alert:
        labels: {severity: ticket}
bash
# sample session
$ sloth generate -i checkout-slo.yaml -o checkout-rules.yaml
$ promtool check rules checkout-rules.yaml
Checking checkout-rules.yaml
  SUCCESS: … rules found

{{.window}} is replaced by each window Sloth needs. Its defaults follow the workbook's windows and burn rates.

Pyrra

Pyrra defines SLOs as a Kubernetes resource and adds a web UI that lists SLOs with their remaining budget and burn rate graphs. It generates multi-window burn-rate alerts too (sample):

yaml
apiVersion: pyrra.dev/v1alpha1
kind: ServiceLevelObjective
metadata:
  name: checkout-availability
  namespace: monitoring
spec:
  target: "99.9"
  window: 4w
  indicator:
    ratio:
      errors:
        metric: http_requests_total{job="checkout",code=~"5.."}
      total:
        metric: http_requests_total{job="checkout"}

OpenSLO and vendor SLOs

OpenSLO is a vendor-neutral YAML specification for SLOs (apiVersion: openslo/v1, kinds such as SLO, SLI, Service, AlertPolicy); some tools import or export it. Managed platforms have their own SLO features: Grafana Cloud SLOs, Google Cloud Monitoring SLOs, Datadog and New Relic service levels. They save work, but keep the SLO definitions in version control either way.

Load testing

Tool Notes
k6 (Grafana) scripts in JavaScript, arrival-rate executors, thresholds that fail the run when the SLO is missed; example in Capacity Planning
Vegeta constant-rate HTTP attacks from the command line, good for quick checks
Locust Python scripts, user-behaviour models
Gatling, JMeter JVM-based, common in enterprises
bash
# sample session: a constant 200 rps for 30 s with Vegeta
$ echo "GET https://checkout.staging.example.com/healthz" | vegeta attack -rate=200 -duration=30s | vegeta report

Chaos tools

Chaos Mesh and LitmusChaos for Kubernetes (Chaos Mesh & LitmusChaos); AWS Fault Injection Service and Azure Chaos Studio for cloud resources; Toxiproxy for network faults in tests; Gremlin as a commercial platform.

Incident management tools

Need Examples
paging, schedules, escalation PagerDuty, Grafana IRM (OnCall), Atlassian's on-call features (Opsgenie is being folded into Jira Service Management and Compass), Splunk On-Call
incident workflow in chat (channels, roles, timelines, postmortem drafts) incident.io, FireHydrant, Rootly, PagerDuty's incident workflows
status pages Atlassian Statuspage, incident.io status pages, Instatus, self-hosted options
postmortem tracking the incident tool, or plain documents plus tickets

Whichever you pick: the paging tool must be reachable when your own infrastructure isn't (don't host it on the cluster it monitors), and schedules, escalation policies and integrations should be managed as code where the tool allows it (for example with its Terraform provider).

Test yourself

What does an SLO generator such as Sloth produce from a short spec?

  1. Dashboards only
  2. Recording rules for each window and multi-window, multi-burn-rate alert rules
  3. Load tests
  4. Postmortems

What is {{.window}} in a Sloth SLI query?

  1. A Helm value
  2. A placeholder Sloth replaces with each window it needs (5m, 30m, 1h, …)
  3. A Prometheus function
  4. A Go comment

Why shouldn't the paging tool run on the cluster it monitors?

  1. Licensing
  2. If the cluster fails, the pages about it would fail too
  3. Performance
  4. It is not allowed by Kubernetes