Skip to content

fix(telemetry): a Job pod exports its metrics while it runs #5916

Closed

Description

@dan-petty

Problem

A cluster Job pod exports its metrics only once, when its process exits. devops-cli keeps its counters in an in-memory DELTA reader (InMemoryMetricReader, src/devops_cli/telemetry/tracer.py:1050) and exports them only when flush() runs. The Service calls tracer.flush() after each round (src/devops_cli/server/service.py:677, :738, #1629), but a Job runs one long command, and its only flush is the atexit shutdown (tracer.py:1693).

Evidence, 2026-11-16, the implement runner Jobs and their samples of devops_cli_ai_tokens_total{job="roadmap-implement"}:

Job Ran Samples
#3529 19:41Z to 20:30Z one, at 20:30Z
#3550 20:44Z to 21:26Z one, at 21:26Z
#3569 21:43Z to 23:42Z one, at 23:42Z

The stage Jobs (job="roadmap-stage") act the same way: about 6 samples for each series in 6 h.

Effects:

  • A Job shows no tokens, requests or spend while it runs, also for a run of 2 h.
  • A Job that the kernel or the deadline kills never exports, so its usage is lost. In the 6 h to 01:35Z, litellm_spend_metric_total gives $1.26 for DeepSeek, and devops_cli_ai_spend_usd_total gives $0.68.
  • rate(...[5m]) never sees two samples of a Job series, so the 5-minute panels of the ai-spend dashboard show only the Service. rate(...[1h]) sometimes sees two samples and extrapolates, so the rolling 1-hour lines show spikes that the 5-minute lines do not (fix(monitoring): read AI spend from the gateway counter #4724).
  • The collector (deltatocumulative, max_stale: 1h) forgets a Job stream after 1 h with no point, so the next Job starts the stream again, and Prometheus reads a reset (9 resets in 6 h on roadmap-stage).

Expected behavior

  • A Job pod exports its metrics at a fixed interval while it runs (the standard is the SDK's PeriodicExportingMetricReader, default 60 s), and once more when it ends.
  • A Job that gets SIGTERM (deadline, eviction, node drain) exports before it exits.
  • The Service keeps its flush after each round.

Test first: a fake exporter records an export from a long command before the command ends.

Related

Activity

  1. added
    type/bug
    scope/telemetry
    source/agent
    on Nov 16, 2026
  2. dan-petty commented on Nov 16, 2026

    @dan-petty
    OwnerAuthor
  3. added
    status/new
    effort/medium
    value/high
    priority/p2-medium
    owner/agent
    status/in-review
    and removed
    status/new
    on Nov 16, 2026
  4. removed
    status/in-review
    owner/agent
    on Nov 16, 2026
  5. devops-cli-service commented on Nov 16, 2026

    @devops-cli-service
    Contributor
  6. devops-cli-service commented on Nov 16, 2026

    @devops-cli-service
    Contributor

    Live since 2026-11-16 03:27 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