Getting started

# This example shows the same example as getting-started.yml but using OpenSLO spec.
# It will generate the Prometheus rules in a Prometheus rules format.
#
# `sloth generate -i ./examples/openslo-getting-started.yml`
#
apiVersion: openslo/v1alpha
kind: SLO
metadata:
  name: sloth-slo-my-service
  displayName: Requests Availability
spec:
  service: my-service
  description: "Common SLO based on availability for HTTP request responses."
  budgetingMethod: Occurrences
  objectives:
    - ratioMetrics:
        good:
          source: prometheus
          queryType: promql
          query: sum(rate(http_request_duration_seconds_count{job="myservice",code!~"(5..|429)"}[{{.window}}]))
        total:
          source: prometheus
          queryType: promql
          query: sum(rate(http_request_duration_seconds_count{job="myservice"}[{{.window}}]))
      target: 0.999
  timeWindows:
    - count: 30
      unit: Day
---
# Code generated by Sloth (dev): https://github.com/slok/sloth.
# DO NOT EDIT.

groups:
- name: sloth-slo-sli-recordings-my-service-sloth-slo-my-service-0
  rules:
  - record: slo:sli_error:ratio_rate5m
    expr: |-
      (
        1 - (
          (
            sum(rate(http_request_duration_seconds_count{job="myservice",code!~"(5..|429)"}[5m]))
          )
          /
          (
            sum(rate(http_request_duration_seconds_count{job="myservice"}[5m]))
          )
        )
      )
    labels:
      cmd: examplesgen.sh
      sloth_id: my-service-sloth-slo-my-service-0
      sloth_service: my-service
      sloth_slo: sloth-slo-my-service-0
      sloth_window: 5m
  - record: slo:sli_error:ratio_rate30m
    expr: |-
      (
        1 - (
          (
            sum(rate(http_request_duration_seconds_count{job="myservice",code!~"(5..|429)"}[30m]))
          )
          /
          (
            sum(rate(http_request_duration_seconds_count{job="myservice"}[30m]))
          )
        )
      )
    labels:
      cmd: examplesgen.sh
      sloth_id: my-service-sloth-slo-my-service-0
      sloth_service: my-service
      sloth_slo: sloth-slo-my-service-0
      sloth_window: 30m
  - record: slo:sli_error:ratio_rate1h
    expr: |-
      (
        1 - (
          (
            sum(rate(http_request_duration_seconds_count{job="myservice",code!~"(5..|429)"}[1h]))
          )
          /
          (
            sum(rate(http_request_duration_seconds_count{job="myservice"}[1h]))
          )
        )
      )
    labels:
      cmd: examplesgen.sh
      sloth_id: my-service-sloth-slo-my-service-0
      sloth_service: my-service
      sloth_slo: sloth-slo-my-service-0
      sloth_window: 1h
  - record: slo:sli_error:ratio_rate2h
    expr: |-
      (
        1 - (
          (
            sum(rate(http_request_duration_seconds_count{job="myservice",code!~"(5..|429)"}[2h]))
          )
          /
          (
            sum(rate(http_request_duration_seconds_count{job="myservice"}[2h]))
          )
        )
      )
    labels:
      cmd: examplesgen.sh
      sloth_id: my-service-sloth-slo-my-service-0
      sloth_service: my-service
      sloth_slo: sloth-slo-my-service-0
      sloth_window: 2h
  - record: slo:sli_error:ratio_rate6h
    expr: |-
      (
        1 - (
          (
            sum(rate(http_request_duration_seconds_count{job="myservice",code!~"(5..|429)"}[6h]))
          )
          /
          (
            sum(rate(http_request_duration_seconds_count{job="myservice"}[6h]))
          )
        )
      )
    labels:
      cmd: examplesgen.sh
      sloth_id: my-service-sloth-slo-my-service-0
      sloth_service: my-service
      sloth_slo: sloth-slo-my-service-0
      sloth_window: 6h
  - record: slo:sli_error:ratio_rate1d
    expr: |-
      (
        1 - (
          (
            sum(rate(http_request_duration_seconds_count{job="myservice",code!~"(5..|429)"}[1d]))
          )
          /
          (
            sum(rate(http_request_duration_seconds_count{job="myservice"}[1d]))
          )
        )
      )
    labels:
      cmd: examplesgen.sh
      sloth_id: my-service-sloth-slo-my-service-0
      sloth_service: my-service
      sloth_slo: sloth-slo-my-service-0
      sloth_window: 1d
  - record: slo:sli_error:ratio_rate3d
    expr: |-
      (
        1 - (
          (
            sum(rate(http_request_duration_seconds_count{job="myservice",code!~"(5..|429)"}[3d]))
          )
          /
          (
            sum(rate(http_request_duration_seconds_count{job="myservice"}[3d]))
          )
        )
      )
    labels:
      cmd: examplesgen.sh
      sloth_id: my-service-sloth-slo-my-service-0
      sloth_service: my-service
      sloth_slo: sloth-slo-my-service-0
      sloth_window: 3d
  - record: slo:sli_error:ratio_rate30d
    expr: |
      sum_over_time(slo:sli_error:ratio_rate5m{sloth_id="my-service-sloth-slo-my-service-0", sloth_service="my-service", sloth_slo="sloth-slo-my-service-0"}[30d])
      / ignoring (sloth_window)
      count_over_time(slo:sli_error:ratio_rate5m{sloth_id="my-service-sloth-slo-my-service-0", sloth_service="my-service", sloth_slo="sloth-slo-my-service-0"}[30d])
    labels:
      sloth_window: 30d
