mik-laj commented on a change in pull request #9354: URL: https://github.com/apache/airflow/pull/9354#discussion_r446610902
########## File path: airflow/www/views.py ########## @@ -760,22 +760,35 @@ def log(self, session=None): execution_date=execution_date, form=form, root=root, wrapped=conf.getboolean('webserver', 'default_wrap')) - @expose('/elasticsearch') + @expose('/redirect_to_external_log') @has_dag_access(can_dag_read=True) @has_access @action_logging - def elasticsearch(self): + @provide_session + def redirect_to_external_log(self, session=None): dag_id = request.args.get('dag_id') task_id = request.args.get('task_id') execution_date = request.args.get('execution_date') + dttm = timezone.parse(execution_date) try_number = request.args.get('try_number', 1) - elasticsearch_frontend = conf.get('elasticsearch', 'frontend') - log_id_template = conf.get('elasticsearch', 'log_id_template') - log_id = log_id_template.format( - dag_id=dag_id, task_id=task_id, - execution_date=execution_date, try_number=try_number) - url = 'https://' + elasticsearch_frontend.format(log_id=quote(log_id)) - return redirect(url) + + ti = session.query(models.TaskInstance).filter( + models.TaskInstance.dag_id == dag_id, + models.TaskInstance.task_id == task_id, + models.TaskInstance.execution_date == dttm).first() + + if not ti: + flash(f"Task [{dag_id}.{task_id}] does not exist", "error") + return redirect(url_for('Airflow.index')) + + try: + task_log_reader = TaskLogReader() + handler = task_log_reader.log_handler + url = handler.get_external_log_url(ti, try_number) + return redirect(url) + except AttributeError: + flash("Cannot redirect to external log, task log handler is not external", "error") + return redirect(url_for('Airflow.index')) Review comment: ```suggestion task_log_reader = TaskLogReader() if not task_log_reader.supports_external_links: flash("Ttask log handler is not support external links", "error") return redirect(url_for('Airflow.index')) handler = task_log_reader.log_handler url = handler.get_external_log_url(ti, try_number) return redirect(url) ``` This exception here may mean that the handler does not support external links or that a failure occurred while generating links. ---------------------------------------------------------------- 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: us...@infra.apache.org