fix(prometheus): rate-limit gauges drop the emit when value is 0

The remaining_requests and remaining_tokens gauges are guarded by a
truthy check:

    if remaining_requests:
        ...emit metric

When the value is 0 (the upstream has actually exhausted the user's
quota), Python evaluates 0 as falsy and the metric is never emitted.
This is exactly the moment the metric is most useful for alerting.

The rest of this file already uses the correct `is not None` pattern
for similar nullable values (lines 1688, 1710, 1856, 1868, 1901, etc.),
and even for these exact variables in the *non*-init path at lines 2419
and 2431. The two checks at 2519 and 2537 are the holdouts.

Changed truthy to `is not None`. No behavior change when the upstream
header is genuinely absent (still skipped); only difference is that 0
now flows through to the gauge.
This commit is contained in:
Bungic 2026-05-28 18:40:11 +03:00
parent 24123269cc
commit 3bd18ef773

View file

@ -2691,7 +2691,7 @@ class PrometheusLogger(CustomLogger):
label_context=label_context,
)
if remaining_requests:
if remaining_requests is not None:
"""
"model_group",
"api_provider",
@ -2705,7 +2705,7 @@ class PrometheusLogger(CustomLogger):
)
self.litellm_remaining_requests_metric.labels(**_labels).set(remaining_requests)
if remaining_tokens:
if remaining_tokens is not None:
_labels = prometheus_label_factory(
supported_enum_labels=self.get_labels_for_metric(metric_name="litellm_remaining_tokens_metric"),
enum_values=enum_values,