mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-11 08:38:24 +00:00
refactor(proxy): move UNMATCHED_REQUEST_ROUTE to constants
Centralize the Prometheus unmatched-route sentinel in constants.py so metrics paths share one canonical value.
This commit is contained in:
parent
53acca8a4b
commit
f53f6d2259
4 changed files with 7 additions and 11 deletions
|
|
@ -1334,6 +1334,8 @@ LITELLM_TRUNCATION_DB_SAFEGUARD_NOTE: Final = (
|
|||
########################### LiteLLM Proxy Specific Constants ###########################
|
||||
########################################################################################
|
||||
|
||||
UNMATCHED_REQUEST_ROUTE: Final = "/unmatched"
|
||||
|
||||
# Standard headers that are always checked for customer/end-user ID (no configuration required)
|
||||
# These headers work out-of-the-box for tools like Claude Code that support custom headers
|
||||
STANDARD_CUSTOMER_ID_HEADERS: Final = [
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ from fastapi import HTTPException, Request, status
|
|||
import litellm
|
||||
from litellm import Router, provider_list
|
||||
from litellm._logging import verbose_proxy_logger
|
||||
from litellm.constants import MINIMUM_CUSTOM_KEY_LENGTH, STANDARD_CUSTOMER_ID_HEADERS
|
||||
from litellm.constants import MINIMUM_CUSTOM_KEY_LENGTH, STANDARD_CUSTOMER_ID_HEADERS, UNMATCHED_REQUEST_ROUTE
|
||||
from litellm.litellm_core_utils.safe_json_loads import safe_json_loads
|
||||
from litellm.litellm_core_utils.url_utils import (
|
||||
SSRFError,
|
||||
|
|
@ -767,8 +767,6 @@ def normalize_request_route(route: str) -> str:
|
|||
return route
|
||||
|
||||
|
||||
UNMATCHED_REQUEST_ROUTE: Final = "/unmatched"
|
||||
|
||||
# Literal proxy routes safe to emit when FastAPI's route template is unavailable
|
||||
# (e.g. auth failure on an unmatched scope). Dynamic segments must never appear
|
||||
# here — those are covered by get_request_route_template() or normalize_request_route().
|
||||
|
|
|
|||
|
|
@ -451,10 +451,8 @@ def test_route_normalization_preserves_static_routes():
|
|||
|
||||
def test_unmatched_scanner_routes_collapse_for_metrics():
|
||||
"""Unknown paths must not create unbounded Prometheus route labels."""
|
||||
from litellm.proxy.auth.auth_utils import (
|
||||
UNMATCHED_REQUEST_ROUTE,
|
||||
resolve_request_route_for_metrics,
|
||||
)
|
||||
from litellm.constants import UNMATCHED_REQUEST_ROUTE
|
||||
from litellm.proxy.auth.auth_utils import resolve_request_route_for_metrics
|
||||
|
||||
scanner_paths = [
|
||||
"/files/pRzAdaV1.php",
|
||||
|
|
|
|||
|
|
@ -2951,10 +2951,8 @@ class TestResolveRequestRouteForMetrics:
|
|||
assert resolve_request_route_for_metrics(None, route) == route
|
||||
|
||||
def test_collapses_unknown_paths_to_unmatched(self):
|
||||
from litellm.proxy.auth.auth_utils import (
|
||||
UNMATCHED_REQUEST_ROUTE,
|
||||
resolve_request_route_for_metrics,
|
||||
)
|
||||
from litellm.constants import UNMATCHED_REQUEST_ROUTE
|
||||
from litellm.proxy.auth.auth_utils import resolve_request_route_for_metrics
|
||||
|
||||
scanner_paths = [
|
||||
"/files/pRzAdaV1.php",
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue