mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-27 03:34:10 +00:00
(UI + Proxy) Cache Health Check Page - Cleanup/Improvements (#8665)
All checks were successful
Read Version from pyproject.toml / read-version (push) Successful in 14s
All checks were successful
Read Version from pyproject.toml / read-version (push) Successful in 14s
* fixes for redis cache ping serialization * fix cache ping check * fix cache health check ui * working error details on ui * ui expand / collapse error * move cache health check to diff file * fix displaying error from cache health check * ui allow copying errors * ui cache health fixes * show redis details * clean up cache health page * ui polish fixes * fix error handling on cache health page * fix redis_cache_params on cache ping response * error handling * cache health ping response * fx error response from cache ping * parsedLitellmParams * fix cache health check * fix cache health page * cache safely handle json dumps issues * test caching routes * test_primitive_types * fix caching routes * litellm_mapped_tests * fix pytest-mock * fix _serialize * fix linting on safe dumps * test_default_max_depth * pip install "pytest-mock==3.12.0" * litellm_mapped_tests_coverage * add readme on new litellm test dir
This commit is contained in:
parent
39db3147e8
commit
fff15543d9
16 changed files with 807 additions and 58 deletions
|
@ -5,8 +5,11 @@ from fastapi import APIRouter, Depends, HTTPException, Request
|
|||
import litellm
|
||||
from litellm._logging import verbose_proxy_logger
|
||||
from litellm.caching.caching import RedisCache
|
||||
from litellm.litellm_core_utils.safe_json_dumps import safe_dumps
|
||||
from litellm.litellm_core_utils.sensitive_data_masker import SensitiveDataMasker
|
||||
from litellm.proxy._types import ProxyErrorTypes, ProxyException
|
||||
from litellm.proxy.auth.user_api_key_auth import user_api_key_auth
|
||||
from litellm.types.caching import CachePingResponse
|
||||
|
||||
masker = SensitiveDataMasker()
|
||||
|
||||
|
@ -18,6 +21,7 @@ router = APIRouter(
|
|||
|
||||
@router.get(
|
||||
"/ping",
|
||||
response_model=CachePingResponse,
|
||||
dependencies=[Depends(user_api_key_auth)],
|
||||
)
|
||||
async def cache_ping():
|
||||
|
@ -27,27 +31,17 @@ async def cache_ping():
|
|||
litellm_cache_params: Dict[str, Any] = {}
|
||||
specific_cache_params: Dict[str, Any] = {}
|
||||
try:
|
||||
|
||||
if litellm.cache is None:
|
||||
raise HTTPException(
|
||||
status_code=503, detail="Cache not initialized. litellm.cache is None"
|
||||
)
|
||||
litellm_cache_params = {}
|
||||
specific_cache_params = {}
|
||||
for k, v in vars(litellm.cache).items():
|
||||
try:
|
||||
if k == "cache":
|
||||
continue
|
||||
litellm_cache_params[k] = v
|
||||
except Exception:
|
||||
litellm_cache_params[k] = "<unable to copy or convert>"
|
||||
for k, v in vars(litellm.cache.cache).items():
|
||||
try:
|
||||
specific_cache_params[k] = v
|
||||
except Exception:
|
||||
specific_cache_params[k] = "<unable to copy or convert>"
|
||||
litellm_cache_params = masker.mask_dict(litellm_cache_params)
|
||||
specific_cache_params = masker.mask_dict(specific_cache_params)
|
||||
litellm_cache_params = masker.mask_dict(vars(litellm.cache))
|
||||
# remove field that might reference itself
|
||||
litellm_cache_params.pop("cache", None)
|
||||
specific_cache_params = (
|
||||
masker.mask_dict(vars(litellm.cache.cache)) if litellm.cache else {}
|
||||
)
|
||||
|
||||
if litellm.cache.type == "redis":
|
||||
# ping the redis cache
|
||||
ping_response = await litellm.cache.ping()
|
||||
|
@ -63,24 +57,35 @@ async def cache_ping():
|
|||
)
|
||||
verbose_proxy_logger.debug("/cache/ping: done with set_cache()")
|
||||
|
||||
return {
|
||||
"status": "healthy",
|
||||
"cache_type": litellm.cache.type,
|
||||
"ping_response": True,
|
||||
"set_cache_response": "success",
|
||||
"litellm_cache_params": litellm_cache_params,
|
||||
"redis_cache_params": specific_cache_params,
|
||||
}
|
||||
return CachePingResponse(
|
||||
status="healthy",
|
||||
cache_type=str(litellm.cache.type),
|
||||
ping_response=True,
|
||||
set_cache_response="success",
|
||||
litellm_cache_params=safe_dumps(litellm_cache_params),
|
||||
redis_cache_params=safe_dumps(specific_cache_params),
|
||||
)
|
||||
else:
|
||||
return {
|
||||
"status": "healthy",
|
||||
"cache_type": litellm.cache.type,
|
||||
"litellm_cache_params": litellm_cache_params,
|
||||
}
|
||||
return CachePingResponse(
|
||||
status="healthy",
|
||||
cache_type=str(litellm.cache.type),
|
||||
litellm_cache_params=safe_dumps(litellm_cache_params),
|
||||
)
|
||||
except Exception as e:
|
||||
raise HTTPException(
|
||||
status_code=503,
|
||||
detail=f"Service Unhealthy ({str(e)}).Cache parameters: {litellm_cache_params}.specific_cache_params: {specific_cache_params}",
|
||||
import traceback
|
||||
|
||||
traceback.print_exc()
|
||||
error_message = {
|
||||
"message": f"Service Unhealthy ({str(e)})",
|
||||
"litellm_cache_params": safe_dumps(litellm_cache_params),
|
||||
"redis_cache_params": safe_dumps(specific_cache_params),
|
||||
"traceback": traceback.format_exc(),
|
||||
}
|
||||
raise ProxyException(
|
||||
message=safe_dumps(error_message),
|
||||
type=ProxyErrorTypes.cache_ping_error,
|
||||
param="cache_ping",
|
||||
code=503,
|
||||
)
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue