You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by bb...@apache.org on 2022/04/08 14:55:24 UTC

[airflow] branch main updated: Support log download in task log view (#22804)

This is an automated email from the ASF dual-hosted git repository.

bbovenzi pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/main by this push:
     new b29cbbdc1b Support log download in task log view (#22804)
b29cbbdc1b is described below

commit b29cbbdc1bbc290d67e64aa3a531caf2b9f6846b
Author: Hank Ehly <he...@gmail.com>
AuthorDate: Fri Apr 8 23:55:00 2022 +0900

    Support log download in task log view (#22804)
    
    * Add download button to ti_log view
    
    * Use native anchor tag for ti_log download button
    
    * Replace regex with data attribute
    
    * Update airflow/www/static/js/ti_log.js
    
    Co-authored-by: Brent Bovenzi <br...@gmail.com>
    
    Co-authored-by: Brent Bovenzi <br...@gmail.com>
---
 airflow/www/static/js/ti_log.js           | 24 ++++++++++++++++++++++++
 airflow/www/templates/airflow/ti_log.html |  5 +++--
 2 files changed, 27 insertions(+), 2 deletions(-)

diff --git a/airflow/www/static/js/ti_log.js b/airflow/www/static/js/ti_log.js
index 919c42f9df..7253152384 100644
--- a/airflow/www/static/js/ti_log.js
+++ b/airflow/www/static/js/ti_log.js
@@ -140,6 +140,24 @@ function autoTailingLog(tryNumber, metadata = null, autoTailing = false) {
     ));
   });
 }
+
+function setDownloadUrl(tryNumber) {
+  if (!tryNumber) {
+    // default to the currently selected tab
+    tryNumber = $('#ti_log_try_number_list .active a').data('try-number');
+  }
+  const query = new URLSearchParams({
+    dag_id: dagId,
+    task_id: taskId,
+    execution_date: executionDate,
+    try_number: tryNumber,
+    metadata: 'null',
+    format: 'file',
+  });
+  const url = `${logsWithMetadataUrl}?${query}`;
+  $('#ti_log_download_active').attr('href', url);
+}
+
 $(document).ready(() => {
   // Lazily load all past task instance logs.
   // TODO: We only need to have recursive queries for
@@ -153,4 +171,10 @@ $(document).ready(() => {
     const autoTailing = i === TOTAL_ATTEMPTS;
     autoTailingLog(i, null, autoTailing);
   }
+
+  setDownloadUrl();
+  $('#ti_log_try_number_list a').click(function () {
+    const tryNumber = $(this).data('try-number');
+    setDownloadUrl(tryNumber);
+  });
 });
diff --git a/airflow/www/templates/airflow/ti_log.html b/airflow/www/templates/airflow/ti_log.html
index 6fbf1ea12e..0710e973c0 100644
--- a/airflow/www/templates/airflow/ti_log.html
+++ b/airflow/www/templates/airflow/ti_log.html
@@ -41,10 +41,10 @@
   <h4>{{ title }}</h4>
   <div class="row">
     <div class="col-md-8">
-      <ul class="nav nav-pills" role="tablist">
+      <ul id="ti_log_try_number_list" class="nav nav-pills" role="tablist">
         {% for log in logs %}
           <li role="presentation" class="{{ 'active' if loop.last else '' }}">
-            <a href="#{{ loop.index }}" aria-controls="{{ loop.index }}" role="tab" data-toggle="tab">
+            <a href="#{{ loop.index }}" aria-controls="{{ loop.index }}" role="tab" data-toggle="tab" data-try-number="{{ loop.index }}">
               {{ loop.index }}
             </a>
           </li>
@@ -54,6 +54,7 @@
     <div class="col-md-4 text-right">
       <a class="btn btn-default" onclick="scrollBottomLogs()">Jump To End</a>
       <a class="btn btn-default" onclick="toggleWrapLogs()">Toggle Wrap</a>
+      <a class="btn btn-default" id="ti_log_download_active">Download</a>
     </div>
   </div>
   <div class="tab-content">