Skip to content

Show a deferred task's trigger logs from CloudWatch, OSS and HDFS after it finishes - #76631

Open
seanghaeli wants to merge 1 commit into
apache:mainfrom
aws-mwaa:ghaeli/to8-cloudwatch-trigger-log-streams
Open

seanghaeli wants to merge 1 commit into
apache:mainfrom
aws-mwaa:ghaeli/to8-cloudwatch-trigger-log-streams

Conversation

@seanghaeli

@seanghaeli seanghaeli commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

closes: #70317

This PR makes CloudWatch, OSS and HDFS remote logging work for trigger logs:

  • Deferred tasks' trigger logs show after the task finishes. The trigger's lines are uploaded to a separate file next to the task log (<task log>.trigger.<triggerer job id>.log), and these readers only fetched the task log itself, meaning the trigger lines disappeared from the UI once the task finished. They now read every file starting with its name.
  • They can read a whole folder, or just the last N lines of each log, which Read any trigger's logs by id with GET /triggers/{trigger_id}/logs #76560's trigger Logs tab uses to show an asset watcher's history.
  • An optional trigger_log_group_arn in [logging] remote_task_handler_kwargs sends asset watchers' own logs to a separate CloudWatch log group.
  • CloudWatch no longer loses lines when many log streams open at once, such as when a triggerer takes over another's watchers. A stream still being created when the triggerer stops still loses its lines.

Reading needs logs:DescribeLogStreams on CloudWatch and oss:ListObjects on OSS, now in the docs. Without them, each reads the task log alone, as before.

Tested on Breeze with CloudWatch: after a deferred task finished, main showed none of its trigger lines and this PR shows all of them, including across a triggerer restart, with no duplicates.

This picks up the read-side approach from #70635 by @bujjibabukatta, which closed as stale.


Was generative AI tooling used to co-author this PR?
  • Yes (please specify the tool below)

Generated-by: Claude Code (Opus 5.5) following the guidelines

@seanghaeli
seanghaeli force-pushed the ghaeli/to8-cloudwatch-trigger-log-streams branch 2 times, most recently from d437819 to 3bfd939 Compare November 12, 2026 22:48
@seanghaeli seanghaeli changed the title Show a deferred task's trigger logs from CloudWatch after it finishes Show a deferred task's trigger logs from CloudWatch, OSS and HDFS after it finishes Nov 12, 2026
@seanghaeli
seanghaeli force-pushed the ghaeli/to8-cloudwatch-trigger-log-streams branch 2 times, most recently from 608abef to 12322d6 Compare November 18, 2026 01:12
@seanghaeli
seanghaeli force-pushed the ghaeli/to8-cloudwatch-trigger-log-streams branch from 12322d6 to 32109b7 Compare November 20, 2026 23:56
@seanghaeli
seanghaeli marked this pull request as ready for review November 21, 2026 06:14
…er it finishes

A deferred task's triggerer stores its log beside the task log, as
<task log>.trigger.<triggerer job id>.log, but the CloudWatch, OSS and
HDFS readers read only the task log itself. Once the task left DEFERRED
(no more live read from the triggerer), its trigger lines vanished from
the UI, even though they were stored. Read every stream, object or file
the path is a prefix of, as the S3, GCS and WASB readers already do.
The same read shows an asset watcher's history on CloudWatch, which
keeps one stream per triggerer that ran it.

CloudWatch: while the task is deferred, skip the current triggerer's
stream, which the task log reader reads live. A path ending in "/" with
no stream under it has no logs, rather than a "No log stream found"
notice as its one line, and one that can't be listed raises, as the S3
reader does. Listing needs logs:DescribeLogStreams, which the docs now
say; without it a task log falls back to its exact stream.

OSS and HDFS: if listing fails, read the task log alone, as before. OSS
gets OSSHook.list_keys; listing needs oss:ListObjects, which the docs
now say.

CloudWatch also reads a stream from its end when asked for its last
lines (stream(..., tail_lines=N)), so the trigger logs endpoint no longer
reads a long-running watcher's stream from its head. A trigger_log_group_arn
in remote_task_handler_kwargs sends a trigger's own logs, under
triggers/trigger_id=<id>/, to their own log group.

CloudWatch no longer drops lines while it opens a stream. watchtower
creates a stream only once a put to it fails, and meanwhile its handler,
which serves every stream of a process, drops every thread's lines. A new
stream is now created before its first put, backing off on throttling, so
a triggerer opening many streams at once no longer loses batches either.
An upload flushes only its own stream, so it no longer waits on streams
still being created, nor fails with "dictionary changed size during
iteration" when another thread opens a stream.

HDFS also reads the files under a matching directory, such as the rotated/
parts of an asset watcher's log, instead of failing on the directory.

closes: apache#70317
@seanghaeli
seanghaeli force-pushed the ghaeli/to8-cloudwatch-trigger-log-streams branch from 32109b7 to c3e6bdd Compare November 21, 2026 06:23

@o-nikolas o-nikolas 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.

@amoghrajesh Maybe you want to look at this one too?

The trigger of a deferred task writes to its own log stream, and Airflow finds it by listing the streams that
start with the task's log name. Without the permission, Airflow reads the task's own stream alone.

On Airflow versions that write asset watcher logs, a watcher's logs go under ``triggers/trigger_id=<id>/``.

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.

nit: "On Airflow versions that write asset watcher logs" is hard to act on for a reader. Could this name the version, e.g. "From Airflow 3.5.0" (assuming #76527 ships there)?

if not self.shutting_down:
self._send_queued(list(self.queues.items()), self.FLUSH)

def close(self) -> None:

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.

nit: watchtower's own close() warns "Timed out while delivering logs" when a queue still holds records after the wait. This override drops that, and it now skips streams still being created on purpose, so lines lost at shutdown go unreported. Could we keep a warning for queues that aren't empty here?

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Logs produced by deferrable tasks disapper from Airflow UI after completion of the task

2 participants