Skip to content

feat(monitoring): the ai-spend dashboard counts gateway traffic from the gateway's own series, shows failed attempts and names each caller #1668

Closed

Description

@dan-petty

Friction

  • Every ai-spend-telemetry panel reads only devops_cli_ai_*, which only devops-cli writes. A call another client sends through the gateway never shows, and neither does an attempt that failed.
  • Open WebUI (about 47 requests, mostly around 2026-10-09) and the Kilo Code editor extension (about 20, on 2026-09-30) used the gateway. Neither appears on the dashboard.
  • Gateway timeouts (5 x 408 on devops-background on 2026-10-10) appear nowhere.
  • The gateway cannot say who called. Every request carries the master key (hashed_api_key=litellm_proxy_master_key, user=default_user_id, end_user=None). Every workstation request arrives from the ingress controller's address. devops-cli sends the generic python-httpx2/2.13.1 user agent.
  • The gateway's token series carry no caller label at all, so tokens cannot be split by caller.
  • In the 24 h ending 2026-10-17 13:20 UTC devops-cli was the only caller and nothing failed, so this item does not explain today's gap. It makes the dashboard complete for every caller from now on.

Evidence

Checked at main 3dd7fa6 (v0.2.36) on 2026-10-17, read-only. LiteLLM source read from the cached 1.103.0 wheel, the gateway's image version.

  • Dashboard: no expression in k8s/monitoring/dashboards/ai-spend.json (:83-877) reads a litellm_* series, and none filters on job.
  • Gateway: only master_key, no database (k8s/llm/gateway/configmap.yaml:187-191, k8s/llm/gateway/deployment.yaml:47-63), so virtual keys are unavailable. feat(agent): devops agent env gives an agent session its own expiring gateway key, run-index access and a read-only kube identity, written to its settings file or a child process and never printed, with --revoke and an audit of every grant #1154 drafts the database item.
  • LiteLLM takes an end-user id from the x-litellm-end-user-id header or the OpenAI user field with no database (litellm/proxy/auth/auth_utils.py:1589-1640, auth_checks.py:1930-1934).
  • It puts that id on request and token series as end_user only when litellm_settings.enable_end_user_cost_tracking_prometheus_only is true (litellm/utils.py:9795-9799). The gateway config does not set it.
  • Live label names: litellm_proxy_total_requests_metric_total carries status_code, client_ip and user_agent. litellm_input_tokens_metric_total and litellm_output_tokens_metric_total carry end_user but neither client_ip nor user_agent.
  • Live 24 h: the gateway counted 54 chat and 136 embedding requests, all status 200, all one user agent. Its increase() equals the LiteLLM access-log count exactly.
  • Some older gateway series exist twice, with and without k8s_cluster_name, after a label rename, so summing across both double-counts.
  • devops-cli sets no User-Agent of its own: chat headers come from _openai_compat_headers (src/devops_cli/ai/client/openai.py:53, used at :185, :213, :240); embeddings build their own client (src/devops_cli/ai/rag/embeddings.py:375-380, :659).
  • The broker's default User-Agent is a stale hard-coded devops-cli/0.2.9 (src/devops_cli/http/broker.py:41).
  • Open WebUI also has direct Ollama URLs and RAG_EMBEDDING_ENGINE=ollama (k8s/llm/values-open-webui.yaml:20-22, :38-41), which bypass the gateway. No direct call appeared in 7 days of Ollama logs, and ollama-24gib has no running pod.

Remedy

Tests first, reading the dashboard JSON and gateway YAML, plus an httpx2 MockTransport for the client headers. No network, cluster or model:

  • In tests/test_k8s_monitoring_dashboards.py: "AI Requests in Range" and "Tokens Processed in Range" take gateway traffic only from litellm_* series filtered to status_code=~"2..", add devops_cli_ai_*{provider!="gateway"} for traffic that bypasses the gateway, and never add both families for the same call.
  • The same test: a "Gateway attempts by status" panel, a "Gateway requests and tokens by caller" panel and a "devops-cli coverage" stat (devops-cli gateway requests over gateway 2xx requests) exist.
  • In tests/test_k8s_monitoring_integration.py: the gateway configmap sets enable_end_user_cost_tracking_prometheus_only: true.
  • In the client tests: a devops-cli chat request and embedding request each carry x-litellm-end-user-id from a closed set (the OTel service.name, such as devops-cli or roadmap-service) and User-Agent: devops-cli/<__version__>.
  • The broker's default User-Agent reads __version__.

