Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix hanging inline OPA on very long log lines #489

Merged
merged 1 commit into from
Aug 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion packages/opal-client/opal_client/engine/logger.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import asyncio
import json
import logging
from enum import Enum
Expand Down Expand Up @@ -32,8 +33,17 @@ async def pipe_opa_logs(stream, logs_format: EngineLogFormat):
if logs_format == EngineLogFormat.NONE:
return

line = b""
roekatz marked this conversation as resolved.
Show resolved Hide resolved
while True:
line = await stream.readline()
try:
line += await stream.readuntil(b"\n")
except asyncio.exceptions.IncompleteReadError as e:
line += e.partial
except asyncio.exceptions.LimitOverrunError as e:
# No new line yet but buffer limit exceeded, read what's available and try again
line += await stream.readexactly(e.consumed)
continue

if not line:
break
try:
Expand All @@ -54,6 +64,8 @@ async def pipe_opa_logs(stream, logs_format: EngineLogFormat):
log_entire_dict(level, msg, log_line)
except json.JSONDecodeError:
logger.info(line)
finally:
line = b""


def log_event_name(level: str, msg: Optional[str]) -> bool:
Expand Down
Loading