ashb commented on a change in pull request #6722: [AIRFLOW-4922]Fix task get
log by Web UI
URL: https://github.com/apache/airflow/pull/6722#discussion_r360438032
##########
File path: airflow/utils/log/file_task_handler.py
##########
@@ -81,6 +82,34 @@ def _render_filename(self, ti, try_number):
execution_date=ti.execution_date.isoformat(),
try_number=try_number)
+ @provide_session
+ def query_task_hostname(self, ti, try_number, session=None):
+ """
+ Get task log hostname by log table and try_number
+
+ :param ti: task instance record
+ :param try_number: current try_number to read log from
+ :param session: database session
+ :type session: sqlalchemy.orm.session.Session
+ :return: log message hostname
+ """
+ from airflow import models
+ res_log = session.query(models.Log).filter(
+ models.Log.dag_id == ti.dag_id,
+ models.Log.task_id == ti.task_id,
+ models.Log.execution_date == ti.execution_date,
+ models.Log.owner != 'anonymous',
+ models.Log.event == 'cli_run',
+ models.Log.extra.like('%--raw%')
+ ).order_by(models.Log.id).limit(1).offset(try_number - 1).first()
Review comment:
> querying task_instance does not get the exact hostname.
Why not? Do you need to configure the hostname detection in airflow.cfg:
```
# Hostname by providing a path to a callable, which will resolve the hostname
# The format is "package:function". For example,
# default value "socket:getfqdn" means that result from getfqdn() of
"socket" package will be used as hostname
# No argument should be required in the function specified.
# If using IP address as hostname is preferred, use value
"airflow.utils.net:get_host_ip_address"
hostname_callable = socket:getfqdn
```
----------------------------------------------------------------
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