o-nikolas commented on code in PR #76560:
URL: https://github.com/apache/airflow/pull/76560#discussion_r4736065137
##########
airflow-core/docs/administration-and-deployment/logging-monitoring/triggers.rst:
##########
@@ -121,3 +121,46 @@ Metrics and logs
``triggers.failed`` and ``triggers.succeeded`` are tagged with
``trigger_kind``, and the ``triggers.failing``
gauge counts, per triggerer and ``trigger_kind``, the triggers that are
failing. When a failing trigger
recovers, the triggerer logs ``Trigger recovered`` with its ``trigger_id`` and
``after_failures``.
+
+Logs
+----
+
+``GET /api/v2/triggers/{trigger_id}/logs?tail_lines=200`` returns a trigger's
latest lines, in JSON or, with
+``Accept: application/x-ndjson``, as NDJSON, in the same shape as task logs:
+
+* for a deferred task's trigger, the trigger part of that task try's log,
``<try log>.trigger.<triggerer job
+ id>.log``;
+* for a callback's trigger, the callback's log;
+* for an asset watcher, its own files from every triggerer that ran it (see
+ :ref:`asset-watcher-logs`), which also get the triggerer's ``Trigger
recovered`` line for it.
+
+Each is read live from the trigger's triggerer through its log server, from
remote logging, and from the API
+server's own log folder, and merged in time order. The log of the task or
callback that uses the trigger stays
+the place to read its whole story.
+
+Reading a trigger's logs needs the trigger to be visible, by the rules above
for its kind, and task log access
+to the Dag of its task instance or callback. An asset watcher's logs need read
access to one of its assets and
+task log access to a Dag scheduled on it (directly or on
``Asset.ref(name=...)`` / ``Asset.ref(uri=...)`` of
+it), in the trigger's team. A trigger you can see but whose logs you can't
read returns 403.
+
+Limits:
+
+* On handlers that upload files (S3, GCS, Azure Blob Storage), each rotated
part of a watcher's file is uploaded
+ once the file reaches ``[triggerer] watcher_log_max_bytes``, but the current
part is uploaded only when the
+ watcher leaves its triggerer or the triggerer stops. Until then it is read
live.
+* After a triggerer is killed, the lines it had not uploaded yet stay on its
disk until a triggerer starts on the
+ same disk, which uploads them. On a disk that does not outlive the triggerer
they are lost, apart from the
+ standard output copy.
+* Lines are kept per trigger id, so a new trigger (see `Identity`_) starts a
new history.
+* A watcher's files are read newest first: its current triggerer, then the at
most 50 that heartbeat last
+ since the trigger was created. Reading stops once ``tail_lines`` lines are
found and the next triggerer stopped
+ before the oldest of them, or after 64 MiB; the sources then say so. Files
of triggerer jobs that ``airflow db
+ clean`` removed are read only if none of its triggerers is left. After a
remote read fails, or the store
+ could not read 3 files, no further remote file is read: older triggerers'
files are read only live and locally.
+* To read watcher files back from remote storage, a remote log handler that
stores files has to treat a path
+ ending in ``/`` as a prefix. S3 and GCS do. A handler that streams each line
(CloudWatch) keeps one stream per
+ triggerer, read by its name, so it needs no listing permission.
Elasticsearch, OpenSearch and Cloud Logging key
Review Comment:
his no longer holds: CloudWatch, OSS, HDFS and Azure Blob Storage read a
path ending in `/` as a prefix too (so L162's list needs them), and the reader
reads the trigger's whole directory while no triggerer holds the watcher
(`trigger_log_reader.py` L359), which on CloudWatch is a `DescribeLogStreams`
call. Without that permission the listing raises, and L369 then turns off
remote reads for every job, including the streams read by name. So with a role
built from this page, a watcher shows no remote lines while its triggerers are
down. Could this name `logs:DescribeLogStreams` and `oss:ListObjects`, and
could a failed read of the directory leave the by-name reads on?
##########
airflow-core/src/airflow/utils/log/trigger_log.py:
##########
@@ -93,3 +95,22 @@ def list_trigger_log_files(producer_dir: Path) -> list[Path]:
producer_dir / TRIGGER_LOG_HELD_FILE_NAME,
producer_dir / TRIGGER_LOG_FILE_NAME,
]
+
+
+def get_callback_log_relative_path(dag_id: str, run_id: str, callback_id: UUID
| str) -> str:
+ """
+ Return the path of the log of a callback run by the triggerer, which its
trigger writes.
+
+ One directory per callback: with ``delete_local_logs``, remote handlers
delete the log file's parent
+ directory after upload, which must not hold other callbacks' logs.
+ """
+ return f"triggerer_callbacks/{dag_id}/{run_id}/{callback_id}/callback.log"
+
+
+def get_callback_trigger_log_relative_path(callback: Callback) -> str:
+ """Return the log a callback's trigger writes, under ``unknown`` for a Dag
or run its context lacks."""
+ data = callback.data or {}
+ dag_run = ((data.get("kwargs") or {}).get("context") or {}).get("dag_run")
or {}
+ dag_id = data.get("dag_id") or dag_run.get("dag_id") or "unknown"
+ run_id = data.get("run_id") or dag_run.get("dag_run_id") or "unknown"
Review Comment:
The `data.get("run_id")` branch is back in this push, after 8c93558 removed
it. I couldn't find anything in core that puts `run_id` in a callback's `data`,
and the triggerer now writes callback logs through this helper too. Intended,
or a leftover from the rebase?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]