Skip to content

Commit

Permalink
Handle errors when adding logs to the archive
Browse files Browse the repository at this point in the history
  • Loading branch information
narrieta committed Nov 9, 2023
1 parent d10cdff commit 63c0ea9
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions azurelinuxagent/ga/logcollector.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,9 +360,18 @@ def collect_logs_and_get_archive(self):
try:
compressed_archive = zipfile.ZipFile(COMPRESSED_ARCHIVE_PATH, "w", compression=zipfile.ZIP_DEFLATED)

max_errors = 8
error_count = 0
for file_to_collect in files_to_collect:
archive_file_name = LogCollector._convert_file_name_to_archive_name(file_to_collect)
compressed_archive.write(file_to_collect.encode("utf-8"), arcname=archive_file_name)
try:
archive_file_name = LogCollector._convert_file_name_to_archive_name(file_to_collect)
compressed_archive.write(file_to_collect.encode("utf-8"), arcname=archive_file_name)
except Exception as e:
error_count += 1
if error_count >= max_errors:
raise Exception("Too many errors, giving up. Last error: {0}".format(ustr(e)))
else:
_LOGGER.warning("Failed to add file %s to the archive: %s", file_to_collect, ustr(e))

compressed_archive_size = os.path.getsize(COMPRESSED_ARCHIVE_PATH)
_LOGGER.info("Successfully compressed files. Compressed archive size is %s b", compressed_archive_size)
Expand Down

0 comments on commit 63c0ea9

Please sign in to comment.