refactor: remove AuthMetrics and related combined_view query metrics

This commit deletes the AuthMetrics class and its associated methods, which were responsible for tracking combined_view SQL query metrics. The PrometheusLogger integration has been updated to remove references to these metrics, streamlining the codebase. Additionally, minor whitespace adjustments were made in the cache coordinator for consistency.
This commit is contained in:
harish-berri 2026-04-30 22:13:11 +00:00
parent 1f72ae5442
commit 76fb9d3c96
5 changed files with 1 additions and 83 deletions

View file

@ -266,19 +266,6 @@ class PrometheusLogger(CustomLogger):
# LiteLLM Virtual API KEY metrics
########################################
# Auth DB load diagnostic: count direct combined_view SQL queries.
# Each increment means a virtual-key cache miss that hit the DB.
# Useful for validating that enable_redis_auth_cache is working.
self.litellm_auth_combined_view_queries_total = self._counter_factory(
"litellm_auth_combined_view_queries_total",
"Number of times the combined_view SQL query was issued for virtual-key auth. "
"Each count is a cache miss that hit the database. Use to validate "
"enable_redis_auth_cache is reducing DB load.",
labelnames=self.get_labels_for_metric(
"litellm_auth_combined_view_queries_total"
),
)
# Remaining MODEL RPM limit for API Key
self.litellm_remaining_api_key_requests_for_model = self._gauge_factory(
"litellm_remaining_api_key_requests_for_model",

View file

@ -59,7 +59,6 @@ from litellm.proxy._types import (
SpecialModelNames,
UserAPIKeyAuth,
)
from litellm.proxy.auth.auth_metrics import AuthMetrics
from litellm.proxy.auth.route_checks import RouteChecks
from litellm.proxy.db.exception_handler import PrismaDBExceptionHandler
from litellm.proxy.guardrails.tool_name_extraction import (
@ -2262,7 +2261,6 @@ async def _fetch_key_object_from_db_with_reconnect(
Fetch key object from DB and retry once if a DB connection error can be healed.
"""
try:
AuthMetrics.inc_combined_view_query(hashed_token)
return await prisma_client.get_data(
token=hashed_token,
table_name="combined_view",

View file

@ -1,60 +0,0 @@
"""
Prometheus metric helpers for the auth layer.
All metrics are thin wrappers around the shared ``PrometheusLogger`` instance so
that every counter follows the same registration path (``_counter_factory``,
label-filter config) as the rest of LiteLLM's metrics.
Usage::
from litellm.proxy.auth.auth_metrics import AuthMetrics
AuthMetrics.inc_combined_view_query(hashed_token="sk-xxx")
"""
from litellm._logging import verbose_proxy_logger
from litellm.types.integrations.prometheus import UserAPIKeyLabelValues
class AuthMetrics:
"""Static helpers for incrementing auth-layer Prometheus counters."""
@staticmethod
def _get_prom():
"""Return the active PrometheusLogger, or None if Prometheus is not configured."""
try:
from litellm.router_utils.cooldown_callbacks import (
_get_prometheus_logger_from_callbacks,
)
return _get_prometheus_logger_from_callbacks()
except Exception:
return None
@staticmethod
def inc_combined_view_query(hashed_token: str) -> None:
"""
Increment ``litellm_auth_combined_view_queries_total``.
Called once per virtual-key DB lookup (combined_view query). Each
increment represents a cache miss that hit the database — use this to
validate that ``enable_redis_auth_cache`` is reducing DB load.
"""
try:
prom = AuthMetrics._get_prom()
if prom is not None:
# Counter labelnames include ``hashed_api_key`` plus any
# ``custom_prometheus_metadata_labels`` / ``custom_prometheus_tags``
# (see ``PrometheusMetricLabels.get_labels``). Use the same
# ``_inc_labeled_counter`` + ``prometheus_label_factory`` path as
# other metrics so label cardinality always matches registration.
prom._inc_labeled_counter(
prom.litellm_auth_combined_view_queries_total,
"litellm_auth_combined_view_queries_total",
UserAPIKeyLabelValues(hashed_api_key=hashed_token),
)
except Exception as e:
verbose_proxy_logger.debug(
"AuthMetrics.inc_combined_view_query: failed to increment counter: %s",
e,
)

View file

@ -153,7 +153,7 @@ class EventDrivenCacheCoordinator:
elapsed_ms,
value,
)
await cache.async_set_cache(key=cache_key, value=value)
if self._log_prefix:
verbose_proxy_logger.debug("%s Result cached", self._log_prefix)

View file

@ -228,8 +228,6 @@ DEFINED_PROMETHEUS_METRICS = Literal[
"litellm_guardrail_latency_seconds",
"litellm_guardrail_errors_total",
"litellm_guardrail_requests_total",
# Auth DB diagnostic metrics
"litellm_auth_combined_view_queries_total",
# Cache metrics
"litellm_cache_hits_metric",
"litellm_cache_misses_metric",
@ -309,11 +307,6 @@ class PrometheusMetricLabels:
litellm_guardrail_errors_total: List[str] = []
litellm_guardrail_requests_total: List[str] = []
# Auth DB diagnostic - label by key so you can see which virtual key causes DB hits
litellm_auth_combined_view_queries_total = [
UserAPIKeyLabelNames.API_KEY_HASH.value,
]
litellm_proxy_total_requests_metric = [
UserAPIKeyLabelNames.END_USER.value,
UserAPIKeyLabelNames.API_KEY_HASH.value,