Skip to content

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

Closed

Description

@dan-petty

Problem

Prometheus rejects whole Alloy batches, mostly because of devops-cli series. Checked on 2026-10-03.

  • Over 24h: sum by (code) (increase(prometheus_http_requests_total{handler="/api/v1/write"}[24h])) = 16,677 accepted (204) and 219 rejected (400). increase(prometheus_tsdb_out_of_order_samples_total[24h]) = 505.
  • Prometheus v3.15.0's v1 remote-write handler (storage/remote/write_handler.go, write()) returns on the first out-of-order sample and rolls back the whole request. Every sample in that batch is lost, unrelated node and cAdvisor series included. alloy-metrics-0 logged 22 such errors since 04:53Z, losing about 15.3k samples (69 to 2,000 per batch).
  • Loki holds 24h of the server's Out of order sample from remote write lines. By job: devops-cli 211, dcgm-exporter 6, cadvisor 1, node_exporter 1. By metric: target_info 189, devops_cli_subprocess_seconds 19, up 4.
  • server.tsdb is unset in k8s/monitoring/prometheus-values.yaml, so the out-of-order window is the default 0s.

devops-cli metrics take two remote-write hops. The collector's metrics pipeline is otlp, then memory_limiter, deltatocumulative and batch, then prometheusremotewrite.

  • It writes to k8s-monitoring-alloy-metrics:9090/api/v1/metrics/write (k8s/otel/values.yaml:87-92; k8s-monitoring prometheusMetricsReceiver), and Alloy then remote-writes to Prometheus. That is about 135k points a day.
  • Because of the second hop, a late CLI sample poisons a whole Alloy batch of cluster metrics.
  • The Prometheus server already runs a remote-write receiver (server.extraArgs.web.enable-remote-write-receiver, prometheus-values.yaml:14-15), and the monitoring perimeter admits otel on 9090 (k8s/monitoring/networkpolicy.yaml:53-62).

The collector can't simply be replaced by k8s-monitoring's applicationObservability, because devops-cli exports DELTA temporality (src/devops_cli/telemetry/tracer.py:917, :949). The feature's processors are batch, interval, resourceDetection, memoryLimiter, filter and transform. otelcol.processor.deltatocumulative exists only in collectors/alloy-experimental.yaml.

The collector carries chart defaults its pipelines never use (chart opentelemetry-collector 0.175.0; live ConfigMap otel-collector-opentelemetry-collector):

  • Receivers jaeger (14250, 6831, 14268), zipkin (9411) and prometheus (self-scrape of :8888) are merged in from the chart, while every pipeline lists only otlp. They are never started: startup logs show only the OTLP servers. The Service and container ports jaeger-compact, jaeger-grpc, jaeger-thrift and zipkin are still declared.
  • memory_limiter renders the chart's limit_percentage: 80 and spike_limit_percentage: 25 next to the repo's limit_mib: 400 and spike_limit_mib: 100. The MiB values take precedence, so the percentages are dead keys.
  • The debug exporter (verbosity basic) is on all three pipelines. Over 24h it wrote 9,425 of the collector's 10,381 log lines (91%) and 5.03 of 5.16 MB (97%) to Loki.
  • The collector warns at startup that the "prometheusremotewrite" alias is deprecated in favour of "prometheus_remote_write".
  • image.tag is 0.159.0, while the deployed chart's appVersion is 0.161.0.
  • The idle logs pipeline and its otlp_http/loki exporter are feat(telemetry): send devops-cli logs with trace ids to Loki #813 scaffolding added by fix(k8s): grafana k8s-monitoring missing metrics, sre service dashboard and otel loki exporter #922. They are not dead config.

Acceptance criteria

  • k8s/monitoring/prometheus-values.yaml sets server.tsdb.out_of_order_time_window: 10m, with a comment that the v1 receiver otherwise drops a whole batch for one late sample.
  • In k8s/otel/values.yaml, the remote-write exporter key is prometheus_remote_write and is configured as follows:
  • k8s/monitoring/k8s-monitoring-values.yaml no longer enables prometheusMetricsReceiver.
  • k8s/otel/values.yaml also gets these changes:
    • config.receivers sets jaeger, zipkin and prometheus to null;
    • ports.jaeger-compact, ports.jaeger-thrift, ports.jaeger-grpc and ports.zipkin are enabled: false;
    • config.processors.memory_limiter sets limit_percentage and spike_limit_percentage to null;
    • debug is removed from every pipeline and from exporters;
    • image.tag matches the deployed chart's appVersion (0.161.0).
  • A comment on the logs pipeline says it is kept for feat(telemetry): send devops-cli logs with trace ids to Loki #813.
  • tests/test_k8s_monitoring_integration.py::test_otel_collector_remote_writes_to_the_path_alloy_serves is replaced. The new test asserts one structural tuple:
    • the exporter's host, port and path (prometheus-server.monitoring.svc.cluster.local, 9090, /api/v1/write);
    • that the server's remote-write receiver flag is set;
    • out_of_order_time_window;
    • that prometheusMetricsReceiver is not enabled;
    • the sorted receiver keys of every pipeline, ["otlp"];
    • that debug is absent from every pipeline;
    • the four disabled ports.
  • No test reaches the network. Each new test's call phase is under 1 s. A changelog.d/<n>.md fragment exists; CHANGELOG.md and docs/ROADMAP.md are untouched.
  • Pending a person, after the infra and otel stacks are redeployed:

