apiVersion: monitoring.coreos.com/v1
kind: PrometheusRule
metadata:
  labels:
    prometheus: k8s
    role: alert-rules
  name: machine-api-operator-prometheus-rules
  namespace: openshift-machine-api
  annotations:
    exclude.release.openshift.io/internal-openshift-hosted: "true"
spec:
  groups:
    - name: machine-without-valid-node-ref
      rules:
        - alert: MachineWithoutValidNode
          expr: |
             (mapi_machine_created_timestamp_seconds unless on(node) kube_node_info) > 0
          for: 60m
          labels:
            severity: warning
          annotations:
            message: "machine {{ $labels.name }} does not have valid node reference"
    - name: machine-with-no-running-phase
      rules:
        - alert: MachineWithNoRunningPhase
          expr: |
            (mapi_machine_created_timestamp_seconds{phase!="Running"}) > 0
          for: 60m
          labels:
            severity: warning
          annotations:
            message: "machine {{ $labels.name }} is in phase: {{ $labels.phase }}"
    - name: machine-api-operator-metrics-collector-up
      rules:
        - alert: MachineAPIOperatorMetricsCollectionFailing
          expr: |
             mapi_mao_collector_up == 0
          for: 5m
          labels:
            severity: critical
          annotations:
            message: "machine api operator metrics collection is failing. For more details:  oc logs <machine-api-operator-pod-name> -n openshift-machine-api"
    - name: machine-api-operator-down
      rules:
        - alert: MachineAPIOperatorDown
          expr: |
             absent(up{job="machine-api-operator"} == 1)
          for: 5m
          labels:
            severity: critical
          annotations:
            message: "machine api operator is down"
