mik-laj commented on a change in pull request #9354:
URL: https://github.com/apache/airflow/pull/9354#discussion_r446086992



##########
File path: airflow/www/views.py
##########
@@ -760,22 +761,33 @@ 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()
+
+        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 as e:
+            error_message = [
+                f"Task log handler does not support external log 
URLs.\n{str(e)}\n"
+            ]
+            return jsonify(message=error_message, error=True)

Review comment:
       I am not sure if this is the correct response format. This is not an 
API, but a view for the end-user, so the response should be text/html.




----------------------------------------------------------------
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]


Reply via email to