Key questions

Strategic alignment

Update 2026-10-08: refinement

#755 closed without dropping image.tag, and the chart is pinned (commands/k8s/stack_lifecycle.py:129, k8s/argocd/apps/otel-collector.yaml:13).

  • (replaces the appVersion criterion) image.tag is removed from k8s/otel/values.yaml, and the test asserts none is set.

Proposed design

Problem statement

The devops-cli metrics are being sent through an unnecessary two-hop remote-write path, causing Prometheus to drop entire batches of metrics when a single late sample is encountered. This leads to significant data loss and excessive logging in the collector.

Acceptance criteria

  • Criterion 1: Prometheus server is configured with out-of-order time window set to 10 minutes
    Verification: Check that k8s/monitoring/prometheus-values.yaml contains server.tsdb.out_of_order_time_window: 10m with a comment explaining the reason.
  • Criterion 2: OTel collector remote-write exporter uses correct endpoint and external labels
    Verification: Verify that k8s/otel/values.yaml has prometheus_remote_write configured with endpoint: http://prometheus-server.monitoring.svc.cluster.local:9090/api/v1/write`` and includes cluster label from k8s/monitoring/k8s-monitoring-values.yaml.
  • Criterion 3: Prometheus metrics receiver is disabled in k8s-monitoring values
    Verification: Confirm that k8s/monitoring/k8s-monitoring-values.yaml no longer enables prometheusMetricsReceiver.
  • Criterion 4: OTel collector config removes unused receivers and processors
    Verification: Ensure that k8s/otel/values.yaml sets jaeger, zipkin and prometheus receivers to null, disables corresponding ports, removes memory_limiter percentage settings, and removes debug exporter from all pipelines.
  • Criterion 5: OTel collector image tag matches deployed chart version
    Verification: Validate that k8s/otel/values.yaml has image.tag set to the deployed chart's appVersion (0.161.0) or remove it if chart is pinned.
  • Criterion 6: Test validates new remote write configuration
    Verification: Run tests/test_k8s_monitoring_integration.py::test_otel_collector_remote_writes_to_the_path_alloy_serves and verify it asserts the correct exporter endpoint, server flags, out-of-order window, disabled prometheusMetricsReceiver, receiver keys, absence of debug from pipelines, and disabled ports.

