Skip to content

fix(monitoring): follow the step in AI request and token panels #5922

Done

Description

@dan-petty

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 counters devops_cli_ai_tokens_total and devops_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.json has the same spend defect: AI Spend in Range and AI Spend Rate by Server ($/hr) read devops_cli_ai_spend_usd_total with rate(...[5m]).

Expected behavior

Acceptance criteria

  • tests/fixtures/dashboard_queries/ai-spend.yaml holds 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.py passes.

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 __interval set to 1h.
  • THEN uv run pytest tests/prometheus/test_dashboard_queries.py passes 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.py passes 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 bars passes 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 __interval set to 15m.
  • THEN uv run pytest tests/prometheus/test_dashboard_queries.py passes 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-rag run.
  • THEN uv run pytest tests/prometheus/test_dashboard_queries.py passes with litellm_spend_metric_total in 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.py passes 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 min rate window 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.
  • Which series count a gateway call in the request and token panels?: Use litellm_proxy_total_requests_metric_total for requests and litellm_total_tokens_metric_total for tokens. Add only devops_cli_ai_requests_total and devops_cli_ai_tokens_total calls 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]
  • Which window do the rolling panels use?: Use $__rate_interval for rate queries and $__interval for 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_interval or $__interval. The test calculates $__rate_interval from 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.
  • 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.
  • Which spend counter do the spend panels of devops-ai-rag.json read?: Read litellm_spend_metric_total, as the spend panels of ai-spend.json do 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.
  • Does the dashboard query test support a bars case with a total?: Yes. A case with bars evaluates sum_over_time((query)[range:interval]), and test_the_bars_of_each_case_add_up_to_its_total_within_one_percent checks each expected sample against total within 1 %. [sources: tests/prometheus/test_dashboard_queries.py]

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Activity

  1. added
    type/bug
    source/agent
    status/new
    value/medium
    effort/medium
    scope/monitoring
    on Nov 16, 2026
  2. dan-petty commented on Nov 16, 2026

    @dan-petty
    OwnerAuthor
  3. added
    priority/p2-medium
    on Nov 16, 2026
  4. devops-cli-service commented on Nov 17, 2026

    @devops-cli-service
    Contributor

    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:

    • Grafana dashboard linter validate PromQL queries JSON, results: 5
    • promtool test rules unit test PromQL increase query fixture yaml, results: 5
    • dashboard-linter rules list grafana/dashboard-linter docs, results: 5
    • cloudflare pint lint Grafana dashboard json support promql checks, results: 5
    • pint prometheus linter promql/rate promql/series checks, results: 5
    • tool to test Grafana dashboard panel queries against synthetic Prometheus data, results: 5
    • dashboard-linter target-rate-interval-rule rate_interval rate irate increase, results: 5

    Sources:

  5. devops-cli-service commented on Nov 24, 2026

    @devops-cli-service
    Contributor

    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:

    • open source tool lint Grafana dashboard PromQL queries rate window too short, results: 5
    • Grafana dashboard PromQL rate on sparse counters increase $__interval min step 1h, results: 5
    • litellm prometheus grafana dashboard template, results: 5
    • cloudflare pint promql linter dashboard, results: 5
    • github cloudflare pint promql, results: 5
    • prometheus promql increase sparse samples last_over_time, results: 5

    Sources:

  6. added
    status/ready
    and removed
    status/new
    on Nov 27, 2026
  7. devops-cli-service commented on Nov 27, 2026

    @devops-cli-service
    Contributor

    Next step: the stage job writes the plan of the item. See the section Proposed design of the body.

  8. added
    owner/agent
    status/in-progress
    status/in-review
    and removed
    status/ready
    status/in-progress
    on Nov 29, 2026
  9. removed
    status/in-review
    owner/agent
    on Nov 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    effort/mediumpriority/p2-mediumscope/monitoringsource/agenttype/bugvalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions