Skip to content

fix(monitoring): stop the gateway labeldrop losing samples #6439

Closed

Description

@dan-petty

Problem Description

Since 2026-11-15T23:26Z, Prometheus refuses about 8 % of the samples that Alloy sends to it by remote write. Each refusal drops a full batch of up to 2,000 samples, so the series of unrelated targets get gaps. On 2026-11-19, 7,372,993 of 90,762,413 samples failed in 24 h (8.1 %).

Cause. #5896 (merged 2026-11-15T22:58:41Z, closes #4545) adds two labeldrop rules for client_ip and user_agent to the gateway ServiceMonitor (k8s/llm/gateway/servicemonitor.yaml:20-24). LiteLLM writes these two labels on litellm_deployment_total_requests and on six other metric families (LiteLLM Prometheus documentation). After the drop, two series that differ only in client_ip or user_agent have the same label set and different values at one timestamp. Alloy sends both samples. The remote-write receiver of Prometheus answers HTTP 400 "duplicate sample for timestamp", and Alloy drops the full batch as a non-recoverable error. The first refusal comes 28 minutes after the merge of #5896. Since 2026-11-12, each non-recoverable remote-write error in the Alloy log is of this kind.

The loss grows each day. Failed samples: 0.5 % (24 h to 2026-11-16T14:53Z), 1.6 % (11-17), 5.7 % (11-18), 8.1 % (11-19). Lines with "duplicate sample" in the Alloy log: 19 (2026-11-15), 218 (11-16), 647 (11-17), 1,129 (11-18). The growth agrees with LiteLLM keeping each caller pod address as a new series until the gateway restarts.

Effects. Samples of up in 2 h (expected 120 at a 60 s interval, 480 for the gateway at 15 s):

Job 2 h to 2026-11-15T12:00Z 2 h to 2026-11-19T14:50Z
llm-gateway 480 242
roadmap-service 120 60.5
valkey-devops 120 79
integrations/kubernetes/resources 120 96.2
valkey 120 120

Reproduction Steps

  1. In Grafana Explore on the Prometheus data source, run sum(increase(prometheus_remote_storage_samples_failed_total{job="integrations/alloy"}[24h])) / sum(increase(prometheus_remote_storage_samples_total{job="integrations/alloy"}[24h])). The result is above 0.
  2. In Loki, run sum(count_over_time({namespace="monitoring", container="alloy"} |= "duplicate sample" [1d])). The count is above 0 on each day since 2026-11-15.
  3. Take the "existing" value of one refusal, for example 1.79485251474689e+09. Run litellm_deployment_total_requests_created > 1794852514 < 1794852515. The result is a job="llm-gateway" series with no client_ip label.
  4. Run sum by(job)(count_over_time(up[2h])) / on(job) group_left count by(job)(max_over_time(up[2h])). llm-gateway, roadmap-service and valkey-devops are below their expected counts.

Expected vs Actual Behavior

  • Expected: Prometheus stores each sample that Alloy sends, AlloyRemoteWriteSamplesFailed is quiet, and each target keeps all of its scrapes.
  • Actual: Prometheus refuses about 8 % of all samples in batches of 2,000, the alert fires, and targets that have no fault, such as valkey-devops and roadmap-service, lose up to half of their samples.

Environment Diagnostics

  • DevOps CLI Version: 0.180.0 (origin/main 0d90de5)
  • LiteLLM image: ghcr.io/berriai/litellm:v1.103.11 (k8s/llm/gateway/deployment.yaml:46)
  • Collector: the alloy-metrics StatefulSet of the k8s-monitoring chart, one replica, remote write to the Prometheus server
  • Scrape: the llm-gateway ServiceMonitor, interval 15s, path /metrics/

Logs, Traces, or Terminal Output

