Skip to content

Commit 1b33eb6

Browse files
[v3-1-test] Emit log stream stopped warning as ndjson (#56474) (#56480)
Changes the format of the log stream stopped warning emitted by the TaskLogReader to ndjson when it encounters no end of log marker in a stream. Mixing ndjson and non-ndjson means the UI will not show any logs at all. (cherry picked from commit 8782650) Co-authored-by: Ian Buss <[email protected]>
1 parent 4cf03c0 commit 1b33eb6

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

airflow-core/src/airflow/utils/log/log_reader.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,8 @@ def read_log_stream(
147147
empty_iterations += 1
148148
if empty_iterations >= self.STREAM_LOOP_STOP_AFTER_EMPTY_ITERATIONS:
149149
# we have not received any logs for a while, so we stop the stream
150-
yield "(Log stream stopped - End of log marker not found; logs may be incomplete.)\n"
150+
# this is emitted as json to avoid breaking the ndjson stream format
151+
yield '{"event": "Log stream stopped - End of log marker not found; logs may be incomplete."}\n'
151152
return
152153
else:
153154
# https://mypy.readthedocs.io/en/stable/typed_dict.html#supported-operations

airflow-core/tests/unit/utils/log/test_log_reader.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ def test_read_log_stream_no_end_of_log_marker(self, mock_read):
268268
log_stream = task_log_reader.read_log_stream(ti=self.ti, try_number=1, metadata={})
269269
assert list(log_stream) == [
270270
'{"timestamp":null,"event":"hello"}\n',
271-
"(Log stream stopped - End of log marker not found; logs may be incomplete.)\n",
271+
'{"event": "Log stream stopped - End of log marker not found; logs may be incomplete."}\n',
272272
]
273273
assert mock_read.call_count == 11
274274

0 commit comments

Comments
 (0)