Repository navigation
MAF-20805: feat(deploy): chart token-weighted tokenizer cache reuse - #188
bongwoobak wants to merge 6 commits into
Conversation
Replace the per-lookup "Cache hit ratio" panel with hit_prefix_tokens_total / encoded_tokens_total. Every chat prompt shares its leading special token, so the lookup ratio sat at 100% even when a hit reused one token of a 68k prompt. The lookup panels read the renamed lookup_hits_total / lookup_misses_total and fall back to the previous names while older gateways are still scraped. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Apply fallbacks per scrape target before aggregation to handle mixed-version rollouts correctly; clarify the panel description.
Review effort: Lite
Findings: 2
Open (3)
What changed in this PR
Updates the AIGateway Grafana dashboard with token-weighted tokenizer cache metrics and legacy metric fallbacks.
Changes:
- Replaces lookup-based cache ratio with token-weighted reuse.
- Adds renamed metric queries with legacy fallbacks.
- Updates descriptions for panels 77–79.
| File | Summary |
|---|---|
deploy/helm/moai-inference-framework/files/dashboards/mif-aigateway.json |
Updates tokenizer cache dashboard panels and PromQL queries. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
…unters Applying `or` after `sum by (model)` let any pod exporting the renamed lookup counters hide every pod of the same model still on the old names, so a mixed-version rollout undercounted lookups and overstated the average reused tokens per hit. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Old gateways export hit_prefix_tokens_total but not encoded_tokens_total, so during a mixed-version rollout their reused tokens landed in the numerator with no matching denominator and pushed the ratio past 100%. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Add a script that feeds a local Prometheus from fake gateways, one model with a renamed pod beside an old one and one model with old pods only, and asserts what panels 77-79 report. It fails on the aggregate-then-fallback queries and passes on the per-target ones. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
hhk7734
left a comment
There was a problem hiding this comment.
The query changes look correct. I ran hack/dashboards/verify_aigateway_tokenizer_cache.py on 06bcc98 with Prometheus 3.15.0: all 4 checks pass. With the queries from 4e5771f, all 4 fail (1.52, 10, 10, 152), as the description says. The changes below are about the PR text and the artifact, not the code.
Note: mif is a public repository, so I rewrote the description in English. I also removed links to internal repositories, internal hostnames, production values and other ticket keys. Please keep them in Jira. I did not change the structure, so the points below still apply to the current text.
1. Start the description with the JIRA and Artifact lines.
Put these two lines first, before the summary. Move the Jira: MAF-20805 line from the bottom into the first one:
JIRA: [MAF-20805](https://moreh.atlassian.net/browse/MAF-20805)
Artifact: [<title>](https://claude.ai/artifact/Uworr7xayd1ir6ViixxfFc)
2. Update the Verification section to match head.
The numbers come from the first manual run, where the new and old exporters were different models (78: 10/0 and 30/10, 79: 1.0 and 100.0). Your own thread says this setup missed the case where one model has both a new and an old pod. Please replace them with the script output on head, and write the head SHA next to them. On 06bcc98 I got:
- 77 A:
{A: 0.02} - 78 A:
{A: 40, B: 5} - 78 B:
{A: 20, B: 5} - 79 A:
{A: 38, B: 10}
Also, the panel 77 row in the table shows rate(hit_prefix_tokens_total) / rate(encoded_tokens_total). It does not show the and encoded_tokens_total limit added in 6f51c1c. Please add it. For panels 78 and 79, say that the fallback is applied per pod, before sum by (model).
3. Update the artifact to match head.
The artifact the description links does not show a head SHA. It shows panel 77 without the and limit, and it does not mention the per-pod fallback fix (f4fdb09, 6f51c1c) or the verification script. Its verification section describes the same earlier run with separate exporters. Please bring it up to 06bcc98 (or the new head), with the final queries and the script result.
|
@hhk7734 All three points are addressed.
I also rewrote my earlier review comments on this PR in English, following the new public-repository rule in |
Description, verification (script output on head 2ccf70e) and artifact updated as requested.
|
The dashboard was removed in #191 |


JIRA: MAF-20805
Artifact: Token-weighted cache reuse
What this PR does
It changes panels 77, 78 and 79 in the Tokenizer cache row of the
mif-aigatewaydashboard to token-weighted metrics.The problem
Panel 77, "Cache hit ratio by model", plotted the per-lookup ratio
hits / (hits + misses). A lookup counts as one hit even when it reuses only one token. Every chat prompt starts with the same special token, so the panel showed close to 100% for every model, even for long prompts that reused only that one token.The fix
sum by (model) (rate(hit_prefix_tokens_total) and rate(encoded_tokens_total)) / sum by (model) (rate(encoded_tokens_total)). Theandkeeps the numerator to pods that also export the denominator, so old pods in a rolling update do not push the ratio above 100%.sum by (model) (rate(lookup_*_total) or rate(*_total)). The fallback to the old names is applied per pod, beforesum by (model), so old and new pods of the same model are both counted.Panels 77 and 78 now have a description that explains what they measure.
Verification
hack/dashboards/verify_aigateway_tokenizer_cache.pyon head 2ccf70e (06bcc98 with main merged in; the dashboard and the script are unchanged by the merge), Prometheus 3.15.0. Fake gateways: model A has one new pod and one old pod, model B has an old pod only.{A: 0.02}{A: 40, B: 5}{A: 20, B: 5}{A: 38, B: 10}With the queries from 4e5771f, where the fallback is applied after
sum by (model)and panel 77 has noand, all 4 checks fail: 1.52, 10, 10 and 152.The JSON was rewritten with
json.dumps(indent=2). I first checked that the file before the change was byte-identical to this format, so the diff shows only these panels.Copies of this dashboard
Copies of this dashboard in other deployments are updated separately and tracked in Jira.
🤖 Generated with Claude Code