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 2018/12/18 04:20:16 UTC

[GitHub] stale[bot] closed pull request #1922: [AIRFLOW-675] Add error log to UI

stale[bot] closed pull request #1922: [AIRFLOW-675] Add error log to UI
URL: https://github.com/apache/incubator-airflow/pull/1922
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/airflow/www/app.py b/airflow/www/app.py
index c2c180ac9c..5df479e48a 100644
--- a/airflow/www/app.py
+++ b/airflow/www/app.py
@@ -88,6 +88,8 @@ def create_app(config=None, testing=False):
             models.Pool, Session, name="Pools", category="Admin"))
         av(vs.ConfigurationView(
             name='Configuration', category="Admin"))
+        av(vs.ErrorLogView(
+            name='Error Log', category="Admin"))
         av(vs.UserModelView(
             models.User, Session, name="Users", category="Admin"))
         av(vs.ConnectionModelView(
diff --git a/airflow/www/templates/airflow/log.html b/airflow/www/templates/airflow/log.html
new file mode 100644
index 0000000000..50950f3ca7
--- /dev/null
+++ b/airflow/www/templates/airflow/log.html
@@ -0,0 +1,39 @@
+{#
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+
+#}
+{% extends "airflow/master.html" %}
+
+{% block title %}
+    {{ title }}
+{% endblock %}
+
+{% block body %}
+    {{ super() }}
+    <h2>{{ title }}</h2>
+
+    {% if subtitle %}
+        <h5>{{ subtitle }}</h5>
+    {% endif %}
+
+    {% if post_subtitle %}
+        <h5>{{ post_subtitle }}</h5>
+    {% endif %}
+
+    {% if log %}
+        <pre>{{ log }}</pre>
+    {% endif %}
+{% endblock %}
diff --git a/airflow/www/views.py b/airflow/www/views.py
index d22e8e4b3f..8ffd70f912 100644
--- a/airflow/www/views.py
+++ b/airflow/www/views.py
@@ -2620,6 +2620,36 @@ def conf(self):
                 table=table)
 
 
+class ErrorLogView(wwwutils.SuperUserMixin, BaseView):
+    @expose('/')
+    def error_log(self):
+        raw = request.args.get('raw') == "true"
+        title = "Airflow Error Log"
+        log_base = os.path.expanduser(conf.get('core', 'BASE_LOG_FOLDER'))
+        error_log_path = os.path.normpath(log_base + "/error.log")
+        subtitle = "Error log path: " + error_log_path
+        post_subtitle = None
+        error_log = None
+
+        if not (os.path.isfile(error_log_path)):
+            post_subtitle = "The error log file does not exist."
+        elif os.stat(error_log_path).st_size == 0:
+            post_subtitle = "The error log file is empty."
+        else:
+            with open(error_log_path, 'r') as f:
+                error_log = f.read()
+
+        if raw:
+            return Response(
+                response=error_log,
+                status=200,
+                mimetype="application/text")
+        else:
+            return self.render(
+                'airflow/log.html', log=error_log, title=title, subtitle=subtitle,
+                post_subtitle=post_subtitle)
+
+
 class DagModelView(wwwutils.SuperUserMixin, ModelView):
     column_list = ('dag_id', 'owners')
     column_editable_list = ('is_paused',)
diff --git a/tests/core.py b/tests/core.py
index 24315f186b..390639237a 100644
--- a/tests/core.py
+++ b/tests/core.py
@@ -1397,6 +1397,10 @@ def test_dag_views(self):
             '/admin/configurationview/')
         assert "Airflow Configuration" in response.data.decode('utf-8')
         assert "Running Configuration" in response.data.decode('utf-8')
+        response = self.app.get(
+            '/admin/errorlogview/')
+        assert "Airflow Error Log" in response.data.decode('utf-8')
+        assert "Error log path" in response.data.decode('utf-8')
         response = self.app.get(
             '/admin/airflow/rendered?'
             'task_id=runme_1&dag_id=example_bash_operator&'


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on 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