Ver Fonte

HUE-8651 [frontend] Add an execution analysis component

Johan Ahlen há 7 anos atrás
pai
commit
d4b188f41d

Diff do ficheiro suprimidas por serem muito extensas
+ 0 - 0
desktop/core/src/desktop/static/desktop/css/hue-embedded.css


Diff do ficheiro suprimidas por serem muito extensas
+ 0 - 0
desktop/core/src/desktop/static/desktop/css/hue.css


Diff do ficheiro suprimidas por serem muito extensas
+ 0 - 0
desktop/core/src/desktop/static/desktop/css/hue3-extra.css


+ 24 - 0
desktop/core/src/desktop/static/desktop/less/components/hue-execution-analysis.less

@@ -0,0 +1,24 @@
+/*
+ Licensed to Cloudera, Inc. under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  Cloudera, Inc. 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.
+*/
+
+.hue-execution-analysis {
+
+  .no-analysis {
+    font-style: italic;
+  }
+}

+ 0 - 27
desktop/core/src/desktop/static/desktop/less/hue-assist.less

@@ -803,33 +803,6 @@
       .nowrap-ellipsis();
       .nowrap-ellipsis();
     }
     }
   }
   }
-
-  .risk-list {
-    list-style: none;
-    margin: 0 0 0 10px;
-
-    .risk-list-high {
-      color: @cui-red-700;
-    }
-
-    .risk-list-normal {
-      color: @cui-orange-700;
-    }
-
-    .risk-list-title {
-      white-space: normal;
-    }
-
-    .risk-list-description {
-      margin-left:5px;
-      white-space: normal;
-      font-style: italic;
-    }
-
-    .risk-quickfix {
-      margin-left: 5px;
-    }
-  }
 }
 }
 
 
 .assist-preloader-wrapper {
 .assist-preloader-wrapper {

+ 1 - 0
desktop/core/src/desktop/static/desktop/less/hue-cross-version.less

@@ -22,6 +22,7 @@
 @import "components/hue-catalog-entries-table.less";
 @import "components/hue-catalog-entries-table.less";
 @import "components/hue-demi-modal.less";
 @import "components/hue-demi-modal.less";
 @import "components/hue-dw-sidebar.less";
 @import "components/hue-dw-sidebar.less";
+@import "components/hue-execution-analysis.less";
 @import "components/hue-filechooser.less";
 @import "components/hue-filechooser.less";
 @import "components/hue-gridster.less";
 @import "components/hue-gridster.less";
 @import "components/hue-inputautocomplete.less";
 @import "components/hue-inputautocomplete.less";

+ 27 - 0
desktop/core/src/desktop/static/desktop/less/hue4.less

@@ -793,6 +793,33 @@ a:visited {
   background-color: @hue-primary-color-dark !important;
   background-color: @hue-primary-color-dark !important;
 }
 }
 
 
+.risk-list {
+  list-style: none;
+  margin: 0 0 0 10px;
+
+  .risk-list-high {
+    color: @cui-red-700;
+  }
+
+  .risk-list-normal {
+    color: @cui-orange-700;
+  }
+
+  .risk-list-title {
+    white-space: normal;
+  }
+
+  .risk-list-description {
+    margin-left: 5px;
+    white-space: normal;
+    font-style: italic;
+  }
+
+  .risk-quickfix {
+    margin-left: 5px;
+  }
+}
+
 #importerComponents {
 #importerComponents {
   .step-indicator-fixed {
   .step-indicator-fixed {
     position: static!important;
     position: static!important;

+ 8 - 6
desktop/core/src/desktop/templates/ko_components.mako

@@ -19,8 +19,11 @@
 <%namespace name="koCatalogEntriesTable" file="/ko_components/ko_catalog_entries_table.mako" />
 <%namespace name="koCatalogEntriesTable" file="/ko_components/ko_catalog_entries_table.mako" />
 <%namespace name="koContextPopover" file="/ko_components/ko_context_popover.mako" />
 <%namespace name="koContextPopover" file="/ko_components/ko_context_popover.mako" />
 <%namespace name="koContextSelector" file="/ko_components/ko_context_selector.mako" />
 <%namespace name="koContextSelector" file="/ko_components/ko_context_selector.mako" />
+<%namespace name="koCreateDirModal" file="/ko_components/ko_create_directory_modal.mako" />
+<%namespace name="koDeleteDocModal" file="/ko_components/ko_delete_doc_modal.mako" />
 <%namespace name="koDropDown" file="/ko_components/ko_drop_down.mako" />
 <%namespace name="koDropDown" file="/ko_components/ko_drop_down.mako" />
 <%namespace name="koDwSidebar" file="/ko_components/ko_dw_sidebar.mako" />
 <%namespace name="koDwSidebar" file="/ko_components/ko_dw_sidebar.mako" />
+<%namespace name="koExecutionAnalysis" file="/ko_components/ko_execution_analysis.mako" />
 <%namespace name="koFavoriteApp" file="/ko_components/ko_favorite_app.mako" />
 <%namespace name="koFavoriteApp" file="/ko_components/ko_favorite_app.mako" />
 <%namespace name="koGlobalSearch" file="/ko_components/ko_global_search.mako" />
 <%namespace name="koGlobalSearch" file="/ko_components/ko_global_search.mako" />
 <%namespace name="koHistoryPanel" file="/ko_components/ko_history_panel.mako" />
 <%namespace name="koHistoryPanel" file="/ko_components/ko_history_panel.mako" />
@@ -29,11 +32,9 @@
 <%namespace name="koMultiClusterSidebar" file="/ko_components/ko_multi_cluster_sidebar.mako" />
 <%namespace name="koMultiClusterSidebar" file="/ko_components/ko_multi_cluster_sidebar.mako" />
 <%namespace name="koNavProperties" file="/ko_components/ko_nav_properties.mako" />
 <%namespace name="koNavProperties" file="/ko_components/ko_nav_properties.mako" />
 <%namespace name="koNavTags" file="/ko_components/ko_nav_tags.mako" />
 <%namespace name="koNavTags" file="/ko_components/ko_nav_tags.mako" />
+<%namespace name="koSentryPrivileges" file="/ko_components/ko_sentry_privileges.mako" />
 <%namespace name="koSimpleAceEditor" file="/ko_components/ko_simple_ace_editor.mako" />
 <%namespace name="koSimpleAceEditor" file="/ko_components/ko_simple_ace_editor.mako" />
 <%namespace name="koSqlColumnsTable" file="/ko_components/ko_sql_columns_table.mako" />
 <%namespace name="koSqlColumnsTable" file="/ko_components/ko_sql_columns_table.mako" />
-<%namespace name="koDeleteDocModal" file="/ko_components/ko_delete_doc_modal.mako" />
-<%namespace name="koSentryPrivileges" file="/ko_components/ko_sentry_privileges.mako" />
-<%namespace name="koCreateDirModal" file="/ko_components/ko_create_directory_modal.mako" />
 
 
 <%def name="all()">
 <%def name="all()">
   ${ koAppSwitcher.appSwitcher() }
   ${ koAppSwitcher.appSwitcher() }
@@ -41,8 +42,11 @@
   ${ koCatalogEntriesTable.catalogEntriesTable() }
   ${ koCatalogEntriesTable.catalogEntriesTable() }
   ${ koContextPopover.contextPopover() }
   ${ koContextPopover.contextPopover() }
   ${ koContextSelector.contextSelector() }
   ${ koContextSelector.contextSelector() }
+  ${ koCreateDirModal.createDirectory() }
+  ${ koDeleteDocModal.deleteDoc() }
   ${ koDropDown.dropDown() }
   ${ koDropDown.dropDown() }
   ${ koDwSidebar.dwSidebar() }
   ${ koDwSidebar.dwSidebar() }
+  ${ koExecutionAnalysis.executionAnalysis() }
   ${ koFavoriteApp.favoriteApp() }
   ${ koFavoriteApp.favoriteApp() }
   ${ koGlobalSearch.globalSearch() }
   ${ koGlobalSearch.globalSearch() }
   ${ koHistoryPanel.historyPanel() }
   ${ koHistoryPanel.historyPanel() }
@@ -51,9 +55,7 @@
   ${ koMultiClusterSidebar.multiClusterSidebar() }
   ${ koMultiClusterSidebar.multiClusterSidebar() }
   ${ koNavProperties.navProperties() }
   ${ koNavProperties.navProperties() }
   ${ koNavTags.navTags() }
   ${ koNavTags.navTags() }
+  ${ koSentryPrivileges.sentryPrivileges() }
   ${ koSimpleAceEditor.simpleAceEditor() }
   ${ koSimpleAceEditor.simpleAceEditor() }
   ${ koSqlColumnsTable.sqlColumnsTable() }
   ${ koSqlColumnsTable.sqlColumnsTable() }
-  ${ koDeleteDocModal.deleteDoc() }
-  ${ koSentryPrivileges.sentryPrivileges() }
-  ${ koCreateDirModal.createDirectory() }
 </%def>
 </%def>

+ 126 - 0
desktop/core/src/desktop/templates/ko_components/ko_execution_analysis.mako

@@ -0,0 +1,126 @@
+## Licensed to Cloudera, Inc. under one
+## or more contributor license agreements.  See the NOTICE file
+## distributed with this work for additional information
+## regarding copyright ownership.  Cloudera, Inc. 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.
+
+<%!
+from django.utils.translation import ugettext as _
+
+from notebook.conf import ENABLE_QUERY_SCHEDULING
+
+from desktop.conf import IS_EMBEDDED, IS_MULTICLUSTER_ONLY
+from desktop.lib.i18n import smart_unicode
+from desktop.views import _ko
+%>
+
+<%def name="executionAnalysis()">
+  <script type="text/html" id="health-check-details-content">
+    <div data-bind="text: description"></div>
+  </script>
+
+  <script type="text/html" id="health-check-details-title">
+    <span data-bind="text: name"></span>
+  </script>
+
+  <script type="text/html" id="hue-execution-analysis-template">
+    <div class="hue-execution-analysis">
+      <!-- ko hueSpinner: { spin: loading, inline: true } --><!-- /ko -->
+      <!-- ko ifnot: loading -->
+        <!-- ko if: analysisPossible() && !analysis() -->
+        <div class="no-analysis">${ _('Execute a query to get query execution analysis.') }</div>
+        <!-- /ko -->
+        <!-- ko ifnot: analysisPossible -->
+        ## TODO: This should be removed once we have the proper analysis conditions,
+        ##       it's better to not show the execution analysis tab in the first place.
+        <div class="no-analysis">${ _('Analysis was not possible for the executed query.') }</div>
+        <!-- /ko -->
+        <!-- ko with: analysis -->
+        <ul class="risk-list" data-bind="foreach: healthChecks">
+          <li data-bind="templatePopover : { placement: 'right', contentTemplate: 'health-check-details-content', titleTemplate: 'health-check-details-title', minWidth: '320px', trigger: 'hover' }">
+            <div class="risk-list-title risk-list-normal"><span data-bind="text: name"></span></div>
+          </li>
+        </ul>
+        <!-- /ko -->
+      <!-- /ko -->
+    </div>
+  </script>
+
+  <script type="text/javascript">
+    (function () {
+      var ExecutionAnalysis = function (params) {
+        var self = this;
+        self.disposals = [];
+
+        self.loading = ko.observable(false);
+        self.analysis = ko.observable();
+        self.analysisPossible = ko.observable(true);
+
+        self.lastAnalysisPromise = undefined;
+
+        var clearAnalysisSub = huePubSub.subscribe('editor.clear.execution.analysis', function() {
+          if (!HAS_WORKLOAD_ANALYTICS) {
+            return;
+          }
+          if (self.lastAnalysisPromise) {
+            self.lastAnalysisPromise.cancel();
+          }
+          self.analysis(undefined);
+        });
+
+        var executionAnalysisSub = huePubSub.subscribe('editor.update.execution.analysis', function (details) {
+          if (!HAS_WORKLOAD_ANALYTICS) {
+            return;
+          }
+          if (details.analysisPossible) {
+            self.analysisPossible(true);
+            self.loadAnalysis(details.compute, details.queryId);
+          } else {
+            self.analysisPossible(false);
+          }
+        });
+
+        self.disposals.push(function () {
+          clearAnalysisSub.remove();
+          executionAnalysisSub.remove();
+        });
+      };
+
+      ExecutionAnalysis.prototype.loadAnalysis = function (compute, queryId) {
+        var self = this;
+        self.loading(true);
+        self.lastAnalysisPromise = ApiHelper.getInstance().fetchQueryExecutionAnalysis({
+          silenceErrors: true,
+          compute: compute,
+          queryId: queryId
+        }).done(function (response) {
+          self.analysis(response.query)
+        }).always(function () {
+          self.loading(false);
+        });
+      };
+
+      ExecutionAnalysis.prototype.dispose = function () {
+        var self = this;
+        while (self.disposals.length) {
+          self.disposals.pop()();
+        }
+      };
+
+      ko.components.register('hue-execution-analysis', {
+        viewModel: ExecutionAnalysis,
+        template: { element: 'hue-execution-analysis-template' }
+      });
+    })();
+  </script>
+</%def>

+ 7 - 2
desktop/libs/notebook/src/notebook/static/notebook/js/notebook.ko.js

@@ -1427,7 +1427,7 @@ var EditorViewModel = (function() {
       }
       }
 
 
       if (self.type() === 'impala') {
       if (self.type() === 'impala') {
-        huePubSub.publish('assist.clear.execution.analysis');
+        huePubSub.publish('editor.clear.execution.analysis');
       }
       }
 
 
       self.status('running');
       self.status('running');
@@ -1876,11 +1876,16 @@ var EditorViewModel = (function() {
               if (self.type() === 'impala' && self.compute() && self.compute().crn && self.compute().crn.indexOf('altus') !== -1) {
               if (self.type() === 'impala' && self.compute() && self.compute().crn && self.compute().crn.indexOf('altus') !== -1) {
 
 
                 // TODO: Use real query ID
                 // TODO: Use real query ID
-                huePubSub.publish('assist.update.execution.analysis', {
+                huePubSub.publish('editor.update.execution.analysis', {
+                  analysisPossible: true,
                   compute: self.compute(),
                   compute: self.compute(),
                   queryId: '56433486cd84d475:3a86f97000000000'
                   queryId: '56433486cd84d475:3a86f97000000000'
                 });
                 });
 
 
+              } else {
+                huePubSub.publish('editor.update.execution.analysis', {
+                  analysisPossible: false
+                });
               }
               }
               self.fetchResult(100);
               self.fetchResult(100);
               self.progress(100);
               self.progress(100);

Alguns ficheiros não foram mostrados porque muitos ficheiros mudaram neste diff