larryzhu2018 commented on a change in pull request #7141: [AIRFLOW-6544] add 
log_id to end_of_log mark log record
URL: https://github.com/apache/airflow/pull/7141#discussion_r372643591
 
 

 ##########
 File path: airflow/utils/log/es_task_handler.py
 ##########
 @@ -255,7 +256,9 @@ def close(self):
 
         # Mark the end of file using end of log mark,
         # so we know where to stop while auto-tailing.
-        self.handler.stream.write(self.end_of_log_mark)
+        if self.write_stdout:
+            print()
+        self.handler.emit(logging.makeLogRecord({'msg': self.end_of_log_mark}))
 
 
 Review comment:
   > ```
   >  else logs[-1].message == self.end_of_log_mark.strip()
   > ```
   > 
   > I think this will not work if the `end_of_log_mark` is wrapped as a log 
record, as the `message` will be the format that Kevin mentioned and it also 
depends on the `log formatter`.
   I did not change any production code but did add a test case to show how 
this works. 
   
   in short, you will need to deploy an ingest log processor, and the ones we 
have look like this:
   
   
   "description" : "cluster json log Pipeline",
   "processors" : [
     {
       "rename" : {
         "field" : "message",
         "target_field" : "raw_message"
       }
     },
     {
       "json" : {
         "field" : "raw_message",
         "add_to_root" : false,
         "target_field" : "json_target"
       }
     },
     {
       "grok" : {
         "field" : "json_target.message",
         "patterns" : [
           "Job %{DATA:job_id}: Subtask %{DATA} %{GREEDYDATA:json_msg}",
           "%{GREEDYDATA}"
         ]
       }
     },
     {
       "json" : {
         "field" : "json_msg",
         "add_to_root" : true,
         "if" : "ctx.job_id != null"
       }
     },
     {
       "json" : {
         "field" : "raw_message",
         "add_to_root" : true,
         "if" : "ctx.job_id == null"
       }
     },
     {
       "remove" : {
         "field" : "json_msg",
         "ignore_missing" : true
       }
     },
     {
       "remove" : {
         "field" : "json_target"
       }
     },
     {
       "set" : {
         "field" : "event.kind",
         "value" : "tasks",
         "if" : "ctx.message != null"
       }
     },
     {
       "set" : {
         "field" : "event.dataset",
         "value" : "airflow",
         "if" : "ctx.dag_id != null && ctx.task_id != null"
       }
     },
     {
       "set" : {
         "field" : "log_id",
         "value" : "{{dag_id}}-{{task_id}}-{{execution_date}}-{{try_number}}",
         "if" : "ctx.event?.dataset == 'airflow'"
       }
     },
     {
       "set" : {
         "field" : "offset",
         "value" : "{{log.offset}}",
         "if" : "ctx.event?.dataset == 'airflow'"
       }
     }
   ],
   "on_failure" : [
     {
       "set" : {
         "field" : "error.message",
         "value" : "{{ _ingest.on_failure_message }}"
       }
     }
   ] 
   

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

Reply via email to