apiVersion: monitoring.coreos.com/v1
kind: PrometheusRule
metadata:
  labels:
    release: self-monitoring
  name: self-monitoring-api-gateway-cert-manager-alert-rules
  namespace: self-monitoring
spec:
  groups:
    - name: api-gateway-operator-monitoring
      rules:
        - alert: APIGatewayOperatorAbsent
          expr: absent(up{job="api-gateway-controller-manager-metrics-service"})
          for: 1h
          annotations:
            message: "region: {{ $externalLabels.o11y_k8s_id }}, API Gateway Operator has dissapeared from Prometheus service discovery."
          labels:
            severity: major
            component: api-gateway
        - alert: CustomDomainPendingTooLong
          expr: |
            sum without (exported_namespace)(
              label_replace(
                max by (name, exported_namespace, cond_type, cond_status, namespace) (
                  apigateway_operator_custom_domain_status{cond_type=~"Issuing|Deloying"} == 1
                ), "namespace", "$1", "exported_namespace", "(.+)"
              )
            )
          for: 5m
          annotations:
            message: "region: {{ $externalLabels.o11y_k8s_id }}, The custom domian {{ $labels.name }} is pending in status {{ $labels.cond_type }} too long."
          labels:
            severity: major
            component: api-gateway
        - alert: CustomDomainWaitingDNSTooLong
          expr: |
            sum without (exported_namespace)(
              label_replace(
                max by (name, exported_namespace, cond_type, cond_status, namespace) (
                  apigateway_operator_custom_domain_status{cond_type=~"WaitingDNS"} == 1
                ), "namespace", "$1", "exported_namespace", "(.+)"
              )
            )
          for: 20m
          annotations:
            message: "region: {{ $externalLabels.o11y_k8s_id }}, The custom domian {{ $labels.name }} is pending in status {{ $labels.cond_type }} too long."
          labels:
            severity: major
            component: api-gateway
