---
schema_version: 1
id: premium-keyspace-storage-query-semantics
title: Discover the keyspace label and cardinality for premium TiKV store size metrics
status: active
owner: codex
evaluation:
  mode: adhoc_evidence
environment:
  profile: stable-premium
  cluster_label: premium-main
  cluster_type: premium
  tidb_version: v8.5.x
  cluster_id: '10748116073341772391'
  parent_id: '2026948324023603200'
time_window:
  resolved_by_output: resolved_window
runtime:
  hooks:
  - id: resolve_runtime_window
    stage: before_acp
    kind: python_script
    path: runtime_hook.py
    output_id: resolved_window
    args:
    - resolve-window
    - "--cluster-id"
    - "{{environment.cluster_id}}"
    - "--cluster-label"
    - "{{environment.cluster_label}}"
    - "--metrics-cluster-id"
    - "{{environment.parent_id}}"
    - "--local-hour"
    - '11'
    - "--local-minute"
    - '0'
    - "--duration-minutes"
    - '5'
  - id: build_reference_answer
    stage: before_judge
    kind: python_script
    path: runtime_hook.py
    output_id: reference_answer
    args:
    - build-reference
    - "--cluster-id"
    - "{{environment.cluster_id}}"
    - "--metrics-cluster-id"
    - "{{environment.parent_id}}"
    - "--target-tikv-instance"
    - "{{runtime.resolved_window.target_tikv_instance}}"
    - "--keyspace-label"
    - "keyspace_name"
    - "--start"
    - "{{runtime.resolved_window.start}}"
    - "--end"
    - "{{runtime.resolved_window.end}}"
prompt:
  text: |
    帮我找出 `tikv_store_size_bytes{type="used"}` 在这个 Premium 集群里，哪个 label 表示 keyspace，并统计它在观察窗口末尾的 distinct 值数量：

    - cluster_id: `{{environment.cluster_id}}`
    - parent_id: `{{environment.parent_id}}`
    - target_tikv_instance: `{{runtime.resolved_window.target_tikv_instance}}`
    - 观察窗口: `{{runtime.resolved_window.start}}` 到 `{{runtime.resolved_window.end}}`

    要求：
    1. 你必须自己通过查询发现这个 metric 里哪个 label 表示 keyspace，不要把 label 名称当作已知前提；
    2. 找到 label 之后，再统计它在 `target_tikv_instance` 对应时间点上的 distinct 值数量；
    3. 不要输出额外解释，最终只输出一个 `json` 代码块。

    JSON 字段必须严格为：
    `target_metric`、`window`、`evidence_sufficient`、`clusters`

    `clusters` 中每个元素必须严格包含：
    `cluster_id`、`target_tikv_instance`、`keyspace_label`、`keyspace_value_count`

    JSON 结构如下：

    ```json
    {
      "target_metric": "tikv_store_size_bytes",
      "window": {
        "start": "2026-01-01T03:00:00Z",
        "end": "2026-01-01T03:05:00Z"
      },
      "evidence_sufficient": true,
      "clusters": [
        {
          "cluster_id": "<cluster_id>",
          "target_tikv_instance": "<target_tikv_instance>",
          "keyspace_label": "<keyspace_label>",
          "keyspace_value_count": <integer>
        }
      ]
    }
    ```

    如果证据不足，请把 `evidence_sufficient` 设为 `false`，并把 `clusters` 设为空数组。
tags:
- premium
- storage-metrics
- keyspace
- metric-routing
- structured-output
- adhoc-evidence
case_tier: P1
cost_tier: low
followup:
  scheduled_max_followups: 0
execution:
  acp_bash_timeout_s: 300