Code:

  • Dashboard (k8s/monitoring/dashboards/ai-spend.json) as tested. Sum gateway series without cluster and k8s_cluster_name. Keep devops_cli_ai_*{provider="gateway"} only for per-stage, per-model and cache-hit panels and the coverage ratio.
  • Gateway (k8s/llm/gateway/configmap.yaml): the end-user setting.
  • devops-cli: set the caller header and User-Agent where the shared HTTP client is built, so chat and embeddings both carry them. Coordinate with refactor(cli): Unify HTTP and DNS seams with shared fakes #1314 (one HTTP seam) and fix(security): move the remaining HTTP clients onto the egress-checked factory and delete the pre-flight resolve paths #1381 (egress-checked factory); whichever lands first owns the header.
  • Open WebUI: drop the direct ollamaUrls and switch its RAG embeddings to the gateway, or record why they stay. Its saved connections live in its database, so the live settings change too. Its caller value is a fixed mapping, never per-user ids, so labels stay bounded and hold no user names.
  • Savings panels are not changed here. Whether gateway tokens are priced for savings is the savings-reference item's decision.
  • Pending a person: after the gateway redeploys, sum by (end_user) (increase(litellm_input_tokens_metric_total[1h])) shows devops-cli after a workstation run.

Related: #1019 (failed attempts in the ledger), #1154 (virtual keys need the gateway database; not needed here).

Proposed: type/feature, P2-Medium. No other item waits on it.

Proposed design

Problem statement

The ai-spend dashboard reads only devops_cli_ai_* metrics. Traffic from other callers through the gateway, and failed gateway attempts, are invisible. The gateway cannot name its callers because every request carries the master key and the token series carry no caller label. This item makes the dashboard complete for every caller and shows failed attempts.

Acceptance criteria

  • Criterion 1: The AI Requests in Range and Tokens Processed in Range panels read gateway traffic from litellm_* series filtered to status_code=~"2.." and non-gateway traffic from devops_cli_ai_{provider!="gateway"}, without adding both families for the same call.
    Verification: Run tests/test_k8s_monitoring_dashboards.py. The panel expressions contain litellm_ series and devops_cli_ai_
    {provider!="gateway"}. They do not contain devops_cli_ai_*{provider="gateway"} in those panels.
  • Criterion 2: A Gateway attempts by status panel exists and shows all status codes from the gateway request counter.
    Verification: The dashboard JSON contains a panel titled Gateway attempts by status. Its query reads litellm_proxy_total_requests_metric_total grouped by status_code.
  • Criterion 3: A Gateway requests and tokens by caller panel exists and splits requests and tokens by the end_user label.
    Verification: The dashboard JSON contains a panel titled Gateway requests and tokens by caller. Its queries group by end_user.
  • Criterion 4: A devops-cli coverage stat exists and shows the ratio of devops-cli gateway requests to all gateway 2xx requests.
    Verification: The dashboard JSON contains a stat panel titled devops-cli coverage. Its expression divides devops-cli gateway requests by gateway 2xx requests.
  • Criterion 5: The gateway configmap sets enable_end_user_cost_tracking_prometheus_only to true.
    Verification: Run tests/test_k8s_monitoring_integration.py. The file k8s/llm/gateway/configmap.yaml contains the key enable_end_user_cost_tracking_prometheus_only with value true.
  • Criterion 6: A devops-cli chat request carries x-litellm-end-user-id from the closed set and User-Agent: devops-cli/<version>.
    Verification: Client tests using httpx2 MockTransport assert both headers on a chat request. The end-user-id value is one of the closed set.
  • Criterion 7: A devops-cli embedding request carries x-litellm-end-user-id from the closed set and User-Agent: devops-cli/<version>.
    Verification: Client tests using httpx2 MockTransport assert both headers on an embedding request.
  • Criterion 8: The broker default User-Agent reads version and no longer holds the stale string devops-cli/0.2.9.
    Verification: The file src/devops_cli/http/broker.py sets User-Agent from version. The literal string devops-cli/0.2.9 is absent.
  • Criterion 9: Dashboard expressions for gateway series sum without filtering on cluster or k8s_cluster_name, so the label-rename duplicate does not double-count.
    Verification: Run tests/test_k8s_monitoring_dashboards.py. No gateway-series expression in the dashboard contains a cluster= or k8s_cluster_name= matcher.
  • Criterion 10: Open WebUI drops its direct ollamaUrls or records why they stay, and its RAG embeddings use the gateway.
    Verification: The file k8s/llm/values-open-webui.yaml no longer lists ollamaUrls, or it holds a recorded reason. The RAG embedding engine value points to the gateway.

