Repository navigation
Description
Context & Rationale
Item 3 of #664 was not addressed by #675. The metric exporter in telemetry/tracer.py has three properties that together let delta points arrive out of order:
- it runs with
max_workers=2(:1222); - it stamps points with a raw
time_ns()(:928-931); - it keeps the host-derived
service.instance.id(:805).
Two concurrent increments of one series put two exports in flight, and in a repro they arrived out of time order. With delta temporality, the collector can then drop or misorder points, and totals come out low.
Scope & Deliverables
- Deliverable:
- Each process exports metrics through one ordered lane, and its point timestamps strictly increase.
- TELEMETRY.md records the remaining limitation: processes on one host share an instance id.
- A test exports concurrent increments and asserts they arrive in order.
- Constraint: the host-derived
service.instance.idfrom Review, findings and AI spend metrics reach Prometheus #564 stays as it is. This is the narrower fix agreed while fix(ai): shared agents leak memory across reviewed files, openai caps use the wrong token field, and delta metrics arrive out of order #664 was open.
Strategic Alignment
- Milestone: Backlog (no release)
- Design: none
- Depends on: none
Generated by Claude Code
Monitoring cleanup amendment (2026-10-03): evidence and scope
Over 24h, Prometheus rejected 219 remote-write requests as out of order. Grouped by metric, the rejected series were target_info 189, devops_cli_subprocess_seconds 19 and up 4. Grouped by job, devops-cli accounted for 211. Each rejection drops a whole Alloy batch, about 15.3k samples in total.
Scope (added). target_info is in scope: every CLI process emits it with the same series identity (the host-derived instance id), so two processes' resource metrics interleave out of order.
#1132 adds the receiver-side out_of_order_time_window and removes the Alloy hop. This item remains the sender-side fix. Related to #1128, not a child.
Amended 2026-10-04: metrics go through the OTel SDK, with exponential histograms
Library-first scope, from a latency investigation on 2026-10-04.
-
The review p95 panel showed nearly 30 minutes, but the slowest review took 16.5 minutes.
- The panel computes
histogram_quantile(0.95, … increase(devops_cli_review_duration_seconds_bucket[1h]))(k8s/monitoring/dashboards/devops-cli.json:67). The review buckets jump from 900 s to 1,800 s (telemetry/instruments.py:44). histogram_quantilespreads values evenly inside a bucket. With N reviews in the hour, one 992 s review is drawn as 900 + 900 × (1 − 0.05N): between 1,575 and 1,755 s.- About 43% of the plotted value came from the bucket math alone. The night before, 591–679 s reviews were drawn as 825–885 s.
- The command-duration panel tops out at 600 s (
_SECONDS,instruments.py:43), so a 20-minute gate draws as a flat line.
- The panel computes
-
The hand-built exporter is the root of both this and the ordering problem above.
telemetry/tracer.pybuilds OTLP metric payloads by hand, with fixed bucket tuples, its own worker pool and rawtime_ns()stamps. The OpenTelemetry SDK is already a dependency. -
Metrics go through the SDK. Metrics are emitted through the SDK's
MeterProvider, with DELTA temporality, and flushed once when the command ends. The hand-built metric payload, its worker pool and its timestamping are removed fromtracer.py. This replaces the "one ordered lane" deliverable above: each process sends one export. -
Histograms are exponential. Duration histograms use an
ExponentialBucketHistogramAggregationview, and the fixed bucket tuples ininstruments.pyare removed. -
Prometheus stores native histograms. The collector's remote write sends them as native histograms, and Prometheus ingests them; the receiver side is fix(telemetry): devops-cli metrics reach prometheus in one hop, a late sample no longer drops a whole batch, and the collector runs only what its pipelines use #1132's file,
k8s/otel/values.yaml. Before building, check that the deployed Prometheus version accepts native histograms over remote write. If it does not, record that and keep explicit buckets on this criterion only. -
Duration panels stay honest at low counts. The duration panels in
devops-cli.jsonshow the p95, a mean line (increase(_sum) / increase(_count)) and the sample count, so a quantile drawn from one or two samples reads as such. -
The idle-hour gap is fixed or recorded.
deltatocumulative'smax_stale: 1h(k8s/otel/values.yaml:61) hides the first review after an idle hour from everyincrease()window. Fix it here if the SDK path changes it; otherwise record it as fix(telemetry): devops-cli metrics reach prometheus in one hop, a late sample no longer drops a whole batch, and the collector runs only what its pipelines use #1132's. -
Tests. An export of one 992 s review, read back through a fake OTLP receiver, is an exponential histogram whose bucket holding 992 s has a width under 10% of its value. The existing collector-export tests pass, offline.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
dan-petty commentedon Oct 8, 2026
Folded here instead of a new issue: the agent filing quota (#1153) is spent for this cycle, and this refactor shares this item's change surface. It is recorded here in full so it is not lost.
refactor(telemetry): /metrics is rendered and scraped metrics are parsed by prometheus-client
Problem
Lines cited at 05e9388 (
release/v0.2.29).InMemoryMetricsRegistry.export_prometheus_text(telemetry/metrics.py:174-197). The roadmap service serves it as is (server/service.py:458-463)./metricsroute, which prepends hand-formatted families (server/routes/telemetry.py:60-90).ai/spend/prometheus.py:24-120).metrics.py:29-38,ai/spend/prometheus.py:12-22).server/routes/telemetry.py:74interpolates__version__into a label unescaped.metrics.py:188-195writes# TYPE <name> histogramfollowed only by_countand_sum. There are no_bucketseries and nole="+Inf", which the text format requires.histogram_quantilecannot be applied to, for example,devops_cli_argo_target_sync_duration_seconds(argo/fleet.py:90)._MAX_HISTOGRAM_SAMPLES,metrics.py:23), only to sum and count them.parse_prometheus_exposition(sandbox/metrics.py:312-383) has two defects:\{(?P<labels>[^}]*)\}(:32-34) drops any sample whose label value contains}. Such a value is legal, for examplepath="/api/{id}".:367), so a histogram's_sumis typedgaugeand its_countcounter(:377-383).httpx2.Client(:433).ai/gateway_bench.py:76-85:_VLLM_CACHEand an inline label regex).Proposed remedy
prometheus-clientto the dependencies (Prometheus Authors; 0.26.0, 2026-07-24).CollectorRegistryreplacesInMemoryMetricsRegistry's storage and text export.GLOBAL_METRICScallers keep their call shape overCounter,GaugeandHistogram, with buckets fromtelemetry/instruments.pyor the library defaults.GaugeMetricFamilyandCounterMetricFamily.devops_cli_infobecomes anInfo; uptime and telemetry-enabled become gauges./metricsroutes returngenerate_latest(registry)withCONTENT_TYPE_LATEST.sandbox/metrics.pyparses withprometheus_client.parser.text_string_to_metric_familiesand scrapes through the egress factory (refactor(cli): Unify HTTP and DNS seams with shared fakes #1314).ai/gateway_bench.pystays standard-library only.vllm:cache_config_info. Its existing regex is kept as the single exception and pinned by a recorded vLLM exposition fixture. No fuller hand-written parser is added there.Acceptance criteria
rg -n '"# (TYPE|HELP)' src/devops_cliprints nothing./metricsexposes_bucketseries includingle="+Inf", plus_sumand_count. The registry keeps no raw observations.},",\and a newline returns the same value. A histogram's_sumand_countsamples come back under the histogram family.ai/gateway_bench.pyimports only the standard library. A test readsnum_gpu_blocksandblock_sizefrom a recorded vLLM/metricsfixture.changelog.d/<n>.mdrecords the change;CHANGELOG.mdanddocs/ROADMAP.mdare not edited.uv run devops cipasses.Related: #792, #1132, #974, #569, #1335, #1314, #1334.
Found by the 2026-10-08 client-library audit.
dan-petty commentedon Oct 8, 2026
Linked: #1319 and #813. Each replaces part of the hand-built OTLP in
telemetry/tracer.pywith the SDK: metrics here, spans and the exporter seam in #1319, logs in #813. Found by the 2026-10-08 backlog review.dan-petty commentedon Oct 9, 2026
Finding: v0.2.29 Service gap assessment (2026-10-09)
_send_metricposts one OTLP payload per data point, and httpx logs each POST at INFO: in the v0.2.29 pod, 7,721 metrics POST lines and 4,362 traces POST lines in 3 hours, about two thirds of the log. Many concurrent sends also make the out-of-order delta points this item describes more likely. Proposed: in the single ordered export lane planned here, send one request per emission with all its points, and set the httpx logger to WARNING in the Service.dan-petty commentedon Oct 14, 2026
Moved to v0.2.36: v0.2.36 started with fewer than its 16 items and was topped up to 16 from Ready items, critical fixes and P0 features first. (devops roadmap reprioritize)
fix(telemetry): aggregate delta metrics via OTel SDK MeterProvider an…
dan-petty commentedon Oct 17, 2026
What changed
#1612, merged into
release/v0.2.36as 6e12759.30 file(s) changed.
How it was verified
Check runs at 94151ef:
Acceptance Criteria of
docs/agent/tasks/task-792-telemetry-delta-metrics-and-prometheus-client.md:No Acceptance Criteria section.
feat(release): v0.2.36 (#1615)
fix(monitoring): the Grafana rate panels hold two samples, the dashbo…
fix(service): roadmap-service exports its AI usage counters after eve…