diff --git a/litellm/integrations/prometheus.py b/litellm/integrations/prometheus.py index fa4e6f10695..a08388b4ca1 100644 --- a/litellm/integrations/prometheus.py +++ b/litellm/integrations/prometheus.py @@ -683,7 +683,9 @@ class PrometheusLogger(CustomLogger): # A wildcard group only sets a default label filter - it should # never narrow down which metrics get created. Only groups that # name real metrics feed into enabled_metrics, same as before. - if parsed_config.metrics != [PROMETHEUS_METRICS_WILDCARD]: + if parsed_config.metrics != [ + PROMETHEUS_METRICS_WILDCARD + ]: # mutable-ok: single-item literal used only for equality comparison, never mutated self.enabled_metrics.update(parsed_config.metrics) # Validate all configurations @@ -720,12 +722,14 @@ class PrometheusLogger(CustomLogger): ) if config.include_labels: - all_valid_labels = { + all_valid_labels = { # mutable-ok: local set built once per validation call, not mutated after construction label for metric_name in get_args(DEFINED_PROMETHEUS_METRICS) for label in PrometheusMetricLabels.get_labels(metric_name) } - unknown_labels = [label for label in config.include_labels if label not in all_valid_labels] + unknown_labels = [ + label for label in config.include_labels if label not in all_valid_labels + ] # mutable-ok: local list built once, not mutated after construction if unknown_labels: label_errors.append( LabelValidationError( @@ -782,10 +786,16 @@ class PrometheusLogger(CustomLogger): """Build label filters from validated configurations""" from typing import get_args - label_filters: dict[str, list[str]] = {} + label_filters: dict[ + str, list[str] + ] = {} # mutable-ok: accumulator dict returned to the caller, required by the existing return type - wildcard_configs = [c for c in parsed_configs if c.metrics == [PROMETHEUS_METRICS_WILDCARD]] - named_configs = [c for c in parsed_configs if c.metrics != [PROMETHEUS_METRICS_WILDCARD]] + wildcard_configs = [ + c for c in parsed_configs if c.metrics == [PROMETHEUS_METRICS_WILDCARD] + ] # mutable-ok: accumulator dict returned to the caller, required by the existing return type + named_configs = [ + c for c in parsed_configs if c.metrics != [PROMETHEUS_METRICS_WILDCARD] + ] # mutable-ok: accumulator dict returned to the caller, required by the existing return type for config in wildcard_configs: if not config.include_labels: diff --git a/litellm/types/integrations/prometheus.py b/litellm/types/integrations/prometheus.py index d36cbfe347b..760294b0f62 100644 --- a/litellm/types/integrations/prometheus.py +++ b/litellm/types/integrations/prometheus.py @@ -789,7 +789,9 @@ class PrometheusMetricLabels: # Default to no labels instead of raising, so anything that legitimately # iterates over every defined metric name (e.g. a wildcard config group) # doesn't blow up on a metric like this. - default_labels = getattr(PrometheusMetricLabels, label_name, []) + default_labels = getattr( + PrometheusMetricLabels, label_name, [] + ) # mutable-ok: empty-list default for getattr fallback, never mutated custom_labels = [] # Add custom metadata labels