---
source: tests/generate.rs
expression: yaml
---
groups:
- name: slokit-slo-sli-recordings-myservice-requests-availability
  rules:
  - record: slo:sli_error:ratio_rate5m
    expr: |-
      (sum(rate(http_request_duration_seconds_count{job="myservice",code=~"5.."}[5m])))
      /
      (sum(rate(http_request_duration_seconds_count{job="myservice"}[5m])))
    labels:
      owner: team-platform
      sloth_id: myservice-requests-availability
      sloth_service: myservice
      sloth_slo: requests-availability
      sloth_window: 5m
  - record: slo:sli_error:ratio_rate30m
    expr: |-
      (sum(rate(http_request_duration_seconds_count{job="myservice",code=~"5.."}[30m])))
      /
      (sum(rate(http_request_duration_seconds_count{job="myservice"}[30m])))
    labels:
      owner: team-platform
      sloth_id: myservice-requests-availability
      sloth_service: myservice
      sloth_slo: requests-availability
      sloth_window: 30m
  - record: slo:sli_error:ratio_rate1h
    expr: |-
      (sum(rate(http_request_duration_seconds_count{job="myservice",code=~"5.."}[1h])))
      /
      (sum(rate(http_request_duration_seconds_count{job="myservice"}[1h])))
    labels:
      owner: team-platform
      sloth_id: myservice-requests-availability
      sloth_service: myservice
      sloth_slo: requests-availability
      sloth_window: 1h
  - record: slo:sli_error:ratio_rate2h
    expr: |-
      (sum(rate(http_request_duration_seconds_count{job="myservice",code=~"5.."}[2h])))
      /
      (sum(rate(http_request_duration_seconds_count{job="myservice"}[2h])))
    labels:
      owner: team-platform
      sloth_id: myservice-requests-availability
      sloth_service: myservice
      sloth_slo: requests-availability
      sloth_window: 2h
  - record: slo:sli_error:ratio_rate6h
    expr: |-
      (sum(rate(http_request_duration_seconds_count{job="myservice",code=~"5.."}[6h])))
      /
      (sum(rate(http_request_duration_seconds_count{job="myservice"}[6h])))
    labels:
      owner: team-platform
      sloth_id: myservice-requests-availability
      sloth_service: myservice
      sloth_slo: requests-availability
      sloth_window: 6h
  - record: slo:sli_error:ratio_rate1d
    expr: |-
      (sum(rate(http_request_duration_seconds_count{job="myservice",code=~"5.."}[1d])))
      /
      (sum(rate(http_request_duration_seconds_count{job="myservice"}[1d])))
    labels:
      owner: team-platform
      sloth_id: myservice-requests-availability
      sloth_service: myservice
      sloth_slo: requests-availability
      sloth_window: 1d
  - record: slo:sli_error:ratio_rate3d
    expr: |-
      (sum(rate(http_request_duration_seconds_count{job="myservice",code=~"5.."}[3d])))
      /
      (sum(rate(http_request_duration_seconds_count{job="myservice"}[3d])))
    labels:
      owner: team-platform
      sloth_id: myservice-requests-availability
      sloth_service: myservice
      sloth_slo: requests-availability
      sloth_window: 3d
  - record: slo:sli_error:ratio_rate30d
    expr: |-
      sum_over_time(slo:sli_error:ratio_rate5m{sloth_id="myservice-requests-availability", sloth_service="myservice", sloth_slo="requests-availability"}[30d])
      /
      count_over_time(slo:sli_error:ratio_rate5m{sloth_id="myservice-requests-availability", sloth_service="myservice", sloth_slo="requests-availability"}[30d])
    labels:
      owner: team-platform
      sloth_id: myservice-requests-availability
      sloth_service: myservice
      sloth_slo: requests-availability
      sloth_window: 30d
- name: slokit-slo-meta-recordings-myservice-requests-availability
  rules:
  - record: slo:objective:ratio
    expr: vector(0.999)
    labels:
      owner: team-platform
      sloth_id: myservice-requests-availability
      sloth_service: myservice
      sloth_slo: requests-availability
  - record: slo:error_budget:ratio
    expr: vector(0.001)
    labels:
      owner: team-platform
      sloth_id: myservice-requests-availability
      sloth_service: myservice
      sloth_slo: requests-availability
  - record: slo:time_period:days
    expr: vector(30)
    labels:
      owner: team-platform
      sloth_id: myservice-requests-availability
      sloth_service: myservice
      sloth_slo: requests-availability
  - record: slo:current_burn_rate:ratio
    expr: |-
      slo:sli_error:ratio_rate5m{sloth_id="myservice-requests-availability", sloth_service="myservice", sloth_slo="requests-availability"}
      / on(sloth_id, sloth_slo, sloth_service) group_left
      slo:error_budget:ratio{sloth_id="myservice-requests-availability", sloth_service="myservice", sloth_slo="requests-availability"}
    labels:
      owner: team-platform
      sloth_id: myservice-requests-availability
      sloth_service: myservice
      sloth_slo: requests-availability
  - record: slo:period_burn_rate:ratio
    expr: |-
      slo:sli_error:ratio_rate30d{sloth_id="myservice-requests-availability", sloth_service="myservice", sloth_slo="requests-availability"}
      / on(sloth_id, sloth_slo, sloth_service) group_left
      slo:error_budget:ratio{sloth_id="myservice-requests-availability", sloth_service="myservice", sloth_slo="requests-availability"}
    labels:
      owner: team-platform
      sloth_id: myservice-requests-availability
      sloth_service: myservice
      sloth_slo: requests-availability
  - record: slo:period_error_budget_remaining:ratio
    expr: 1 - slo:period_burn_rate:ratio{sloth_id="myservice-requests-availability", sloth_service="myservice", sloth_slo="requests-availability"}
    labels:
      owner: team-platform
      sloth_id: myservice-requests-availability
      sloth_service: myservice
      sloth_slo: requests-availability
  - record: slo:info
    expr: vector(1)
    labels:
      owner: team-platform
      sloth_id: myservice-requests-availability
      sloth_mode: cli-gen-prometheus
      sloth_objective: '99.9'
      sloth_service: myservice
      sloth_slo: requests-availability
      sloth_spec: prometheus/v1
      sloth_version: [VERSION]
- name: slokit-slo-alerts-myservice-requests-availability
  rules:
  - alert: MyServiceHighErrorRate
    expr: |-
      (
        max(slo:sli_error:ratio_rate1h{sloth_id="myservice-requests-availability", sloth_service="myservice", sloth_slo="requests-availability"} > (14.4 * 0.001)) without (sloth_window)
        and
        max(slo:sli_error:ratio_rate5m{sloth_id="myservice-requests-availability", sloth_service="myservice", sloth_slo="requests-availability"} > (14.4 * 0.001)) without (sloth_window)
      )
      or
      (
        max(slo:sli_error:ratio_rate6h{sloth_id="myservice-requests-availability", sloth_service="myservice", sloth_slo="requests-availability"} > (6 * 0.001)) without (sloth_window)
        and
        max(slo:sli_error:ratio_rate30m{sloth_id="myservice-requests-availability", sloth_service="myservice", sloth_slo="requests-availability"} > (6 * 0.001)) without (sloth_window)
      )
    labels:
      severity: page
      sloth_severity: page
    annotations:
      runbook: https://runbooks.example.com/myservice
      summary: 'page burn-rate alert: SLO ''requests-availability'' on service ''myservice'' is consuming its error budget too fast'
  - alert: MyServiceHighErrorRate
    expr: |-
      (
        max(slo:sli_error:ratio_rate1d{sloth_id="myservice-requests-availability", sloth_service="myservice", sloth_slo="requests-availability"} > (3 * 0.001)) without (sloth_window)
        and
        max(slo:sli_error:ratio_rate2h{sloth_id="myservice-requests-availability", sloth_service="myservice", sloth_slo="requests-availability"} > (3 * 0.001)) without (sloth_window)
      )
      or
      (
        max(slo:sli_error:ratio_rate3d{sloth_id="myservice-requests-availability", sloth_service="myservice", sloth_slo="requests-availability"} > (1 * 0.001)) without (sloth_window)
        and
        max(slo:sli_error:ratio_rate6h{sloth_id="myservice-requests-availability", sloth_service="myservice", sloth_slo="requests-availability"} > (1 * 0.001)) without (sloth_window)
      )
    labels:
      severity: ticket
      sloth_severity: ticket
    annotations:
      runbook: https://runbooks.example.com/myservice
      summary: 'ticket burn-rate alert: SLO ''requests-availability'' on service ''myservice'' is consuming its error budget too fast'
