ashb commented on a change in pull request #5048: [AIRFLOW-3370] Add stdout 
output options to Elasticsearch task log handler
URL: https://github.com/apache/airflow/pull/5048#discussion_r276655326
 
 

 ##########
 File path: airflow/utils/log/es_task_handler.py
 ##########
 @@ -67,19 +72,37 @@ def __init__(self, base_log_folder, filename_template,
 
         self.mark_end_on_close = True
         self.end_of_log_mark = end_of_log_mark
+        self.write_stdout = write_stdout
+        self.json_format = json_format
+        self.json_fields = [label.strip() for label in json_fields.split(",")]
+
+        self.handler = None
 
     def _render_log_id(self, ti, try_number):
         if self.log_id_jinja_template:
             jinja_context = ti.get_template_context()
             jinja_context['try_number'] = try_number
             return self.log_id_jinja_template.render(**jinja_context)
 
+        if self.json_format:
+            execution_date = self._clean_execution_date(ti.execution_date)
+        else:
+            execution_date = ti.execution_date.isoformat()
         return self.log_id_template.format(dag_id=ti.dag_id,
                                            task_id=ti.task_id,
-                                           execution_date=ti
-                                           .execution_date.isoformat(),
+                                           execution_date=execution_date,
                                            try_number=try_number)
 
+    @staticmethod
+    def _clean_execution_date(execution_date):
+        """
+        Clean up an execution date so that it is safe to query in elasticsearch
+        by removing reserved characters.
+        # 
https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html#_reserved_characters
+        :param execution_date: execution date of the dag run.
+        """
+        return re.sub(r"[\+\-\:\.]", "", execution_date.isoformat())
 
 Review comment:
   Where does this show up btw? Using a strftime feels better rather than 
generating it in one format and then stripping some characters out.

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