- name: sloth-slo-meta-recordings-my-service-sloth-slo-my-service-0
  rules:
  - record: slo:objective:ratio
    expr: vector(0.9990000000000001)
    labels:
      cmd: examplesgen.sh
      sloth_id: my-service-sloth-slo-my-service-0
      sloth_service: my-service
      sloth_slo: sloth-slo-my-service-0
  - record: slo:error_budget:ratio
    expr: vector(1-0.9990000000000001)
    labels:
      cmd: examplesgen.sh
      sloth_id: my-service-sloth-slo-my-service-0
      sloth_service: my-service
      sloth_slo: sloth-slo-my-service-0
  - record: slo:time_period:days
    expr: vector(30)
    labels:
      cmd: examplesgen.sh
      sloth_id: my-service-sloth-slo-my-service-0
      sloth_service: my-service
      sloth_slo: sloth-slo-my-service-0
  - record: slo:current_burn_rate:ratio
    expr: |
      slo:sli_error:ratio_rate5m{sloth_id="my-service-sloth-slo-my-service-0", sloth_service="my-service", sloth_slo="sloth-slo-my-service-0"}
      / on(sloth_id, sloth_slo, sloth_service) group_left
      slo:error_budget:ratio{sloth_id="my-service-sloth-slo-my-service-0", sloth_service="my-service", sloth_slo="sloth-slo-my-service-0"}
    labels:
      cmd: examplesgen.sh
      sloth_id: my-service-sloth-slo-my-service-0
      sloth_service: my-service
      sloth_slo: sloth-slo-my-service-0
  - record: slo:period_burn_rate:ratio
    expr: |
      slo:sli_error:ratio_rate30d{sloth_id="my-service-sloth-slo-my-service-0", sloth_service="my-service", sloth_slo="sloth-slo-my-service-0"}
      / on(sloth_id, sloth_slo, sloth_service) group_left
      slo:error_budget:ratio{sloth_id="my-service-sloth-slo-my-service-0", sloth_service="my-service", sloth_slo="sloth-slo-my-service-0"}
    labels:
      cmd: examplesgen.sh
      sloth_id: my-service-sloth-slo-my-service-0
      sloth_service: my-service
      sloth_slo: sloth-slo-my-service-0
  - record: slo:period_error_budget_remaining:ratio
    expr: 1 - slo:period_burn_rate:ratio{sloth_id="my-service-sloth-slo-my-service-0",
      sloth_service="my-service", sloth_slo="sloth-slo-my-service-0"}
    labels:
      cmd: examplesgen.sh
      sloth_id: my-service-sloth-slo-my-service-0
      sloth_service: my-service
      sloth_slo: sloth-slo-my-service-0
  - record: sloth_slo_info
    expr: vector(1)
    labels:
      cmd: examplesgen.sh
      sloth_id: my-service-sloth-slo-my-service-0
      sloth_mode: cli-gen-openslo
      sloth_objective: "99.9"
      sloth_service: my-service
      sloth_slo: sloth-slo-my-service-0
      sloth_spec: openslo/v1alpha
      sloth_version: dev
Back to top