Skip to content

fix(telemetry): key the project gauges by repository #4690

Closed

Description

@dan-petty

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.py
  • src/devops_cli/commands/gh.py
  • tests/github/test_github_metrics.py
  • tests/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/One and then the report of Example/Two in one process.
  • THEN For each PROJECT_* gauge, the collector holds a series with repo=example/one and a series with repo=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) for Example/One, then a report of Example/Two with another label set.
  • THEN No point with the value 0 carries repo=example/one, and Example/Two sends 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) for Example/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/one and 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-telemetry alone.
  • THEN The two filtered runs exit non-zero, print the name of the refused option and send no point; the runs with --limit 10 and with --emit-telemetry alone 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/One with 2 stars and the report of Example/Two with 7 stars.
  • THEN The point with repo=example/one holds 2.0 and the point with repo=example/two holds 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 from INSTRUMENTS.
  • THEN Each description names repo, and the description of PROJECT_ITEMS also names release, state, type and priority.

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 repo label carry?: The label carries RepoRef(report.repo).key, the full casefolded owner/name. It does not use RepoRef.metric_value, which maps a repository outside service.repos to other: two unconfigured repositories would then share one series, and the acceptance test for Example/One and Example/Two would not tell them apart. ADR 0022 says telemetry uses key. (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.repos to other, so two unconfigured repositories share one series and the test for example/one and example/two fails.
  • Where does the emitter add the repo label?: emit_project_metrics_telemetry builds repo_key = RepoRef(report.repo).key once and passes it to the three helpers. The top-level gauges use it directly; _emit_traffic, _emit_item_counts and _emit_item_ages add 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_telemetry and 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_ages already sends report.repo without casefolding it.
    • Rejected: Add the label in the shared emit helper from a process-wide value. A process-wide value hides the repository of a point and breaks when two repositories run in one process.
  • How is the repo label declared?: The label is passed as an attribute in the three emit functions, and the description of each PROJECT_* instrument is extended to name repo. Instrument holds only a description and no structured label set (src/devops_cli/telemetry/instruments.py:29), and PROJECT_ITEM_LABELS stays ("release", "state", "type", "priority") because ItemCountMetric holds no repository. ROADMAP_CLAIM_AGE already names repo in its description and sends it as an attribute, which is the same pattern. The generated docs/TELEMETRY.md changes 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 repo and 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 repo to PROJECT_ITEM_LABELS. That constant is the labels of ItemCountMetric, 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.
  • How does _sent_item_series keep 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_series clears the dict, and _emit_item_counts looks 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 --limit when 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) and collect_project_metrics_report's release_limit (src/devops_cli/github/metrics.py:802). A run with --limit 10 is accepted; a run with --limit 5 is 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 --limit with --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 --milestone whenever --emit-telemetry is set and --milestone is not None. The guard runs at the start of the command, before _resolve_repo, collect_project_metrics_report and 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 max panel, such as stars, releases or views, shows the largest value across the 7 repositories; a sum by panel, such as commits, items or referrers, adds the 7 repositories. The issue records that the project-metrics item adds the repo filter, so this change keeps the queries as they are; until then the panels show multi-repository aggregates, and the deferred live check reads one repo series. (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.

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Activity

  1. added
    source/agent
    on Nov 11, 2026
  2. added
    type/bug
    scope/telemetry
    status/new
    value/high
    effort/medium
    on Nov 11, 2026
  3. dan-petty commented on Nov 11, 2026

    @dan-petty
    OwnerAuthor

    Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones.

    • Type: type/bug. The fix prefix of the title gives the type.
    • Scope: scope/telemetry. The (telemetry) scope of the title gives the scope.
    • Priority: P1-High. Seven repositories write to one unlabeled series, producing wrong values and zeroing each other's data in live dashboards.
    • Value: High. Incorrect project metrics mislead engineering decisions on velocity, releases, and star counts.
    • Effort: Medium. Add one label to existing gauges, key one set by repo, add a CLI guard, and write four test cases across two files.
    • Related: feat(telemetry): name the repository the same way in logs and traces #4576, which asks for a different change. 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.
  4. added
    priority/p1-high
    on Nov 11, 2026
  5. added
    status/ready
    and removed
    status/new
    on Nov 11, 2026
  6. devops-cli-service commented on Nov 11, 2026

    @devops-cli-service
    Contributor

    Status set to Ready at 5c71ad4 (see proposed design in issue body).

    Moved to new items: #4729.

  7. added
    owner/agent
    status/in-progress
    and removed
    status/ready
    on Nov 11, 2026
  8. added a commit that references this issue on Nov 11, 2026
    ec1e3df
  9. removed
    status/in-progress
    owner/agent
    on Nov 11, 2026
  10. devops-cli-service commented on Nov 11, 2026

    @devops-cli-service
    Contributor

    Live since 2026-11-11 22:57 UTC

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/p1-highscope/telemetrysource/agenttype/bugvalue/high

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions