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-22: in-use.
The repository already uses this tool.
Tool: BerriAI/litellm (https://github.com/BerriAI/litellm), NOASSERTION, last activity 2026-11-22, maintained.
Reason: Searches found no better alternative; the gateway the project already runs documents custom_prometheus_metadata_labels, which turns one request metadata value into a Prometheus label, so it covers the need once the metric-label premise check passes.
Covers:
- Request metadata written as a Prometheus label on gateway series
- Setting read from the proxy config already in place
- Existing spend and token counters per caller, model and team
Lacks:
- Docs do not state spend and token counters carry the custom label
- No per-repository label without a client change sending metadata
- No series limit or cardinality guard for the new label
Proposed design
Problem statement
The gateway spend series show spend by caller and by model. They do not show spend by repository, so a person cannot see what one repository's roadmap work costs. This change sends the casefolded RepoRef.key as the repo entry of the x-litellm-spend-logs-metadata header on each gateway call, using the repository scope that #4576 adds. 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: Repository scope of the unit of work
The roadmap unit of work SHALL set the repository scope from the RepoRef of its item before its first gateway call.
Scenario: The scope setup of a unit of work
- WHEN A test calls the repository scope setup of the roadmap unit of work for
dan-petty/devops-cliand callsgateway_caller_headers(). - THEN The headers hold
repoequal todan-petty/devops-cli.
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 and that count(litellm_spend_metric_total) is under 2,000.
Scenario: The panel and the spend count after one day
- WHEN A person opens the spend-by-repository panel and runs
count(litellm_spend_metric_total)on the gateway one day after both merges. - THEN The panel lists USD for each repository that made gateway calls, and the count is under 2,000.
Existing Tool Considered
BerriAI/litellm (https://github.com/BerriAI/litellm), the gateway this repository already runs. The issue's alternatives.block records what the tool lacks. The live check in the issue reply confirms that LiteLLM 1.111.0 puts the repo label on the spend and token counters. This change adds the client header and the dashboard panel; the issue's Existing Tool Considered gives about 200,000 tokens and 3 hours to build, and about 5,000 tokens a month to keep. It builds no replacement for the gateway.
Key questions
- Which request field carries the repository to the gateway?: The
x-litellm-spend-logs-metadataheader. It holds a JSON object of spend-log metadata. LiteLLM turns the entry thatcustom_prometheus_metadata_labelsnames into a Prometheus label. The live check of LiteLLM 1.111.0 shows the header sets the label, also on a streamed request, and wins over the body fieldmetadata.repo.gateway_caller_headers()sets the headers of every gateway call, so one change covers the OpenAI client, the embeddings client and the pydantic-ai requests. (best practice) [sources: src/devops_cli/ai/client/network.py:65]- Chosen: The
x-litellm-spend-logs-metadataheader ingateway_caller_headers(). One hook covers every gateway client, and the live check of LiteLLM 1.111.0 shows the header sets the label, also on a streamed request. - Rejected: The
metadatafield of each request body. Three request builders change, and pydantic-ai builds its own request. The live check shows the header wins when both are set. - Rejected: A suffix on
x-litellm-end-user-id. It merges the repository into the caller label and splits the caller series of the dashboard.
- Chosen: The
- Which label name and value form does the change use?: The label is
repo, with nometadata.prefix. The live check of LiteLLM 1.111.0 shows the gateway key isrepo, so the gateway series, thedevops_cli_*series and the log label use one name. The body namesmetadata_repo; read it asrepo. The value is the casefoldedRepoRef.key, which isowner/namein lowercase. The gateway takes any text as a value, so this client keeps the set closed to that form. (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: The label
repowith the casefoldedRepoRef.key. One type builds the value, a case variant keeps one series, and the project's other series already use thereponame. - Rejected: The label
metadata_repo. The live check shows the gateway key isrepo, so this name would split the gateway series from the project's other series. - Rejected:
owner/nameas written. A case variant splits the spend of one repository into two series.
- Chosen: The label
- Where does the client keep the repository value of a call?: The client reads
current_repo()fromsrc/devops_cli/telemetry/repo_context.py, the one repository scope that feat(telemetry): name the repository the same way in logs and traces #4576 adds.repo_scope()sets it for a block, andgateway_caller_headers()writes its casefoldedRepoRef.keywhen it is set. A second context variable innetwork.pywould give one process two scopes that can disagree. The value travels with the call, like the request priority and the reply cap. (best practice) [sources: openspec/changes/4576-name-the-repository-the-same-way/proposal.md:9, openspec/changes/4576-name-the-repository-the-same-way/tasks.md:10, src/devops_cli/ai/client/network.py:53]- 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, and feat(telemetry): name the repository the same way in logs and traces #4576 already builds it. - Rejected: A new context variable in
src/devops_cli/ai/client/network.py. It duplicates the repository scope, and a call can then read a different repository from the log line of the same work. - Rejected: 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 in the roadmap job?: The unit of work sets
repo_scopefrom its--repoRepoReffor its run. The unit makes every gateway call of its job, and it already names its repository for the Job labels and telemetry. The Service worker sets the same scope for its rounds (feat(telemetry): name the repository the same way in logs and traces #4576); the router and the sweep launch the unit and make no gateway call. (best practice) [sources: openspec/changes/4576-name-the-repository-the-same-way/tasks.md:37, docs/SERVICE_PATTERNS.md:73, src/devops_cli/github/repo_ref.py:139]- Chosen: The unit of work sets the scope for its run. The unit makes every gateway call of its job, and it already holds the
RepoRefthat labels its metrics. - Rejected: The router or the sweep sets the scope. They launch the unit and make no gateway call, so the value would not reach the call.
- Rejected: Each step sets the scope. A step can miss the scope, and a call would then send no repository.
- Chosen: The unit of work sets the scope for its run. The unit makes every gateway call of its job, and it already holds the
- Which dashboard shows spend by repository, and does it need feat(roadmap): a dashboard and alerts for the pipeline #3655?: The panel goes on the pipeline dashboard under
k8s/devops/dashboards/. feat(roadmap): a dashboard and alerts for the pipeline #3655 delivers that dashboard. The AI spend dashboard already holds the gateway spend queries. A second panel there would split one cost view across two dashboards. The body names the pipeline dashboard, so feat(roadmap): a dashboard and alerts for the pipeline #3655 stays a dependency. (best practice) [sources: k8s/devops/dashboards/kustomization.yaml:27, tests/fixtures/dashboard_queries/ai-spend.yaml, openspec/specs/ai-spend-pricing/spec.md]- Chosen: The pipeline dashboard of feat(roadmap): a dashboard and alerts for the pipeline #3655. The body names this dashboard, and feat(roadmap): a dashboard and alerts for the pipeline #3655 delivers it, so the panel and its owner are one artifact.
- Rejected: A second panel on the AI spend dashboard. The body names the pipeline dashboard, and a second panel splits one cost view across two dashboards.
- Does the gateway config change belong to this repository?: No. This repository holds no environment tree. The environment of the homelab cluster lives only in dan-petty/homelab (ADR 0032). The setting
custom_prometheus_metadata_labelsand its live proof are the work ofdan-petty/homelab#271. Its draft pull request isdan-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 here. The gateway config moved to dan-petty/homelab, and a copy here would set nothing.
- Does the change wait for the in-flight stage and refine spend telemetry item?: It reuses the shared repository scope that feat(telemetry): name the repository the same way in logs and traces #4576 adds, so feat(telemetry): name the repository the same way in logs and traces #4576 is a dependency. The body names no issue number for the stage and refine spend telemetry item; if that item merges first, it uses the same
repo_contextmodule and the client still readscurrent_repo(). The change adds no second context. (best practice) [sources: openspec/changes/4576-name-the-repository-the-same-way/proposal.md:9, openspec/changes/4576-name-the-repository-the-same-way/tasks.md:10]- Chosen: Reuse the shared
repo_contextof feat(telemetry): name the repository the same way in logs and traces #4576 and wait for it. The body asks to reuse the context where it fits, and one scope keeps the header, the log line and the metric of one call on one repository. - Rejected: Add a client context now and merge in any order. It creates a second repository scope, and the header can disagree with the log line and the metric of the same work.
- Rejected: Wait for the unnamed spend telemetry item only. It has no issue number, and feat(telemetry): name the repository the same way in logs and traces #4576 already adds the module that the client needs.
- Chosen: Reuse the shared
- How does this item treat the premise check of
dan-petty/homelab#271?: The check is done. The spend and token counters of LiteLLM 1.111.0 carry the label, so the item can proceed. The gateway config is the draftdan-petty/homelab#430. The item starts after that merge. AGENTS.md rule 2 asks for the premise check before the code. (best practice) [sources: AGENTS.md:8]- Chosen: Proceed after the merge of
dan-petty/homelab#430. The person's check found the label on the counters, so the premise holds. - Rejected: Return the item with the evidence. The check found the label, so there is no failed premise to return.
- Chosen: Proceed after the merge of
- What series limit does this change state?: The issue states the limit of
count(litellm_spend_metric_total)as 2,000. The live check in the issue reply has 16 spend series now, 6 of roadmap callers, and 64 at most with 9 repositories for the present callers and models. A person runs the query one day after both merges. The limit counts only the spend counter; the count of all gateway series is not this limit, because the label is on 16 metric families and the all-series count is 1,906 now. (best practice) [sources: k8s/devops/dashboards/ai-spend.json:83]- Chosen: Limit
count(litellm_spend_metric_total)under 2,000 and check it after one day. The live check gives 16 spend series now and 64 at most for the present callers and models, so 2,000 leaves room for new models and callers while keeping the check simple. - Rejected: Limit all gateway series under 2,000. The live check shows 1,906 gateway series now and up to 14,600 with the label, so this limit would fail.
- Rejected: Limit the spend count at 64. 64 covers only the present 9 repositories and 6 roadmap callers; a new model or caller would cross it with no cardinality problem.
- Chosen: Limit
- Which tests prove the header without a gateway?: The tests call
gateway_caller_headers()and assert the returned headers. They send no request to a gateway. The LiteLLM 1.111.0 rule onmock_responseandallow_client_mock_responsedoes not apply to them. A test that needs a gateway call uses a model withmock_responsein the gateway config, or a mock provider. [sources: tests/ai/client/test_gateway_caller_headers.py:54, src/devops_cli/ai/client/network.py:65, docs/TESTING.md]
Fit
Fits in one pull request.
Suspected block
The merge of dan-petty/homelab#430 sets the repo label on the gateway series that the panel and the series check read.
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.