- name: slokit-slo-sli-recordings-myservice-requests-latency
  rules:
  - record: slo:sli_error:ratio_rate5m
    expr: |-
      1 - (
        sum(rate(http_request_duration_seconds_bucket{job="myservice", le="0.3"}[5m]))
        /
        sum(rate(http_request_duration_seconds_count{job="myservice"}[5m]))
      )
    labels:
      owner: team-platform
      sloth_id: myservice-requests-latency
      sloth_service: myservice
      sloth_slo: requests-latency
      sloth_window: 5m
  - record: slo:sli_error:ratio_rate30m
    expr: |-
      1 - (
        sum(rate(http_request_duration_seconds_bucket{job="myservice", le="0.3"}[30m]))
        /
        sum(rate(http_request_duration_seconds_count{job="myservice"}[30m]))
      )
    labels:
      owner: team-platform
      sloth_id: myservice-requests-latency
      sloth_service: myservice
      sloth_slo: requests-latency
      sloth_window: 30m
  - record: slo:sli_error:ratio_rate1h
    expr: |-
      1 - (
        sum(rate(http_request_duration_seconds_bucket{job="myservice", le="0.3"}[1h]))
        /
        sum(rate(http_request_duration_seconds_count{job="myservice"}[1h]))
      )
    labels:
      owner: team-platform
      sloth_id: myservice-requests-latency
      sloth_service: myservice
      sloth_slo: requests-latency
      sloth_window: 1h
  - record: slo:sli_error:ratio_rate2h
    expr: |-
      1 - (
        sum(rate(http_request_duration_seconds_bucket{job="myservice", le="0.3"}[2h]))
        /
        sum(rate(http_request_duration_seconds_count{job="myservice"}[2h]))
      )
    labels:
      owner: team-platform
      sloth_id: myservice-requests-latency
      sloth_service: myservice
      sloth_slo: requests-latency
      sloth_window: 2h
  - record: slo:sli_error:ratio_rate6h
    expr: |-
      1 - (
        sum(rate(http_request_duration_seconds_bucket{job="myservice", le="0.3"}[6h]))
        /
        sum(rate(http_request_duration_seconds_count{job="myservice"}[6h]))
      )
    labels:
      owner: team-platform
      sloth_id: myservice-requests-latency
      sloth_service: myservice
      sloth_slo: requests-latency
      sloth_window: 6h
  - record: slo:sli_error:ratio_rate1d
    expr: |-
      1 - (
        sum(rate(http_request_duration_seconds_bucket{job="myservice", le="0.3"}[1d]))
        /
        sum(rate(http_request_duration_seconds_count{job="myservice"}[1d]))
      )
    labels:
      owner: team-platform
      sloth_id: myservice-requests-latency
      sloth_service: myservice
      sloth_slo: requests-latency
      sloth_window: 1d
  - record: slo:sli_error:ratio_rate3d
    expr: |-
      1 - (
        sum(rate(http_request_duration_seconds_bucket{job="myservice", le="0.3"}[3d]))
        /
        sum(rate(http_request_duration_seconds_count{job="myservice"}[3d]))
      )
    labels:
      owner: team-platform
      sloth_id: myservice-requests-latency
      sloth_service: myservice
      sloth_slo: requests-latency
      sloth_window: 3d
  - record: slo:sli_error:ratio_rate30d
    expr: |-
      sum_over_time(slo:sli_error:ratio_rate5m{sloth_id="myservice-requests-latency", sloth_service="myservice", sloth_slo="requests-latency"}[30d])
      /
      count_over_time(slo:sli_error:ratio_rate5m{sloth_id="myservice-requests-latency", sloth_service="myservice", sloth_slo="requests-latency"}[30d])
    labels:
      owner: team-platform
      sloth_id: myservice-requests-latency
      sloth_service: myservice
      sloth_slo: requests-latency
      sloth_window: 30d
