andriisoldatenko 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_r278982447
##########
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:
@bolkedebruin can you suggest something similar to
`dt.today().strftime("%Y_%m_%dT%H_%I_%S_%f")` from
(pendulum docs)[https://pendulum.eustace.io/docs/#string-formatting]?
----------------------------------------------------------------
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