airflow icon indicating copy to clipboard operation
airflow copied to clipboard

A long-running asset watcher's current log file only reaches remote storage when it leaves its triggerer

Open seanghaeli opened this issue 2 weeks ago • 2 comments

With #76527, each asset watcher logs to triggers/trigger_id=<id>/triggerer_job_id=<id>/trigger.log on its triggerer. With remote logging on, each rotated part is uploaded as soon as the file reaches [triggerer] watcher_log_max_bytes, but the current part only when the watcher leaves that triggerer or the triggerer stops. A killed triggerer's current parts are uploaded when a triggerer next starts on the same disk (WatcherLogs in airflow-core/src/airflow/utils/log/watcher_log.py).

So a watcher that stays on one triggerer for weeks has only its rotated parts in remote storage. Its newest lines, up to 2 MiB by default, are only on the triggerer's disk, and a quiet watcher may have nothing uploaded at all. If the triggerer is killed and its disk goes with it, as with a pod's local volume, those lines are lost apart from the copy in the triggerer's output, if that's kept.

Suggestion: also rotate the current file on a configurable timer, not only by size, whenever it has new lines, so the existing rotated-part upload takes it to remote storage. Uploading the open file directly isn't safe, since several remote handlers empty or delete a file after uploading it. Handlers that send each line as it's written (CloudWatch, Cloud Logging) don't need this.

Done when: a watcher's newest lines reach remote storage within the configured interval while it stays on one triggerer, without uploading when nothing new was written, with tests.

This needs #76527 to merge first. I'd recommend building on top of #76527's branch and rebasing once it's merged.

seanghaeli avatar Nov 13 '26 18:11 seanghaeli

This would also close a gap left in #76560: if a killed triggerer's host doesn't come back, its watchers' lines since the last upload can't be read until they're uploaded.

seanghaeli avatar Nov 20 '26 21:11 seanghaeli

I'd like to take this one. I'm already working on the Elasticsearch part of #77056, so I've been in watcher_log.py quite a bit.

My plan:

  • Add a [triggerer] option for how often the current file is rotated, alongside watcher_log_max_bytes.
  • Check it from the triggerer's main loop, next to the orphaned-log scan, and rotate the current file only when the interval has passed and it has new lines. That way a watcher that has gone quiet still gets its last lines uploaded, and nothing is uploaded when nothing new was written.
  • Reuse the existing rotated-file upload, so the remote handlers don't need changes.

One question: should the interval be off by default (0), or on with something like 5 minutes? On makes the default safer for pods with local disks, but adds an upload per active watcher per interval.

Sam-Razavi avatar Nov 23 '26 19:11 Sam-Razavi