groups:
  - name: drive9-kimi
    rules:
      # Customer-facing Drive9 alerts scoped to a single TiDB Cloud organization
      # (tidbcloud_org_id="97", the Kimi tenant org). Kimi's "workspace" maps to a
      # Drive9 tenant; only the two signals Kimi asked for are included: workspace
      # creation failures and workspace storage quota pressure. oncall_team=none
      # and visibility=external are both required routing labels: deliver these
      # alerts externally without paging the internal Drive9 on-call.

      # Workspace creation is failing: new workspaces cannot become usable until
      # the underlying provisioning error is resolved.
      - alert: Drive9CreateWorkSpaceError
        expr: |
          sum by (namespace, provider, result, tenant_id, tidbcloud_org_id) (
            increase(drive9_business_events_total{event="tenant_provision",result=~"error|cluster_error",tenant_id!="",tenant_id!="unknown",tidbcloud_org_id="97"}[15m])
          ) > 2
        for: 5m
        labels:
          severity: major
          component: drive9-kimi
          oncall_team: none
          visibility: external
        annotations:
          summary: "Drive9 (Kimi) workspace creation is failing"
          description: "Drive9 workspace {{ $labels.tenant_id }} / TiDB org {{ $labels.tidbcloud_org_id }} creation has recorded repeated {{ $labels.result }} outcomes for provider {{ $labels.provider }} over the past 15 minutes. Current value: {{ $value }} failures"

      # Workspace storage quota pressure — surfaced before writes start failing so
      # the customer can clean up or request more capacity.
      - alert: Drive9WorkSpaceQuotaNearLimit
        expr: |
          (
            (
              sum by (namespace, tenant_id, tidbcloud_org_id) (drive9_tenant_storage_bytes{state=~"confirmed|reserved",tidbcloud_org_id="97"})
              /
              sum by (namespace, tenant_id, tidbcloud_org_id) (drive9_tenant_storage_bytes{state="limit",tidbcloud_org_id="97"})
            ) > 0.90
          )
          and on (namespace, tenant_id, tidbcloud_org_id)
          (
            sum by (namespace, tenant_id, tidbcloud_org_id) (drive9_tenant_storage_bytes{state="limit",tidbcloud_org_id="97"}) > 0
          )
        for: 15m
        labels:
          severity: major
          component: drive9-kimi
          oncall_team: none
          visibility: external
        annotations:
          summary: "Drive9 (Kimi) workspace storage quota is near limit"
          description: "Drive9 workspace {{ $labels.tenant_id }} / TiDB org {{ $labels.tidbcloud_org_id }} storage usage has exceeded 90% of its configured limit for 15 minutes. Current value: {{ $value | humanizePercentage }}"