- name: slokit-slo-meta-recordings-myservice-requests-latency
  rules:
  - record: slo:objective:ratio
    expr: vector(0.995)
    labels:
      owner: team-platform
      sloth_id: myservice-requests-latency
      sloth_service: myservice
      sloth_slo: requests-latency
  - record: slo:error_budget:ratio
    expr: vector(0.005)
    labels:
      owner: team-platform
      sloth_id: myservice-requests-latency
      sloth_service: myservice
      sloth_slo: requests-latency
  - record: slo:time_period:days
    expr: vector(30)
    labels:
      owner: team-platform
      sloth_id: myservice-requests-latency
      sloth_service: myservice
      sloth_slo: requests-latency
  - record: slo:current_burn_rate:ratio
    expr: |-
      slo:sli_error:ratio_rate5m{sloth_id="myservice-requests-latency", sloth_service="myservice", sloth_slo="requests-latency"}
      / on(sloth_id, sloth_slo, sloth_service) group_left
      slo:error_budget:ratio{sloth_id="myservice-requests-latency", sloth_service="myservice", sloth_slo="requests-latency"}
    labels:
      owner: team-platform
      sloth_id: myservice-requests-latency
      sloth_service: myservice
      sloth_slo: requests-latency
  - record: slo:period_burn_rate:ratio
    expr: |-
      slo:sli_error:ratio_rate30d{sloth_id="myservice-requests-latency", sloth_service="myservice", sloth_slo="requests-latency"}
      / on(sloth_id, sloth_slo, sloth_service) group_left
      slo:error_budget:ratio{sloth_id="myservice-requests-latency", sloth_service="myservice", sloth_slo="requests-latency"}
    labels:
      owner: team-platform
      sloth_id: myservice-requests-latency
      sloth_service: myservice
      sloth_slo: requests-latency
  - record: slo:period_error_budget_remaining:ratio
    expr: 1 - slo:period_burn_rate:ratio{sloth_id="myservice-requests-latency", sloth_service="myservice", sloth_slo="requests-latency"}
    labels:
      owner: team-platform
      sloth_id: myservice-requests-latency
      sloth_service: myservice
      sloth_slo: requests-latency
  - record: slo:info
    expr: vector(1)
    labels:
      owner: team-platform
      sloth_id: myservice-requests-latency
      sloth_mode: cli-gen-prometheus
      sloth_objective: '99.5'
      sloth_service: myservice
      sloth_slo: requests-latency
      sloth_spec: prometheus/v1
      sloth_version: [VERSION]
- name: slokit-slo-alerts-myservice-requests-latency
  rules:
  - alert: requests-latency
    expr: |-
      (
        max(slo:sli_error:ratio_rate1h{sloth_id="myservice-requests-latency", sloth_service="myservice", sloth_slo="requests-latency"} > (14.4 * 0.005)) without (sloth_window)
        and
        max(slo:sli_error:ratio_rate5m{sloth_id="myservice-requests-latency", sloth_service="myservice", sloth_slo="requests-latency"} > (14.4 * 0.005)) without (sloth_window)
      )
      or
      (
        max(slo:sli_error:ratio_rate6h{sloth_id="myservice-requests-latency", sloth_service="myservice", sloth_slo="requests-latency"} > (6 * 0.005)) without (sloth_window)
        and
        max(slo:sli_error:ratio_rate30m{sloth_id="myservice-requests-latency", sloth_service="myservice", sloth_slo="requests-latency"} > (6 * 0.005)) without (sloth_window)
      )
    labels:
      severity: page
      sloth_severity: page
    annotations:
      summary: 'page burn-rate alert: SLO ''requests-latency'' on service ''myservice'' is consuming its error budget too fast'
  - alert: requests-latency
    expr: |-
      (
        max(slo:sli_error:ratio_rate1d{sloth_id="myservice-requests-latency", sloth_service="myservice", sloth_slo="requests-latency"} > (3 * 0.005)) without (sloth_window)
        and
        max(slo:sli_error:ratio_rate2h{sloth_id="myservice-requests-latency", sloth_service="myservice", sloth_slo="requests-latency"} > (3 * 0.005)) without (sloth_window)
      )
      or
      (
        max(slo:sli_error:ratio_rate3d{sloth_id="myservice-requests-latency", sloth_service="myservice", sloth_slo="requests-latency"} > (1 * 0.005)) without (sloth_window)
        and
        max(slo:sli_error:ratio_rate6h{sloth_id="myservice-requests-latency", sloth_service="myservice", sloth_slo="requests-latency"} > (1 * 0.005)) without (sloth_window)
      )
    labels:
      severity: ticket
      sloth_severity: ticket
    annotations:
      summary: 'ticket burn-rate alert: SLO ''requests-latency'' on service ''myservice'' is consuming its error budget too fast'
