You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2021/04/21 11:30:10 UTC

[GitHub] [airflow] uranusjr commented on a change in pull request #15469: Fix incorrect order of messages in logs when using Elasticsearch

uranusjr commented on a change in pull request #15469:
URL: https://github.com/apache/airflow/pull/15469#discussion_r617450392



##########
File path: airflow/providers/elasticsearch/log/es_task_handler.py
##########
@@ -129,10 +129,11 @@ def _group_logs_by_host(logs):
             key = getattr(log, 'host', 'default_host')
             grouped_logs[key].append(log)
 
-        # return items sorted by timestamp.
-        result = sorted(grouped_logs.items(), key=lambda kv: getattr(kv[1][0], 'message', '_'))
+        # return items sorted by asctime.
+        for host in grouped_logs:
+            grouped_logs[host].sort(key=lambda log: getattr(log, 'asctime', '_'))

Review comment:
       ```suggestion
           def sorter(log):
               return getattr(log, 'asctime', '_')
   
           for logs in grouped_logs.values():
               logs.sort(key=sorter)
   ```
   
   Repeated lambda definition inside a loop is slow.




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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org