Owen-CH-Leung commented on code in PR #53821:
URL: https://github.com/apache/airflow/pull/53821#discussion_r2312199790


##########
providers/elasticsearch/src/airflow/providers/elasticsearch/log/es_task_handler.py:
##########
@@ -368,7 +396,19 @@ def _read(
         # If we hit the end of the log, remove the actual end_of_log message
         # to prevent it from showing in the UI.
         def concat_logs(hits: list[Hit]) -> str:
-            log_range = (len(hits) - 1) if hits[-1].message == 
self.end_of_log_mark else len(hits)
+            # In Airflow 2.x, the log record JSON has a "message" key, e.g.:
+            # {
+            #   "message": "Dag name:dataset_consumes_1 queued_at:2025-08-12 
15:05:57.703493+00:00",
+            #   "offset": 1755011166339518208,
+            #   "log_id": 
"dataset_consumes_1-consuming_1-manual__2025-08-12T15:05:57.691303+00:00--1-1"
+            # }
+            #
+            # In Airflow 3.x, the "message" field is renamed to "event".
+            # We check the correct attribute depending on the Airflow major 
version.
+            if AIRFLOW_V_3_0_PLUS:
+                log_range = (len(hits) - 1) if hits[-1].event == 
self.end_of_log_mark else len(hits)

Review Comment:
   I just tested with airflow 2.11 and it renders log well. But I do agree with 
what @topherinternational suggests.
   
   I think there're 3 scanerios here: 
    - airflow 2 reading old airflow 2.x task jobs (This works as per what I've 
tested) 
    - airflow 3 reading new airflow 3 task jobs (This also works as per what 
I've tested)
    - airflow 3 reading old airflow 2.x task jobs (This is hard to test 
unfortunately)
   
   Logically, case 3 will fail since airflow 2.x task jobs are writing logs 
with message field, but airflow 3 looks for event field. 
   
   I'll file a commit to fix it soon
   



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