Skip to content

Write container logs to the task log in deferrable AzureContainerInstancesOperator - #76330

Merged
dabla merged 2 commits into
apache:mainfrom
Ankitraj-builds:fix/aci-deferrable-container-logs
Nov 5, 2026
Merged

dabla merged 2 commits into
apache:mainfrom
Ankitraj-builds:fix/aci-deferrable-container-logs

Conversation

@Ankitraj-builds

Copy link
Copy Markdown
Contributor

In deferrable mode, AzureContainerInstancesOperator never wrote the container's output to the task log: the trigger only polls the container state, and execute_complete only read the logs for XCom on success. When the container failed with remove_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_complete now 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.

@dabla dabla left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@Ankitraj-builds Ankitraj-builds changed the title Write container logs to the task log in deferrable AzureContainerInstancesOperator Write container logs to the task log in deferrable AzureContainerInstancesOperator Nov 5, 2026
@dabla
dabla merged commit 71a19df into apache:main Nov 5, 2026
77 checks passed
@boring-cyborg

boring-cyborg Bot commented Nov 5, 2026

Copy link
Copy Markdown

Awesome work, congrats on your first merged pull request! You are invited to check our Issue Tracker for additional contributions.

@Ankitraj-builds
Ankitraj-builds deleted the fix/aci-deferrable-container-logs branch November 6, 2026 12:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants