You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ambari.apache.org by "ASF GitHub Bot (JIRA)" <ji...@apache.org> on 2018/11/01 20:16:00 UTC

[jira] [Commented] (AMBARI-24738) Update grafana datasource to get values from new object

    [ https://issues.apache.org/jira/browse/AMBARI-24738?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16672125#comment-16672125 ] 

ASF GitHub Bot commented on AMBARI-24738:
-----------------------------------------

ishanbha closed pull request #6: [AMBARI-24738] Update grafana datasource to get values from new object.
URL: https://github.com/apache/ambari-metrics/pull/6
 
 
   

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/ambari-metrics-grafana/ambari-metrics/datasource.js b/ambari-metrics-grafana/ambari-metrics/datasource.js
index 9050667..6e14f33 100644
--- a/ambari-metrics-grafana/ambari-metrics/datasource.js
+++ b/ambari-metrics-grafana/ambari-metrics/datasource.js
@@ -484,10 +484,10 @@ define([
             }).map(function (uName) {
               return uName.value;
             });
-            selectedUsers = templateSrv._values.Users.lastIndexOf('}') > 0 ? templateSrv._values.Users.slice(1, -1) :
-              templateSrv._values.Users;
-            var selectedUser = selectedUsers.split(',');
-            _.forEach(selectedUser, function (processUser) {
+            if (selectedUsers[0] === "") {
+              selectedUsers = "";
+            }
+            _.forEach(selectedUsers, function (processUser) {
               metricsPromises.push(_.map(options.targets, function (target) {
                 target.hbUser = processUser;
                 var metricTransform = !target.transform || target.transform === "none" ? '' : '._' + target.transform;
@@ -499,10 +499,18 @@ define([
           // Templatized Dashboard for per-table metrics in HBase.
           if (templateSrv.variables[0].query === "hbase-tables") {
             var splitTables = [];
-            var allTables = templateSrv._values.Tables.lastIndexOf('}') > 0 ? templateSrv._values.Tables.slice(1, -1) :
-              templateSrv._values.Tables;
-            var allTable = allTables.split(',');
-            while (allTable.length > 0) {
+            let allTables = [];
+            const tables = templateSrv.index.Tables.options;
+            for (let table of tables) {
+              if (table.text.toLowerCase() === "all" && table.selected) {
+                allTables = "";
+                break;
+              } else if (table.selected) {
+                allTables.push(table.value);
+              }
+            }
+
+            while (allTables.length > 0) {
               splitTables.push(allTable.splice(0, 20));
             }
             _.forEach(splitTables, function (table) {
@@ -530,10 +538,10 @@ define([
             }).map(function (topicName) {
               return topicName.value;
             });
-            selectedTopics = templateSrv._values.Topics.lastIndexOf('}') > 0 ? templateSrv._values.Topics.slice(1, -1) :
-              templateSrv._values.Topics;
-            var selectedTopic = selectedTopics.split(',');
-            _.forEach(selectedTopic, function (processTopic) {
+            if (selectedTopics[0] === "") {
+              selectedTopics = "";
+            }
+            _.forEach(selectedTopics, function (processTopic) {
               metricsPromises.push(_.map(options.targets, function (target) {
                 target.kbTopic = processTopic;
                 target.kbMetric = target.metric.replace('*', target.kbTopic);
@@ -546,15 +554,17 @@ define([
             var allCallers = templateSrv.variables.filter(function (variable) {
               return variable.query === "callers";
             });
-            var selectedCallers = (_.isEmpty(allCallers)) ? "" : allCallers[0].options.filter(function (user) {
-              return user.selected;
-            }).map(function (callerName) {
-              return callerName.value;
-            });
-            selectedCallers = templateSrv._values.Callers.lastIndexOf('}') > 0 ? templateSrv._values.Callers.slice(1, -1) :
-              templateSrv._values.Callers;
-            var selectedCaller = selectedCallers.split(',');
-            _.forEach(selectedCaller, function (processCaller) {
+            let selectedCallers = [];
+            const callers = templateSrv.index.Callers.options;
+            for (let caller of callers) {
+              if (caller.text.toLowerCase() === "all" && caller.selected) {
+                selectedCallers = "";
+                break;
+              } else if (caller.selected) {
+                selectedCallers.push(caller.text);
+              }
+            }
+            _.forEach(selectedCallers, function (processCaller) {
               metricsPromises.push(_.map(options.targets, function (target) {
                 target.nnCaller = processCaller;
                 target.nnMetric = target.metric.replace('*', target.nnCaller);
@@ -573,10 +583,10 @@ define([
             }).map(function (coreName) {
               return coreName.value;
             });
-            selectedCores = templateSrv._values.Cores.lastIndexOf('}') > 0 ? templateSrv._values.Cores.slice(1, -1) :
-              templateSrv._values.Cores;
-            var selectedCore = selectedCores.split(',');
-            _.forEach(selectedCore, function (processCore) {
+            if (selectedCores[0] === "") {
+              selectedCores = "";
+            }
+            _.forEach(selectedCores, function (processCore) {
               metricsPromises.push(_.map(options.targets, function (target) {
                 target.sCore = processCore;
                 target.sCoreMetric = target.metric.replace('*', target.sCore);
@@ -595,10 +605,10 @@ define([
             }).map(function (collectionsName) {
               return collectionsName.value;
             });
-            selectedCollections = templateSrv._values.Collections.lastIndexOf('}') > 0 ? templateSrv._values.Collections.slice(1, -1) :
-              templateSrv._values.Collections;
-            var selectedCollection = selectedCollections.split(',');
-            _.forEach(selectedCollection, function (processCollection) {
+            if (selectedCollections [0] === "") {
+              selectedCollections = "";
+            }
+            _.forEach(selectedCollections, function (processCollection) {
               metricsPromises.push(_.map(options.targets, function (target) {
                 target.sCollection = processCollection;
                 target.sCollectionMetric = target.metric.replace('*', target.sCollection);
@@ -617,10 +627,10 @@ define([
             }).map(function (topoName) {
               return topoName.value;
             });
-            selectedTopologies = templateSrv._values.topologies.lastIndexOf('}') > 0 ? templateSrv._values.topologies.slice(1, -1) :
-              templateSrv._values.topologies;
-            var selectedTopology = selectedTopologies.split(',');
-            _.forEach(selectedTopology, function (processTopology) {
+            if (selectedTopologies === "") {
+              selectedTopologies = "";
+            }
+            _.forEach(selectedTopologies, function (processTopology) {
               metricsPromises.push(_.map(options.targets, function (target) {
                 target.sTopology = processTopology;
                 target.sTopoMetric = target.metric.replace('*', target.sTopology);
@@ -667,10 +677,10 @@ define([
             }).map(function (dataSourceName) {
               return dataSourceName.value;
             });
-            selectedDataSources = templateSrv._values.druidDataSources.lastIndexOf('}') > 0 ? templateSrv._values.druidDataSources.slice(1, -1) :
-              templateSrv._values.druidDataSources;
-            var selectedDataSource = selectedDataSources.split(',');
-            _.forEach(selectedDataSource, function (processDataSource) {
+            if (selectedDataSources[0] === "") {
+              selectedDataSources = "";
+            }
+            _.forEach(selectedDataSources, function (processDataSource) {
               metricsPromises.push(_.map(options.targets, function (target) {
                 target.sDataSource = processDataSource;
                 target.sDataSourceMetric = target.metric.replace('*', target.sDataSource);
@@ -681,14 +691,21 @@ define([
           // To speed up querying on templatized dashboards.
           var indexOfHosts = -1;
           for (var i = 0; i < templateSrv.variables.length; i++) {
-            if (templateSrv.variables[i].name == 'hosts') {
+            if (templateSrv.variables[i].name == 'hosts' && templateSrv.index.hosts) {
               indexOfHosts = i;
             }
           }
           if (indexOfHosts >= 0) {
-            var allHosts = templateSrv._values.hosts.lastIndexOf('}') > 0 ? templateSrv._values.hosts.slice(1, -1) :
-              templateSrv._values.hosts;
-            allHosts = templateSrv._texts.hosts === "All" ? '%' : allHosts;
+            let allHosts = [];
+            const hosts = templateSrv.index.hosts.options
+            for (let host of hosts) {
+              if (host.text.toLowerCase() === "all" && host.selected) {
+                allHosts = '%';
+                break;
+              } else if (host.selected) {
+                allHosts.push(host.text);
+              }
+            };
             metricsPromises.push(_.map(options.targets, function (target) {
               target.templatedHost = allHosts ? allHosts : '';
               target.templatedCluster = templatedCluster;
diff --git a/ambari-metrics-grafana/ambari-metrics/query_ctrl.js b/ambari-metrics-grafana/ambari-metrics/query_ctrl.js
index 5b5c4a9..77f420d 100644
--- a/ambari-metrics-grafana/ambari-metrics/query_ctrl.js
+++ b/ambari-metrics-grafana/ambari-metrics/query_ctrl.js
@@ -131,7 +131,7 @@ var AmbariMetricsQueryCtrl = /** @class */ (function (_super) {
                 this.target.seriesAggregator = "none";
             }
         };
-        _this.$watch('target.app', function (newValue) {
+        $scope.$watch('target.app', function (newValue) {
             if (newValue === '') {
                 this.target.metric = '';
                 this.target.hosts = '';


 

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


> Update grafana datasource to get values from new object
> -------------------------------------------------------
>
>                 Key: AMBARI-24738
>                 URL: https://issues.apache.org/jira/browse/AMBARI-24738
>             Project: Ambari
>          Issue Type: Task
>          Components: ambari-metrics
>            Reporter: Ishan Bhatt
>            Assignee: Ishan Bhatt
>            Priority: Major
>              Labels: pull-request-available
>             Fix For: trunk
>
>
> In the new grafana version templateSrv doesn't have some fields. We need to get these values from a different fields



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)