{{- $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-histogram.rules
rules:
- condition: '{{ true }}'
  expr: histogram_quantile(0.99, sum by (le,resource,{{ $groupLabels }}) (rate(apiserver_request_sli_duration_seconds_bucket{job="apiserver",verb=~"LIST|GET",subresource!~"proxy|attach|log|exec|portforward"}[5m]))) > 0
  labels:
    quantile: '0.99'
    verb: read
  record: cluster_quantile:apiserver_request_sli_duration_seconds:histogram_quantile
- condition: '{{ true }}'
  expr: histogram_quantile(0.99, sum by (le,resource,{{ $groupLabels }}) (rate(apiserver_request_sli_duration_seconds_bucket{job="apiserver",verb=~"POST|PUT|PATCH|DELETE",subresource!~"proxy|attach|log|exec|portforward"}[5m]))) > 0
  labels:
    quantile: '0.99'
    verb: write
  record: cluster_quantile:apiserver_request_sli_duration_seconds:histogram_quantile
