Skip to content

fix(monitoring): drop per-pod labels from gateway spend series #4545

Closed

Description

@dan-petty

Problem or Motivation

The LiteLLM gateway series carry the labels client_ip and user_agent. client_ip changes with each pod address of a caller. When the roadmap jobs move into short pods (stage first), each unit pod adds a new address, about 1,100 a day at the end of the move. Each short pod already adds about 76 metric series, and the plan estimates about 84,000 new series a day against a head of 44,349 before a series budget.

No panel, alert or test reads client_ip or user_agent today.

Proposed Solution & Architectural Design

In k8s/llm/gateway/servicemonitor.yaml, add metricRelabelings with action: labeldrop for client_ip and user_agent.

Target Subsystem

Kubernetes & Minikube Automation (k8s/llm/gateway/, monitoring).

Existing Tool Considered

Prometheus Operator metricRelabelings (configuration of an open tool, no build). Cost: about 50,000 tokens and 1 hour; about 1,000 tokens a month to keep.

Acceptance Criteria

  • count by (__name__) ({__name__=~"litellm_.*", client_ip!=""}) returns nothing after one scrape.
  • The panels of ai-spend.json show the same totals as before.
  • The manifest test of the gateway ServiceMonitor passes.

Dependencies

None. Merge it before "feat(roadmap): run each stage item in its own Job" and before "feat(ai): label gateway spend by repository".

Source: #4517

Proposed design

Problem statement

The LiteLLM gateway series carry the labels client_ip and user_agent. Each caller pod address adds a new client_ip value, and the move of the roadmap jobs into short pods adds about 1,100 addresses and about 84,000 series a day. No panel, alert rule or test reads the two labels: the dashboard queries group by status_code, end_user, model_id and api_base, and the alert rules name neither. The change drops the two labels at scrape time and keeps the spend totals.

Acceptance criteria

Requirement: Gateway endpoint drops the caller labels

The http endpoint of the gateway ServiceMonitor SHALL carry one metricRelabelings entry with action: labeldrop for each of client_ip and user_agent, and SHALL keep its port, path and interval.

Scenario: The endpoint holds one labeldrop rule for each label

  • WHEN a check reads k8s/llm/gateway/servicemonitor.yaml and collects the regex of every metricRelabelings entry with action: labeldrop on the http endpoint
  • THEN the collected values are exactly client_ip and user_agent, and the endpoint still names port http, path /metrics/ and interval 15s

Requirement: Spend and stack queries avoid the dropped labels

Every query of k8s/monitoring/dashboards/ai-spend.json and k8s/monitoring/dashboards/llm-stack.json that reads a litellm_ series MUST NOT group by or filter on client_ip or user_agent.

Scenario: No gateway query groups or filters by the dropped labels

  • WHEN a check reads every target expression of both dashboards and lists the label names in its by clauses and its label matchers
  • THEN no listed name is client_ip or user_agent

Requirement: Alert rules ignore the dropped labels

Every alert rule expression in k8s/monitoring/prometheus-values.yaml MUST NOT select or group by client_ip or user_agent.

Scenario: No alert expression holds the two names

  • WHEN a check reads serverFiles.alerting_rules.yml from k8s/monitoring/prometheus-values.yaml and collects every expr
  • THEN no expression holds client_ip or user_agent

Requirement: The manifest check runs in the k8s gate row

The new ServiceMonitor check MUST run in the k8s row of devops ci, which the Static Analysis check runs in CI.

Scenario: The k8s row collects the new check

  • WHEN the k8s row runs the check_* functions under tests/gate/k8s_checks/
  • THEN the gateway ServiceMonitor label check reports a pass

Existing Tool Considered

No alternatives check has run on this issue. The Prometheus Operator covers the need: its spec.endpoints[].metricRelabelings with action: labeldrop removes client_ip and user_agent at scrape time, so the project builds no code for the drop and keeps only the manifest lines and the gate check. The tool lacks two things: it drops the labels only from the series that Prometheus stores, so the gateway still sends them in every scrape and the scrape payload stays as large; and the drop applies to every series of the endpoint, so a later item that needs caller identity must add a bounded label instead.

Key questions

  • Which mechanism drops the two labels from the stored series?: Add metricRelabelings with action: labeldrop to the http endpoint of the gateway ServiceMonitor. The operator applies it after the scrape and before ingestion, and the gateway scrape config already lives in this file (k8s/llm/kustomization.yaml:12). (best practice) [sources: k8s/llm/gateway/servicemonitor.yaml, k8s/llm/kustomization.yaml:12, tests/fixtures/charts/qdrant/values.yaml:219]
    • Chosen: ServiceMonitor metricRelabelings. The operator applies it after the scrape and before ingestion, and the gateway scrape config already lives in this file.
    • Rejected: Prometheus additionalScrapeConfigs. It moves the gateway scrape config out of k8s/llm/gateway/ and breaks the kustomization that owns it.
    • Rejected: LiteLLM exporter settings. LiteLLM has no setting that drops one Prometheus label, so this needs a fork or custom code.
    • Rejected: Endpoint relabelings. It relabels the target before the scrape and cannot remove a metric label.
  • Does one labeldrop rule hold both names, or one rule each?: Use one labeldrop rule for each label name. (best practice) [sources: k8s/llm/gateway/servicemonitor.yaml]
    • Chosen: One rule for each label name. Each rule names one label, so a reader and a check find the name without a regex.
    • Rejected: One rule with regex: client_ip|user_agent. The check must parse a regex, and each name is less visible in the manifest.
  • Which metric labels grow with each pod address?: client_ip holds one value for each caller address, and user_agent holds one value for each client release. litellm_deployment_*, litellm_proxy_total_requests_metric_*, litellm_requests_metric_* and litellm_spend_metric_* carry both labels. [sources: tests/fixtures/metrics/litellm.yaml:43, tests/fixtures/metrics/litellm.yaml:86, tests/fixtures/metrics/litellm.yaml:103, openspec/changes/archive/2026-10-29-1668-gateway-traffic-dashboard/proposal.md:55]
  • Does any panel, alert rule or test read client_ip or user_agent?: No. The queries of ai-spend.json group by status_code, end_user and filter on route, status_code and provider; the llm-stack.json gateway query groups by model_id and api_base; the alert rules of k8s/monitoring/prometheus-values.yaml name neither label. The only test-side mentions are the metric capture fixture, which lists them as labels the gateway's endpoint serves, and metadata.user_agent in the Collector check, which is an OpenTelemetry span attribute and not a metric label. [sources: k8s/monitoring/dashboards/ai-spend.json:1016, k8s/monitoring/dashboards/ai-spend.json:1081, k8s/monitoring/dashboards/llm-stack.json:127, k8s/monitoring/prometheus-values.yaml:436, tests/fixtures/metrics/litellm.yaml:43, tests/gate/k8s_checks/otel_collector.py:55]
  • Does the metric capture fixture change when the endpoint drops the labels?: No. The fixture records the families and label names that the gateway's /metrics/ endpoint serves, captured through the Kubernetes API service proxy before the ServiceMonitor relabels the samples, so metricRelabelings does not change it. [sources: tests/fixtures/metrics/litellm.yaml:1, tests/fixtures/metrics/litellm.yaml:12, tests/fixtures/metrics/litellm.yaml:15]
  • Where does the offline check of the manifest live?: Add the check to tests/gate/k8s_checks/llm_gateway.py, which already reads k8s/llm/gateway and holds the gateway's manifest checks. The k8s row runs every check_* function of the directory. (best practice) [sources: tests/gate/k8s_checks/llm_gateway.py:17, tests/gate/k8s.py:3, docs/TESTING.md:72, .github/workflows/ci.yml:76]
    • Chosen: Extend tests/gate/k8s_checks/llm_gateway.py. The module already owns the gateway's manifest checks and reads k8s/llm/gateway, so the ServiceMonitor check sits beside the checks of the same directory.
    • Rejected: A new file under tests/gate/k8s_checks/. It splits the gateway's checks across two modules and adds a file for one assertion.
  • How does a person confirm the drop on the live cluster?: After the merge, run count by (__name__) ({__name__=~"litellm_.*", client_ip!=""}) in the cluster. It returns nothing after one scrape of 15 seconds. This is a post-merge check, not an acceptance criterion, because no offline test reaches the cluster. (best practice) [sources: k8s/llm/gateway/servicemonitor.yaml]
    • Chosen: A post-merge cluster query. The query needs a live Prometheus, and the offline check reads the manifest instead.
    • Rejected: An acceptance criterion that runs the query. No offline test can reach the cluster, so the criterion cannot pass in CI.

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Alternatives check of 2026-11-12: in-use.
The item already names this tool.
Tool: prometheus-operator/prometheus-operator (https://github.com/prometheus-operator/prometheus-operator), Apache-2.0, last activity 2026-11-12, maintained.

Activity

  1. added
    source/agent
    on Nov 11, 2026
  2. added
    type/bug
    scope/monitoring
    status/new
    value/high
    effort/low
    on Nov 11, 2026
  3. dan-petty commented on Nov 11, 2026

    @dan-petty
    OwnerAuthor

    Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones.

    • Type: type/bug. The fix prefix of the title gives the type.
    • Scope: scope/monitoring. The (monitoring) scope of the title gives the scope.
    • Priority: P2-Medium. A known series budget will be exceeded in days, but nothing is broken today.
    • Value: High. Prevents series budget exhaustion that would break all gateway monitoring.
    • Effort: Low. Adding two labeldrop entries to an existing ServiceMonitor YAML file.
    • Related: fix(telemetry): Service counters read true across pods and repos #3495, which asks for a different change. Both address pod-level labels causing metric problems, but #3495 fixes counter aggregation logic while this candidate drops labels at scrape time.
  4. added
    priority/p2-medium
    on Nov 11, 2026
  5. added
    status/ready
    and removed
    status/new
    on Nov 11, 2026
  6. devops-cli-service commented on Nov 11, 2026

    @devops-cli-service
    Contributor

    Status set to Ready at 5f75d25 (see proposed design in issue body).

  7. devops-cli-service commented on Nov 12, 2026

    @devops-cli-service
    Contributor

    Alternatives check: in-use

    Reason: The issue itself already names the mechanism it needs: Prometheus Operator spec.endpoints[].metricRelabelings with action: labeldrop, which drops client_ip and user_agent from the stored series at scrape time, so only manifest lines plus a gate check are needed and no code is built. The searches returned nothing better (the search index returned unrelated pages), and the repository facts show the operator is an open, maintained Apache-2.0 project that the project already deploys for its ServiceMonitors, so this is configuration of a tool in use rather than a new tool.

    The item already names this tool.

    Tool: prometheus-operator/prometheus-operator (https://github.com/prometheus-operator/prometheus-operator)

    • License: Apache-2.0
    • Last activity: 2026-11-12
    • Maintained: yes

    Covers:

    • metricRelabelings on a ServiceMonitor endpoint drops named labels after the scrape and before ingestion
    • one labeldrop rule per label name (client_ip, user_agent) removes them from every series of the endpoint
    • the endpoint keeps its port, path and interval; no code or exporter change is needed
    • dashboards and alert rules that never read the two labels keep the same spend totals

    Lacks:

    • the gateway still sends client_ip and user_agent in each scrape, so the scrape payload stays as large
    • the drop applies to all series of the endpoint, so a later item that needs caller identity must add a bounded label instead
    • it cannot be verified offline: the acceptance query count by (__name__) ({__name__=~"litellm_.*", client_ip!=""}) needs a live Prometheus after merge

    Tools considered:

    Searches run:

    • Prometheus Operator ServiceMonitor metricRelabelings labeldrop drop labels, results: 5
    • prometheus-operator api.md metricRelabelings Endpoint RelabelConfig labeldrop, results: 5
    • ServiceMonitor spec endpoints metricRelabelings documentation Prometheus Operator CRD, results: 5
    • github prometheus-operator ServiceMonitor example metricRelabelings action labeldrop regex, results: 5
    • prometheus drop metric label at scrape time labeldrop metric_relabel_configs, results: 5

    Sources:

    Checked on 2026-11-12. A person decides what this means for the item. The check changes no label and closes no issue.

  8. added
    status/in-progress
    status/in-review
    and removed
    status/ready
    status/in-progress
    on Nov 15, 2026
  9. removed
    status/in-review
    on Nov 15, 2026
  10. devops-cli-service commented on Nov 15, 2026

    @devops-cli-service
    Contributor

    Live since 2026-11-15 23:51 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/lowpriority/p2-mediumscope/monitoringsource/agenttype/bugvalue/high

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions