Fix UnicodeDecodeError on non-UTF-8 log lines
Build Docker Image / build-and-deploy-image (push) Successful in 10m4s
Build Docker Image / build-and-deploy-image (push) Successful in 10m4s
Read the access log in binary mode so decoding happens per-line inside the existing contextlib.suppress block. Previously readlines() decoded the whole file as UTF-8 up front and threw on any raw non-UTF-8 byte (e.g. a scanner's malformed URL) before truncate(0) could run, so the bad line was never cleared and every subsequent scrape failed.
This commit is contained in:
@@ -21,8 +21,8 @@ async def read_and_process_logs() -> dict[tuple[str, str], dict[str, float]]:
|
||||
metrics_data: dict[tuple[str, str], dict[str, float]] = {}
|
||||
|
||||
if os.path.exists(unit_log_file):
|
||||
async with aiofiles.open(unit_log_file, mode="r+") as f:
|
||||
lines: list[str] = await f.readlines()
|
||||
async with aiofiles.open(unit_log_file, mode="rb+") as f:
|
||||
lines: list[bytes] = await f.readlines()
|
||||
await f.truncate(0)
|
||||
|
||||
for line in lines:
|
||||
|
||||
Reference in New Issue
Block a user