uranusjr commented on code in PR #49470:
URL: https://github.com/apache/airflow/pull/49470#discussion_r2079018180
##########
airflow-core/src/airflow/api_fastapi/core_api/routes/public/log.py:
##########
@@ -133,24 +135,23 @@ def get_log(
with contextlib.suppress(TaskNotFound):
ti.task = dag.get_task(ti.task_id)
- if accept == Mimetype.JSON or accept == Mimetype.ANY: # default
- logs, metadata = task_log_reader.read_log_chunks(ti, try_number,
metadata)
+ if accept == Mimetype.JSON: # only specified application/json will return
JSON
+ structured_log_stream, out_metadata =
task_log_reader.read_log_chunks(ti, try_number, metadata)
encoded_token = None
- if not metadata.get("end_of_log", False):
- encoded_token =
URLSafeSerializer(request.app.state.secret_key).dumps(metadata)
- return
TaskInstancesLogResponse.model_construct(continuation_token=encoded_token,
content=logs)
- # text/plain, or something else we don't understand. Return raw log content
-
- # We need to exhaust the iterator before we can generate the continuation
token.
- # We could improve this by making it a streaming/async response, and by
then setting the header using
- # HTTP Trailers
- logs = "".join(task_log_reader.read_log_stream(ti, try_number, metadata))
+ if not out_metadata.get("end_of_log", False):
+ encoded_token =
URLSafeSerializer(request.app.state.secret_key).dumps(out_metadata)
+ return TaskInstancesLogResponse.model_construct(
+ continuation_token=encoded_token,
content=list(structured_log_stream)
+ )
+
+ # text/plain, or something else we don't understand. Return raw log
content in ndjson format with StreamingResponse
Review Comment:
Is it a better idea to default to ndjson (and streaming), or a plain json
response? I wonder if defaulting to a simple response is easier for simple
cases.
--
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]