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

Decode logs cp1252 support #74

Merged
merged 1 commit into from
May 17, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion agent/worker/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
)
from worker.app_file_streamer import AppFileStreamer
from worker.telemetry_reporter import TelemetryReporter
from supervisely_lib._utils import _remove_sensitive_information # pylint: disable=import-error, no-name-in-module
from supervisely_lib._utils import _remove_sensitive_information # pylint: disable=import-error, no-name-in-module


class Agent:
Expand Down
23 changes: 17 additions & 6 deletions agent/worker/task_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,8 +308,7 @@ def clean_task_dir(self):
super().clean_task_dir()

tmp_data_dir = os.path.join(
constants.SUPERVISELY_AGENT_FILES_CONTAINER(),
"app_tmp_data", str(self.info["task_id"])
constants.SUPERVISELY_AGENT_FILES_CONTAINER(), "app_tmp_data", str(self.info["task_id"])
)

if sly.fs.dir_exists(tmp_data_dir):
Expand Down Expand Up @@ -409,9 +408,7 @@ def _get_task_volumes(self):
useTmpFromFiles = self.info.get("useTmpFromFiles", False)

if useTmpFromFiles is True:
relative_app_tmp_data_dir = os.path.join(
"app_tmp_data", str(self.info["task_id"])
)
relative_app_tmp_data_dir = os.path.join("app_tmp_data", str(self.info["task_id"]))

host_tmp_data_dir = os.path.join(
constants.SUPERVISELY_AGENT_FILES(),
Expand Down Expand Up @@ -806,11 +803,25 @@ def _process_line(log_line):
if lvl_int != -1:
self.logger.log(lvl_int, msg, extra=res_log)

def _decode(bytes: bytes):
decode_args = [
("utf-8", "strict"),
("cp1252", "strict"),
("utf-8", "replace"),
]
for args in decode_args:
try:
return bytes.decode(*args)
except UnicodeDecodeError:
continue
# if all decodings failed, return the first one to raise error
return bytes.decode(*decode_args[0])

# @TODO: parse multiline logs correctly (including exceptions)
log_line = ""

for log_line_arr in self._logs_output:
for log_part in log_line_arr.decode("utf-8").splitlines():
for log_part in _decode(log_line_arr).splitlines():
logs_found = True
_process_line(log_part)

Expand Down