groups:
# Be cautious to change the group name unless you know what you are doing
- name: resource_usage
  rules:
  - alert: PremiumHighResourceUnitUsage
    expr: |-
      (
        sum by (tidb_cluster_id, tenant) (rate(resource_manager_resource_unit_read_request_unit_sum[2m])) +
        sum by (tidb_cluster_id, tenant) (rate(resource_manager_resource_unit_write_request_unit_sum[2m]))
      ) / sum by (tidb_cluster_id, tenant) (resource_manager_resource_unit_service_limit) > 0.8
    for: 5m
    labels:
      tier: next-gen
      severity: warning
      component: tidb
      visibility: external
      ruleID: "5"
      canEdit: "all"
      status: active
      forwardRule: "internal_major"
      monitorTarget: "Request Unit/s"
      operator: "is greater than {thresholdPercentage}% of Max RCU"
      description: "The Request Unit/s exceeded {thresholdPercentage}% of Max RCU"
      message: |
        The request unit/s of <a href="https://TiDBCloudDomainName/tidbs/{{ $labels.tidb_cluster_id }}/overview?orgId={{ $labels.tenant }}&uiMode=new-offerings-preview">instance TiDBClusterName</a> has exceeded {thresholdPercentage}% of Maximum RCU for more than {triggerInterval} minute.
        1. Check your traffic pattern in the RU metrics to determine if it's a gradual increase or a sharp spike.
        2. If it's a gradual increase, verify if Query Duration has increased. If so, your current max RCU configuration is likely insufficient.
        3. Update your capacity by manually increasing the max RCU in the <a href="https://TiDBCloudDomainName/tidbs/{{ $labels.tidb_cluster_id }}/overview?orgId={{ $labels.tenant }}&uiMode=new-offerings-preview">TiDB Cloud console</a> to meet demand.
        4. For long-term optimization, you can identify and optimize queries consuming the most RUs using the slow query feature.
        If the problem cannot be fixed by your side, you can contact TiDB Cloud Support for further assistance.
    annotations:
      description: "The Request Unit/s exceeded {thresholdPercentage}% of Max RCU"
      message: |
        The request unit/s of <a href="https://TiDBCloudDomainName/tidbs/{{ $labels.tidb_cluster_id }}/overview?orgId={{ $labels.tenant }}&uiMode=new-offerings-preview">instance TiDBClusterName</a> has exceeded {thresholdPercentage}% of Maximum RCU for more than {triggerInterval} minute.
        1. Check your traffic pattern in the RU metrics to determine if it's a gradual increase or a sharp spike.
        2. If it's a gradual increase, verify if Query Duration has increased. If so, your current max RCU configuration is likely insufficient.
        3. Update your capacity by manually increasing the max RCU in the <a href="https://TiDBCloudDomainName/tidbs/{{ $labels.tidb_cluster_id }}/overview?orgId={{ $labels.tenant }}&uiMode=new-offerings-preview">TiDB Cloud console</a> to meet demand.
        4. For long-term optimization, you can identify and optimize queries consuming the most RUs using the slow query feature.
        If the problem cannot be fixed by your side, you can contact TiDB Cloud Support for further assistance.
