Skip to content

fix(telemetry): runner Job counters keep their first count in increase() #5210

Done

Description

@dan-petty

Problem or Motivation

Each runner Job exports its metrics with instance=<pod name>, so each Job makes new series, and each series starts at its first value. increase() and rate() then lose the count up to the first sample. The operations review measured this over 7 days:

  • For devops_cli_ai_requests_total{job="devops-cli-job"}, sum(last_over_time) = 83, but sum(increase) = 1.5.
  • 37 of 92 Job series of devops_cli_ci_checks_total have exactly one sample.

Dashboards that use increase() on Job counters show values that are too low.

Proposed Solution & Architectural Design

  1. Check the premise again with one PromQL query. fix(telemetry): keep one metric stream per workload #4697 puts all runner Jobs in one metric stream (service.instance.id=devops-cli-job). After that change, a new Job still starts its counters at 0, and a new total that is not lower than the old one is not seen as a reset. So check the premise on the state after fix(telemetry): keep one metric stream per workload #4697 when fix(telemetry): keep one metric stream per workload #4697 is merged first.

  2. Then do one of these:

    • Emit a zero sample for each known label set when a Job starts. This is the usual fix for a counter that starts late.
    • Change the Job dashboards and alerts to sum(last_over_time(...)) for each instance.

    Choose the first when the exporter supports it.

Files: src/devops_cli/telemetry/instruments.py, tests/telemetry/test_instruments.py.

Target Subsystem

Kubernetes & Minikube Automation (Grafana dashboards and telemetry).

Existing Tool Considered

The OpenTelemetry SDK exporter that the project uses. Cost: about 0.3M model tokens and half a day.

Acceptance Criteria

  1. A test with a fake exporter shows a zero sample before the first increment of a Job counter.
  2. Real data: a PromQL comparison of sum(increase) and sum(last_over_time) for one Job counter over the 7 days after the deploy, in the pull request comment, differs by less than 5 %.

Dependencies

None. Check the premise against the state of #4697.

Related

Source: #5199

Alternatives check of 2026-11-29: in-use.
The repository already uses this tool.
Tool: open-telemetry/opentelemetry-python (https://github.com/open-telemetry/opentelemetry-python), Apache-2.0, last activity 2026-11-28, maintained.
Reason: Searches returned only unrelated pages; the fact reads confirm the OpenTelemetry Python SDK that the project already uses, whose Counter.add accepts a zero amount with explicit attributes, so a Job can open each label set at zero before its first increment.

Covers:

  • Counter.add with amount zero records a data point for given attributes
  • Series exists at zero before the first increment, so increase counts it
  • Runs through the exporter already wired into the runner Job
  • Same zero-sample pattern the repository already uses elsewhere

Lacks:

  • No automatic enumeration of label sets; the Job must pass each known set
  • Cannot backfill series emitted before the change, so history stays low
  • No dashboard or alert change; panels using increase stay wrong until zero samples land
  • The live PromQL comparison after deploy stays a manual check

Proposed design

Problem statement

Runner Job counters make a new series for each Job. The first sample of a new series starts at the first count. increase() and rate() lose the count before that sample, so dashboards show values that are too low. The change emits a zero sample for each known label set before the first increment. A follow-up verifies the live result after deploy.

Acceptance criteria

Requirement: Zero sample before first increment

A runner Job SHALL emit a zero sample for each known label set before the first increment of that counter.

Scenario: Fake exporter sees the zero sample first

  • WHEN A test starts a runner Job counter with two known label sets and adds the first increment to each.
  • THEN The fake exporter records a zero sample for each label set before its first increment sample.

Requirement: Zero sample carries the first increment attributes

The zero sample MUST carry the same attributes as the first increment of the counter.

Scenario: Attributes match between zero and first increment

  • WHEN A test starts a runner Job counter with a known label set and adds the first increment.
  • THEN The fake exporter records the same attribute set on the zero sample and on the first increment sample.

Requirement: No zero sample for an unused label set

The runner Job MUST NOT emit a zero sample for a label set that it does not use in its run.

Scenario: Unused label set stays absent

  • WHEN A test starts a runner Job with no known label set for a counter.
  • THEN The fake exporter records no zero sample for that counter.

Existing Tool Considered

The alternatives check in the issue body records verdict in-use for open-telemetry/opentelemetry-python (Apache-2.0, maintained). That check lists what the tool covers and lacks. The proposal supplies the known label sets from the Job run and calls Counter.add(0, attributes) before the first increment. The deferred live check measures the result after deploy.

Key questions

  • Which route fixes the missing first count: a zero sample at Job start or a dashboard last_over_time query?: Emit a zero sample for each known label set at Job start. The OpenTelemetry SDK records Counter.add(0, attributes), and the repository already uses a zero sample to keep a series for ROADMAP_TOOL_CALLS_TOTAL. (best practice) [sources: src/devops_cli/telemetry/instruments.py:444]
    • Chosen: Zero sample at Job start. The SDK supports Counter.add(0, attributes), and the repository already uses a zero sample to keep a series for ROADMAP_TOOL_CALLS_TOTAL.
    • Rejected: Dashboard last_over_time query. It needs a live inventory of every Job series and changes each panel and alert.
  • Which label sets does the Job use for the zero samples?: The Job uses the label sets that it knows for its run. The helper takes them from the Job configuration. The Job does not enumerate every possible label set. (best practice) [sources: src/devops_cli/telemetry/instruments.py]
    • Chosen: Label sets from the Job run. The Job knows the labels that it will use, and the zero sample repeats on the first increment.
    • Rejected: All possible label sets. A zero sample for a label set that live traffic never repeats makes a series that never grows.

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Moved to new items

#6425

Activity

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

    @dan-petty
    OwnerAuthor
  4. added
    priority/p2-medium
    on Nov 12, 2026
  5. dan-petty commented on Nov 15, 2026

    @dan-petty
    OwnerAuthor

    The item cannot be completed in a pull request: acceptance criterion 2 reads live Prometheus data over the 7 days after a deploy, and the pull request comment must hold the comparison.

    • Criterion 1 is buildable: a fake exporter shows a zero sample before the first increment.
    • Criterion 2 needs a deployed change, production Job traffic and a 7-day window: sum(increase(...)) against sum(last_over_time(...)) for one Job counter, within 5 %.
    • The premise depends on the state after fix(telemetry): keep one metric stream per workload #4697, which is closed and on main. The stream now holds service.instance.id=devops-cli-job, but a new Job still starts at 0, so the reset rule does not see it.
    • The zero-sample route needs the label sets of each counter, and a zero with a label set that live traffic never repeats makes a series that never grows. The dashboard route needs the same live series inventory to list the panels that Job counters feed.

    No code is written before a person measures the current series set and chooses the route on that data. A person then runs the change, deploys it, and posts the 7-day comparison on this item.

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

    @devops-cli-service
    Contributor

    Waiting for the alternatives check to run. The next refine round looks at the item again after the check records a verdict.

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

    @devops-cli-service
    Contributor

    The result in the alternatives block of the issue body changed. Before this check: no check. A person decides what the new result means for the item.

    Searches (6)

    Tools considered:

    Searches run:

    • OpenTelemetry Python Counter.add(0) emit zero sample counter starts late, results: 5
    • Prometheus increase() missing first sample new series per pod counter zero initialization, results: 5
    • github open-telemetry opentelemetry-python repository, results: 5
    • opentelemetry python sdk metric counter add zero attributes first value, results: 5
    • "opentelemetry-sdk" python package pypi, results: 5
    • open-telemetry-python metrics api Counter add documentation, results: 5

    Sources:

  8. added
    status/ready
    and removed
    status/new
    on Nov 19, 2026
  9. devops-cli-service commented on Nov 19, 2026

    @devops-cli-service
    Contributor

    Next step: the stage job writes the plan of the item. See Moved to new items in the section Proposed design of the body.

  10. added
    owner/agent
    status/in-progress
    status/in-review
    and removed
    status/ready
    status/in-progress
    on Nov 29, 2026
  11. removed
    status/in-review
    owner/agent
    on Nov 29, 2026
  12. devops-cli-service commented on Nov 29, 2026

    @devops-cli-service
    Contributor

    Live since 2026-11-29 16:17 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/lowpriority/p2-mediumscope/telemetrysource/agenttype/bugvalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions