mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-14 23:21:35 +00:00
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:
parent
24123269cc
commit
3bd18ef773
1 changed files with 2 additions and 2 deletions
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue