jason810496 commented on code in PR #49470:
URL: https://github.com/apache/airflow/pull/49470#discussion_r2160345375


##########
airflow-core/src/airflow/api_fastapi/core_api/routes/public/log.py:
##########
@@ -138,24 +144,24 @@ 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)
-        encoded_token = None
+    if accept == Mimetype.NDJSON:  # only specified application/x-ndjson will 
return streaming response
+        log_stream = task_log_reader.read_log_stream(ti, try_number, metadata) 
 # type: ignore[arg-type]
+        headers = 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))
-    headers = None
-    if not metadata.get("end_of_log", False):
-        headers = {
-            "Airflow-Continuation-Token": 
URLSafeSerializer(request.app.state.secret_key).dumps(metadata)
-        }
-    return Response(media_type="application/x-ndjson", content=logs, 
headers=headers)
+            headers = {
+                "Airflow-Continuation-Token": 
URLSafeSerializer(request.app.state.secret_key).dumps(metadata)
+            }
+        return StreamingResponse(media_type="application/x-ndjson", 
content=log_stream, headers=headers)
+
+    # application/json, or something else we don't understand.
+    # Return JSON format, which will be more easily for users to debug.
+    structured_log_stream, out_metadata = task_log_reader.read_log_chunks(ti, 
try_number, metadata)  # type: ignore[arg-type]
+    encoded_token = None

Review Comment:
   Sure. I just add this comment to my backlog. I will raise follow-up PR after 
this get merged.



-- 
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]

Reply via email to