Key questions

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Activity

  1. added
    scope/k8s
    scope/telemetry
    priority/p2-medium
    on Oct 3, 2026
  2. dan-petty commented on Oct 17, 2026

    @dan-petty
    OwnerAuthor

    Amendment from the gateway usage investigation of 2026-10-17, at main 3dd7fa6.

    Why

    Proposed changes to the acceptance criteria

    • deltatocumulative.max_stale sits far above any idle gap and dashboard range (proposed 720h). The comment at k8s/otel/values.yaml:58-60 and docs/TELEMETRY.md:14-18 say what an eviction does. This line depends on nothing else in refactor(k8s): the monitoring stack runs on k8s-monitoring and chart features, with no duplicate collection, dead defaults or leftovers #1128 and can merge first, as its own commit or PR.
    • Pull instead of push for the metrics pipeline: the collector's prometheus exporter on its own port, with translation_strategy: UnderscoreEscapingWithoutSuffixes and metric_expiration equal to max_stale.
    • prometheusremotewrite leaves the metrics pipeline, and prometheusMetricsReceiver stays disabled 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 already says.
    • The Prometheus server gets a dedicated scrape job for that port: 15 s interval, honor_labels: true so job and instance stay as devops-cli sets them, the existing *cluster post-relabel, and scrape_protocols that allow PrometheusProto so native histograms survive. The existing kubernetes-pods job keeps scraping the collector's own :8888.
    • The out-of-order window stays if any remote writer still uses the receiver, or goes if none does. The PR says which.
    • The structural tuple test also asserts the exporter, the scrape job, max_stale and metric_expiration.
    • Optional, experimental: created-timestamp-zero-ingestion for that job, so a brand-new series' first value counts. The contrib exporter already exposes created timestamps on counters with a start time.
    • Pending a person: for a day of normal use, sum(increase(devops_cli_ai_requests_total{cached="false"}[1h])) matches the gateway's chat count in every hour, single-command hours included.

    Expected effect

    • Replaying the real 24 h deltas through a 15 s scrape gives 24 h exact, hourly +0.4% and 5-minute +3 to +4.5%, which is ordinary extrapolation.
    • A stopgap that needs no deploy exists but is not proposed: increase(last_over_time(x[2d])[1h:5s]) recovers single-sample hours but not hidden resets, and its fine step is costly at 30 days.

    Priority

  3. dan-petty commented on Oct 18, 2026

    @dan-petty
    OwnerAuthor

    Update 2026-10-18 from a read-only cluster audit (main 3dd7fa6). Two of this item's figures have moved.

    • Debug exporter share. Over the last 24h the collector wrote 82,435 lines. About 7,638 (9%) were debug-exporter lines; the 91% figure here predates Tempo. 32,945 lines were retry_sender/queue_sender/base_exporter failures, because the Tempo exporter has sent 0 spans since Tempo was deployed: the tempo pod is refused by the otel namespace's restricted PodSecurity (filed as its own P0). Removing debug is still right. The bigger log cost will go once Tempo runs.
    • Out-of-order rejections after fix(telemetry): delta metrics from one process can reach the collector out of order #792. In 7 days, Prometheus's v1 write handler rejected 9 Alloy batches with 400. Eight were on target_info{job="devops-cli"} and one on go_memstats_heap_inuse_bytes{job="cloudflared"}. Together they lost 8,772 samples (failedSampleCount summed from k8s-monitoring-alloy-metrics-0's prometheus.remote_write.localprometheus errors); the latest was 2026-10-17T21:24Z. That is down from 219 a day on 2026-10-03. The cloudflared rejection shows Alloy's own scrapes can hit this too, which supports keeping out_of_order_time_window after the pull change.
    • The alert on collector export failures (otelcol_exporter_send_failed_*, queue fill) is filed separately as part of refactor(k8s): the monitoring stack runs on k8s-monitoring and chart features, with no duplicate collection, dead defaults or leftovers #1128's sequence. It is not part of this item.
  4. added
    priority/p1-high
    and removed
    priority/p2-medium
    on Oct 18, 2026
  5. dan-petty commented on Oct 18, 2026

    @dan-petty
    OwnerAuthor

    Status set to Ready at 25e2cda (see proposed design in issue body).

  6. dan-petty commented on Oct 19, 2026

    @dan-petty
    OwnerAuthor

    Amendment (2026-10-19): folded here by intake under the agent filing quota

    The cycle's agent filing allowance (#1153) was used, so devops roadmap intake filed nothing and named this item as the nearest. The candidate below is telemetry work: an OpenTelemetry thread that the SDK starts at import. It can land with this item or be filed on its own in a later cycle. #1664 names this amendment as the follow-up for its unmet "at most 2 tasks per worker at collection" criterion. Candidate title: "perf(ai): importing the review pipeline starts no OpenTelemetry resource-detection thread, so test collection holds 2 threads per worker".

    Friction

    Collecting the test suite starts an OpenTelemetry thread in every worker. Under #1664's OpenBLAS change, each xdist worker holds 2 threads at collection, briefly 3 while OpenTelemetry's resource detection runs. So the amendment's criterion, at most 2 tasks per worker at collection, is not met for that moment. The same import chain runs whenever a devops command imports the review pipeline, so the command pays for resource detection at import too.

    Evidence

    Checked at release/v0.2.37 3b70671 plus #1664's branch, by wrapping threading.Thread.start during a pytest --collect-only -n0 tests run:

    • Collection starts exactly one short-lived thread, ThreadPoolExecutor-0_0.
    • The chain: tests/ai/review/test_cited_code.py:10 imports devops_cli.ai.review.pipeline, which imports devops_cli.ai.agents.agent (pipeline.py:32). That module imports pydantic_ai (agent.py:20), which pulls in pydantic_graph, then logfire_api, then logfire, then opentelemetry.sdk._logs.
    • At import, Resource.create({}) runs resource detection in a ThreadPoolExecutor(max_workers=4) (opentelemetry/sdk/resources/__init__.py, get_aggregated_resources, opentelemetry-sdk 1.44.0).
    • refactor(ai): delete the pass-through package facades and the two stagepipeline protocols nothing implements #1002 made the pydantic_ai imports lazy on the command and help dispatch paths. This path, a module-level import in ai/agents/agent.py reached from ai/review/pipeline.py, was left as it is.

    Remedy

    Acceptance criteria

  7. added this to the v0.2.38 milestone on Oct 20, 2026
  8. dan-petty commented on Oct 20, 2026

    @dan-petty
    OwnerAuthor

    What changed

    #1756, merged into release/v0.2.38 as 071b191.

    Resolves #1132

    7 file(s) changed.

    How it was verified

    Check runs at a23877f:

    • Prune PR DevContainer Images: pass
    • Audit Defect PR Hardening: skipping
    • zizmor: pass
    • devops-cli: pass
    • bandit: pass
    • CodeQL: pass
    • Rule Pack Tests: pass
    • Fail-to-Pass Self-Check: pass
    • Changed-Test Independence: pass
    • Tests & Coverage: pass
    • Analyze (python): pass
    • Fail-to-Pass Check: pass
    • Analyze (actions): pass
    • Static Analysis: pass
    • DevContainer Image: skipping
    • Service Image: skipping
    • Dependency Freshness: skipping

    Acceptance Criteria of docs/agent/tasks/task-1132-devops-cli-metrics-direct-prometheus.md:

    No Acceptance Criteria section.

  9. added
    type/bug
    and removed 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

    priority/p1-highscope/k8sscope/telemetrytype/bug

    Type

    No type

    Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions