feat(prometheus): support wildcard metric name in prometheus_metrics_…#34622
Conversation
…config for default label filtering
Greptile SummaryThis PR adds wildcard label-filter defaults for Prometheus metrics.
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains; the wildcard is handled before ordinary metric-name validation, and the tests now restore the process-global Prometheus configuration.
|
| Filename | Overview |
|---|---|
| litellm/integrations/prometheus.py | Implements wildcard validation and label-filter expansion while preserving independent metric enablement; the previously reported initialization issue is fixed. |
| litellm/types/integrations/prometheus.py | Defines the wildcard constant, documents its configuration semantics, and safely handles the existing label-less in-flight metric. |
| tests/test_litellm/integrations/test_prometheus_wildcard_labels.py | Covers wildcard defaults, named overrides, enablement behavior, invalid configurations, and restores modified global configuration through monkeypatch. |
Reviews (2): Last reviewed commit: "fix: apply wildcard label-filter logic t..." | Re-trigger Greptile
| append(ch) | ||
| return "".join(parts) | ||
|
|
||
| PROMETHEUS_METRICS_WILDCARD = "*" |
There was a problem hiding this comment.
Wildcard rejected during initialization
When prometheus_metrics_config contains metrics: ["*"], PrometheusLogger.__init__ passes the wildcard through the existing metric-name validator, which rejects it because it is not in DEFINED_PROMETHEUS_METRICS and raises ValueError. The production parser also lacks the wildcard expansion and enablement handling asserted by these tests, so the advertised configuration cannot apply default labels.
Knowledge Base Used: Logging & Observability Integrations
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
TLDR
Problem this solves:
How it solves it:
Relevant issues
Fixes #30532
Linear ticket
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
@greptileaito re-request a review after pushing changes)Delays in PR merge?
If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).
Screenshots / Proof of Fix
I set
prometheus_metrics_configto a single wildcard group (metrics: ["*"],include_labels: ["hashed_api_key", "team"]), ran the proxy locally, and sent a request through it.Before (commit
2bfd50ed37):/metricsshows no series at all forlitellm_proxy_failed_requests_metric,litellm_proxy_total_requests_metric,litellm_deployment_failure_responses,litellm_deployment_total_requests, orlitellm_llm_api_failed_requests_metric- just theHELP/TYPElines, no data.After (commit
4c1166405e), same request:litellm_proxy_failed_requests_metric_total{hashed_api_key="None",team="None"} 2.0
litellm_proxy_total_requests_metric_total{hashed_api_key="None",team="None"} 2.0
litellm_deployment_failure_responses_total{hashed_api_key="None",team="None"} 1.0
litellm_deployment_total_requests_total{hashed_api_key="None",team="None"} 1.0
litellm_llm_api_failed_requests_metric_total{hashed_api_key="None",team="None"} 2.0
Each of these normally carries 13-14 default labels and they're all different sets between metrics. With the wildcard config, every one collapsed to just the two I configured - proof the filter applies uniformly across metrics that don't share a label schema, not just the one I originally tested against.
Type
🆕 New Feature
Changes
prometheus_metrics_configgroups can now setmetrics: ["*"]to applyinclude_labelsas the default label set for every metric, instead of listing all ~70 by hand. It only sets defaults - it never disables a metric, that's still controlled separately by naming real metrics in another group. A group naming a specific metric still wins over the wildcard for that one metric, so I can set a broad default and carve out exceptions. A group can't mix the wildcard with named metrics; I raise a clear error if it tries.While building this I found
litellm_in_flight_requestsis listed inDEFINED_PROMETHEUS_METRICSbut was missing a matching entry inPrometheusMetricLabels. Nothing caught it before because no existing code path iterated over every defined metric name at once - the wildcard is the first thing that does. I fixedget_labels()to default to an empty label list instead of raising, so this metric (and any other one like it) doesn't break when a wildcard group touches it.Added
tests/test_litellm/integrations/test_prometheus_wildcard_labels.pycovering: wildcard applying defaults across every metric, a named group overriding the wildcard, the wildcard never disabling a metric it doesn't name, wildcard + a separate enabled-metrics group working together, the mixed-wildcard-and-named-metric error, and an unknown label under the wildcard getting reported instead of silently dropped.Final Attestation