Skip to content

fix(telemetry): the age metrics keep their reads across pods #3634

Closed

Description

@dan-petty

Problem

The metrics row now spends far more of the GitHub budget, and each rollout likely adds to it.

  • Prometheus, sum by (row)(increase(devops_cli_github_requests_total[1h])) with row metrics: about 222 to 305 an hour until the hour that ended 2026-11-05T12:00Z. Then 627 at 13:00Z, 757 at 14:00Z and 1000 in the hour that ended about 14:24Z.
  • feat(telemetry): measure how long roadmap items wait in each state #3601 merged at 12:05:22Z and adds item_ages=True to the metrics row. Its cache _item_label_times is per process, so a new pod reads the label events of the open items again.
  • The Service rolled 5 times from 12:35Z to 14:22Z. The budget is 2000 requests an hour and it holds every row. The log line at 13:24:04Z says 2000 of 2000.

The link to #3601 is likely, from the time and the code. The cost of one new pod was not measured. increase() also extrapolates across pod restarts (#3495), so the totals are approximate.

Expected

The age metrics cost a small, fixed share of the budget, and a rollout does not cost a full read of the open items.

Acceptance criteria

  • Measure the requests of the metrics row for one new pod, and state the number in the pull request.
  • A test: a new process does not read the events of an item whose updated_at it already holds in the kept record.
  • A test: the row reads events for at most a fixed number of items in a round, and the rest wait for later rounds.
  • Run live: the metrics row stays near its level before feat(telemetry): measure how long roadmap items wait in each state #3601 over a period with two rollouts.

Existing tool considered

Existing project code: the Service keeps state across a restart (keep_state_record), and the REST If-None-Match read of the GitHub session. No new tool.

Related

Related: #3601, #3497, #3495

Proposed design

Problem statement

The metrics row re-reads the label events of every open item when a new pod starts. The per-process _item_label_times cache makes each rollout spend a large part of the 2000-request hourly budget. The fix persists the cache in the Service state record and caps the item reads in one round.

Acceptance criteria

Requirement: Persist item label times

The metrics row SHALL write each open item's updated_at and label times to the Service state record after a round.

Scenario: State record round trip

  • WHEN A metrics round reads label events for an open item and the round completes
  • THEN The state record holds the item's updated_at and label times under the repository and issue key

Requirement: Skip items held in the state record

A new process MUST NOT request label events for an item whose updated_at equals the value in the kept state record.

Scenario: New process with a kept record

  • WHEN A new process loads the state record and lists an open item with the same updated_at
  • THEN The process makes no label-event request for that item

Requirement: Bound item reads per round

The metrics row MUST read label events for at most _MAX_ITEM_AGE_READS_PER_ROUND items in one round.

Scenario: More stale items than the cap

  • WHEN More open items have a changed updated_at than the cap in one round
  • THEN The row reads exactly the cap and keeps the remaining items for later rounds

Requirement: Queue deferred items

The metrics row SHALL read items deferred by the cap before it reads items that were never deferred.

Scenario: Deferred items are read first

  • WHEN A round starts with deferred items in the state record and new changed items
  • THEN The round reads the deferred items first and fills the rest of the cap with new items

Requirement: Prune closed items

The metrics row SHALL remove a cache entry when the item is no longer in the open item list.

Scenario: Closed item leaves the cache

  • WHEN An item in the state record is not in the current open item list
  • THEN The next state record write does not hold that item

Requirement: Report measured cost

The change SHALL record the measured GitHub requests for one new pod in the change's design.md.

Scenario: Measurement is recorded

  • WHEN The pull request is opened
  • THEN The design.md states the request count for one new pod and the method used

Existing Tool Considered

No alternatives check has run. No external tool or library covers this need. The change reuses existing project code: keep_state_record in src/devops_cli/server/service.py:158 persists the Service state across restarts, and the GitHub session's conditional If-None-Match read stays as the fallback. The change adds no new dependency and builds no replacement tool. The cost is the edit to src/devops_cli/github/metrics.py and its tests.

Key questions

  • Where does the per-item label-time cache live so that a new pod keeps the reads?: In the Service state record that keep_state_record writes, under a new item_label_times key. The record already survives a restart. (best practice) [sources: src/devops_cli/server/service.py:158, src/devops_cli/roadmap/run.py:1106, openspec/changes/archive/2026-10-28-2474-service-state-survives-restart/design.md:15, src/devops_cli/github/metrics.py:481]
    • Chosen: Persist in the Service state record. The record already survives a restart and the Service writes it each round.
    • Rejected: Write a separate shared file. It adds a second state path and a volume that the Service does not need.
    • Rejected: Re-read every item on each new pod. That is the defect that spends the GitHub budget.
  • How many items may the metrics row read label events for in one round?: At most 20 items per round. The row keeps the rest in the state record for later rounds. The cap holds the row near its pre-feat(telemetry): measure how long roadmap items wait in each state #3601 cost of about 222 to 305 requests an hour. (best practice) [sources: src/devops_cli/github/metrics.py:481, src/devops_cli/github/metrics.py:518]
    • Chosen: Cap at 20 items per round. 20 items at the metrics schedule stays within the pre-feat(telemetry): measure how long roadmap items wait in each state #3601 hourly cost and leaves budget for other rows.
    • Rejected: Cap at 100 items per round. A new pod would still spend a large share of the 2000-request budget in one round.
    • Rejected: No cap. A new pod reads all open items and repeats the defect.
  • What key and version identify a cache entry?: The key is the repository full name and the issue number. The version is the item's updated_at. A match lets the row skip the label-event read. (best practice) [sources: src/devops_cli/github/metrics.py:481, src/devops_cli/github/metrics.py:518]
    • Chosen: Use (repo, issue number) with updated_at. The key finds the item and updated_at changes when the item changes.
    • Rejected: Use only (repo, issue number). Labels can change without a new issue number, so the row would miss the change.
    • Rejected: Use a hash of the issue body. updated_at already changes on edits and needs no hash.
  • What happens when the state record write fails?: The metrics row logs one error and keeps the in-memory cache. The next round writes the record again. (best practice) [sources: src/devops_cli/server/service.py:158, openspec/changes/archive/2026-10-28-2474-service-state-survives-restart/design.md:15]
    • Chosen: Log and continue. A write failure must not end the worker or restart the pod.
    • Rejected: Fail the metrics round. An exception ends the worker and /healthz restarts the pod with no halt.
  • What happens to cache entries for items that are no longer open?: The metrics row removes the entry at the end of the round when the open item list no longer holds the item. (best practice) [sources: src/devops_cli/github/metrics.py:524, src/devops_cli/github/metrics.py:525]
    • Chosen: Prune at the end of the round. The state record stays small and holds only open items.
    • Rejected: Keep the entry forever. The state record grows without a limit.
    • Rejected: Prune only when the record is full. It adds a second limit and delays the removal.
  • How does the change measure the requests for one new pod?: Run one new pod with the kept state record. Read the devops_cli_github_requests_total counter with row metrics before and after one metrics round. State the difference in design.md. (best practice) [sources: src/devops_cli/github/metrics.py]
    • Chosen: Use the existing devops_cli_github_requests_total counter. The counter already labels each GitHub request by row.
    • Rejected: Add a new measurement counter. The existing counter gives the same number without new code.

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

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

Activity

  1. added
    source/agent
    type/bug
    scope/telemetry
    status/new
    value/high
    effort/medium
    on Nov 5, 2026
  2. dan-petty commented on Nov 5, 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: P2-Medium. The Service exhausts its 2000-request budget and a rollout adds the cost, but the Service still runs and the cause is known.
    • Value: High. Every rollout burns the full GitHub budget for the metrics row, which can starve other Service work.
    • Effort: Medium. It needs a persisted cache, a bounded read per round, two tests, and a live soak check.
    • Related: fix(telemetry): Service counters read true across pods and repos #3495, which asks for a different change. Both address telemetry behaviour that changes across pods, but #3495 fixes counter accuracy in Prometheus while the candidate reduces GitHub API reads on pod start.
  3. added
    priority/p2-medium
    on Nov 5, 2026
  4. added
    status/ready
    and removed
    status/new
    on Nov 6, 2026
  5. devops-cli-service commented on Nov 6, 2026

    @devops-cli-service
    Contributor

    Status set to Ready at 27c7019 (see proposed design in issue body).

    Moved to new items: #3794.

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

    @devops-cli-service
    Contributor

    Alternatives check: none

    Reason: The searches returned no results (the search provider answered none of the queries), and the issue itself asks for no new tool: the fix persists the per-process item label-time cache in the Service's existing state record (keep_state_record) and caps the item reads per round, keeping the GitHub session's conditional If-None-Match read as the fallback. No external tool or library covers a persisted, per-round-bounded item label-event cache, and the project ADRs select no candidate for it (ADR 0006 already fixes the session transport as gidgethub).

    Tool: none found

    Lacks:

    • No tool found that persists an item label-time cache across processes and bounds label-event reads per round
    • The need is met by editing existing project code (src/devops_cli/github/metrics.py) and the state record written by keep_state_record

    Searches run:

    • python library cache GitHub issue label events incrementally with updated_at state, results: 0
    • persist GitHub API ETag conditional request cache across pod restarts to cut rate limit usage, results: 0
    • GitHub REST API conditional requests ETag rate limit caching best practice, results: 0
    • prometheus counter increase across pod restarts, results: 0

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

  7. added
    owner/service
    and removed
    owner/service
    on Nov 15, 2026
  8. 70 remaining items

  9. dan-petty commented on Nov 19, 2026

    @dan-petty
    OwnerAuthor

    New evidence from the Service config review of 2026-11-19: the GitHub request budget holds follow the Service starts.

    • 7 d to 2026-11-19: 25 of 25 budget-hold episodes of 5 min or more (devops_cli_service_budget_spent_requests >= 3950) began within 1 h after a Service pod start. Those hours cover only 46% of the time. There were 122 Service pod starts in 7 d and 12 in the last 24 h.
    • Counted (not 304) Service requests in the 20 min after the starts of 2026-11-18 at 13:18, 16:22 and 17:42 UTC: 1,819, 1,667 and 1,683. Other 20-min windows from 12:00 to 19:00 gave 342 to 1,244. Query: sum(increase(devops_cli_github_requests_total{job="roadmap-service",status!="304"}[20m])).
    • A cold ETag cache does not explain the spike. The whole Service gets about 9,353 answers of 304 in 24 h, about 130 per 20 min. A spike adds about 1,000. After the 13:18 start, the status-200 reads of the metrics row rose by about 555 in 40 min.
    • The refine row also rose after a start: about 796 counted requests in 40 min, against about 500 at other times. No issue covers that yet.

    Plan: after #6326 is live, measure the counted requests by row in the 40 min after the next Service starts. File a new issue only for a row that still spikes, for example refine. A persisted ETag store is not needed for this.

  10. removed
    status/in-review
    owner/agent
    on Nov 19, 2026
  11. devops-cli-service commented on Nov 19, 2026

    @devops-cli-service
    Contributor

    Live since 2026-11-19 11:42 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/p2-mediumscope/telemetrysource/agenttype/bugvalue/high

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions