Skip to content

fix(service): the metrics row sends too many counted requests #3941

Closed

Description

@dan-petty

Problem

The row metrics of the roadmap Service is the largest source of requests that GitHub counts. Prometheus, 2026-11-07, one hour, job="roadmap-service", status other than 304: metrics 288, refine 286, other 236, implement 139. The row runs every 13 minutes for each repository (DEFAULT_ROADMAP_METRICS_INTERVAL_MINUTES).

Per round, collect_project_metrics_report (src/devops_cli/github/metrics.py) reads the workflow runs (repos/<repo>/actions/runs), the milestones (repos/<repo>/milestones?state=all), the open issues for the label taxonomy (repos/<repo>/issues?state=open, paginated) and the traffic, all through GhCliClient.api. A gh command has no ETag cache, so it always counts: its status is none. It then reads the Items and the label events of the Items whose status changed. The open issues are read again by the store.

Expected

The row reads through the GitHub session, which sends a conditional request (#3497), so an unchanged answer is a 304 that GitHub and the Service budget do not count (#3939). The taxonomy counts come from the Items that the store has already read, with no second listing.

Acceptance criteria

  • A test shows that one metrics round of a repository sends no second listing of the open issues.
  • A test shows that the workflow runs and milestones are read through the session.
  • After the change is live, sum(increase(devops_cli_github_requests_total{job="roadmap-service", row="metrics", status!="304"}[1h])) is lower than 288, and the issue records the result.

Existing tool considered

The GitHub session with ETags (#3497) already exists. No library is needed.

Related

Related: #3939, #3794 (the cost of this row over two rollouts), #3497.

Proposed design

Problem statement

The metrics row of the roadmap Service sends 288 counted requests in one hour. It uses GhCliClient.api, which has no ETag cache, and it lists open issues again after the store has read them. The change reads workflow runs and milestones through the existing GitHub session with conditional requests. It also derives taxonomy counts from the open Items that the store already holds.

Acceptance criteria

Requirement: Store-derived taxonomy

The metrics collector SHALL derive taxonomy counts from the open Items that the roadmap store already holds.

Scenario: No second open issue listing

  • WHEN one metrics round runs for a repository with a roadmap store
  • THEN the collector sends no request to repos/<repo>/issues?state=open and the taxonomy counts match the labels of the open Items in the store.

Requirement: Session-based workflow run read

The metrics collector SHALL read workflow runs through the GitHub session that sends conditional requests.

Scenario: Workflow runs use the session

  • WHEN the metrics collector reads workflow runs for a repository
  • THEN the read goes through the session and makes no uncached gh api repos/<repo>/actions/runs call.

Requirement: Session-based milestone read

The metrics collector SHALL read milestones through the GitHub session that sends conditional requests.

Scenario: Milestones use the session

  • WHEN the metrics collector reads milestones for a repository
  • THEN the read goes through the session and makes no uncached gh api repos/<repo>/milestones call.

Existing Tool Considered

No alternatives check has run. The existing GitHub session with ETags (#3497) covers the need for conditional requests, and no library is needed. It is project code, and it lacks nothing this issue needs. The change reuses that session and builds no new request layer.

Key questions

  • Does the repository already have a GitHub session that sends conditional requests?: Yes. The GitHub session with ETags from fix(service): the rows stop repeating reads that find no change #3497 exists, and ADR 0003 requires polling to use conditional requests so an unchanged answer costs nothing. [sources: docs/adr/0003-polling-is-how-the-roadmap-sees-changes.md, src/devops_cli/github/client.py]
  • How should the metrics collector get the GitHub session for workflow run and milestone reads?: Add an optional session argument to collect_project_metrics_report, get_ci_workflow_metrics and get_milestone_metrics. The report passes one session to both readers, so they share its ETag cache. A direct caller that passes no session gets a new session. (best practice) [sources: src/devops_cli/github/metrics.py, src/devops_cli/github/client.py, docs/adr/0003-polling-is-how-the-roadmap-sees-changes.md]
    • Chosen: Pass one session from the report. It shares the ETag cache and keeps the row on one conditional-request path.
    • Rejected: Create a session in each reader. It splits the cache and can send duplicate requests for the same round.
    • Rejected: Keep GhCliClient.api. It has no ETag cache, so every call counts.
  • Where should the taxonomy counts come from, and should the old issue listing stay?: Change get_label_taxonomy_metrics to count the open Items that the roadmap store already holds. Count each label that contains / and group it by its prefix. Do not keep the old open-issue listing, because the project removes replaced paths before 1.0. (best practice) [sources: src/devops_cli/github/metrics.py, docs/adr/0001-github-is-the-roadmap-source.md]
    • Chosen: Count open Items in the store. The store has already read the issues, so the round sends no second listing.
    • Rejected: Keep the open-issue listing. It is the second paginated read that this issue removes.
    • Rejected: Add a second taxonomy cache. It duplicates the store and adds a second source of truth.
  • Does the metrics command still have a store when no store is passed?: Yes. collect_project_metrics_report calls roadmap_store.get_roadmap_store(target_repo) when store is None, so the command uses the same store-derived taxonomy. [sources: src/devops_cli/github/metrics.py]

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Alternatives check of 2026-11-09: none.
Tool: none found.

Activity

  1. added
    source/agent
    type/bug
    scope/service
    status/new
    value/medium
    effort/medium
    on Nov 7, 2026
  2. dan-petty commented on Nov 7, 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/service. The (service) scope of the title gives the scope.
    • Priority: P2-Medium. The metrics row is the largest source of counted requests and risks budget exhaustion, but the service still functions.
    • Value: Medium. Reducing counted requests prevents budget warnings and keeps the service responsive under load.
    • Effort: Medium. Requires changing the read path to use the session, removing a duplicate listing, and adding two tests.
    • Related: fix(service): the request budget counts only requests GitHub counts #3939, which asks for a different change. Both reduce the metrics row's counted request cost, but #3939 changes the budget counting logic while the candidate changes the metrics row to use the session for conditional requests.
  3. added
    priority/p2-medium
    on Nov 7, 2026
  4. added
    status/ready
    and removed
    status/new
    on Nov 8, 2026
  5. devops-cli-service commented on Nov 8, 2026

    @devops-cli-service
    Contributor

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

    Moved to new items: #4118.

  6. devops-cli-service commented on Nov 9, 2026

    @devops-cli-service
    Contributor

    Alternatives check: none

    Reason: Searches for a Python GitHub client or HTTP cache that sends conditional requests found only generic protocol documentation on ETags and 304 responses, not an open, maintained library that could be dropped into this row. The need here is internal wiring — route the workflow-run and milestone reads through the project's own GitHub session with ETags (#3497) and derive the taxonomy counts from the store the round already read — and the issue states that no library is needed, so nothing external covers it.

    Tool: none found

    Lacks:

    • No library found that derives the label taxonomy from the roadmap store's already-read open Items, so the second open-issue listing would still be sent
    • No library found that replaces GhCliClient.api inside collect_project_metrics_report with the project's session-based read for repos/<repo>/actions/runs and repos/<repo>/milestones
    • A generic HTTP cache does not know the project's session, its ETag store or its request ledger, so it cannot satisfy the acceptance tests of this issue

    Searches run:

    • Python GitHub API client with ETag conditional requests caching library, results: 5
    • hishel httpx HTTP cache ETag conditional requests library, results: 5
    • gidgethub Python GitHub API async client ETag, results: 5
    • githubkit Python GitHub client ETag caching hishel, results: 5
    • githubkit repository yanyongyu maintained release, results: 5
    • GitHub REST API conditional requests 304 does not count rate limit, results: 5
    • hishel PyPI httpx caching package, results: 5
    • PyGithub etag caching conditional request feature request, results: 5

    Sources:

    Checked on 2026-11-09. A person decides what this means for the item. The check changes no label and closes no issue.

  7. added
    owner/agent
    status/in-progress
    and removed
    status/ready
    on Nov 17, 2026
  8. removed
    status/in-progress
    owner/agent
    on Nov 17, 2026
  9. devops-cli-service commented on Nov 17, 2026

    @devops-cli-service
    Contributor

    Live since 2026-11-17 09:25 UTC

  10. dan-petty commented on Nov 19, 2026

    @dan-petty
    OwnerAuthor

    New evidence from the Service config review of 2026-11-19: the metrics row is above the target of this issue again.

    • The target of this issue was fewer than 288 counted requests an hour for the metrics row. The row now sends about 821 an hour: 19,707 of about 72,800 counted Service requests in 24 h (27%), the largest single row. A re-run on 2026-11-19 gave 804 an hour. Query: sum(increase(devops_cli_github_requests_total{job="roadmap-service",row="metrics",status!="304"}[24h])) / 24.
    • Only 5.4% of the reads of the row come back 304 (797 of 14,667).
    • One round for devops-cli costs about 119 counted requests (about 10,562 a day), against about 17 for each other repository.
    • The budget gauge shows 2.1 h of holds in 24 h and 9.2 h in 7 d. All 25 holds of 5 min or more began within 1 h after a Service pod start (details on fix(telemetry): the age metrics keep their reads across pods #3634).

    Plan: no change of roadmap.metrics.interval_minutes now. Draft PR #6326 (for #3634) removes one restart cost of this row, the per-process _item_label_times cache (src/devops_cli/github/metrics.py:517). After #6326 is live, measure the row again. If it is still above 288 an hour, a slower cadence is one option, but it must keep a sample of devops_cli_roadmap_stalled_items in the window of the alert RoadmapServiceItemStuck.

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-mediumscope/servicesource/agenttype/bugvalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions