This commit is contained in:
DanielVASE 2026-09-23 14:48:19 +00:00 • committed by GitHub
commit 32a6816181
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 42 additions and 8 deletions

View file

@ -3531,13 +3531,17 @@ class PrometheusLogger(CustomLogger):
"""
increment metric when litellm.Router / load balancing logic places a deployment in cool down
"""
self.litellm_deployment_cooled_down.labels(
_sanitize_prometheus_label_value(litellm_model_name),
_sanitize_prometheus_label_value(model_id),
_sanitize_prometheus_label_value(api_base),
_sanitize_prometheus_label_value(api_provider),
_sanitize_prometheus_label_value(exception_status),
).inc()
_labels: Final = prometheus_label_factory(
supported_enum_labels=self.get_labels_for_metric(metric_name="litellm_deployment_cooled_down"),
enum_values=UserAPIKeyLabelValues(
litellm_model_name=litellm_model_name,
model_id=model_id,
api_base=api_base,
api_provider=api_provider,
exception_status=exception_status,
),
)
self.litellm_deployment_cooled_down.labels(**_labels).inc()
def increment_callback_logging_failure(
self,

View file

@ -1222,7 +1222,11 @@ def test_increment_deployment_cooled_down(prometheus_logger):
)
prometheus_logger.litellm_deployment_cooled_down.labels.assert_called_once_with(
"gpt-5-mini", "model-123", "https://api.openai.com", "openai", "429"
litellm_model_name="gpt-5-mini",
model_id="model-123",
api_base="https://api.openai.com",
api_provider="openai",
exception_status="429",
)
mock_chain.inc.assert_called_once()

View file

@ -157,3 +157,29 @@ def test_virtual_key_rate_limit_metrics_preserve_zero_remaining_values(
assert any(sample.value == 0 for sample in token_samples)
assert not any(sample.value == sys.maxsize for sample in request_samples)
assert not any(sample.value == sys.maxsize for sample in token_samples)
def test_increment_deployment_cooled_down_accepts_custom_metadata_labels(
monkeypatch: pytest.MonkeyPatch, caplog: pytest.LogCaptureFixture
):
prometheus_logger = _create_prometheus_logger_with_custom_labels(monkeypatch)
with caplog.at_level(logging.ERROR):
prometheus_logger.increment_deployment_cooled_down(
litellm_model_name="gpt-4o-mini",
model_id="model-123",
api_base="https://api.openai.com",
api_provider="openai",
exception_status="429",
)
assert "Incorrect label count" not in caplog.text
samples = _metric_samples("litellm_deployment_cooled_down_total")
assert any(
sample.labels.get("litellm_model_name") == "gpt-4o-mini"
and sample.labels.get("exception_status") == "429"
and "metadata_department" in sample.labels
and "metadata_environment" in sample.labels
and sample.value == 1
for sample in samples
)