From ca60a0ec94ec3fa12357473407729360dd2fa481 Mon Sep 17 00:00:00 2001 From: "bodong.yang" Date: Sat, 30 Nov 2024 13:06:00 +0000 Subject: [PATCH] server_app: use burst_suppressed_logger for all requests error logging --- src/ota_proxy/server_app.py | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/ota_proxy/server_app.py b/src/ota_proxy/server_app.py index 0ab4e467c..d1f815b30 100644 --- a/src/ota_proxy/server_app.py +++ b/src/ota_proxy/server_app.py @@ -43,11 +43,11 @@ from .ota_cache import OTACache logger = logging.getLogger(__name__) -connection_err_logger = logging.getLogger(f"{__name__}.connection_err") -# NOTE: for connection_error, only allow max 6 lines of logging per 30 seconds -connection_err_logger.addFilter( +burst_suppressed_logger = logging.getLogger(f"{__name__}.request_error") +# NOTE: for request_error, only allow max 6 lines of logging per 30 seconds +burst_suppressed_logger.addFilter( BurstSuppressFilter( - f"{__name__}.connection_err", + f"{__name__}.request_error", upper_logger_name=__name__, burst_round_length=30, burst_max=6, @@ -211,11 +211,11 @@ async def _error_handling_for_cache_retrieving(self, url: str, send): yield _is_succeeded _is_succeeded.set() except aiohttp.ClientResponseError as e: - logger.error(f"{_common_err_msg} due to HTTP error: {e!r}") + burst_suppressed_logger.error(f"{_common_err_msg} due to HTTP error: {e!r}") # passthrough 4xx(currently 403 and 404) to otaclient await self._respond_with_error(e.status, e.message, send) except aiohttp.ClientConnectionError as e: - connection_err_logger.error( + burst_suppressed_logger.error( f"{_common_err_msg} due to connection error: {e!r}" ) await self._respond_with_error( @@ -224,12 +224,14 @@ async def _error_handling_for_cache_retrieving(self, url: str, send): send, ) except aiohttp.ClientError as e: - logger.error(f"{_common_err_msg} due to aiohttp client error: {e!r}") + burst_suppressed_logger.error( + f"{_common_err_msg} due to aiohttp client error: {e!r}" + ) await self._respond_with_error( HTTPStatus.SERVICE_UNAVAILABLE, f"client error: {e!r}", send ) except (BaseOTACacheError, StopAsyncIteration) as e: - logger.error( + burst_suppressed_logger.error( f"{_common_err_msg} due to handled ota_cache internal error: {e!r}" ) await self._respond_with_error( @@ -238,7 +240,7 @@ async def _error_handling_for_cache_retrieving(self, url: str, send): except Exception as e: # exceptions rather than aiohttp error indicates # internal errors of ota_cache - logger.exception( + burst_suppressed_logger.exception( f"{_common_err_msg} due to unhandled ota_cache internal error: {e!r}" ) await self._respond_with_error( @@ -255,13 +257,13 @@ async def _error_handling_during_transferring(self, url: str, send): try: yield except (BaseOTACacheError, StopAsyncIteration) as e: - logger.error( + burst_suppressed_logger.error( f"{_common_err_msg=} due to handled ota_cache internal error: {e!r}" ) await self._send_chunk(b"", False, send) except Exception as e: # unexpected internal errors of ota_cache - logger.exception( + burst_suppressed_logger.error( f"{_common_err_msg=} due to unhandled ota_cache internal error: {e!r}" ) await self._send_chunk(b"", False, send) @@ -292,7 +294,7 @@ async def _pull_data_and_send(self, url: str, scope, send): # retrieve_file executed successfully, but return nothing if _is_succeeded.is_set(): _msg = f"failed to retrieve fd for {url} from otacache" - logger.warning(_msg) + burst_suppressed_logger.warning(_msg) await self._respond_with_error( HTTPStatus.INTERNAL_SERVER_ERROR, _msg, send )