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 2019/04/18 12:52:08 UTC
[GitHub] [airflow] andriisoldatenko commented on a change in pull request
#5048: [AIRFLOW-3370] Add stdout output options to Elasticsearch task log
handler
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_r276648762
##########
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:
@ashb what do you think if it should be:
```
In [5]: dt.today().strftime("%Y_%m_%dT%H_%I_%S_%f")
Out[5]: '2019_04_18T15_03_06_899836'
```
cc @schnie
----------------------------------------------------------------
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
With regards,
Apache Git Services