apiVersion: monitoring.coreos.com/v1
kind: PrometheusRule
metadata:
  labels:
    app.kubernetes.io/component: storage
    app.kubernetes.io/managed-by: cdi-operator
    cdi.kubevirt.io: ""
    prometheus.cdi.kubevirt.io: "true"
  name: prometheus-cdi-rules
  namespace: "{{ namespace }}"
spec:
  groups:
    - name: cdi.rules
      rules:
        - expr: sum(up{namespace='{{ namespace }}', pod=~'cdi-operator-.*'} or vector(0))
          record: kubevirt_cdi_operator_up_total
        - expr: count(kube_pod_container_status_restarts_total{pod=~'importer-.*', container='importer'} > 3)
          record: kubevirt_cdi_import_dv_unusual_restartcount_total
        - expr: count(kube_pod_container_status_restarts_total{pod=~'cdi-upload-.*', container='cdi-upload-server'} > 3)
          record: kubevirt_cdi_upload_dv_unusual_restartcount_total
        - expr: count(kube_pod_container_status_restarts_total{pod=~'.*-source-pod', container='cdi-clone-source'} > 3)
          record: kubevirt_cdi_clone_dv_unusual_restartcount_total
        - expr: sum(kubevirt_cdi_dataimportcron_outdated or vector(0))
          record: kubevirt_cdi_dataimportcron_outdated_total
        - alert: CDIOperatorDown
          annotations:
            runbook_url: https://kubevirt.io/monitoring/runbooks/CDIOperatorDown
            summary: CDI operator is down
          expr: kubevirt_cdi_operator_up_total == 0
          for: 5m
          labels:
            kubernetes_operator_component: containerized-data-importer
            kubernetes_operator_part_of: kubevirt
            operator_health_impact: critical
            severity: warning
        - alert: CDINotReady
          annotations:
            runbook_url: https://kubevirt.io/monitoring/runbooks/CDINotReady
            summary: CDI is not available to use
          expr: kubevirt_cdi_cr_ready == 0
          for: 5m
          labels:
            kubernetes_operator_component: containerized-data-importer
            kubernetes_operator_part_of: kubevirt
            operator_health_impact: critical
            severity: warning
        - alert: CDIDataVolumeUnusualRestartCount
          annotations:
            runbook_url: https://kubevirt.io/monitoring/runbooks/CDIDataVolumeUnusualRestartCount
            summary: Cluster has DataVolumes (PVC population request) with an unusual restart count, meaning they are probably failing and need to be investigated
          expr: kubevirt_cdi_import_dv_unusual_restartcount_total > 0 or kubevirt_cdi_upload_dv_unusual_restartcount_total > 0 or kubevirt_cdi_clone_dv_unusual_restartcount_total > 0
          for: 5m
          labels:
            kubernetes_operator_component: containerized-data-importer
            kubernetes_operator_part_of: kubevirt
            operator_health_impact: warning
            severity: warning
        - alert: CDIStorageProfilesIncomplete
          annotations:
            runbook_url: https://kubevirt.io/monitoring/runbooks/CDIStorageProfilesIncomplete
            summary: Incomplete StorageProfiles exist, accessMode/volumeMode cannot be inferred by CDI for PVC population request
          expr: kubevirt_cdi_incomplete_storageprofiles_total > 0
          for: 5m
          labels:
            kubernetes_operator_component: containerized-data-importer
            kubernetes_operator_part_of: kubevirt
            operator_health_impact: warning
            severity: info
        - alert: CDIDataImportCronOutdated
          annotations:
            runbook_url: https://kubevirt.io/monitoring/runbooks/CDIDataImportCronOutdated
            summary: DataImportCron (recurring polling of VM templates disk image sources, also known as golden images) PVCs are not being updated on the defined schedule
          expr: kubevirt_cdi_dataimportcron_outdated_total > 0
          for: 15m
          labels:
            kubernetes_operator_component: containerized-data-importer
            kubernetes_operator_part_of: kubevirt
            operator_health_impact: warning
            severity: info