apiVersion: monitoring.coreos.com/v1
kind: PrometheusRule
metadata:
  labels:
    prometheus: k8s
  name: prometheus-k8s-rules
  namespace: monitoring
spec:
  groups:
  - name: apiserver.rules
    rules:
    - expr: |
        rate(apiserver_request_duration_seconds_bucket[5m]) and on (job) kubernetes_build_info{major="[0-1]",minor=~"^([0-9]|1[0-9]|2[0-2])$"}
        or
        rate(apiserver_request_slo_duration_seconds_bucket[5m]) and on (job) kubernetes_build_info{major="1",minor=~"^2[3-5]$"}
        or
        rate(apiserver_request_sli_duration_seconds_bucket[5m]) and on (job) kubernetes_build_info{major="1",minor=~"^(2[6-9]|[3-9][0-9])$"}
      record: apiserver:request_latency:rate5m
    - expr: |
        histogram_quantile(0.99, sum(apiserver:request_latency:rate5m) by (resource,  subresource, verb, scope, le))
      record: apiserver:apiserver_request_latency:histogram_quantile
      labels:
        quantile: "0.99"
    - expr: |
        histogram_quantile(0.9, sum(apiserver:request_latency:rate5m) by (resource,  subresource, verb, scope, le))
      record: apiserver:apiserver_request_latency:histogram_quantile
      labels:
        quantile: "0.90"
    - expr: |
        histogram_quantile(0.5, sum(apiserver:request_latency:rate5m) by (resource,  subresource, verb, scope, le))
      record: apiserver:apiserver_request_latency:histogram_quantile
      labels:
        quantile: "0.50"
  - name: probes.rules
    rules:
    - expr: |
        histogram_quantile(0.99, sum(rate(probes_in_cluster_network_latency_seconds_bucket[5m])) by (le))
      record: probes:in_cluster_network_latency:histogram_quantile
      labels:
        quantile: "0.99"
    - expr: |
        histogram_quantile(0.90, sum(rate(probes_in_cluster_network_latency_seconds_bucket[5m])) by (le))
      record: probes:in_cluster_network_latency:histogram_quantile
      labels:
        quantile: "0.90"
    - expr: |
        histogram_quantile(0.50, sum(rate(probes_in_cluster_network_latency_seconds_bucket[5m])) by (le))
      record: probes:in_cluster_network_latency:histogram_quantile
      labels:
        quantile: "0.50"
    - expr: |
        histogram_quantile(0.99, sum(rate(probes_in_cluster_dns_latency_seconds_bucket[5m])) by (le))
      record: probes:dns_lookup_latency:histogram_quantile
      labels:
        quantile: "0.99"
    - expr: |
        histogram_quantile(0.90, sum(rate(probes_in_cluster_dns_latency_seconds_bucket[5m])) by (le))
      record: probes:dns_lookup_latency:histogram_quantile
      labels:
        quantile: "0.90"
    - expr: |
        histogram_quantile(0.50, sum(rate(probes_in_cluster_dns_latency_seconds_bucket[5m])) by (le))
      record: probes:dns_lookup_latency:histogram_quantile
      labels:
        quantile: "0.50"
    - expr: |
        sum(max_over_time(probes_dns_propagation_seconds[1h]))/sum(max_over_time(probes_dns_propagation_count[1h]))
      record: probes:dns_propagation_average
  - name: kube-proxy.rules
    rules:
    - expr: |
        histogram_quantile(0.99, sum(rate(kubeproxy_network_programming_duration_seconds_bucket[5m])) by (le))
      record: kubeproxy:kubeproxy_network_programming_duration:histogram_quantile
      labels:
        quantile: "0.99"
    - expr: |
        histogram_quantile(0.90, sum(rate(kubeproxy_network_programming_duration_seconds_bucket[5m])) by (le))
      record: kubeproxy:kubeproxy_network_programming_duration:histogram_quantile
      labels:
        quantile: "0.90"
    - expr: |
        histogram_quantile(0.50, sum(rate(kubeproxy_network_programming_duration_seconds_bucket[5m])) by (le))
      record: kubeproxy:kubeproxy_network_programming_duration:histogram_quantile
      labels:
        quantile: "0.50"
    - expr: |
        histogram_quantile(0.99, sum(rate(kubeproxy_network_programming_duration_seconds_bucket[5m])) by (le, pod))
      record: kubeproxy:kubeproxy_network_programming_duration:histogram_quantile_by_pod
      labels:
        quantile: "0.99"
    - expr: |
        histogram_quantile(0.90, sum(rate(kubeproxy_network_programming_duration_seconds_bucket[5m])) by (le, pod))
      record: kubeproxy:kubeproxy_network_programming_duration:histogram_quantile_by_pod
      labels:
        quantile: "0.90"
    - expr: |
        histogram_quantile(0.50, sum(rate(kubeproxy_network_programming_duration_seconds_bucket[5m])) by (le, pod))
      record: kubeproxy:kubeproxy_network_programming_duration:histogram_quantile_by_pod
      labels:
        quantile: "0.50"
  - name: apiserver.1m.rules
    rules:
    - expr: |
        histogram_quantile(0.99, sum(rate(apiserver_request_duration_seconds_bucket[1m])) by (resource,  subresource, verb, scope, le))
      record: apiserver:apiserver_request_latency_1m:histogram_quantile
      labels:
        quantile: "0.99"
    - expr: |
        histogram_quantile(0.9, sum(rate(apiserver_request_duration_seconds_bucket[1m])) by (resource,  subresource, verb, scope, le))
      record: apiserver:apiserver_request_latency_1m:histogram_quantile
      labels:
        quantile: "0.90"
    - expr: |
        histogram_quantile(0.5, sum(rate(apiserver_request_duration_seconds_bucket[1m])) by (resource,  subresource, verb, scope, le))
      record: apiserver:apiserver_request_latency_1m:histogram_quantile
      labels:
        quantile: "0.50"
    - expr: |
        histogram_quantile(0.99, sum(rate(apiserver_request_slo_duration_seconds_bucket[1m])) by (resource,  subresource, verb, scope, le))
      record: apiserver:apiserver_request_slo_latency_1m:histogram_quantile
      labels:
        quantile: "0.99"
    - expr: |
        histogram_quantile(0.9, sum(rate(apiserver_request_slo_duration_seconds_bucket[1m])) by (resource,  subresource, verb, scope, le))
      record: apiserver:apiserver_request_slo_latency_1m:histogram_quantile
      labels:
        quantile: "0.90"
    - expr: |
        histogram_quantile(0.5, sum(rate(apiserver_request_slo_duration_seconds_bucket[1m])) by (resource,  subresource, verb, scope, le))
      record: apiserver:apiserver_request_slo_latency_1m:histogram_quantile
      labels:
        quantile: "0.50"
    - expr: |
        histogram_quantile(0.99, sum(rate(apiserver_request_sli_duration_seconds_bucket[1m])) by (resource,  subresource, verb, scope, le))
      record: apiserver:apiserver_request_sli_latency_1m:histogram_quantile
      labels:
        quantile: "0.99"
    - expr: |
        histogram_quantile(0.9, sum(rate(apiserver_request_sli_duration_seconds_bucket[1m])) by (resource,  subresource, verb, scope, le))
      record: apiserver:apiserver_request_sli_latency_1m:histogram_quantile
      labels:
        quantile: "0.90"
    - expr: |
        histogram_quantile(0.5, sum(rate(apiserver_request_sli_duration_seconds_bucket[1m])) by (resource,  subresource, verb, scope, le))
      record: apiserver:apiserver_request_sli_latency_1m:histogram_quantile
      labels:
        quantile: "0.50"
