groups:
- name: tidb-operator.rules
  rules:
  - alert: TiDBOperatorNoAvailableReplicas
    expr: kube_deployment_status_replicas_available{deployment="tidb-operator-v2"}==0
    for: 15m
    labels:
      component: tidb-operator
      oncall_team: premium
      severity: critical
      response_class: page
      tier: next-gen
    annotations:
      description: 'TiDB Operator v2 deployment has no available replicas running for 15 minutes. This affects cluster management, scaling operations, and automated maintenance tasks. Please immediately check the deployment status, resource availability, and restart the TiDB Operator pods to restore cluster management functionality.'
      summary: 'TiDB Operator v2 has no available replicas for 15 minutes'
  # - preserve metric `component` (pd/tikv/tidb/...) as `tidb_component`
  #   before rule-level `component: tidb-operator` overrides it.
  # - strip the `tidb` prefix from the metric's `exported_namespace`
  #   (scrape-time rename of the metric's `namespace` dim) to surface the
  #   resource pool id in annotations.
  - alert: TiDBOperatorInstanceConditionAbnormal
    expr: |-
      label_replace(
        label_replace(
          tidb_operator_abnormal_instance{condition=~"Ready|Synced"} == 1,
          "tidb_component", "$1", "component", "(.*)"
        ),
        "resource_pool", "$1", "exported_namespace", "tidb(.*)"
      )
    for: 30m
    labels:
      component: tidb-operator
      oncall_team: premium
      severity: major
      response_class: ticket
      tier: next-gen
    annotations:
      description: 'TiDB Operator reports condition {{ $labels.condition }}=False on {{ $labels.tidb_component }} instance {{ $labels.exported_instance }} (tidb cluster {{ $labels.exported_cluster }}, resource pool {{ $labels.resource_pool }} on k8s cluster {{ $labels.cluster }}) for over 30 minutes. This typically indicates a stuck rolling update, failed config sync, or an unready pod. Inspect the instance CR status, pod events, and operator reconcile logs.'
      summary: 'TiDB Operator reports an abnormal instance condition for 30 minutes'