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


##########
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:
   I’m not thinking about cases where the client asks for a format correctly, 
but those catch-all fallbacks. Our front _shouldn’t_ use those in any cases, 
but a custom client might (like when you want to debug the endpoint directly 
with postman or something). Defaulting to streaming on an unrecognised Accept 
header might make those cases more difficult, but I guess it’s not a big 
problem since you should just set the header correctly anyway. But in that 
case, why do we do this at all? Why not just return 406 Not Acceptable instead?



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