diff --git a/litellm/integrations/prometheus.py b/litellm/integrations/prometheus.py index 467ec72dc4a..ef512212cbf 100644 --- a/litellm/integrations/prometheus.py +++ b/litellm/integrations/prometheus.py @@ -3307,13 +3307,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, diff --git a/tests/enterprise/litellm_enterprise/enterprise_callbacks/test_prometheus_logging_callbacks.py b/tests/enterprise/litellm_enterprise/enterprise_callbacks/test_prometheus_logging_callbacks.py index 05886e4b7f6..74a9351ac34 100644 --- a/tests/enterprise/litellm_enterprise/enterprise_callbacks/test_prometheus_logging_callbacks.py +++ b/tests/enterprise/litellm_enterprise/enterprise_callbacks/test_prometheus_logging_callbacks.py @@ -1204,7 +1204,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() diff --git a/tests/test_litellm/integrations/test_prometheus_custom_metadata_label_counts.py b/tests/test_litellm/integrations/test_prometheus_custom_metadata_label_counts.py index 99eb5abb7b5..19d2e2ba4be 100644 --- a/tests/test_litellm/integrations/test_prometheus_custom_metadata_label_counts.py +++ b/tests/test_litellm/integrations/test_prometheus_custom_metadata_label_counts.py @@ -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 + )