A long-running asset watcher's current log file only reaches remote storage when it leaves its triggerer
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.
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.
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, alongsidewatcher_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.