Key questions

  • Where does devops-cli set the caller header and User-Agent so both chat and embeddings carry them?: In the shared HTTP client (the broker), so every request built through it carries both headers without per-client duplication. (proposed) [sources: src/devops_cli/http/broker.py]
  • What value does devops-cli send for x-litellm-end-user-id?: The OTel service.name, a closed set such as devops-cli or roadmap-service. It is never a per-user identifier. (proposed) [sources: src/devops_cli/http/broker.py]
  • What caller value does Open WebUI use?: A fixed mapping, never per-user ids, so the end_user label stays bounded and holds no user names. (proposed) [sources: k8s/llm/values-open-webui.yaml]
  • Are the savings panels changed by this item?: No. Whether gateway tokens are priced for savings is the savings-reference item's decision. (proposed) [sources: k8s/monitoring/dashboards/ai-spend.json]
  • Does the gateway need a database for end-user tracking?: No. LiteLLM reads the end-user id from the x-litellm-end-user-id header with no database. The gateway runs with only a master key and no database. [sources: k8s/llm/gateway/deployment.yaml]
  • How does the dashboard avoid double-counting gateway series that exist with and without k8s_cluster_name after the label rename?: Sum gateway series without a cluster or k8s_cluster_name matcher so both variants collapse into one sum. (proposed) [sources: k8s/monitoring/dashboards/ai-spend.json]
  • Does this item depend on refactor(cli): Unify HTTP and DNS seams with shared fakes #1314 or fix(security): move the remaining HTTP clients onto the egress-checked factory and delete the pre-flight resolve paths #1381?: No hard dependency. Whichever of refactor(cli): Unify HTTP and DNS seams with shared fakes #1314 or fix(security): move the remaining HTTP clients onto the egress-checked factory and delete the pre-flight resolve paths #1381 lands first owns the header seam. This item coordinates with it but can proceed independently. (proposed) [sources: src/devops_cli/http/broker.py]

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Activity

  1. added
    source/agent
    type/feature
    on Oct 18, 2026
  2. dan-petty commented on Oct 18, 2026

    @dan-petty
    OwnerAuthor

    Intake placed this item to the backlog: at intake only a critical fix goes into a release; a release start pulls Ready items in, P0 features first.

    • Type: type/feature. The candidate proposes adding new functionality to the AI spend dashboard.
    • Priority: P2-Medium. The feature improves observability but does not fix a critical issue or introduce a security concern.
    • Value: High. The change makes the dashboard complete by showing all gateway traffic, including failed attempts and caller information.
    • Effort: Medium. Requires changes to tests, gateway configuration, and client headers, but does not involve major architectural shifts.
  3. dan-petty commented on Oct 28, 2026

    @dan-petty
    OwnerAuthor

    Status set to Ready at 4da1e34 (see proposed design in issue body).

  4. added
    priority/p2-medium
    status/ready
    effort/medium
    value/high
    on Oct 28, 2026
  5. removed
    status/ready
    on Oct 30, 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-mediumsource/agenttype/featurevalue/high

    Type

    No type

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions