mirror of
https://github.com/tiennm99/litellm.git
synced 2026-07-09 15:09:20 +00:00
style: apply Black formatting to Prometheus integration modules
Reformat prometheus logger, types, and metrics auth middleware so lint CI (black --check) passes. Made-with: Cursor
This commit is contained in:
@@ -88,7 +88,9 @@ class PrometheusLogger(CustomLogger):
|
||||
|
||||
_custom_buckets = litellm.prometheus_latency_buckets
|
||||
self.latency_buckets = (
|
||||
tuple(_custom_buckets) if _custom_buckets is not None else LATENCY_BUCKETS
|
||||
tuple(_custom_buckets)
|
||||
if _custom_buckets is not None
|
||||
else LATENCY_BUCKETS
|
||||
)
|
||||
|
||||
# Create metric factory functions
|
||||
@@ -1097,9 +1099,11 @@ class PrometheusLogger(CustomLogger):
|
||||
),
|
||||
client_ip=standard_logging_payload["metadata"].get("requester_ip_address"),
|
||||
user_agent=standard_logging_payload["metadata"].get("user_agent"),
|
||||
stream=str(standard_logging_payload.get("stream"))
|
||||
if litellm.prometheus_emit_stream_label
|
||||
else None,
|
||||
stream=(
|
||||
str(standard_logging_payload.get("stream"))
|
||||
if litellm.prometheus_emit_stream_label
|
||||
else None
|
||||
),
|
||||
)
|
||||
|
||||
if (
|
||||
@@ -1767,9 +1771,11 @@ class PrometheusLogger(CustomLogger):
|
||||
client_ip=_metadata.get("requester_ip_address"),
|
||||
user_agent=_metadata.get("user_agent"),
|
||||
model_id=model_id,
|
||||
stream=str(request_data.get("stream"))
|
||||
if litellm.prometheus_emit_stream_label
|
||||
else None,
|
||||
stream=(
|
||||
str(request_data.get("stream"))
|
||||
if litellm.prometheus_emit_stream_label
|
||||
else None
|
||||
),
|
||||
)
|
||||
_labels = prometheus_label_factory(
|
||||
supported_enum_labels=self.get_labels_for_metric(
|
||||
@@ -2093,9 +2099,9 @@ class PrometheusLogger(CustomLogger):
|
||||
):
|
||||
try:
|
||||
verbose_logger.debug("setting remaining tokens requests metric")
|
||||
standard_logging_payload: Optional[
|
||||
StandardLoggingPayload
|
||||
] = request_kwargs.get("standard_logging_object")
|
||||
standard_logging_payload: Optional[StandardLoggingPayload] = (
|
||||
request_kwargs.get("standard_logging_object")
|
||||
)
|
||||
|
||||
if standard_logging_payload is None:
|
||||
return
|
||||
@@ -2728,9 +2734,7 @@ class PrometheusLogger(CustomLogger):
|
||||
)
|
||||
return
|
||||
|
||||
async def fetch_keys(
|
||||
page_size: int, page: int
|
||||
) -> Tuple[
|
||||
async def fetch_keys(page_size: int, page: int) -> Tuple[
|
||||
List[Union[str, UserAPIKeyAuth, LiteLLM_DeletedVerificationToken]],
|
||||
Optional[int],
|
||||
]:
|
||||
@@ -2921,9 +2925,11 @@ class PrometheusLogger(CustomLogger):
|
||||
org_alias=org.organization_alias or "",
|
||||
spend=org.spend or 0.0,
|
||||
max_budget=budget_table.max_budget if budget_table else None,
|
||||
budget_reset_at=getattr(budget_table, "budget_reset_at", None)
|
||||
if budget_table
|
||||
else None,
|
||||
budget_reset_at=(
|
||||
getattr(budget_table, "budget_reset_at", None)
|
||||
if budget_table
|
||||
else None
|
||||
),
|
||||
)
|
||||
|
||||
async def _set_team_budget_metrics_after_api_request(
|
||||
@@ -3405,10 +3411,10 @@ class PrometheusLogger(CustomLogger):
|
||||
from litellm.constants import PROMETHEUS_BUDGET_METRICS_REFRESH_INTERVAL_MINUTES
|
||||
from litellm.integrations.custom_logger import CustomLogger
|
||||
|
||||
prometheus_loggers: List[
|
||||
CustomLogger
|
||||
] = litellm.logging_callback_manager.get_custom_loggers_for_type(
|
||||
callback_type=PrometheusLogger
|
||||
prometheus_loggers: List[CustomLogger] = (
|
||||
litellm.logging_callback_manager.get_custom_loggers_for_type(
|
||||
callback_type=PrometheusLogger
|
||||
)
|
||||
)
|
||||
# we need to get the initialized prometheus logger instance(s) and call logger.initialize_remaining_budget_metrics() on them
|
||||
verbose_logger.debug("found %s prometheus loggers", len(prometheus_loggers))
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
"""
|
||||
Prometheus Auth Middleware - Pure ASGI implementation
|
||||
"""
|
||||
|
||||
import json
|
||||
from typing import Any, List, MutableMapping
|
||||
|
||||
|
||||
@@ -676,9 +676,9 @@ class PrometheusMetricLabels:
|
||||
|
||||
litellm_managed_batch_created_total = _batch_user_labels
|
||||
|
||||
litellm_managed_file_size_bytes: List[
|
||||
str
|
||||
] = [] # labels: purpose, file_type, model, api_provider, user (custom)
|
||||
litellm_managed_file_size_bytes: List[str] = (
|
||||
[]
|
||||
) # labels: purpose, file_type, model, api_provider, user (custom)
|
||||
|
||||
litellm_managed_batch_duration_seconds = [
|
||||
UserAPIKeyLabelNames.v1_LITELLM_MODEL_NAME.value,
|
||||
@@ -687,9 +687,9 @@ class PrometheusMetricLabels:
|
||||
|
||||
litellm_managed_file_created_total = _batch_user_labels
|
||||
|
||||
litellm_managed_file_deleted_total: List[
|
||||
str
|
||||
] = [] # only "result" label, added at metric creation
|
||||
litellm_managed_file_deleted_total: List[str] = (
|
||||
[]
|
||||
) # only "result" label, added at metric creation
|
||||
|
||||
litellm_check_batch_cost_jobs_polled: List[str] = []
|
||||
|
||||
|
||||
Reference in New Issue
Block a user