groups:
- name: data-migration
  rules:
  - alert: DMJobInCreatingPhaseForTooLong
    annotations:
      message: "DM job {{ $labels.job_id }} for cluster {{ $labels.cluster_id }} being in creating phase for too long."
    expr: |
      dataflow_dm_job_duration_in_phase{phase="creating"} > 20*60 # 20 minutes. in most case the job will be created in less than 5 minutes
    labels:
      severity: critical
      response_class: page
      component: data-migration
      oncall_team: tidb_x_tools
  - alert: DMJobInDeletingPhaseForTooLong
    annotations:
      message: "DM job {{ $labels.job_id }} for cluster {{ $labels.cluster_id }} being in deleting phase for too long."
    expr: |
      dataflow_dm_job_duration_in_phase{phase="deleting"} > 30*60 # 30 minutes.
    labels:
      severity: critical
      response_class: page
      component: data-migration
      oncall_team: tidb_x_tools
  - alert: DMJobInModifyingPhaseForTooLong
    annotations:
      message: "DM job {{ $labels.job_id }} for cluster {{ $labels.cluster_id }} being in modifying phase for too long."
    expr: |
      dataflow_dm_job_duration_in_phase{phase="modifying"} > 15*60 # 15 minutes.
    labels:
      severity: critical
      response_class: page
      component: data-migration
      oncall_team: tidb_x_tools

  # Direct failure alerts — complement the timeout alerts above
  - alert: DMCreateStageFailure
    annotations:
      message: "DM job {{ $labels.job_id }} for cluster {{ $labels.cluster_id }} hit a create-stage failure (stage={{ $labels.stage }}, reason={{ $labels.reason_class }})."
    expr: |
      increase(dataflow_dm_create_stage_failed_total[5m]) > 0
    labels:
      severity: major
      response_class: ticket
      component: data-migration
      oncall_team: tidb_x_tools
  - alert: DMModifyFailure
    annotations:
      message: "DM job {{ $labels.job_id }} for cluster {{ $labels.cluster_id }} hit a modify/scale failure (step={{ $labels.step }}, reason={{ $labels.reason_class }})."
    expr: |
      increase(dataflow_dm_modify_failed_total[5m]) > 0
    labels:
      severity: major
      response_class: ticket
      component: data-migration
      oncall_team: tidb_x_tools
