Skip to content

Commit

Permalink
Error handling for when Azure container log cannot be read in properl…
Browse files Browse the repository at this point in the history
…y. (apache#34627)

* Error handling for broken or null Azure logs.

* Updated logging syntax to match rest of the code.

* Moved broken log checking closer to the source to avoid catching more general errors.

* Fixed style issues.

* Changed log exception to log error.

* Changed failure case return type to list. Not an empty list as that ruins normal operation - instead [None.

* Cleaner checking of logs list not being empty

Co-authored-by: Wei Lee <weilee.rx@gmail.com>

---------

Co-authored-by: Wei Lee <weilee.rx@gmail.com>
  • Loading branch information
krisfur and Lee-W authored Oct 13, 2023
1 parent d27d0bb commit 546c850
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
2 changes: 2 additions & 0 deletions airflow/providers/microsoft/azure/hooks/container_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@ def get_logs(self, resource_group: str, name: str, tail: int = 1000) -> list:
:return: A list of log messages
"""
logs = self.connection.containers.list_logs(resource_group, name, name, tail=tail)
if logs.content is None:
return [None]
return logs.content.splitlines(True)

def delete(self, resource_group: str, name: str) -> None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,9 @@ def _monitor_logging(self, resource_group: str, name: str) -> int:
if state in ["Running", "Terminated", "Succeeded"]:
try:
logs = self._ci_hook.get_logs(resource_group, name)
if logs and logs[0] is None:
self.log.error("Container log is broken, marking as failed.")
return 1
last_line_logged = self._log_last(logs, last_line_logged)
except CloudError:
self.log.exception(
Expand Down

0 comments on commit 546c850

Please sign in to comment.