{{- $Values := (.helm).Values | default .Values }}
{{- $runbookUrl := ($Values.defaultRules).runbookUrl | default "https://runbooks.prometheus-operator.dev/runbooks" }}
{{- $clusterLabel := ($Values.global).clusterLabel | default "cluster" }}
{{- $additionalGroupByLabels := append $Values.defaultRules.additionalGroupByLabels $clusterLabel }}
{{- $groupLabels := join "," $additionalGroupByLabels }}
{{- $grafanaHost := ternary (index (($Values.grafana).ingress).hosts 0) (($Values.external).grafana).host ($Values.grafana).enabled }}
condition: '{{ ($Values.kubeApiServer).enabled }}'
name: kube-apiserver-slos
rules:
- alert: KubeAPIErrorBudgetBurn
  annotations:
    description: 'The API server is burning too much error budget on cluster {{`{{`}} $labels.{{ $clusterLabel }} {{`}}`}}.'
    runbook_url: '{{ $runbookUrl }}/kubernetes/kubeapierrorbudgetburn'
    summary: 'The API server is burning too much error budget.'
  condition: '{{ true }}'
  expr: |-
    sum by ({{ $groupLabels }}) (apiserver_request:burnrate1h) > (14.40 * 0.01000)
    and on ({{ $groupLabels }})
    sum by ({{ $groupLabels }}) (apiserver_request:burnrate5m) > (14.40 * 0.01000)
  for: 2m
  labels:
    long: 1h
    severity: critical
    short: 5m
- alert: KubeAPIErrorBudgetBurn
  annotations:
    description: 'The API server is burning too much error budget on cluster {{`{{`}} $labels.{{ $clusterLabel }} {{`}}`}}.'
    runbook_url: '{{ $runbookUrl }}/kubernetes/kubeapierrorbudgetburn'
    summary: 'The API server is burning too much error budget.'
  condition: '{{ true }}'
  expr: |-
    sum by ({{ $groupLabels }}) (apiserver_request:burnrate6h) > (6.00 * 0.01000)
    and on ({{ $groupLabels }})
    sum by ({{ $groupLabels }}) (apiserver_request:burnrate30m) > (6.00 * 0.01000)
  for: 15m
  labels:
    long: 6h
    severity: critical
    short: 30m
- alert: KubeAPIErrorBudgetBurn
  annotations:
    description: 'The API server is burning too much error budget on cluster {{`{{`}} $labels.{{ $clusterLabel }} {{`}}`}}.'
    runbook_url: '{{ $runbookUrl }}/kubernetes/kubeapierrorbudgetburn'
    summary: 'The API server is burning too much error budget.'
  condition: '{{ true }}'
  expr: |-
    sum by ({{ $groupLabels }}) (apiserver_request:burnrate1d) > (3.00 * 0.01000)
    and on ({{ $groupLabels }})
    sum by ({{ $groupLabels }}) (apiserver_request:burnrate2h) > (3.00 * 0.01000)
  for: 1h
  labels:
    long: 1d
    severity: warning
    short: 2h
- alert: KubeAPIErrorBudgetBurn
  annotations:
    description: 'The API server is burning too much error budget on cluster {{`{{`}} $labels.{{ $clusterLabel }} {{`}}`}}.'
    runbook_url: '{{ $runbookUrl }}/kubernetes/kubeapierrorbudgetburn'
    summary: 'The API server is burning too much error budget.'
  condition: '{{ true }}'
  expr: |-
    sum by ({{ $groupLabels }}) (apiserver_request:burnrate3d) > (1.00 * 0.01000)
    and on ({{ $groupLabels }})
    sum by ({{ $groupLabels }}) (apiserver_request:burnrate6h) > (1.00 * 0.01000)
  for: 3h
  labels:
    long: 3d
    severity: warning
    short: 6h
