Skip to content

Commit 834ca80

Browse files
dstandishCloud Composer Team
authored and
Cloud Composer Team
committed
Fix log tailing issues with legacy log view (#29496)
Probably we should just chop this view in favor of grid view logging which is the future. But this fixes rendering issues raised here apache/airflow#29447 (comment). What we do, is in log tailing context (which apparently isn't used in grid, and that's why I did not see this in developing trigger logging) we don't add the messages to the log content. So, whenever log_pos is in metadata we don't add messages. It means the messages could be a bit stale but that seems ok. Refreshing the page could fix that. Longer term, we could update the API so that log content is just content and the messages are themselves returned in the metadata dict. That's probably the "right" solution ultimately. But can be saved for another day. Also resolve the "cannot load lazy instance" issue when invoking the reader logic from this different context. GitOrigin-RevId: 7cf5cea76e3ff8b790d7185632b6dd7b0196f0e3
1 parent 5fc40d4 commit 834ca80

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

airflow/utils/log/file_task_handler.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,8 @@ def _read(
340340
if metadata and "log_pos" in metadata:
341341
previous_chars = metadata["log_pos"]
342342
logs = logs[previous_chars:] # Cut off previously passed log test as new tail
343-
return messages + logs, {"end_of_log": end_of_log, "log_pos": log_pos}
343+
out_message = logs if "log_pos" in (metadata or {}) else messages + logs
344+
return out_message, {"end_of_log": end_of_log, "log_pos": log_pos}
344345

345346
@staticmethod
346347
def _get_pod_namespace(ti: TaskInstance):

airflow/www/views.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1523,7 +1523,15 @@ def get_logs_with_metadata(self, session=None):
15231523

15241524
ti = (
15251525
session.query(models.TaskInstance)
1526-
.filter_by(dag_id=dag_id, task_id=task_id, execution_date=execution_date, map_index=map_index)
1526+
.filter(
1527+
TaskInstance.task_id == task_id,
1528+
TaskInstance.dag_id == dag_id,
1529+
TaskInstance.execution_date == execution_date,
1530+
TaskInstance.map_index == map_index,
1531+
)
1532+
.join(TaskInstance.dag_run)
1533+
.options(joinedload("trigger"))
1534+
.options(joinedload("trigger.triggerer_job"))
15271535
.first()
15281536
)
15291537

0 commit comments

Comments
 (0)