Repository navigation
Description
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-0logged 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 writelines. By job: devops-cli 211, dcgm-exporter 6, cadvisor 1, node_exporter 1. By metric:target_info189,devops_cli_subprocess_seconds19,up4. server.tsdbis unset ink8s/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-monitoringprometheusMetricsReceiver), 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 admitsotelon 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) andprometheus(self-scrape of :8888) are merged in from the chart, while every pipeline lists onlyotlp. They are never started: startup logs show only the OTLP servers. The Service and container portsjaeger-compact,jaeger-grpc,jaeger-thriftandzipkinare still declared. memory_limiterrenders the chart'slimit_percentage: 80andspike_limit_percentage: 25next to the repo'slimit_mib: 400andspike_limit_mib: 100. The MiB values take precedence, so the percentages are dead keys.- The
debugexporter (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.tagis0.159.0, while the deployed chart's appVersion is0.161.0.- The idle
logspipeline and itsotlp_http/lokiexporter 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.yamlsetsserver.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 isprometheus_remote_writeand is configured as follows:endpoint: http://prometheus-server.monitoring.svc.cluster.local:9090/api/v1/write, the chart's own Service, not theprometheusalias that fix(k8s): the pyroscope Service alias collides with the pyroscope Helm release's own Service, so a fresh deploy-stack can't install Pyroscope #1104 removes;external_labelswithclusterset to the value ofcluster.nameink8s/monitoring/k8s-monitoring-values.yaml, the label Alloy added on the old path;translation_strategykept.
-
k8s/monitoring/k8s-monitoring-values.yamlno longer enablesprometheusMetricsReceiver. -
k8s/otel/values.yamlalso gets these changes:config.receiverssetsjaeger,zipkinandprometheustonull;ports.jaeger-compact,ports.jaeger-thrift,ports.jaeger-grpcandports.zipkinareenabled: false;config.processors.memory_limitersetslimit_percentageandspike_limit_percentagetonull;debugis removed from every pipeline and fromexporters;image.tagmatches the deployed chart's appVersion (0.161.0).
- A comment on the
logspipeline 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_servesis 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
prometheusMetricsReceiveris not enabled; - the sorted receiver keys of every pipeline,
["otlp"]; - that
debugis absent from every pipeline; - the four disabled ports.
- the exporter's host, port and path (
- No test reaches the network. Each new test's call phase is under 1 s. A
changelog.d/<n>.mdfragment exists; CHANGELOG.md and docs/ROADMAP.md are untouched. - Pending a person, after the infra and otel stacks are redeployed:
sum by (code) (increase(prometheus_http_requests_total{handler="/api/v1/write"}[24h]))has no400row 24h later;increase(prometheus_remote_storage_samples_failed_total[24h])read on alloy-metrics is 0 (through feat(k8s): the alloy collectors, grafana and pyroscope are scraped through chart integrations, and a dropped sample or log entry alerts #1131's scrape, or the pod proxy before it);devops_cli_command_totalkeeps rising after a fewdevopscommands;kubectl get svc -n otel otel-collector-opentelemetry-collector -o jsonpath='{.spec.ports[*].name}'lists onlymetrics,otlpandotlp-http;{job="otel/opentelemetry-collector"}in Loki drops to tens of lines a day.
Key questions
- Is the out-of-order window a band-aid over fix(telemetry): delta metrics from one process can reach the collector out of order #792? Proposed: no, it is the receiver's half of the fix. Any remote-write receiver behind a batching, retrying sender sees late samples, and Prometheus's v1 handler turns one late sample into a lost batch. fix(telemetry): delta metrics from one process can reach the collector out of order #792 fixes the sender's ordering. fix(telemetry): delta metrics from one process can reach the collector out of order #792 is amended to include
target_info, which accounts for 189 of the 219 rejections. - Why 10m? Proposed: it covers Alloy's retry backoff and the collector's 5s batch with margin, and it is far below the 2h head block. Out-of-order samples cost a small extra head chunk per series, with no change to retention.
- Does skipping Alloy lose anything? Proposed: only the
cluster/k8s_cluster_nameexternal labels.external_labelsrestorescluster, and no devops-cli dashboard reads either label (grep clusterfinds nothing in devops-cli.json, ai-spend.json, project-metrics.json or otel-collector.json). Alloy's own pipeline is unchanged. - Can Alloy replace the collector later? Proposed: revisit when Alloy's
deltatocumulativeleaves experimental, or if fix(telemetry): delta metrics from one process can reach the collector out of order #792's rework moves the CLI to cumulative temporality. fix(k8s): the prometheus server scrapes only itself and the otel collector, and k8s-monitoring discovers every other target #1130's ownership table records this. - Drop the image tag to follow the chart? Proposed: not yet. The chart floats until feat(k8s): argo cd keeps the homelab cluster at the current release branch, with automated sync, prune and self-heal that never delete data #755 pins it, so an empty tag would follow an unpinned chart. Set the tag to the deployed appVersion now. feat(k8s): argo cd keeps the homelab cluster at the current release branch, with automated sync, prune and self-heal that never delete data #755 is amended to drop the tag once the chart is pinned.
- Should the 1.2%
prometheusremotewritesend-failure rate seen on the old path be fixed here? Proposed: re-measure after this change. If it persists on the direct path, it belongs to fix(telemetry): delta metrics from one process can reach the collector out of order #792.
Strategic alignment
- P2 bug: about 15k cluster samples a day are lost to devops-cli's late samples, and the collector logs mostly debug output.
- Value: medium (complete metrics and one fewer hop). Effort: S (three values files, one test).
- Library-first: the receiver's documented
out_of_order_time_window, the exporter'sexternal_labels, and chartnulloverrides and port flags. No custom processors. - Related: fix(telemetry): delta metrics from one process can reach the collector out of order #792 (amended: sender-side ordering,
target_info), fix(telemetry): the collector remote-writes devops-cli metrics to the path alloy serves #829 (chose the Alloy path, superseded here), feat(telemetry): send devops-cli logs with trace ids to Loki #813 (keeps the logs pipeline), feat(telemetry): sandbox egress port scoping, collector lane & in-container trace context #702 (collector lane), fix(security): Loki admits only the OpenTelemetry collector from otel, and persona exemplars always come from the review target's project #1100 (Loki ingress keyed to the collector's labels; unchanged), fix(k8s): the pyroscope Service alias collides with the pyroscope Helm release's own Service, so a fresh deploy-stack can't install Pyroscope #1104 (absorbs chore(k8s): drop the kube-prometheus-stack service aliases #818: it deletes the alias Services and repoints Alloy'slocalPrometheusdestination; no order constraint with this item, whichever lands second rebasesk8s-monitoring-values.yaml), fix(k8s): the prometheus server scrapes only itself and the otel collector, and k8s-monitoring discovers every other target #1130 (ownership table row), feat(k8s): the alloy collectors, grafana and pyroscope are scraped through chart integrations, and a dropped sample or log entry alerts #1131 (the alert that proves this fix), feat(telemetry): traces are stored in tempo on a volume, and grafana and devops-cli read them, linked to logs and profiles #1135 (also editsk8s/otel/values.yaml).
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.tagis removed fromk8s/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 thatk8s/monitoring/prometheus-values.yamlcontainsserver.tsdb.out_of_order_time_window: 10mwith a comment explaining the reason. - Criterion 2: OTel collector remote-write exporter uses correct endpoint and external labels
Verification: Verify thatk8s/otel/values.yamlhasprometheus_remote_writeconfigured withendpoint:http://prometheus-server.monitoring.svc.cluster.local:9090/api/v1/write`` and includesclusterlabel fromk8s/monitoring/k8s-monitoring-values.yaml. - Criterion 3: Prometheus metrics receiver is disabled in k8s-monitoring values
Verification: Confirm thatk8s/monitoring/k8s-monitoring-values.yamlno longer enablesprometheusMetricsReceiver. - Criterion 4: OTel collector config removes unused receivers and processors
Verification: Ensure thatk8s/otel/values.yamlsetsjaeger,zipkinandprometheusreceivers 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 thatk8s/otel/values.yamlhasimage.tagset 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: Runtests/test_k8s_monitoring_integration.py::test_otel_collector_remote_writes_to_the_path_alloy_servesand 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
- Is the out-of-order window a band-aid over fix(telemetry): delta metrics from one process can reach the collector out of order #792?: No, it is the receiver's half of the fix. Any remote-write receiver behind a batching, retrying sender sees late samples, and Prometheus's v1 handler turns one late sample into a lost batch. fix(telemetry): delta metrics from one process can reach the collector out of order #792 fixes the sender's ordering. [sources: src/devops_cli/telemetry/tracer.py:917, src/devops_cli/telemetry/tracer.py:949]
- Why 10m?: It covers Alloy's retry backoff and the collector's 5s batch with margin, and it is far below the 2h head block. Out-of-order samples cost a small extra head chunk per series, with no change to retention. [sources: k8s/monitoring/prometheus-values.yaml]
- Does skipping Alloy lose anything?: Only the
cluster/k8s_cluster_nameexternal labels.external_labelsrestorescluster, and no devops-cli dashboard reads either label. [sources: k8s/monitoring/k8s-monitoring-values.yaml] - Can Alloy replace the collector later?: Revisit when Alloy's
deltatocumulativeleaves experimental, or if fix(telemetry): delta metrics from one process can reach the collector out of order #792's rework moves the CLI to cumulative temporality. (proposed) [sources: docs/ROADMAP.md] - Drop the image tag to follow the chart?: Not yet. The chart floats until feat(k8s): argo cd keeps the homelab cluster at the current release branch, with automated sync, prune and self-heal that never delete data #755 pins it, so an empty tag would follow an unpinned chart. Set the tag to the deployed appVersion now. (proposed) [sources: k8s/otel/values.yaml]
- Should the 1.2%
prometheusremotewritesend-failure rate seen on the old path be fixed here?: Re-measure after this change. If it persists on the direct path, it belongs to fix(telemetry): delta metrics from one process can reach the collector out of order #792. (proposed) [sources: k8s/otel/values.yaml]
Fit
Fits in one pull request.
Suspected block
None.
Dependencies
None.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
dan-petty commentedon Oct 17, 2026
Amendment from the gateway usage investigation of 2026-10-17, at main 3dd7fa6.
Why
docs/TELEMETRY.md:14-18says the collector'smax_stale: 1hidle eviction is tracked under 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, and fix(telemetry): delta metrics from one process can reach the collector out of order #792's criteria deferred "the idle-hour gap" to 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. 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 criteria never picked it up.increase()never counts.max_stalethat Prometheus cannot see as resets, because the restarted value was not lower:ollama-48gib-fast1→1 at 01:00:15,ollama-48gib-fast1→2 andollama-64gib-standard1→1 at 13:12:10.k8s/otel/values.yaml:58-60is wrong. An evicted stream restarts at the next delta, not at zero, and Prometheus counts a reset only when that value is lower.Proposed changes to the acceptance criteria
deltatocumulative.max_stalesits far above any idle gap and dashboard range (proposed720h). The comment atk8s/otel/values.yaml:58-60anddocs/TELEMETRY.md:14-18say 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.prometheusexporter on its own port, withtranslation_strategy: UnderscoreEscapingWithoutSuffixesandmetric_expirationequal tomax_stale.prometheusremotewriteleaves the metrics pipeline, andprometheusMetricsReceiverstays 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.honor_labels: truesojobandinstancestay as devops-cli sets them, the existing*clusterpost-relabel, andscrape_protocolsthat allow PrometheusProto so native histograms survive. The existingkubernetes-podsjob keeps scraping the collector's own:8888.max_staleandmetric_expiration.created-timestamp-zero-ingestionfor that job, so a brand-new series' first value counts. The contrib exporter already exposes created timestamps on counters with a start time.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
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
dan-petty commentedon Oct 18, 2026
Update 2026-10-18 from a read-only cluster audit (main 3dd7fa6). Two of this item's figures have moved.
retry_sender/queue_sender/base_exporterfailures, because the Tempo exporter has sent 0 spans since Tempo was deployed: the tempo pod is refused by theotelnamespace's restricted PodSecurity (filed as its own P0). Removingdebugis still right. The bigger log cost will go once Tempo runs.target_info{job="devops-cli"}and one ongo_memstats_heap_inuse_bytes{job="cloudflared"}. Together they lost 8,772 samples (failedSampleCountsummed fromk8s-monitoring-alloy-metrics-0'sprometheus.remote_write.localprometheuserrors); 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 keepingout_of_order_time_windowafter the pull change.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.dan-petty commentedon Oct 18, 2026
Status set to Ready at 25e2cda (see proposed design in issue body).
dan-petty commentedon Oct 19, 2026
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 intakefiled 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
devopscommand 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.startduring apytest --collect-only -n0 testsrun:ThreadPoolExecutor-0_0.tests/ai/review/test_cited_code.py:10importsdevops_cli.ai.review.pipeline, which importsdevops_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, thenopentelemetry.sdk._logs.Resource.create({})runs resource detection in aThreadPoolExecutor(max_workers=4)(opentelemetry/sdk/resources/__init__.py,get_aggregated_resources, opentelemetry-sdk 1.44.0).ai/agents/agent.pyreached fromai/review/pipeline.py, was left as it is.Remedy
devops_cli/ai/agents/agent.py, or in the pipeline's import of it, so that importingdevops_cli.ai.review.pipelinedoes not import logfire. Use the same pattern refactor(ai): delete the pass-through package facades and the two stagepipeline protocols nothing implements #1002 used for the dispatch paths.Acceptance criteria
import devops_cli.ai.review.pipelinein a fresh interpreter starts no thread. Check this by wrappingthreading.Thread.startbefore the import, or by readingThreads:in/proc/self/status./proc(test(cli): tests wait for a background thread with one generous bound, not a 1-second deadline, so they pass under load #1664's amendment).tests/test_cli_startup_imports.py) still pass, anduv run devops cipasses.fix(telemetry): devops-cli metrics reach prometheus in one hop (#1132) (
dan-petty commentedon Oct 20, 2026
What changed
#1756, merged into
release/v0.2.38as 071b191.7 file(s) changed.
How it was verified
Check runs at a23877f:
Acceptance Criteria of
docs/agent/tasks/task-1132-devops-cli-metrics-direct-prometheus.md:No Acceptance Criteria section.
feat(release): v0.2.38 (#1799)
feat(release): v0.2.38 (#1798)
fix(service): roadmap-service exports its AI usage counters after eve…