Repository navigation
Write container logs to the task log in deferrable AzureContainerInstancesOperator - #76330
Conversation
dabla
left a comment
There was a problem hiding this comment.
Addressed
Nothing since the previous round (first review of this PR; no other reviews or comments on it yet).
Open
- [1] the log-fetch guard also covers the success path, so an XCom consumer gets
[]instead of a failed task when the logs cannot be read. - Not commented: the PR title starts with three spaces.
The fix itself looks right: logs are now read before on_kill() removes the group on error, and the success path reuses the same fetch for XCom. AirflowTaskTimeout derives from BaseException, so except Exception does not swallow a timeout. Note that get_logs returns only the last 1000 lines (tail=1000), while non-deferrable mode streams everything. That is an API limit, not a bug in this change. Reviewed at 339f1e1a in diff mode, with the operator, the sync/async hook get_logs and the trigger read in full at the PR head. The tests were not run locally: I traced finding [1] through the code instead of running a probe.
|
Awesome work, congrats on your first merged pull request! You are invited to check our Issue Tracker for additional contributions. |
In deferrable mode,
AzureContainerInstancesOperatornever wrote the container's output to the task log: the trigger only polls the container state, andexecute_completeonly read the logs for XCom on success. When the container failed withremove_on_error=True(the default), the container group was deleted before anyone could read its logs, so the cause of the failure was lost. In non-deferrable mode the output is streamed to the task log, so the two modes behaved differently.execute_completenow fetches the logs once, writes them to the task log, and only then raises or removes the container group. The same logs are reused for XCom, so there is no extra API call. A failure while fetching logs is logged as a warning, so it does not replace the container's own error.Tests (in
test_container_instances.py):test_execute_complete_error_event_logs_container_output_before_removal: on error, logs are written before the container group is deleted.test_execute_complete_success_logs_container_output: on success, logs are written to the task log.test_execute_complete_log_fetch_failure_keeps_container_error: an error while fetching logs does not hide the container error.The first two fail on main and pass with this change. All 33 tests in the file pass.
Same class of bug as #76325 (KubernetesJobOperator), fixed in #76328.