Repository navigation
Description
Update 2026-11-26 (infra move): the gateway config moved to dan-petty/homelab.
This issue keeps the client part (send repo as request metadata from gateway_caller_headers, with its tests) and the spend-by-repository panel in k8s/devops/dashboards/. The custom_prometheus_metadata_labels setting, the premise check on the live /metrics and the series count are in the homelab follow-up. Do that one first: its premise check decides if this item can proceed.
Follow-up: dan-petty/homelab#271.
Problem or Motivation
The gateway spend series show spend by caller (end_user) and model, but not by repository. A person cannot see what one repository's roadmap work costs. After the move, the row comes from end_user = roadmap-<row> (the service name of each row pod), so only the repository is missing.
Proposed Solution & Architectural Design
- Premise check first (AGENTS.md rule 2): the LiteLLM page documents
custom_prometheus_metadata_labels, but does not say thatlitellm_spend_metricandlitellm_total_tokens_metriccarry these labels (https://docs.litellm.ai/docs/proxy/prometheus). Send one request with metadata to the gateway and read/metrics. If the two metrics lack the label, return the item with the evidence. src/devops_cli/ai/client/network.py(gateway_caller_headers, line 64): a context variable that the router, the sweep or a unit pod sets for the repository of the work, sent as request metadatarepo= the casefoldedkeyofRepoRef.- Gateway config (dan-petty/homelab follow-up):
custom_prometheus_metadata_labels: ["metadata.repo"]. - No row label: the row comes from
end_user. - Start after the in-flight stage and refine spend telemetry merges, and reuse its context where it fits.
Target Subsystem
AI & Agentic Review Pipeline (gateway client and LiteLLM gateway configuration).
Existing Tool Considered
LiteLLM custom_prometheus_metadata_labels (configuration of an open tool) and a small client change. Cost: about 200,000 tokens and 3 hours, about 5,000 tokens a month to keep.
Acceptance Criteria
- The two gateway series carry
metadata_repo= the casefoldedowner/namefor each Service call, and no repo for a call outside a repository scope. - The issue states a series limit (repository values x caller names x models), and a query shows
count(litellm_spend_metric_total)under it after one day. - The pipeline dashboard shows USD by repository.
Dependencies
- feat(roadmap): a dashboard and alerts for the pipeline #3655 (the pipeline dashboard).
- "fix(monitoring): drop per-pod labels from gateway spend series".
- "feat(roadmap): name each repository's resources from one RepoRef".
- The in-flight stage and refine spend telemetry.
Source: #4517
Alternatives check of 2026-11-27: in-use.
The repository already uses this tool.
Tool: BerriAI/litellm (https://github.com/BerriAI/litellm), NOASSERTION, last activity 2026-11-28, maintained.
Reason: Searches found LiteLLM, the gateway already in use, documents spend and token counters with caller and model labels and supports custom metadata labels; only the client header and dashboard panel remain.
Covers:
- Request metadata becomes a Prometheus label on gateway metrics
- Spend and token counters already carry caller and model dimensions
- One OpenAI-compatible gateway serves chat, embeddings and agent calls
Lacks:
- No repository value until the client sends request metadata
- No built-in spend-by-repository dashboard panel
- No cardinality limit on custom label values
Proposed design
Problem statement
The gateway spend series show spend by caller and by model. They do not show spend by repository. This change sends the casefolded RepoRef.key as the repo entry of the LiteLLM spend-log metadata header from gateway_caller_headers(). It adds a spend-by-repository panel to the pipeline dashboard. The gateway label setting and its live proof are in dan-petty/homelab#271 and its draft dan-petty/homelab#430.
Acceptance criteria
Requirement: Repository spend-log metadata
Every gateway call inside a repository scope SHALL send the casefolded RepoRef.key as the repo entry of its x-litellm-spend-logs-metadata header.
Scenario: A call inside a repository scope
- WHEN A test enters
repo_scope("Dan-Petty/DevOps-CLI")and callsgateway_caller_headers(). - THEN The headers hold
x-litellm-spend-logs-metadatawith the JSON entryrepoequal todan-petty/devops-cli.
Requirement: No repository outside a scope
A gateway call outside a repository scope MUST send no repo entry.
Scenario: A call with no repository scope
- WHEN A test calls
gateway_caller_headers()with no repository scope set. - THEN The headers hold no
x-litellm-spend-logs-metadataheader, or its value holds norepoentry.
Requirement: Scope ends with its block
The repository scope MUST end with its block, so a later call sends no repo entry.
Scenario: A call after the scope ends
- WHEN A test leaves a
repo_scopeblock and callsgateway_caller_headers(). - THEN The headers hold no
repoentry.
Requirement: Spend by repository panel
The pipeline dashboard SHALL show gateway spend in USD by repository, grouped by the repo label.
Scenario: The dashboard manifest validates
- WHEN
uv run devops ci --check --only k8sruns on the branch after feat(roadmap): a dashboard and alerts for the pipeline #3655 merges. - THEN The check validates the dashboard manifest and reports no failure.
Requirement: Pending a person after the merge
One day after this change and the merge of dan-petty/homelab#430, a person MUST confirm that the panel lists USD by repository.
Scenario: The panel after one day
- WHEN A person opens the spend-by-repository panel one day after both merges.
- THEN The panel lists USD for each repository that made gateway calls.
Existing Tool Considered
BerriAI/litellm (https://github.com/BerriAI/litellm), verdict in-use. The issue's alternatives block records what the tool covers and lacks. This change adds the client repo metadata and the dashboard panel. It builds no replacement for the gateway. The series limit stays in dan-petty/homelab#271.
Key questions
- Which request metadata carries the repository to the gateway?: The LiteLLM spend-log metadata header,
x-litellm-spend-logs-metadata, with the JSON entryrepo.gateway_caller_headers()adds it, so every gateway client sends it. (best practice) [sources: src/devops_cli/ai/client/network.py:64]- Chosen: Use the
x-litellm-spend-logs-metadataheader ingateway_caller_headers(). One hook covers every gateway client. The issue asks for request metadata fromgateway_caller_headers. - Rejected: Set the
metadatafield in each request body. Three request builders change, and pydantic-ai builds its own request. - Rejected: Add a suffix to
x-litellm-end-user-id. It merges the repository into the caller label and splits the caller series.
- Chosen: Use the
- Which label name and value form does the change use?: The label is
repo. The value is the casefoldedRepoRef.key, which isowner/namein lowercase. (best practice) [sources: src/devops_cli/github/repo_ref.py:139, docs/adr/0022-one-repository-reference-names-the-objects-labels-and-keys-of-each-repository.md]- Chosen: Use
repowith the casefoldedRepoRef.key. One type builds the value, and the casefolded form keeps one series for one repository. - Rejected: Use
metadata_repo. The gateway key isrepo, so this name would split the gateway series from the project's other series. - Rejected: Use the
owner/namespelling as written. A case variant splits the spend of one repository into two series.
- Chosen: Use
- Where does the client read the repository of a call?: The client reads
current_repo()fromsrc/devops_cli/telemetry/repo_context.py. The sharedrepo_scopesets it. The client writes no second context variable. (best practice) [sources: src/devops_cli/telemetry/repo_context.py:21]- Chosen: Reuse
repo_scopeandcurrent_repofromsrc/devops_cli/telemetry/repo_context.py. One repository scope serves the logs, the metrics, the traces and the gateway header. feat(telemetry): name the repository the same way in logs and traces #4576 builds it. - Rejected: Add a new context variable in
src/devops_cli/ai/client/network.py. It duplicates the repository scope. A call can then read a different repository from the log line of the same work. - Rejected: Add a parameter on each call. Every layer between the call site and the provider takes the parameter.
- Chosen: Reuse
- Which code sets the repository scope for a roadmap job?: The roadmap unit of work sets
repo_scopefrom its--repoRepoReffor its run. The router and the sweep make no gateway call. [sources: docs/SERVICE_PATTERNS.md:73] - Which dashboard holds the spend-by-repository panel?: The pipeline dashboard under
k8s/devops/dashboards/, after feat(roadmap): a dashboard and alerts for the pipeline #3655 merges. The AI spend dashboard already holds the gateway spend queries, so a second panel there would split one cost view. (best practice) [sources: k8s/devops/dashboards/kustomization.yaml:27, tests/fixtures/dashboard_queries/ai-spend.yaml]- Chosen: Add the panel to the pipeline dashboard from feat(roadmap): a dashboard and alerts for the pipeline #3655. The issue names the pipeline dashboard, and feat(roadmap): a dashboard and alerts for the pipeline #3655 delivers it.
- Rejected: Add a second panel to the AI spend dashboard. The issue names the pipeline dashboard. A second panel splits one cost view across two dashboards.
- Does the gateway label setting belong to this repository?: No. The environment tree lives in dan-petty/homelab (ADR 0032). The setting and its live proof are in
dan-petty/homelab#271and its draftdan-petty/homelab#430. (best practice) [sources: docs/adr/0032-infrastructure-templates-live-in-four-homes.md:41, CONTEXT.md]- Chosen: Keep the gateway config in dan-petty/homelab. This repository ships no environment tree, so no manifest here sets the gateway.
- Rejected: Change the gateway config in this repository. The gateway config moved to dan-petty/homelab. A copy here would set nothing.
Fit
Fits in one pull request.
Suspected block
The premise check in dan-petty/homelab#271 and the merge of its draft dan-petty/homelab#430 set the repo label on the gateway series that the panel reads.
Activity
dan-petty commentedon Nov 11, 2026
Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones.
featprefix of the title gives the type.(ai)scope of the title gives the scope.Improves cost attribution but does not fix a broken or unsafe behaviour.Lets a person see per-repository spend, which aids budget decisions.One context variable, one config line, and a premise check; the body estimates about 3 hours.Both improve gateway spend visibility, but #1668 adds dashboard panels for callers and failures while the candidate adds a repo label to the metrics themselves.devops-cli-service commentedon Nov 11, 2026
Refine cannot set this item to Ready at 818ac6f while the items below stay open. The next refine round looks at the item again when they close, or when a person replies in a comment or edits the body.
devops-cli-service commentedon Nov 22, 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 (8)
Tools considered:
Searches run:
Sources:
devops-cli-service commentedon Nov 26, 2026
Next step: the open items close, or a person replies in a comment or edits the body. See Dependencies in the section Proposed design of the body.
dan-petty commentedon Nov 27, 2026
The premise check of dan-petty/homelab#271 is done, and the gateway part is the draft dan-petty/homelab#430. This item can proceed after that merge. Results for LiteLLM 1.111.0, from its source at the tag
v1.111.0and from a test gateway pod with the config of that pull request:litellm_spend_metric_totalandlitellm_total_tokens_metric_totalhad the repository of each request. So had 14 more metric families: the request counters, five latency histograms, the deployment counters and the two gauges of the key limits.repo, notmetadata_repo. The gateway key isrepo, with no prefixmetadata., so the gateway series, thedevops_cli_*series and the log label of dan-petty/homelab#270 use one name. The acceptance criterion of this issue namesmetadata_repo: read it asrepo.x-litellm-spend-logs-metadata: {"repo": "<owner>/<name>"}got the label, also a streamed one. The body fieldmetadata.repoworks too, and the header wins when both are set. A value with/,-and.kept its text.repogetsrepo="None". A call outside a repository scope sends nothing.RepoRef.key, which is the value form of therepolabel of thedevops_cli_*series (9 repository values now).count(litellm_spend_metric_total)is 16 now, 6 of roadmap callers, so 64 at most with 9 repositories for the present callers and models. The limit of under 2,000 is the limit of this count. All gateway series are 1,906 now and pass 2,000 with the label (14,600 at most), because the label is on 16 families.litellm_llm_api_failed_requests_metric_totalhad the repository.litellm_proxy_failed_requests_metric_totaland the failed rows oflitellm_proxy_total_requests_metric_totalhadNone.mock_responseof a client unless the key or the team allows it (allow_client_mock_response). A test needs a model withmock_responsein the gateway config, or a mock provider.The check of the series count one day after the client sends the repository stays in this item, with the panel.
devops-cli-service commentedon Nov 27, 2026
Next step: the open items close, or a person replies in a comment or edits the body. See Dependencies in the section Proposed design of the body.
devops-cli-service commentedon Dec 1, 2026
Owner question: See Suspected block in the section Proposed design of the body.
Options
Recommendation: Decide the question: only a person can answer it.
Evidence