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

Handle errors when adding logs to the archive #2982

Merged
merged 1 commit into from
Nov 10, 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
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
Loading