Skip to content

Give each asset watcher its own log file on the triggerer - #76527

Merged
vincbeck merged 1 commit into
apache:mainfrom
aws-mwaa:ghaeli/to8-trigger-logs
Nov 20, 2026
Merged

vincbeck merged 1 commit into
apache:mainfrom
aws-mwaa:ghaeli/to8-trigger-logs

Conversation

@seanghaeli

@seanghaeli seanghaeli commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Building on #76260.

An asset watcher's lines only reach the triggerer's stdout, so they can't be read back and are lost when the triggerer goes away. Deferred tasks and callbacks already log to a file; this gives each watcher one too, uploaded with remote logging. A follow-up adds GET /triggers/{trigger_id}/logs to read them.

  • Each watcher logs to triggers/trigger_id=<id>/triggerer_job_id=<id>/trigger.log on its triggerer. Lines still go to stdout by default.
  • Remote logging uploads the file when the watcher leaves the triggerer or the triggerer stops, and each part as soon as the file reaches its size cap. A triggerer that starts uploads what a killed one left on the same disk.
  • Disk use and open files are capped ([triggerer] watcher_log_max_bytes, watcher_log_max_open_files). If the store stays down, old parts are dropped to keep the cap.

Not in this PR: uploading on a timer so a long-running watcher's remote copy stays current, and reading the runner's last lines on stop (#76867).

How to review: start with utils/log/watcher_log.py. About 1,050 lines of source; the rest is tests and docs.

Airflow CI image, Postgres 16, LocalExecutor, S3 remote logging: one watcher logging 5 lines a second, on a triggerer that is stopped, started, killed with kill -9, started again on the same disk and stopped (triggerer jobs 2, 4 and 5):

# before (main), at the end:
  ly_0: logged 915 lines to stdout; 0 in any file under triggers/ (none is written), 0 in S3
# after, S3 at the end:
  triggers/trigger_id=1/triggerer_job_id=2/trigger.log 135038 B, 340 lines
  triggers/trigger_id=1/triggerer_job_id=4/trigger.log 114980 B, 290 lines
  triggers/trigger_id=1/triggerer_job_id=5/trigger.log 117218 B, 295 lines
[info     ] Uploaded a trigger log left behind by a triggerer that is not alive [airflow.utils.log.watcher_log] loc=watcher_log.py:466 path='triggers/trigger_id=1/triggerer_job_id=4/trigger.log' triggerer_job_id=4
  ly_0: logged 925, in S3 925, missing 0, duplicated 0

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

Copy link
Copy Markdown
Contributor Author

@hussein-awala, this touches some of the same files as your PRs for issue #76209, let me know if you have any preferences on merge order

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

This PR also has a stopping triggerer upload the task and callback logs of triggers that are still running, which is what #76514 does too. Have you and that author agreed which PR lands that part? If #76514 goes first, this one could stick to the watcher files, which would also make it a bit smaller.

triggerer_job_runner.py grows by about 600 lines here, to about 2,660. Would you be open to moving the watcher log handling (the capped logger, the rotated uploads and the orphan scan) into its own module next to utils/log/trigger_log.py? I think it'd be easier to follow, and easier to change when #76640 lands. A follow-up is fine if you'd rather not churn this PR.


Drafted-by: Kiro (claude-opus-5.5); reviewed by @o-nikolas before posting

@seanghaeli

Copy link
Copy Markdown
Contributor Author

Thanks @o-nikolas for pointing out the overlap with #76514. The part of this PR that overlaps it is just a bug fix, so this PR doesn't need to wait for that one to merge. Since #76514 is handling that gap, I've removed that part of the code here.

@seanghaeli
seanghaeli force-pushed the ghaeli/to8-trigger-logs branch 2 times, most recently from 4ff0d49 to 32f685c Compare November 12, 2026 21:27
@seanghaeli

Copy link
Copy Markdown
Contributor Author

Also, moved the watcher log handling into its own module

@seanghaeli
seanghaeli force-pushed the ghaeli/to8-trigger-logs branch from fc5d2e1 to eb0e784 Compare November 18, 2026 09:49
@seanghaeli
seanghaeli force-pushed the ghaeli/to8-trigger-logs branch 8 times, most recently from 525c629 to 308b99a Compare November 19, 2026 07:03
@seanghaeli
seanghaeli force-pushed the ghaeli/to8-trigger-logs branch 2 times, most recently from f27ec66 to 3743fef Compare November 19, 2026 16:24

@ramitkataria ramitkataria 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.

Posted a couple of minor concerns but looks good to me otherwise!

@eladkal eladkal added this to the Airflow 3.5.0 milestone Nov 20, 2026
@eladkal eladkal added the type:improvement Changelog: Improvements label Nov 20, 2026

@shahar1 shahar1 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.

The split into watcher_log.py reads well and CI is green. I have four small observations inline, none blocking, and ramitkataria's two open threads still need an answer before this merges.

Smaller observations

  • On the open older-provider thread: the class-name lists in watcher_log.py tie core to what each provider's handler does to the local file after an upload, and that differs between provider versions. I'd like to see that thread answered, since core can't require a provider version.
  • The tests for CappedBytesLogger, WatcherLogs and upload_watcher_log_file are all in tests/unit/jobs/test_triggerer_job.py, while the code is in airflow/utils/log/watcher_log.py. AGENTS.md (Testing Standards): "Test location mirrors source: airflow/cli/cli_parser.py → tests/cli/test_cli_parser.py." The ones that need no supervisor could move to tests/unit/utils/log/test_watcher_log.py.
  • Four more are inline: the stale-claim takeover, parts kept with HDFS, a function-level import, and mocks without a spec.

This review was drafted by an AI-assisted tool and
confirmed by an Apache Airflow maintainer. The findings
below are observations, not blockers; an Apache Airflow
maintainer — a real person — will take the next look at the
PR. If you think a finding is mis-applied, please reply on
the PR and a maintainer will weigh in.

More on how Apache Airflow handles maintainer review:
Contributing guide.

@seanghaeli
seanghaeli force-pushed the ghaeli/to8-trigger-logs branch from da30c4d to b7c89b0 Compare November 20, 2026 09:33
@seanghaeli
seanghaeli force-pushed the ghaeli/to8-trigger-logs branch from b7c89b0 to 53dce0d Compare November 20, 2026 10:30
@seanghaeli

Copy link
Copy Markdown
Contributor Author

On the two points in the review summary:

  • The class-name lists are gone. Core now counts a file as stored once the handler has removed the uploaded link to it, which every handler that stores files does after a write that went through, whatever its version. The two kinds that keep no copy are told apart by what they have: processors for one that streams each line, log_id_template for one that only takes task logs.
  • Moved the tests that don't need a supervisor to tests/unit/utils/log/test_watcher_log.py.

@vincbeck
vincbeck enabled auto-merge (squash) November 20, 2026 14:43
@vincbeck
vincbeck merged commit 7055657 into apache:main Nov 20, 2026
92 checks passed
@vincbeck
vincbeck deleted the ghaeli/to8-trigger-logs branch November 20, 2026 16:28
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.

7 participants