Repository navigation
Description
Problem or Motivation
The Service metrics row runs for 7 repositories (src/devops_cli/roadmap/run.py:765-768), but the PROJECT_* gauges have no repo label (src/devops_cli/github/metrics.py:944-971). So 7 writers share one series. Measured: devops_cli_project_releases has 236 changes in 24 h and flips 10/0/4 seconds apart; sum(devops_cli_project_items{job='roadmap-service'}) at a 5 min step goes 1,940, 6, 1,940, 13; devops_cli_project_stars shows 1 while the GitHub API gives 2 (274 changes in 24 h). _sent_item_series (metrics.py:897) is one set for the process, so each repository's run sends 0 for the item label sets of the repository before. A second writer: 'devops gh metrics --emit-telemetry' writes the same gauges under job devops-cli, also with --limit and --milestone (src/devops_cli/commands/gh.py:2224-2232); its 2026-10-27 snapshot (items closed 1,083, open 232) is still in the default 30 d range of project-metrics.json.
Proposed Solution & Architectural Design
Add {'repo': report.repo} to every gauge that emit_project_metrics_telemetry, _emit_traffic and _emit_item_counts send. Key _sent_item_series by repo, so a snapshot sends 0 only for the label sets of its own repository that are gone. In gh.py, refuse --emit-telemetry together with --milestone or a --limit other than the default, with a message that names the option, so a filtered snapshot never enters the series. The dashboard queries keep working (they sum over the new label) until the project-metrics item adds the filter. Tests first. Use the casefolded RepoRef key as the value, as #4576 sets for all telemetry. Owner decision 1 of the tracker moves the release, CI run, star and fork facts to the GitHub data source; until that item removes those gauges, they get the label too.
Target Subsystem
Kubernetes & Minikube Automation (Grafana dashboards and telemetry).
Existing Tool Considered
No tool is needed: the change adds one label to the existing emitter.
Acceptance Criteria
- A test emits the reports of repository A and repository B in one process and finds, for each
PROJECT_*gauge, one series for each repository with its repo label. - The same test finds no 0 written for a label set of repository A during the run of repository B.
- A test shows that a label set that goes away from repository A gets one 0 in repository A only.
- A test shows that 'devops gh metrics --emit-telemetry --milestone X' and '--emit-telemetry --limit 5' exit with an error that names the option and emit nothing.
- Live, 24 h after the rollout: count by (repo) (last_over_time(devops_cli_project_items{job='roadmap-service'}[1h])) gives 7 repositories; for the devops-cli repository, max over min of sum(devops_cli_project_items{job='roadmap-service'}) over 24 h is below 1.2 (today 1,940 against 6); the stars value equals stargazers_count from the GitHub API.
Files
src/devops_cli/github/metrics.pysrc/devops_cli/commands/gh.pytests/github/test_github_metrics.pytests/commands/test_gh_cmd.py
Dependencies
None.
Related
#4576 (one repository name in logs, metrics and traces), #4579.
Source: #4675
Proposed design
Problem statement
The metrics row of the Service runs for 7 repositories in one process. The PROJECT_* gauges carry no repo label, so 7 writers share one series and overwrite each other; the dashboard shows values that belong to no one repository (stars read 1 while the GitHub API gives 2, and the items sum flips between 1,940 and 6). _sent_item_series is one set for the process, so a repository sends 0 for the item label sets of the repository before it. The command devops gh metrics --emit-telemetry adds a filtered snapshot to the same series.
Acceptance criteria
Requirement: Repo label on every project gauge
Each PROJECT_* gauge that the emitter sends SHALL carry a repo label with the casefolded RepoRef key of its repository.
Scenario: Two repositories in one process
- WHEN A test emits the report of
Example/Oneand then the report ofExample/Twoin one process. - THEN For each
PROJECT_*gauge, the collector holds a series withrepo=example/oneand a series withrepo=example/two, each with its own value.
Requirement: No zero for another repository's label sets
The emitter MUST send a 0 only for an item label set that its own repository sent before.
Scenario: A run of a second repository
- WHEN A test emits the item label set
(open, bug)forExample/One, then a report ofExample/Twowith another label set. - THEN No point with the value 0 carries
repo=example/one, andExample/Twosends its own label set only.
Requirement: One zero for a label set that goes away
The emitter SHALL send one 0 for an item label set of its repository that a later report drops.
Scenario: An item closes
- WHEN A test emits
(open, bug)forExample/One, then a report of the same repository that holds only(closed, bug). - THEN The collector holds one point of value 0 with
repo=example/oneand label set(open, bug), and the next report of that repository sends no point for it.
Requirement: Refused filter on the telemetry option
The command devops gh metrics --emit-telemetry MUST exit with an error that names the option when --milestone is given or when --limit differs from its default.
Scenario: A filtered snapshot
- WHEN A test runs
devops gh metrics --emit-telemetry --milestone 2026-11,--emit-telemetry --limit 5,--emit-telemetry --limit 10, and--emit-telemetryalone. - THEN The two filtered runs exit non-zero, print the name of the refused option and send no point; the runs with
--limit 10and with--emit-telemetryalone send their points.
Requirement: Each repository keeps its own value
Each point of a PROJECT_* gauge SHALL carry the value of the report that its repo label names.
Scenario: Two star counts
- WHEN A test emits the report of
Example/Onewith 2 stars and the report ofExample/Twowith 7 stars. - THEN The point with
repo=example/oneholds 2.0 and the point withrepo=example/twoholds 7.0, and no point holds the value of the other repository.
Requirement: The project instrument descriptions name the repo label
The description of each PROJECT_* instrument SHALL name repo.
Scenario: A reader of the instruments
- WHEN A test reads the descriptions of the
PROJECT_*instruments fromINSTRUMENTS. - THEN Each description names
repo, and the description ofPROJECT_ITEMSalso namesrelease,state,typeandpriority.
Existing Tool Considered
The OpenTelemetry Python SDK 1.45.1 is already a direct dependency (pyproject.toml:52) and builds the MeterProvider that records and exports the gauges (src/devops_cli/telemetry/tracer.py:1031); it is open and maintained (PyPI opentelemetry-sdk, src/devops_cli/ai/knowledge_base/devops_cli/libraries/opentelemetry.md:22). It covers the repo label because each gauge attribute becomes a Prometheus label through the OTLP exporter and the collector. It lacks the per-repository _sent_item_series key and the CLI guard. The project code that the SDK does not cover is a dict key in _sent_item_series and a guard in src/devops_cli/commands/gh.py, about 20 lines; it costs about 2,000 tokens to write, about 100 tokens a quarter to keep, about 1,000 tokens to fix, and about half a day with one CI run. The change adds no dependency and no exporter of its own.
Key questions
- Which value does the
repolabel carry?: The label carriesRepoRef(report.repo).key, the full casefoldedowner/name. It does not useRepoRef.metric_value, which maps a repository outsideservice.repostoother: two unconfigured repositories would then share one series, and the acceptance test forExample/OneandExample/Twowould not tell them apart. ADR 0022 says telemetry useskey. (best practice) [sources: docs/adr/0022-one-repository-reference-names-the-objects-labels-and-keys-of-each-repository.md:51, src/devops_cli/github/repo_ref.py:129, src/devops_cli/github/repo_ref.py:201]- Chosen: RepoRef(report.repo).key. The ADR says telemetry uses the casefolded key, and the issue asks for the key of each repository; the label then names each repository in the acceptance test.
- Rejected: RepoRef(report.repo).metric_value(service.repos). It maps a repository outside
service.repostoother, so two unconfigured repositories share one series and the test forexample/oneandexample/twofails.
- Where does the emitter add the
repolabel?:emit_project_metrics_telemetrybuildsrepo_key = RepoRef(report.repo).keyonce and passes it to the three helpers. The top-level gauges use it directly;_emit_traffic,_emit_item_countsand_emit_item_agesadd it to each point they send. Each point gets the key of the report that holds it, and the cache and the points use the same value. (best practice) [sources: src/devops_cli/github/metrics.py:906, src/devops_cli/github/metrics.py:919, src/devops_cli/github/metrics.py:932, src/devops_cli/github/metrics.py:944]- Chosen: Build the key once in
emit_project_metrics_telemetryand add it in the three emit functions. One conversion gives every point and the cache the same casefolded value, and each function still holds the points it sends. - Rejected: Build the key in each helper from
report.repo. Three conversions can drift, and_emit_item_agesalready sendsreport.repowithout casefolding it. - Rejected: Add the label in the shared
emithelper from a process-wide value. A process-wide value hides the repository of a point and breaks when two repositories run in one process.
- Chosen: Build the key once in
- How is the
repolabel declared?: The label is passed as an attribute in the three emit functions, and the description of eachPROJECT_*instrument is extended to namerepo.Instrumentholds only a description and no structured label set (src/devops_cli/telemetry/instruments.py:29), andPROJECT_ITEM_LABELSstays("release", "state", "type", "priority")becauseItemCountMetricholds no repository.ROADMAP_CLAIM_AGEalready namesrepoin its description and sends it as an attribute, which is the same pattern. The generateddocs/TELEMETRY.mdchanges with the description. (best practice) [sources: src/devops_cli/telemetry/instruments.py:29, src/devops_cli/telemetry/instruments.py:402, src/devops_cli/telemetry/instruments.py:598, src/devops_cli/github/metrics.py:127, openspec/specs/project-metrics-dashboard/spec.md:44]- Chosen: Extend each instrument description to name
repoand pass it as an attribute. The spec says the description names the labels, the dashboards read it, and the age gauges already use this pattern. - Rejected: Add
repotoPROJECT_ITEM_LABELS. That constant is the labels ofItemCountMetric, which has no repository;labels()would fail, and the item's own labels stay four. - Rejected: Pass the label with no description. The description that the spec and the dashboards read would miss the label.
- Chosen: Extend each instrument description to name
- How does
_sent_item_serieskeep its state?: It becomes a dict keyed by the repo key. Each entry holds the item label sets that its own repository sent.reset_sent_item_seriesclears the dict, and_emit_item_countslooks up the set of the repository that the report names. (best practice) [sources: src/devops_cli/github/metrics.py:897, src/devops_cli/github/metrics.py:906, tests/conftest.py:113]- Chosen: A dict keyed by the repo key. A lookup by the repo key gives the sets of one repository in one step.
- Rejected: One set for the process. This is the defect: a second repository sends 0 for the sets of the first.
- Rejected: A list of sets that each report scans. The scan is linear, and the repository is not the key of the state.
- When does the command refuse
--limit?: The command refuses--limitwhen its value differs from the default that the option declares. One named constant holds that default and is used by both the Typer option (src/devops_cli/commands/gh.py:2184) andcollect_project_metrics_report'srelease_limit(src/devops_cli/github/metrics.py:802). A run with--limit 10is accepted; a run with--limit 5is refused. (best practice) [sources: src/devops_cli/commands/gh.py:2184, src/devops_cli/github/metrics.py:802]- Chosen: Compare the value with one named default constant. The rule is one comparison, and the CLI option and the collector share the same default.
- Rejected: Read the click parameter source of the option. The rule then sits in framework state and is harder to check in a CLI test; it would also refuse an explicit
--limit 10, which the issue allows. - Rejected: Refuse every
--limitwith--emit-telemetry. A user who repeats the default value asks for the same series, so the command accepts it.
- When does the command refuse
--milestone?: The command refuses--milestonewhenever--emit-telemetryis set and--milestoneis not None. The guard runs at the start of the command, before_resolve_repo,collect_project_metrics_reportand the dry-run return, so a refused combination makes no request and emits no point; the error names--milestone. (best practice) [sources: src/devops_cli/commands/gh.py:2193, src/devops_cli/commands/gh.py:2219, src/devops_cli/commands/gh.py:2224]- Chosen: Refuse before resolving the repository and collecting the report. The command makes no request and sends no point, and the CLI test can check the error and the empty collector.
- Rejected: Collect the report and refuse before emitting. The command still spends GitHub requests on a snapshot that it refuses, and the error arrives later.
- Do the dashboard queries keep their values when the gauges get the new label?: They keep evaluating, but their values change. A
maxpanel, such as stars, releases or views, shows the largest value across the 7 repositories; asum bypanel, such as commits, items or referrers, adds the 7 repositories. The issue records that the project-metrics item adds therepofilter, so this change keeps the queries as they are; until then the panels show multi-repository aggregates, and the deferred live check reads onereposeries. (best practice) [sources: k8s/monitoring/dashboards/project-metrics.json:52, k8s/monitoring/dashboards/project-metrics.json:178, k8s/monitoring/dashboards/project-metrics.json:306, k8s/monitoring/dashboards/project-metrics.json:500]- Chosen: Add the label now and keep the queries until the project-metrics item adds the filter. The issue records that the project-metrics item owns the filter; the panels keep a value, and the 7-writer defect ends now. The values become aggregates over the repositories for one cycle.
- Rejected: Add the label and filter the dashboard now. It adds the dashboard file and a hardcoded repository to this change, which the issue assigns to the project-metrics item.
- Rejected: Add the label after the dashboards get the filter. The 7 writers share one series for longer, and the defect stays.
- Do the release, CI run, star and fork gauges get the label too?: Yes. Every
PROJECT_*gauge gets the same label, including releases, CI runs, stars and forks, until the item of owner decision 1 moves those facts to the GitHub data source and removes the gauges. A gauge with no label would still have 7 writers. (best practice) [sources: src/devops_cli/github/metrics.py:944, src/devops_cli/github/metrics.py:946, k8s/monitoring/dashboards/project-metrics.json:500]- Chosen: Label every
PROJECT_*gauge now. One rule covers every gauge, and the item that removes the four gauges needs no second change. - Rejected: Label the item, traffic and count gauges only. The release, CI run, star and fork gauges then keep the shared series and the wrong values.
- Chosen: Label every
Fit
Fits in one pull request.
Suspected block
None.
Dependencies
None.
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.
fixprefix of the title gives the type.(telemetry)scope of the title gives the scope.Seven repositories write to one unlabeled series, producing wrong values and zeroing each other's data in live dashboards.Incorrect project metrics mislead engineering decisions on velocity, releases, and star counts.Add one label to existing gauges, key one set by repo, add a CLI guard, and write four test cases across two files.Both use the casefolded RepoRef key for telemetry; #4576 sets the naming convention for logs and traces, while the candidate applies it as a label on existing project gauges.devops-cli-service commentedon Nov 11, 2026
Status set to Ready at 5c71ad4 (see proposed design in issue body).
Moved to new items: #4729.
fix(telemetry): key the project gauges by repository
devops-cli-service commentedon Nov 11, 2026
Released in v0.114.0: https://github.com/dan-petty/devops-cli/releases/tag/v0.114.0
devops-cli-service commentedon Nov 11, 2026
Live since 2026-11-11 22:57 UTC