From 6c087b167c6919e084dee83d57c5dd1cb3ebf3da Mon Sep 17 00:00:00 2001 From: tmalka2022 <116073197+tmalka2022@users.noreply.github.com> Date: Mon, 13 Jul 2026 11:42:26 +0300 Subject: [PATCH] fix(dashboard): normalize model label inside sum so token timeseries stop erroring "Tokens by Model x Type Over Time" and "Token Volume Over Time by Model" applied label_replace AFTER `sum by (model[, type])`. The regex strips model suffixes, so `claude-opus-4-8[1m]` collapsed onto the already-present `claude-opus-4-8`; since label_replace rewrites rather than re-aggregates, two series ended up with the same labelset and PromQL aborted the panel with `vector cannot contain metrics with the same labelset` (rendered as the red error triangle + "No data"). Latent until both a plain and a suffixed variant of the same base model coexist in the query window. Move normalization inside the aggregation using the same three-pass form the Model Comparison panel already uses (strip -YYYYMMDD, [..], leading ~), so the sum merges the variants instead of colliding. Verified against the live stack through Grafana's datasource proxy: old expr errors, new expr returns success (3 model series / 12 model x type series with real datapoints). Co-Authored-By: Claude Opus 4.8 (1M context) Claude-Session: https://claude.ai/code/session_01TrMEKd8TZniXL9v3PvVHP2 --- grafana-dashboards/claude-code.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/grafana-dashboards/claude-code.json b/grafana-dashboards/claude-code.json index 91cca68..7adf9a6 100644 --- a/grafana-dashboards/claude-code.json +++ b/grafana-dashboards/claude-code.json @@ -538,7 +538,7 @@ "type": "prometheus", "uid": "prometheus" }, - "expr": "label_replace(sum by (model, type) (rate(claude_code_token_usage_tokens_total{session_id=~\"$session.*\"}[$__rate_interval])) * $__interval_ms / 1000, \"model\", \"$1\", \"model\", \"^([^[]+).*$\")", + "expr": "sum by (model, type) (label_replace(label_replace(label_replace(rate(claude_code_token_usage_tokens_total{session_id=~\"$session.*\"}[$__rate_interval]),\"model\",\"$1\",\"model\",\"^(.*)-[0-9]{8}$\"),\"model\",\"$1\",\"model\",\"^([^[]+)[[].*$\"),\"model\",\"$1\",\"model\",\"^~(.*)$\")) * $__interval_ms / 1000", "refId": "A", "legendFormat": "{{model}} - {{type}}" } @@ -582,7 +582,7 @@ "type": "prometheus", "uid": "prometheus" }, - "expr": "label_replace(sum by (model) (rate(claude_code_token_usage_tokens_total{session_id=~\"$session.*\"}[$__rate_interval])) * $__interval_ms / 1000, \"model\", \"$1\", \"model\", \"^([^[]+).*$\")", + "expr": "sum by (model) (label_replace(label_replace(label_replace(rate(claude_code_token_usage_tokens_total{session_id=~\"$session.*\"}[$__rate_interval]),\"model\",\"$1\",\"model\",\"^(.*)-[0-9]{8}$\"),\"model\",\"$1\",\"model\",\"^([^[]+)[[].*$\"),\"model\",\"$1\",\"model\",\"^~(.*)$\")) * $__interval_ms / 1000", "refId": "A", "legendFormat": "{{model}}" }