Repository navigation
fix(monitoring): the ai spend dashboard shows local savings for every range in retention, priced at the reference model that devops ai cost uses - #2203
Merged
Conversation
… range in retention, priced at the reference model that devops ai cost uses The AI spend dashboard showed $0 local savings for 2026-10-01 to 2026-10-22. The savings queries multiplied the tokens by a recording rule that had samples only from 2026-10-24T05:21Z, they selected only the series with the labels `local` and `operation`, which #1672 and #1623 added, and the rule priced chat tokens at gpt-4o-mini, not at the gpt-4o of `devops ai cost`. - DEFAULT_AI_REFERENCE_MODEL is gpt-4o. - The hidden dashboard constant reference_price_usd_per_token holds genai-prices' price of each default reference, and the recording rule is deleted. The eight savings queries read only the token counter, so every range is priced. - The savings queries count a series without `local` as local when the gateway served it (the gateway serves only local models), and a series without `operation` as chat. - A test replays the recorded answers of the live Prometheus to the query of "Local Cloud Savings in Range": $423.03 for 2026-10-01 to 2026-10-22. Closes #2194
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The AI spend dashboard (
k8s/monitoring/dashboards/ai-spend.json, uidai-spend-telemetry) showed $0 local savings for 2026-10-01 to 2026-10-22, while Prometheus holds the tokens of that range. On main, the query of "Local Cloud Savings in Range" gives0at 2026-10-22T00:00Z over 21 d. There were three causes:devops_cli:ai_reference_price_usd_per_token. Its first sample is at 2026-10-24T05:21:33Z (min_over_time(timestamp(...)[3d:1m])), so a range that ended before that had no price.local="true"and joined onoperation. The series from before fix(ai): local savings use one reference price per request kind for every process, and an unknown model or reference warns instead of pricing at $0 #1672 have nolocallabel, and the series from before fix(ai): embedding requests reach the spend ledger and the AI usage counters, priced against an embedding reference model #1623 have nooperationlabel.gpt-4o-mini. The owner'sai.reference_modelisgpt-4o, anddevops ai costprices at it.What changes:
DEFAULT_AI_REFERENCE_MODELisgpt-4o(the owner's choice).text-embedding-3-smallstays the embedding reference.reference_price_usd_per_token: a PromQL vector of genai-prices' price of the default reference of each operation and token type. It is the one copy of each price in git. The eight savings queries multiply the local tokens by${reference_price_usd_per_token:raw}and read onlydevops_cli_ai_tokens_total, so every range in the retention window is priced. The recording rule is deleted.localas local when its provider isgatewayand its server is notcache, and a series withoutoperationas chat. The gateway serves only local models: each model ofk8s/llm/gateway/config.yaml, and of each of the 13 versions of the gateway configuration since 2026-09-15, has anapi_baseat an in-cluster Service, and each version setsstore_model_in_db: false. Before fix(ai): embedding requests reach the spend ledger and the AI usage counters, priced against an embedding reference model #1623, the counters did not record embedding requests. This mapping can go whencount(last_over_time(devops_cli_ai_tokens_total{local=""}[30d]))is empty, after about 2026-11-23 (the last such sample was at about 2026-10-24T00:28Z, and Prometheus keeps 30 d).tests/fixtures/recorded_queries/ai_spend_local_savings.yamlrecords the answers of the live Prometheus to the panel query over two ranges, and the token series that it read. The test checks that the record is of the panel query, and that each answer is the total of the recorded series at the dashboard prices. No test, CI job ortools.lockentry uses promtool, so the test replays recorded answers of the real engine, as the OpenSpec tests replay the real OpenSpec.config/defaults.pynow finds a literal only where it names a reference model, becausegpt-4ois also the default of settings that are no reference (for example, the tokenizer model ofcontext_budget.py).Live check, read-only, of the new "Local Cloud Savings in Range" expression for 2026-10-01T00:00Z to 2026-10-22T00:00Z (
$__range=1814400s), throughkubectl execintoprometheus-serverand through the Grafana MCP server (Prometheus 3.15.0):ai.<domain>)llm-gateway.llm.svc.cluster.local:4000)For 2026-10-22T22:00Z to 2026-10-24T22:00Z, where series with both labels, without
local, and without both are, it gives $17.44, the total of the recorded series. A range query over 25 days and the grouped query of "Local Savings per Hour by Backend Server" gave no error.Fail-to-pass:
uv run devops ci fail-to-pass --base origin/mainreports 4 failed on base.Pending a person: after Argo CD applies the dashboard, set its time range to 2026-10-01 to 2026-10-21 and check that "Local Cloud Savings in Range" shows about $423.
Follow-up
Item
Closes #2194
Change:
openspec/changes/archive/2026-10-24-2194-dashboard-local-savings/