ts=2026-11-15T23:26:16.623Z level=error msg="non-recoverable error" component_id=prometheus.remote_write.localprometheus failedSampleCount=2000 err="server returned HTTP status 400 Bad Request: duplicate sample for timestamp 1794785174253; overrides not allowed: existing 1.7947618562847917e+09, new value 1.7947848863663995e+09"
ts=2026-11-19T14:44:40.782Z level=error msg="non-recoverable error" component_id=prometheus.remote_write.localprometheus failedSampleCount=2000 err="server returned HTTP status 400 Bad Request: duplicate sample for timestamp 1795099476547; overrides not allowed: existing 1.79485251474689e+09, new value 1.7949222435950286e+09"

The most frequent value pairs in 24 h: "existing 13, new value 7" (29 times), "existing 4, new value 1" (28 times). These are counter values of the same families.

Pre-Submission Checklist

  • I have verified that no sensitive credentials, private keys, or internal tokens are contained in this issue report.
  • I have checked existing issues and pull requests to ensure this is not a duplicate.

Acceptance Criteria

  • The gateway writes no client_ip and no user_agent label at the source, so no two series collide. The LiteLLM Prometheus documentation names litellm_settings.prometheus_exclude_labels and the include_labels of prometheus_metrics_config. The builder confirms which key LiteLLM 1.103.11 reads, or names the release that adds it.
  • The two labeldrop rules leave k8s/llm/gateway/servicemonitor.yaml, and the check check_the_gateway_endpoint_drops_the_caller_labels (tests/gate/k8s_checks/llm_gateway.py:196) changes with them.
  • count({job="llm-gateway", client_ip!=""}) returns no series.
  • 24 h after the rollout, sum(increase(prometheus_remote_storage_samples_failed_total{job="integrations/alloy"}[24h])) is 0, and AlloyRemoteWriteSamplesFailed is resolved.
  • 24 h after the rollout, the Loki count of step 2 is 0, and the query of step 4 gives 120 for roadmap-service and valkey-devops.

Dependencies

None. Related: #4545 and #5896 (the label drop), #1131 (the alert), #4624 (its measures read the series with gaps).

Proposed design

Problem statement

The gateway ServiceMonitor drops client_ip and user_agent after scrape. LiteLLM writes those labels on several metric families. The drop makes distinct series identical, so Prometheus rejects duplicate samples and Alloy drops full batches. The fix removes the two labeldrop rules and updates the k8s check. Source-level label exclusion is deferred.

Acceptance criteria

Requirement: Gateway ServiceMonitor drops no caller labels

The gateway ServiceMonitor SHALL NOT hold a labeldrop rule for client_ip or user_agent.

Scenario: k8s row accepts the ServiceMonitor without caller-label drops

  • WHEN uv run devops ci --check --only k8s runs on the change
  • THEN the k8s row passes and check_the_gateway_endpoint_drops_the_caller_labels reports no labeldrop rule for client_ip or user_agent.

Requirement: Gateway scrape endpoint unchanged

The gateway ServiceMonitor SHALL keep port http, path /metrics/ and interval 15s.

Scenario: k8s row accepts the gateway scrape endpoint

  • WHEN uv run devops ci --check --only k8s runs on the change
  • THEN the k8s row passes and reports port http, path /metrics/ and interval 15s.

Requirement: No failed remote-write samples after rollout

Prometheus MUST store every sample that Alloy sends to it after the change.

Scenario: 24 h remote-write check

  • WHEN the live check runs sum(increase(prometheus_remote_storage_samples_failed_total{job="integrations/alloy"}[24h])) 24 h after the rollout
  • THEN the query returns 0 and AlloyRemoteWriteSamplesFailed is resolved.

Requirement: No duplicate sample log lines after rollout

Alloy MUST log no duplicate sample error after the change.

Scenario: 24 h Alloy log check

  • WHEN the live check runs sum(count_over_time({namespace="monitoring", container="alloy"} |= "duplicate sample" [1d])) 24 h after the rollout
  • THEN the query returns 0.

Requirement: Targets keep their scrapes after rollout

The roadmap-service and valkey-devops targets MUST keep their expected up samples after the change.

Scenario: 2 h scrape coverage check

  • WHEN the live check runs sum by(job)(count_over_time(up[2h])) / on(job) group_left count by(job)(max_over_time(up[2h])) 24 h after the rollout
  • THEN the query returns 120 for roadmap-service and valkey-devops.

Existing Tool Considered

No alternatives check has run. Prometheus Operator's ServiceMonitor relabeling covers the removal of the two labeldrop rules, and the LiteLLM gateway covers source-level label exclusion. The plan builds no code. The immediate change uses the ServiceMonitor; the LiteLLM key for image 1.103.11 is unconfirmed, so source-level exclusion is deferred.

Key questions

  • What causes Prometheus to reject whole Alloy batches?: The two labeldrop rules remove client_ip and user_agent from every gateway series. LiteLLM writes both labels on several metric families. Two series that differ only in those labels become identical with different values. Prometheus answers HTTP 400 duplicate sample for timestamp, and Alloy treats that as non-recoverable and drops the full batch. [sources: k8s/llm/gateway/servicemonitor.yaml:20-24, tests/gate/k8s_checks/llm_gateway.py:196, openspec/specs/gateway-caller-telemetry/spec.md:85]
  • Which change stops the duplicate series?: Remove both labeldrop rules from the gateway ServiceMonitor. Keep the labels in the scraped series so their label sets stay distinct. Do not deduplicate in Alloy or retry the batch, because the receiver rejects the duplicate sample as non-recoverable. (best practice) [sources: k8s/llm/gateway/servicemonitor.yaml:20-24, openspec/specs/gateway-caller-telemetry/spec.md:85]
    • Chosen: Remove both labeldrop rules. The scraped series keep distinct label sets, so the receiver accepts them. This is the smallest change that stops the loss.
    • Rejected: Keep the rules and add source exclusion in the same change. The LiteLLM key for image 1.103.11 is not confirmed. The rules still collide until that key works.
    • Rejected: Drop only client_ip. user_agent still creates duplicate series, so the loss continues.
  • Should source-level label exclusion ship with this fix?: No. Defer it. Removing the labeldrop rules stops the sample loss. Source-level exclusion needs a confirmed LiteLLM key or a named release, and the issue leaves that fact open. (best practice) [sources: k8s/llm/gateway/deployment.yaml:46, k8s/llm/gateway/config.yaml, k8s/llm/gateway/servicemonitor.yaml:20-24]
    • Chosen: Defer source-level exclusion. The rest of the fix is workable now. The deferred issue can confirm the LiteLLM key or release.
    • Rejected: Ship source exclusion now. The LiteLLM 1.103.11 key is not sourced. A wrong key leaves the labels in place and does not fix the loss.
    • Rejected: Keep labeldrop until source exclusion ships. The loss continues while the source change waits.
  • Which check must change?: check_the_gateway_endpoint_drops_the_caller_labels in tests/gate/k8s_checks/llm_gateway.py must assert that the gateway endpoint has no labeldrop rule for client_ip or user_agent. The k8s row runs it. [sources: tests/gate/k8s_checks/llm_gateway.py:196, k8s/llm/gateway/servicemonitor.yaml:20-24]
  • Does the alert AlloyRemoteWriteSamplesFailed need a change?: No. The alert is generic and fires on failed remote-write samples. It should resolve when the duplicate sample errors stop. The change keeps the alert. [sources: k8s/monitoring/prometheus-values.yaml:552-560, k8s/README.md:641]
  • Which spec must change?: The gateway-caller-telemetry spec at line 85 requires the labeldrop rules. The change must update that requirement and its scenario to match the ServiceMonitor without caller-label drops. [sources: openspec/specs/gateway-caller-telemetry/spec.md:85, openspec/specs/gateway-caller-telemetry/spec.md:87]

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Activity

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

    @dan-petty
    OwnerAuthor
    • Priority: P1-High. Sample loss is growing from 0.5% to 8.1% in four days, an alert fires continuously, and multiple targets lose up to half their scrapes.
    • Related: fix(monitoring): drop per-pod labels from gateway spend series #4545, which asks for a different change. Both items touch the gateway ServiceMonitor label handling, but #4545 delivers the labeldrop and the candidate fixes the duplicate-sample rejection that the labeldrop introduced.
  3. added
    status/new
    effort/medium
    value/high
    scope/monitoring
    priority/p1-high
    on Nov 19, 2026
  4. devops-cli-service commented on Nov 19, 2026

    @devops-cli-service
    Contributor

    Next step: the alternatives check records a verdict. See the section Proposed design of the body.

  5. added
    owner/agent
    status/in-progress
    and removed
    status/new
    on Nov 19, 2026
  6. dan-petty commented on Nov 19, 2026

    @dan-petty
    OwnerAuthor

    Design change: exclude the caller labels at the LiteLLM source

    The refine block defers source-level exclusion because the LiteLLM key for image v1.103.11 was not confirmed. That reason is gone. The build uses the source key, as the first acceptance criterion asks.

    The key exists in LiteLLM v1.103.11

    • litellm/__init__.py:477-478 declares prometheus_exclude_metrics and prometheus_exclude_labels.
    • litellm/integrations/prometheus.py:275 reads the setting into the logger, and :897-919 checks each name against the defined labels.
    • The metric factory at :1158-1178 makes each metric without the excluded label names. _ExcludedLabelMetric.labels() (:163-184) drops the excluded values, so LiteLLM adds the counts of all callers into one series before exposition.
    • get_labels_for_metric (:1188-1204) and _inc_labeled_counter (:1304-1317) are the increment path of all seven families.
    • No premium or licence check gates this setting.

    The change

    1. k8s/llm/gateway/config.yaml: add prometheus_exclude_labels: ["client_ip", "user_agent"] under litellm_settings, before callbacks: ["prometheus", "otel"]. Key order has mattered for other Prometheus settings (proxy_server.py:5857-5860), so the key comes first.
    2. k8s/llm/gateway/servicemonitor.yaml: remove the comment and the metricRelabelings block with its two labeldrop rules.
    3. tests/gate/k8s_checks/llm_gateway.py: remove check_the_gateway_endpoint_drops_the_caller_labels. It asserts manifest values, which docs/TESTING.md forbids. No check replaces it. The two reader checks stay: no dashboard query and no alert expression may use the two labels.
    4. The gateway-caller-telemetry spec changes through an OpenSpec change folder. The live check after the Argo CD sync is the proof: count({job="llm-gateway", client_ip!=""}) and count({job="llm-gateway", user_agent!=""}) return no series, and litellm_deployment_total_requests_total{job="llm-gateway"} still exists (about 15 series, not 323).

    Why the other options lose

    • Remove the labeldrop rules only (the refine design): it stops the collisions but gives up the fix(monitoring): drop per-pod labels from gateway spend series #4545 bound. The deployment families have no end_user label, so the TTL never removes their series (about 1,330 to 1,500 extra series after 3 days).
    • prometheus_metrics_config with include_labels: it is include-based (prometheus.py:1150-1156), so each family that is not listed stops.
    • Upgrade LiteLLM for prometheus_metrics_max_series_per_metric: not in v1.103.11, and it keeps the labels, so readers still read split values.
    • Aggregate in Alloy or the OTel Collector: correct, but 40 to 60 lines of custom glue for one target.
    • Relabel the labels to a constant: a relabel rule cannot add values, so the collisions stay.
    • Scrape the gateway directly with Prometheus: the TSDB keeps the first sample of each label set and drops the rest with no signal.
    • Alloy remote write 2.0: it keeps the samples of other targets only; the gateway samples still drop.
    • use_x_forwarded_for and a user agent without the release: each caller must comply, and the header can bypass the rate limit by source.

    Out of scope here (a person decides): the runbook and description of AlloyRemoteWriteSamplesFailed, and a mark on the wrong gateway history from 2026-11-15T23Z to the rollout.

  7. 1 remaining item

  8. added
    status/in-review
    and removed
    status/in-progress
    on Nov 19, 2026
  9. removed
    status/in-review
    owner/agent
    on Nov 19, 2026
  10. dan-petty commented on Nov 19, 2026

    @dan-petty
    OwnerAuthor

    Live check after the merge of #6459 (bc57c1e). Argo CD synced Application llm at 2026-11-19T22:41:49Z. The sync made a new gateway pod at 22:41:48Z, with the ConfigMap llm-gateway-config-4cfcbcbd7d. I read these values at 23:21Z, 39 minutes after the rollout. All checks are read only.

    Check Before the rollout After the rollout
    Lines with client_ip= or user_agent= on the raw /metrics/ of the gateway 1502 0
    litellm_ lines on the raw /metrics/ present 1117
    count({job="llm-gateway", __name__="litellm_deployment_total_requests_total"}) 15 (at 22:40Z) 7
    "Prometheus exclude configuration validation failed" in the gateway log, last 1 h none 0
    max(scrape_samples_scraped{job="llm-gateway"}) 2940 1133
    Alloy samples refused, increase(prometheus_remote_storage_samples_failed_total[36m]) 248,542 of 2,326,009 (10.7 %), window to 22:41Z 0 of 2,082,214
    HTTP 400 on /api/v1/write, 36 min 124 of 1,198 0 of 1,080
    Prometheus log "Out of order sample from remote write", 36 min 125 0
    Alloy log "duplicate sample", 36 min - 0
    ALERTS{alertname="AlloyRemoteWriteSamplesFailed"} firing no series

    The new gateway has fewer litellm_deployment_total_requests_total series because the counters start again at the restart. A series comes back when a model gets its first request.

    These checks need a full day after the rollout (from 2026-11-20T22:42Z):

    • The failed samples, the HTTP 400 answers and the two log queries above, each with [24h]: each must be 0.
    • The up count of step 4 of this issue gives 120 for roadmap-service and valkey-devops, and 480 for llm-gateway.
    • sum(increase(litellm_deployment_total_requests_total[1d])) / sum(increase(litellm_llm_api_latency_metric_count[1d])) comes back to the band before 2026-11-15 (about 1.0 to 1.6).
  11. devops-cli-service commented on Nov 20, 2026

    @devops-cli-service
    Contributor
  12. devops-cli-service commented on Nov 20, 2026

    @devops-cli-service
    Contributor

    Live since 2026-11-20 00:02 UTC

  13. dan-petty commented on Nov 20, 2026

    @dan-petty
    OwnerAuthor

    24-hour live check of the fix of this issue (PR #6459, merge bc57c1e). Argo CD synced Application llm at 2026-11-19T22:41:49Z. I read these values at 2026-11-20T22:47Z, so each 24 h window starts after the rollout. All reads are read only, through short port-forwards to Prometheus and Loki.

    # Check Value Expected Result
    1 Alloy samples refused, increase(prometheus_remote_storage_samples_failed_total{job="integrations/alloy"}[24h]) 0 of 82,350,668 sent 0 pass
    2 HTTP 400 on /api/v1/write, 24 h 0 of 42,717 writes 0 pass
    3 Alloy log "duplicate sample", 24 h 0 (2,292 Alloy lines in the window) 0 pass
    4 Prometheus log "Out of order sample from remote write", 24 h 0 (232 Prometheus lines in the window) 0 pass
    5 count_over_time(up[2h]) by job roadmap-service 120, valkey-devops 120, llm-gateway 479 120, 120, 480 pass
    6 litellm_deployment_total_requests_total / litellm_llm_api_latency_metric_count, 1 d 1.01 (11,061 / 10,946) about 1.0 to 1.6 pass
    7 max_over_time(max(scrape_samples_scraped{job="llm-gateway"})[24h:5m]) 1,368 below about 2,000 pass

    The alert AlloyRemoteWriteSamplesFailed has no series. The value 479 of check 5 is one sample short of 480 because the 2 h window starts between two scrapes; the 15 s scrape of llm-gateway gives 480 in a full window.

    Before the fix, Alloy lost 10.7 % of its samples and Prometheus refused about 10 % of the remote writes (see the first check of 2026-11-19). The window from 2026-11-15T23:26Z to the rollout stays wrong in the stored data (#6457).

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/p1-highscope/monitoringsource/agenttype/bugvalue/high

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions