Skip to content

Commit

Permalink
server_app: use burst_suppressed_logger for all requests error logging
Browse files Browse the repository at this point in the history
  • Loading branch information
Bodong-Yang committed Nov 30, 2024
1 parent 81f8c1b commit ca60a0e
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions src/ota_proxy/server_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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)
Expand Down Expand Up @@ -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
)
Expand Down

0 comments on commit ca60a0e

Please sign in to comment.