Skip to content

Commit

Permalink
cp1252 decode logs support
Browse files Browse the repository at this point in the history
  • Loading branch information
NikolaiPetukhov committed May 17, 2024
1 parent 9ae80ae commit 8b857f0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
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

0 comments on commit 8b857f0

Please sign in to comment.