Repository navigation
Description
Update 2026-11-26 (infra move): tests/prometheus/test_k8s_monitoring_dashboards.py is gone (#7234). The dashboard cases run in tests/prometheus/test_dashboard_queries.py.
Split from #4724. The pull request of #4724 changes only the spend panels of k8s/devops/dashboards/ai-spend.json. These parts of #4724 stay open:
Problem
- Token Processing Rate (tokens/sec) and Request Rate by Model use
rate(...[5m])on the sparse OTLP countersdevops_cli_ai_tokens_totalanddevops_cli_ai_requests_total. A Job pod sends about 6 samples for each series in 6 h, so a 5 min window holds 0 or 1 sample. At 7 d the panels show 37 % of the requests and 42 % of the tokens (measure of fix(monitoring): read AI spend from the gateway counter #4724). Their rolling lines use fixed[30m]windows. - Response Cache Hit Share, Gateway Attempts by Status and Gateway Requests and Tokens by Caller use rolling
[1h]windows at steps under 1 h, so the points overlap. - Ollama Slot Wait by Priority (p95) has no series in 30 d (query of 2026-11-16:
count by (priority, outcome) (last_over_time(devops_cli_ai_ollama_slot_wait_seconds[30d]))is empty). k8s/devops/dashboards/devops-ai-rag.jsonhas the same spend defect: AI Spend in Range and AI Spend Rate by Server ($/hr) readdevops_cli_ai_spend_usd_totalwithrate(...[5m]).
Expected behavior
- The request and token panels draw bars per hour with
increase(...[$__interval])and a Min interval of 1h. A call through the gateway comes from the gateway series (litellm_proxy_total_requests_metric_total,litellm_total_tokens_metric_total), as AI Requests in Range and Tokens Processed in Range do (feat(monitoring): the ai-spend dashboard counts gateway traffic from the gateway's own series, shows failed attempts and names each caller #1668). - Each time series window follows the step (
$__intervalor$__rate_interval). - The slot-wait panel shows a series that the client sends, or the dashboard removes it.
openspec/specs/llm-slot-wait/spec.mdchanges with it. - The spend panels of
devops-ai-rag.jsonread the gateway spend counterlitellm_spend_metric_total, as the spend panels ofai-spend.jsondo after fix(monitoring): read AI spend from the gateway counter #4724.
Acceptance criteria
tests/fixtures/dashboard_queries/ai-spend.yamlholds a bars case for the request and token panels, and the bars add up to the fixture total within 1 %.- Live at 7 d: the request bars add up to at least 95 % of
sum(increase(devops_cli_ai_requests_total[7d])). tests/prometheus/test_dashboard_queries.pypasses.
Source: #4724
Alternatives check of 2026-11-24: none.
Tool: none found.
Reason: Searches found only PromQL linters and dashboard generators; none rewrites panel queries or handles sparse counters, so the fix stays in the dashboard JSON with increase(...[$__interval]), a 1 h Min step and the repo's fixture test.
Lacks:
- No tool rewrites rate() windows inside panel JSON
- No handling of counters with one sample per hour
- No switch to gateway series or drop of slot-wait panel
- No fixture test that bar totals add up
Proposed design
Problem statement
AI request and token panels lose most counts because rate(...[5m]) reads sparse counters. Several panels use fixed windows at shorter steps, and the Ollama slot-wait panel has no series. The RAG dashboard spend panels still read the direct spend counter. The change makes each panel follow the step, uses gateway counters for gateway calls, removes the empty slot-wait panel and its spec requirement, and moves the RAG spend panels to the gateway spend counter. A person checks the live 7-day request total after the merge.
Acceptance criteria
Requirement: Hourly request and token bars
The request and token panels SHALL draw one bar per hour with increase(...[$__interval]) and a Min interval of 1h.
Scenario: Request and token bars follow the step
- WHEN The dashboard query cases for the request and token panels run with
__intervalset to 1h. - THEN
uv run pytest tests/prometheus/test_dashboard_queries.pypasses and each query uses a 3600 s window.
Requirement: Gateway counters for gateway calls
The request and token panels SHALL take gateway calls from litellm_proxy_total_requests_metric_total and litellm_total_tokens_metric_total.
Scenario: Gateway calls use gateway series
- WHEN The dashboard query cases for the request and token panels run.
- THEN
uv run pytest tests/prometheus/test_dashboard_queries.pypasses with the two gateway counters in the queries.
Requirement: Bars add up to fixture total
Each bars case of tests/fixtures/dashboard_queries/ai-spend.yaml SHALL add up to its total within 1 %.
Scenario: Sparse counter bars add up
- WHEN The bars cases of the ai-spend fixture run.
- THEN
uv run pytest tests/prometheus/test_dashboard_queries.py -k barspasses with each bar sum within 1 % of its total.
Requirement: Rolling windows follow the step
Response Cache Hit Share, Gateway Attempts by Status and Gateway Requests and Tokens by Caller SHALL use $__interval or $__rate_interval instead of a fixed window.
Scenario: Sub-hour steps do not overlap
- WHEN The dashboard query cases for these panels run with
__intervalset to 15m. - THEN
uv run pytest tests/prometheus/test_dashboard_queries.pypasses with the window variables interpolated at the 15m step.
Requirement: Gateway spend counter in the RAG dashboard
The AI Spend in Range and AI Spend Rate by Server panels of k8s/devops/dashboards/devops-ai-rag.json SHALL read litellm_spend_metric_total.
Scenario: RAG spend panels use the gateway counter
- WHEN The dashboard query cases for
devops-ai-ragrun. - THEN
uv run pytest tests/prometheus/test_dashboard_queries.pypasses withlitellm_spend_metric_totalin both queries.
Requirement: Slot-wait panel removed with its spec
The AI spend dashboard SHALL remove the Ollama Slot Wait by Priority panel and openspec/specs/llm-slot-wait/spec.md SHALL remove the requirement that the dashboard charts the p95 Ollama slot wait by priority.
Scenario: Slot-wait panel is absent
- WHEN The dashboard query cases run after the panel removal.
- THEN
uv run pytest tests/prometheus/test_dashboard_queries.pypasses and no case names the removed panel.
Requirement: Pending a person after the merge
A person SHALL check at 7 days after the merge that the request bars add up to at least 95 % of sum(increase(devops_cli_ai_requests_total[7d])).
Scenario: Live 7-day request bars add up
- WHEN A person runs the live 7-day query after the merge.
- THEN The request bars add up to at least 95 % of
sum(increase(devops_cli_ai_requests_total[7d])).
Existing Tool Considered
The alternatives check in the issue body records verdict none and no tool. The proposal edits k8s/devops/dashboards/ai-spend.json, k8s/devops/dashboards/devops-ai-rag.json, tests/fixtures/dashboard_queries/ai-spend.yaml and tests/fixtures/dashboard_queries/devops-ai-rag.yaml directly. The block's Lacks: list gives what the considered tools lack.
Key questions
- Which window and interval do the request and token panels use?: Use
increase(...[$__interval])and a Min interval of 1h. A 5 minratewindow holds 0 or 1 sample of a counter that sends about 6 samples in 6 h. (best practice) [sources: k8s/devops/dashboards/ai-spend.json, tests/prometheus/test_dashboard_queries.py, tests/fixtures/dashboard_queries/ai-spend.yaml]- Chosen:
increase(...[$__interval])with Min interval 1h. It follows the step and a bars case adds up to the fixture total within 1 %. - Rejected:
rate(...[5m]). A 5 min window holds 0 or 1 sample, so the panel loses most counts. - Rejected:
increase(...[1h]). A fixed 1h window does not follow a step under 1h and overlaps the points.
- Chosen:
- Which series count a gateway call in the request and token panels?: Use
litellm_proxy_total_requests_metric_totalfor requests andlitellm_total_tokens_metric_totalfor tokens. Add onlydevops_cli_ai_requests_totalanddevops_cli_ai_tokens_totalcalls that did not go through the gateway. (best practice) [sources: k8s/devops/dashboards/ai-spend.json, k8s/devops/monitoring/prometheus-rules-values.yaml, tests/fixtures/prometheus_rules/slo_llm_gateway_requests_tests.yaml]- Chosen: Gateway counters for gateway calls. AI Requests in Range and Tokens Processed in Range already use them (feat(monitoring): the ai-spend dashboard counts gateway traffic from the gateway's own series, shows failed attempts and names each caller #1668).
- Rejected:
devops_cli_ai_requests_totalanddevops_cli_ai_tokens_totalalone. They are sparse and miss calls that the gateway serves for other callers.
- Which window do the rolling panels use?: Use
$__rate_intervalfor rate queries and$__intervalfor increase queries. Do not use a fixed[1h]window at a step under 1h. (best practice) [sources: tests/prometheus/test_dashboard_queries.py, k8s/devops/dashboards/ai-spend.json]- Chosen:
$__rate_intervalor$__interval. The test calculates$__rate_intervalfrom the step and the scrape interval, so the points do not overlap. - Rejected: fixed
[1h]. At a 15 min step the points overlap four times.
- Chosen:
- What does the change do with the Ollama Slot Wait by Priority panel?: Remove the panel and remove its requirement from
openspec/specs/llm-slot-wait/spec.md. No series exists in 30 days, and a new client metric is outside this dashboard fix. (best practice) [sources: openspec/specs/llm-slot-wait/spec.md, k8s/devops/dashboards/ai-spend.json]- Chosen: Remove the panel and its spec requirement. The query
count by (priority, outcome) (last_over_time(devops_cli_ai_ollama_slot_wait_seconds[30d]))is empty, so the panel shows nothing. - Rejected: Add a client metric for slot wait. The issue gives no client series and no test for a new metric, so this part is larger than the dashboard fix.
- Rejected: Keep the panel with no change. The panel stays empty and the spec stays wrong.
- Chosen: Remove the panel and its spec requirement. The query
- Which spend counter do the spend panels of
devops-ai-rag.jsonread?: Readlitellm_spend_metric_total, as the spend panels ofai-spend.jsondo after fix(monitoring): read AI spend from the gateway counter #4724. (best practice) [sources: k8s/devops/dashboards/ai-spend.json, k8s/devops/dashboards/devops-ai-rag.json, tests/fixtures/dashboard_queries/devops-ai-rag.yaml]- Chosen:
litellm_spend_metric_total. It is the gateway spend counter and it covers every caller, as the ai-spend panels show. - Rejected:
devops_cli_ai_spend_usd_total. It is sparse and low for direct calls, and fix(monitoring): read AI spend from the gateway counter #4724 replaced it in the ai-spend spend panels.
- Chosen:
- Does the dashboard query test support a bars case with a total?: Yes. A case with
barsevaluatessum_over_time((query)[range:interval]), andtest_the_bars_of_each_case_add_up_to_its_total_within_one_percentchecks each expected sample againsttotalwithin 1 %. [sources: tests/prometheus/test_dashboard_queries.py]
Fit
Fits in one pull request.
Suspected block
None.
Dependencies
None.
Activity
dan-petty commentedon Nov 16, 2026
Both fix fixed time windows in monitoring dashboards, but #4732 targets llm-stack.json while the candidate targets ai-spend.json and devops-ai-rag.json.fix(monitoring): read AI spend from the gateway counter (#5924)
devops-cli-service commentedon Nov 17, 2026
The result in the alternatives block of the issue body changed. Before this check: no check. A person decides what the new result means for the item.
Searches (7)
Tools considered:
Searches run:
Sources:
devops-cli-service commentedon Nov 24, 2026
The result in the alternatives block of the issue body changed. Before this check:
partly, tool https://github.com/grafana/dashboard-linter. A person decides what the new result means for the item.Searches (6)
Tools considered:
Searches run:
Sources:
devops-cli-service commentedon Nov 27, 2026
Next step: the stage job writes the plan of the item. See the section Proposed design of the body.
fix(monitoring): follow the step in AI request and token panels (#5922)