{{- /*
Copyright Broadcom, Inc. All Rights Reserved.
SPDX-License-Identifier: APACHE-2.0
*/}}

{{- if and .Values.prometheus.enabled .Values.prometheus.defaultRules.create .Values.prometheus.defaultRules.rules.kubelet }}
apiVersion: monitoring.coreos.com/v1
kind: PrometheusRule
metadata:
  name: {{ printf "%s-kubelet.rules" (include "kube-prometheus.prometheus.fullname" .) }}
  namespace: {{ include "common.names.namespace" . | quote }}
  labels: {{ include "kube-prometheus.prometheus.labels" . | nindent 4 }}
  {{- if .Values.commonAnnotations }}
  annotations: {{- include "common.tplvalues.render" ( dict "value" .Values.commonAnnotations "context" . ) | nindent 4 }}
  {{- end }}
spec:
  groups:
    - name: kubelet.rules
      rules:
        - expr: |-
            histogram_quantile(
              0.99,
              sum(rate(kubelet_pleg_relist_duration_seconds_bucket{job="kubelet", metrics_path="/metrics"}[5m])) by (cluster, instance, le)
              * on (cluster, instance) group_left (node)
              max by (cluster, instance, node) (kubelet_node_name{job="kubelet", metrics_path="/metrics"})
            )
          labels:
            quantile: '0.99'
          record: node_quantile:kubelet_pleg_relist_duration_seconds:histogram_quantile
        - expr: |-
            histogram_quantile(
              0.9,
              sum(rate(kubelet_pleg_relist_duration_seconds_bucket{job="kubelet", metrics_path="/metrics"}[5m])) by (cluster, instance, le)
              * on (cluster, instance) group_left (node)
              max by (cluster, instance, node) (kubelet_node_name{job="kubelet", metrics_path="/metrics"})
            )
          labels:
            quantile: '0.9'
          record: node_quantile:kubelet_pleg_relist_duration_seconds:histogram_quantile
        - expr: |-
            histogram_quantile(
              0.5,
              sum(rate(kubelet_pleg_relist_duration_seconds_bucket{job="kubelet", metrics_path="/metrics"}[5m])) by (cluster, instance, le)
              * on (cluster, instance) group_left (node)
              max by (cluster, instance, node) (kubelet_node_name{job="kubelet", metrics_path="/metrics"})
            )
          labels:
            quantile: '0.5'
          record: node_quantile:kubelet_pleg_relist_duration_seconds:histogram_quantile
{{- end }}
