Skip to content

fix(roadmap): the metrics job asks for repository traffic that the App's scoped token cannot read, and each refused request takes the Service's budget #2537

Closed

Description

@dan-petty

Problem Description

The roadmap Service's metrics job asks for each repository's traffic, and GitHub refuses each of these requests with HTTP 403. The job runs for each repository in service.repos every 15 minutes (DEFAULT_ROADMAP_METRICS_INTERVAL_MINUTES) and at the start of each pod (first_run_due=True). get_repository_traffic_metrics (src/devops_cli/github/metrics.py:523) sends four requests: traffic/views, traffic/clones, traffic/popular/referrers and traffic/popular/paths.

For a GitHub App, the traffic endpoints need the repository permission Administration (read). The installation token of the Service is scoped to actions, checks, contents, issues, metadata and pull_requests (#2473), so GitHub refuses each traffic request. With 7 repositories, that is about 112 refused requests in each hour. They count against the Service's hourly budget (service.github_requests_per_hour, 500 by default), so about a fifth of the budget gives no data. Each refusal also logs a warning, which hides other warnings.

Reproduction Steps

  1. Run the Service as GitHub App devops-cli-service with the scoped installation token.
  2. Wait for the first metrics round.
  3. Read the pod log: four warnings for each repository.

Expected vs Actual Behavior

Expected: the Service sends no request that its token cannot make. Either the metrics job does not ask for traffic when the token does not grant Administration (read), or the scoped token asks for administration: read and k8s/README.md and ADR 0015 list it. The issue's proposal must check which dashboard panels read the traffic series before it chooses. Least privilege prefers the first choice when no panel needs them.

Actual: four refused requests and four warnings for each repository in each round.

Environment Diagnostics

Image from main at 657b03d. The token log line: GitHub App devops-cli-service[bot] has a new installation token with these permissions: actions, checks, contents, issues, metadata, pull_requests.

Logs, Traces, or Terminal Output

Failed to query traffic views for dan-petty/devops-cli: gh api call failed with exit code 1: gh: Resource not accessible by integration (HTTP 403)
Failed to query traffic clones for dan-petty/devops-cli: gh api call failed with exit code 1: gh: Resource not accessible by integration (HTTP 403)
Failed to query traffic referrers for dan-petty/devops-cli: gh api call failed with exit code 1: gh: Resource not accessible by integration (HTTP 403)
Failed to query popular paths for dan-petty/devops-cli: gh api call failed with exit code 1: gh: Resource not accessible by integration (HTTP 403)

The same four lines appear for each of the 7 repositories in each pod.

Pre-Submission Checklist

  • I have verified that no sensitive credentials, private keys, or internal tokens are contained in this issue report.
  • I have checked existing issues and pull requests to ensure this is not a duplicate.

Proposed design

Problem statement

The metrics job sends four traffic API requests per repository per round, but the GitHub App token lacks the administration: read permission those endpoints require. With 7 repositories and a 15-minute interval, about 112 refused requests per hour waste 20 percent of the 500-request budget and generate warnings that hide other signals.

Acceptance criteria

Requirement: Skip traffic requests without permission

The metrics job SHALL NOT send a traffic API request when the installation token does not grant the administration: read permission.

Scenario: Token lacks administration permission

  • WHEN The installation token's permission set does not include administration: read
  • THEN The metrics job sends zero requests to traffic/views, traffic/clones, traffic/popular/referrers, or traffic/popular/paths for any repository

Requirement: Log skip at info level

The metrics job SHALL log a single info-level message per repository when it skips traffic collection, and SHALL NOT log a warning for the skip.

Scenario: Skip message is info level

  • WHEN The metrics job skips traffic collection for a repository because the token lacks administration: read
  • THEN The log line for that repository is at info level and names the reason as the missing permission

Requirement: Non-traffic metrics unaffected

The metrics job SHALL collect all non-traffic metrics for every repository in service.repos regardless of the administration permission.

Scenario: Non-traffic metrics still collected

  • WHEN The metrics job runs a round with a token that lacks administration: read
  • THEN All non-traffic metric series for each repository are written to the metrics store as before

Existing Tool Considered

No external tool covers this need. The fix is a permission guard in the existing code at src/devops_cli/github/metrics.py. The written cost is about 30 lines of code (a check plus a skip path) and about 40 lines of test, built once and kept with the file. No new dependency is added.

Key questions

  • Which dashboard panels read the traffic series (views, clones, popular referrers, popular paths)?: This must be verified by reading k8s/monitoring/dashboards/project-metrics.json and k8s/monitoring/dashboards/devops-cli.json for queries that select the traffic metric names. The k8s/README.md states that a panel without data reads 'No data' rather than zero, so even if a panel references the series, skipping the requests leaves the panel in an acceptable empty state. [sources: k8s/monitoring/dashboards/project-metrics.json, k8s/monitoring/dashboards/devops-cli.json, k8s/README.md]
  • Should the fix skip the traffic requests or add administration: read to the token scope?: Skip the traffic requests. ADR 0015 and k8s/README.md step 1 deliberately scope the App without Administration. The body states that least privilege prefers skipping when no panel needs the data. Adding administration: read would widen the token's blast radius for data that the Service does not need for its roadmap jobs. (best practice) [sources: docs/adr/0015-roadmap-jobs-act-as-a-github-app-on-the-personal-account.md, k8s/README.md]
    • Chosen: Skip traffic requests when token lacks administration: read. Least privilege. ADR 0015 scopes the App without Administration. The dashboard shows 'No data' for missing series, which is acceptable. No token change is needed.
    • Rejected: Add administration: read to the App and token scope. Widens the token's permission set. Requires updating the App in GitHub settings, k8s/README.md, and ADR 0015. Increases the blast radius of a leaked token. Rejected because the Service's roadmap jobs do not need Administration.
  • Where in the code should the permission check live?: In the caller of get_repository_traffic_metrics, at the point where the metrics job decides which metric groups to collect for a repository. The function at src/devops_cli/github/metrics.py:512 already returns a TrafficSummaryMetric; the guard should wrap the call so that when the permission is absent, the function is not called and the traffic fields are left empty. (best practice) [sources: src/devops_cli/github/metrics.py:512, src/devops_cli/github/metrics.py:563]
    • Chosen: Guard at the caller (metrics job round). The caller already knows the token's permission set from the installation token mint. It can skip the call and leave the traffic fields empty. This keeps get_repository_traffic_metrics unchanged and testable.
    • Rejected: Guard inside get_repository_traffic_metrics. Would require passing the permission set into the function, changing its signature and all existing tests. More invasive for no benefit.
  • How does the code determine whether the token grants administration: read?: The installation token mint already logs the permission set (the issue's log line shows 'actions, checks, contents, issues, metadata, pull_requests'). The code that mints the token can expose the granted permissions as a set, and the metrics job checks whether 'administration' is in that set with scope 'read'. (best practice) [sources: src/devops_cli/github/app_installation.py]
    • Chosen: Read the permission set from the token mint response. The GitHub API returns the granted permissions when minting an installation token. The code already parses this for the log line. Exposing it as a set is a small addition.
    • Rejected: Hard-code the expected permission list. Fragile. If the App's permissions change, the hard-coded list drifts. Rejected.

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Activity

  1. added
    source/agent
    type/bug
    status/new
    value/medium
    effort/low
    on Oct 28, 2026
  2. dan-petty commented on Oct 28, 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 metrics job sends requests the token cannot fulfill, wasting budget and generating log noise.
    • Priority: P2-Medium. About 20 percent of the hourly API budget is wasted and warnings hide other signals, but the Service still functions.
    • Value: Medium. Recovers API budget and removes log noise for every pod in the cluster.
    • Effort: Low. Add a permission check before the four traffic requests or gate them on a configuration flag.
    • Related: feat(telemetry): add github traffic metrics to project velocity and automate collection in roadmap-service #1227, which asks for a different change. #1227 added the traffic metrics collection; this candidate reports that those requests fail under the scoped token from #2473.
  3. added
    priority/p2-medium
    on Oct 28, 2026
  4. added
    status/ready
    and removed
    status/new
    on Oct 29, 2026
  5. devops-cli-service commented on Oct 29, 2026

    @devops-cli-service
    Contributor

    Status set to Ready at 0f7bc26 (see proposed design in issue body).

  6. added
    scope/roadmap
    on Oct 30, 2026
  7. dan-petty commented on Oct 30, 2026

    @dan-petty
    OwnerAuthor

    Done by #2752 (PR 2759, released in 0.22.x): the Service no longer asks for the four traffic endpoints, because its installation token cannot read them. Evidence on 2026-10-30: the pod roadmap-service-5c87655b65-6sg75, started at 13:10 UTC, logged no Failed to query traffic ... or Failed to query popular paths ... warning since it started. A person's gh login on a workstation still collects them.

    The metrics row still sends about 199 GitHub reads an hour for the seven repositories. These are the other collectors and are not part of this issue.

  8. removed
    status/ready
    on Oct 30, 2026
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/lowpriority/p2-mediumscope/roadmapsource/agenttype/bugvalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions