- id: 143
  name: "JDBC set recommended"
  qualified: true
  level: warning
  end2end: true
  switch: on
  category: 
    - other
  component: "Application"
  condition: "(abs(avg_stats['cps:by_type']['StmtClose'] - avg_stats['cps:by_type']['StmtExecute']) < avg_stats['cps:by_type']['StmtExecute'] * 0.2) and (abs(avg_stats['cps:by_type']['StmtPrepare'] - avg_stats['cps:by_type']['StmtExecute']) < avg_stats['cps:by_type']['StmtExecute'] * 0.2) and (avg_stats['cps:by_type']['StmtExecute'] > 10)"
  advice:
    key: "metrics_diag_143"
    variables:

- id: 144
  name: "Latency bottleneck outside TiDB"
  qualified: true
  level: warning
  end2end: true
  switch: on
  category: 
    - idle_duration
  component: "Application"
  # condition: "avg_stats['avg_conn_idle_in_txn_duration:total'] > avg_stats['avg_cluster_duration:total']"
  condition: "(avg_stats['avg_conn_idle_in_txn_duration:total'] > 3 * avg_stats['avg_cluster_duration:total']) and (avg_stats['avg_conn_idle_in_txn_duration:total'] > 0.01) and (avg_stats['avg_cluster_duration:total'] < 0.05)"
  advice:
    key: "metrics_diag_144"
    variables:
    - var_1: "avg_stats['avg_conn_idle_in_txn_duration:total'] * 1000"
    - var_2: "avg_stats['avg_cluster_duration:total'] * 1000"

- id: 145
  name: "Plan cache hit rate is low"
  qualified: true
  level: warning
  end2end: true
  switch: on
  category: 
    - qps
  component: "Application"
  condition: "(avg_stats['plan_cache:total'] > 0.1) and (avg_stats['plan_cache:total'] / (avg_stats['cps:by_type']['StmtExecute'] + 0.01) < 0.2)"
  advice:
    key: "metrics_diag_145"
    variables:

- id: 146
  name: "QPS downward trend follows active connection counts"
  qualified: true
  level: warning
  end2end: true
  switch: on
  category: 
    - connection
  component: "Application"
  # condition: "(qps_trend < -0.1) and (corr_qps_actconn > 0.85)"
  condition: "(qps_trend < -0.1) and (corr_qps_actconn > 0.85) and (tidb_duration_trend < 0.1)"
  advice:
    key: "metrics_diag_146"
    variables:

- id: 147
  name: "QPS is not balanced from applications"
  qualified: true
  level: warning
  end2end: true
  switch: on
  category: 
    - qps
  component: "Application"
  condition: "cal_imbalance(qps_by_instance)"
  advice:
    key: "metrics_diag_147"
    variables:

- id: 148
  name: "Active connection counts are imbalance"
  qualified: false
  level: warning
  end2end: true
  switch: on
  category: 
    - connection
  component: "Application"
  condition: "cal_imbalance(act_conn_by_instance)"
  advice:
    key: "metrics_diag_148"
    variables:

- id: 149
  name: "TiKV CPU is high"
  qualified: false
  level: warning
  end2end: true
  switch: on
  category: 
    - Resource_TiKV
  component: "TiKV"
  condition: "min(tikv_cpu_by_instance) > 0.6"
  advice:
    key: "metrics_diag_149"
    variables:
    - var_1: "min(tikv_cpu_by_instance) * 100"

- id: 150
  name: "TiKV disk usage is high"
  qualified: true
  level: warning
  end2end: true
  switch: on
  category: 
    - Resource_TiKV
  component: "TiKV"
  condition: "min(tikv_disk_by_instance) > 0.7"
  advice:
    key: "metrics_diag_150"
    variables:
    - var_1: "min(tikv_disk_by_instance) * 100"

- id: 151
  name: "TiDB CPU is high"
  qualified: true
  level: warning
  end2end: true
  switch: on
  category: 
    - Resource_TiDB
  component: "TiDB"
  condition: "min(tidb_cpu_by_instance) > 0.6"
  advice:
    key: "metrics_diag_151"
    variables:
    - var_1: "min(tidb_cpu_by_instance) * 100"

- id: 152
  name: "Plan cache is not enabled"
  qualified: true
  level: warning
  end2end: true
  switch: off
  category: 
    - qps
  component: "TiDB"
  condition: "avg_stats['plan_cache:total'] < 0.0001"
  advice:
    key: "metrics_diag_152"
    variables:

- id: 153
  name: "Scatter scheduler should be disabled"
  qualified: true
  level: warning
  end2end: false
  switch: on
  category: 
    - scheduler
  component: "PD"
  condition: "has_scatter_flag"
  advice:
    key: "metrics_diag_153"
    variables:

- id: 154
  name: "Raft-engine is not enable"
  qualified: true
  level: warning
  end2end: false
  switch: on
  category: 
    - other
  component: "TiKV"
  condition: "max(raft_engine_curve) == 0"
  advice:
    key: "metrics_diag_154"
    variables:

- id: 155
  name: "TiKV AsyncIO is not enabled"
  qualified: false
  level: warning
  end2end: false
  switch: on
  category: 
    - other
  component: "TiKV"
  # condition: "np.isnan(avg_stats['asyncio_cpu:total']) and (avg_stats['tikv_cpu_usage:total'] < 0.75)"
  condition: "avg_stats['asyncio_cpu:total'] < 1e-5 and (avg_stats['tikv_cpu_usage:total'] < 0.75)"
  advice:
    key: "metrics_diag_155"
    variables:

- id: 156
  name: "Network latency high between TiDB and TiKV"
  qualified: false
  level: warning
  end2end: false
  switch: on
  category: 
    - latency
  component: "Network"
  condition: "avg_stats['kv_request_duration:total'] - avg_stats['tikv_duration:total'] >= 0.03"
  advice:
    key: "metrics_diag_156"
    variables:
      - var_1: "(avg_stats['kv_request_duration:total'] - avg_stats['tikv_duration:total']) * 1000"

- id: 157
  name: "StmtPrepare usage is low"
  qualified: true
  level: warning
  end2end: false
  switch: on
  category: 
    - qps
  component: "TiDB"
  condition: "avg_stats['cps:by_type']['StmtExecute'] / (avg_stats['cps:total'] + 0.01) < 0.2"
  advice:
    key: "metrics_diag_157"
    variables:

- id: 158
  name: "The CPU usage of TiKV nodes is not balanced"
  qualified: false
  level: warning
  end2end: false
  switch: on
  category: 
    - Resource_TiKV
  component: "TiKV"
  condition: "cal_imbalance(tikv_cpu_by_instance)"
  advice:
    key: "metrics_diag_158"
    variables:

- id: 159
  name: "Active connection increased while QPS not"
  qualified: false
  level: warning
  end2end: false
  switch: on
  category: 
    - connection
  component: "TiDB"
  condition: "(act_conn_trend > 0) and (qps_trend <= 0) and (tidb_duration_trend > 0)"
  advice:
    key: "metrics_diag_159"
    variables:

- id: 160
  name: "Too many failed QPS"
  qualified: true
  level: warning
  end2end: false
  switch: on
  category: 
    - qps
  component: "TiDB"
  condition: "avg_stats['qps_failed:total'] > 10"
  advice:
    key: "metrics_diag_160"
    variables:

- id: 161
  name: "The latency of TiDB nodes is not balanced"
  qualified: false
  level: warning
  end2end: false
  switch: on
  category: 
    - latency
  component: "TiDB"
  condition: "cal_imbalance(tidb_duration_by_instance)"
  advice:
    key: "metrics_diag_161"
    variables:

- id: 162
  name: "The memory usage of TiKV nodes is not balanced"
  qualified: true
  level: warning
  end2end: false
  switch: on
  category: 
    - Resource_TiKV
  component: "TiKV"
  condition: "cal_imbalance(tikv_mem_by_instance)"
  advice:
    key: "metrics_diag_162"
    variables:

- id: 163
  name: " The CPU of TiDB nodes is not balanced"
  qualified: true
  level: warning
  end2end: false
  switch: on
  category: 
    - Resource_TiDB
  component: "TiDB"
  condition: "cal_imbalance(tidb_cpu_by_instance)"
  advice:
    key: "metrics_diag_163"
    variables:

- id: 164
  name: "The memory of TiDB nodes is not balanced"
  qualified: false
  level: warning
  end2end: true
  switch: on
  category: 
    - Resource_TiDB
  component: "TiDB"
  condition: "cal_imbalance(tidb_mem_by_instance)"
  advice:
    key: "metrics_diag_164"
    variables:

- id: 165
  name: "GC process is abnormal"
  qualified: true
  level: warning
  end2end: true
  switch: on
  category: 
    - gc
  component: "TiKV"
  condition: "max(diff_timestamp) / quantile(diff_timestamp, 0.5) > 5"
  advice:
    key: "metrics_diag_165"
    variables:

- id: 166
  name: "Region size is too large"
  qualified: true
  level: warning
  end2end: true
  switch: on
  category: 
    - Resource_TiKV
  component: "TiKV"
  condition: "avg_stats['tikv_region_size:total'] > 1024 * 1024 * 1024"
  advice:
    key: "metrics_diag_166"
    variables:
      - var_1: "avg_stats['tikv_region_size:total'] / 1024 / 1024"

- id: 167
  name: "PD schedulers are abnormal"
  qualified: false
  level: warning
  end2end: false
  switch: on
  category: 
    - scheduler
  component: "PD"
  condition: "balance_schedulers_lack_flag"
  advice:
    key: "metrics_diag_167"
    variables:

- id: 168
  name: "Too many heartbeat messages"
  qualified: false
  level: warning
  end2end: false
  switch: off
  category: 
    - other
  component: "TiKV"
  condition: "raft_message_abnormal"
  advice:
    key: "metrics_diag_168"
    variables:

- id:
  name: ""
  qualified: false
  level: warning
  end2end: true
  switch: off
  category: 
    - other
  component: "TiDB"
  condition: "(avg_stats['plan_cache:total'] > 0.1) and (abs(avg_stats['cps:by_type']['StmtReset'] - avg_stats['cps:by_type']['StmtExecute']) < avg_stats['cps:by_type']['StmtExecute'] * 0.1) and (avg_stats['cps:by_type']['StmtExecute'] > 10)"
  advice:
    key: ""
    variables:
    - var_1: "avg_stats['cps:by_type']['StmtReset']"
    - var_2: "avg_stats['cps:by_type']['StmtExecute']"

- id:
  name: ""
  qualified: false
  level: warning
  end2end: false
  switch: off
  category: 
    - other
  component: "TiDB"
  condition: "(total_conn_trend > 0) and (act_conn_trend <= 0) and (avg_stats['act_conn:total'] < 1000)"
  advice:
    key: ""
    variables:

- id: 38
  name: "Get-token is slow in TiDB"
  qualified: false
  level: warning
  end2end: true
  switch: on
  category: 
    - latency
  component: "TiDB"
  condition: "max_key_value(avg_stats['get_token_duration:by_instance'])[1] > 1"
  advice:
    key: "tidb_get_token_duration_38"
    variables:
    - var_1: "max_key_value(avg_stats['get_token_duration:by_instance'])[0]"
    - var_2: "max_key_value(avg_stats['get_token_duration:by_instance'])[1]"

- id: 39
  name: "Parsing query string is slow in TiDB"
  qualified: false
  level: warning
  end2end: true
  switch: on
  category: 
    - latency
  component: "TiDB"
  condition: "max_key_value(avg_stats['parse_duration:by_instance'])[1] > 0.003"
  advice:
    key: "tidb_diag_parser_duration_39"
    variables:
    - var_1: "max_key_value(avg_stats['parse_duration:by_instance'])[0]"
    - var_2: "max_key_value(avg_stats['parse_duration:by_instance'])[1]"

- id: 40
  name: "Compiling query statement is slow in TiDB"
  qualified: false
  level: warning
  end2end: true
  switch: on
  category: 
    - latency
  component: "TiDB"
  condition: "max_key_value(avg_stats['compile_duration:by_instance'])[1] > 0.003"
  advice:
    key: "tidb_diag_compile_duration_40"
    variables:
    - var_1: "max_key_value(avg_stats['compile_duration:by_instance'])[0]"
    - var_2: "max_key_value(avg_stats['compile_duration:by_instance'])[1]"

- id: 43
  name: "TiDB takes a long time to wait for tso"
  qualified: false
  level: warning
  end2end: true
  switch: on
  category: 
    - latency
  component: "TiDB"
  condition: "max_key_value(avg_stats['pd_wait_duration:by_instance'])[1] > 8"
  advice:
    key: "tidb_wait_tso_duration_43"
    variables:
    - var_1: "max_key_value(avg_stats['pd_wait_duration:by_instance'])[0]"
    - var_2: "max_key_value(avg_stats['pd_wait_duration:by_instance'])[1]"

- id: 44
  name: "Tso rpc duration is high"
  qualified: false
  level: warning
  end2end: true
  switch: on
  category: 
    - latency
  component: "TiDB"
  condition: "max_key_value(avg_stats['tso_rpc_duration:by_instance'])[1] > 0.007"
  advice:
    key: "tidb_wait_tso_duration_44"
    variables:
    - var_1: "max_key_value(avg_stats['tso_rpc_duration:by_instance'])[0]"
    - var_2: "max_key_value(avg_stats['tso_rpc_duration:by_instance'])[1]" 

- id: 51
  name: "Pessimistic lock wait time is too long"
  qualified: false
  level: warning
  end2end: true
  switch: on
  category: 
    - latency
  component: "TiKV"
  condition: "max_key_value(avg_stats['tikv_pesslock_wait_time:by_instance'])[1] > 0.05"
  advice:
    key: "tikv_pessmistic_txn_conflict_51"
    variables:
    - var_1: "max_key_value(avg_stats['tikv_pesslock_wait_time:by_instance'])[0]"
    - var_2: "max_key_value(avg_stats['tikv_pesslock_wait_time:by_instance'])[1]" 

- id: 51
  name: "Pessimistic lock wait count is too many"
  qualified: false
  level: warning
  end2end: true
  switch: off
  category: 
    - other
  component: "TiKV"
  condition: "avg_stats['tikv_pesslock_wait_count:total'] > 100"
  advice:
    key: "tikv_pessmistic_txn_conflict_5111"
    variables:
    - var_1: "avg_stats['tikv_pesslock_wait_count:total']"  

- id: 78
  name: "The wait duration of raft propose is high"
  qualified: false
  level: warning
  end2end: true
  switch: on
  category: 
    - latency
  component: "TiKV"
  condition: "max_key_value(avg_stats['tikv_raft_propose_wait:by_instance'])[1] > 15"
  advice:
    key: "tikv_raft_propose_wait_duration_78"
    variables:
    - var_1: "max_key_value(avg_stats['tikv_raft_propose_wait:by_instance'])[0]"
    - var_2: "max_key_value(avg_stats['tikv_raft_propose_wait:by_instance'])[1]" 

- id: 85
  name: "Too many MVCC versions"
  qualified: false
  level: warning
  end2end: true
  switch: on
  category: 
    - mvcc
  component: "TiKV"
  condition: "avg_stats['scan_total_versions:total'] > 5 * avg_stats['scan_processed_keys:total']"
  advice:
    key: "tikv_diag_mvcc_versions_too_many_85"
    variables:

- id: 171
  name: "TiDB coprocessor duration is high"
  qualified: false
  level: warning
  end2end: true
  switch: on
  category: 
    - latency
  component: "TiDB"
  condition: "max_key_value(avg_stats['coprocessor_duration:by_instance'])[1] > 0.02"
  advice:
    key: "tikv_diag_cop_task_duration_171"
    variables:
    - var_1: "max_key_value(avg_stats['coprocessor_duration:by_instance'])[0]"
    - var_2: "max_key_value(avg_stats['coprocessor_duration:by_instance'])[1]"