Noël BARDELOT created AIRFLOW-7110:
--------------------------------------

             Summary: Refactor the way logs are written to/read from 
Elasticsearch
                 Key: AIRFLOW-7110
                 URL: https://issues.apache.org/jira/browse/AIRFLOW-7110
             Project: Apache Airflow
          Issue Type: Improvement
          Components: configuration, logging, operators, ui
    Affects Versions: 1.10.9
            Reporter: Noël BARDELOT


See:

- in the configuration,
  - under section 'core' options named 'remote_logging'
  - under section 'elasticsearch' options named 'host', 'log_id_template', 
'end_of_log_mark', 'frontend', 'write_stdout' and 'json_format'
- in the documentation,
  - https://airflow.apache.org/docs/stable/howto/write-logs.html
- in the Airflow code,
  - BaseOperator in airflow/models/baseoperator.py
  - ElasticsearchTaskHandler in airflow/utils/log/es_task_handler.py
  - the detail of a task's view in airflow/www/views.py

Current behaviour:

If one sets the options as stated in the documentation in order to write logs 
from the task to the worker stdout logs in JSON format, and upload those logs 
in Elasticsearch (using ELK or an equivalent stack), the field 'log_id' needed 
by the handler and the view to work is not written by default to the logs.

One needs to adapt the log collection from the worker's container stdout logs 
in order to provide this 'log_id' field, which agregates other usual fields 
(see 'log_id_template' which is used by the handler to request logs from 
Elasticsearch to be shown in the view).

An example:

    # Also add log_id to airflow.task logs
    <filter airflow.task.**>
      @type record_transformer
      enable_ruby
      <record>
        log_id 
${record["dag_id"]}_${record["task_id"]}_${record["execution_date"]}_${record["try_number"]}
        offset ${time = Time.now; time.to_i * (10 ** 9) + time.nsec}
      </record>
    </filter>

What we expect:

It should be the job of the Operator to log the needed 'log_id' field (Airflow 
reads it and needs it, so Airflow should write it itself...). That should be 
done in the BaseOperator, so that it's available to all children classes.

Plus, there is no benefit to make the 'log_id_template' configurable. As is, 
there is no way to make anything else than the current value work, and nobody 
should ever modify it.

Plus, the 'frontend' configuration option should not presume that 'https://' is 
the protoocol to use in order to make a link to the external log viewer (Kibana 
or other...). The 'frontend' option should
contain the whole URL templated by 'log_id'.

Plus, all this behaviour should be far more documented in the 'write-logs' 
documentation.

Plus, a DAG example should be added to Airflow's already existing example, in 
order to show how a subclass of BaseOperator should use the logging mechanism 
to write a log.

Plus, Elasticsearch's 'host' option under Airflow's configuration is wrongly 
named and documented. It is not a host, but a server with host and port.

Plus, for the same 'host' option, a default port is computed, but if 'use_ssl' 
to True in section 'elasticsearch_configs' of the configuration, that default 
port is not changed to 443 as should be.





--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to