fix(caching.py): fix async redis health check

This commit is contained in:
Krrish Dholakia 2024-07-06 09:14:29 -07:00
parent c7338f9798
commit 3f83e8a8d4
3 changed files with 22 additions and 7 deletions

View file

@ -248,9 +248,15 @@ class RedisCache(BaseCache):
# asyncio.get_running_loop().create_task(self.ping())
result = asyncio.get_running_loop().create_task(self.ping())
except Exception as e:
verbose_logger.error(
"Error connecting to Async Redis client", extra={"error": str(e)}
)
if "no running event loop" in str(e):
verbose_logger.debug(
"Ignoring async redis ping. No running event loop."
)
else:
verbose_logger.error(
"Error connecting to Async Redis client - {}".format(str(e)),
extra={"error": str(e)},
)
### SYNC HEALTH PING ###
try:

View file

@ -600,8 +600,7 @@ class Logging:
verbose_logger.error(
"LiteLLM.LoggingError: [Non-Blocking] Exception occurred while building complete streaming response in success logging {}\n{}".format(
str(e), traceback.format_exc()
),
log_level="ERROR",
)
)
complete_streaming_response = None
else:

View file

@ -1607,7 +1607,17 @@ def test_caching_redis_simple(caplog):
print(m)
print(time.time() - s2)
redis_async_caching_error = False
redis_service_logging_error = False
captured_logs = [rec.message for rec in caplog.records]
assert "LiteLLM Redis Caching: async set" not in captured_logs
assert "ServiceLogging.async_service_success_hook" not in captured_logs
print(f"captured_logs: {captured_logs}")
for item in captured_logs:
if "Error connecting to Async Redis client" in item:
redis_async_caching_error = True
if "ServiceLogging.async_service_success_hook" in item:
redis_service_logging_error = True
assert redis_async_caching_error is False
assert redis_service_logging_error is False