From 637c720de5bf7a59263abd3d5b7ea820af313260 Mon Sep 17 00:00:00 2001 From: Harald Kraemer Date: Wed, 30 Apr 2014 09:40:06 +0200 Subject: [PATCH 1/2] Modified metricKeys to handle multiple graphite sources. This wasn't all too hard to change, I mostly changed the single http get to multiple http gets, one for each data source of type graphite. It's still not a good idea to call this on the web frontend, since the whole thing was working for about 20 - 30 minutes when I clicked it, so I'm not committing my changes to settings.js or the view itself. --- src/app/controllers/metricKeys.js | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/app/controllers/metricKeys.js b/src/app/controllers/metricKeys.js index e39d2b43c18..333be68baef 100644 --- a/src/app/controllers/metricKeys.js +++ b/src/app/controllers/metricKeys.js @@ -52,14 +52,16 @@ function (angular, _, config) { $scope.loadAll = function() { $scope.infoText = "Fetching all metrics from graphite..."; - return $http.get(config.graphiteUrl + "/metrics/index.json") - .then(saveMetricsArray) - .then(function () { + return $q.all( _.map( config.datasources, function( datasource ) { + if ( datasource.type = 'graphite' ) { + return $http.get( datasource.url + "/metrics/index.json" ) + .then( saveMetricsArray ); + } + } ) ).then( function() { $scope.infoText = "Indexing complete!"; - }) - .then(null, function(err) { + }).then(null, function(err) { $scope.errorText = err; - }); + }); }; function saveMetricsArray(data, currentIndex) @@ -155,6 +157,7 @@ function (angular, _, config) { function saveMetricKey(metricId) { // Create request with id as title. Rethink this. + console.log( config.grafana_metrics_index, metricId ); var request = $scope.ejs.Document(config.grafana_metrics_index, 'metricKey', metricId).source({ metricPath: metricId }); @@ -177,4 +180,4 @@ function (angular, _, config) { }); -}); \ No newline at end of file +}); From 52e1f5273ceef5b4fee262e90763606eb9c79c64 Mon Sep 17 00:00:00 2001 From: Harald Kraemer Date: Wed, 30 Apr 2014 13:13:51 +0200 Subject: [PATCH 2/2] Extracted multi-graphite query function, fixed loadRecursive The new function in metricKeys generalizes what my loadAll from the previous commit did, it takes a request and a callback. The request is executed on each graphite installation and the callback is executed for each result. This makes implementing loadAll and loadRecursive almost as simple as it was. --- src/app/controllers/metricKeys.js | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/app/controllers/metricKeys.js b/src/app/controllers/metricKeys.js index 333be68baef..fa39bfd4ad3 100644 --- a/src/app/controllers/metricKeys.js +++ b/src/app/controllers/metricKeys.js @@ -52,18 +52,23 @@ function (angular, _, config) { $scope.loadAll = function() { $scope.infoText = "Fetching all metrics from graphite..."; - return $q.all( _.map( config.datasources, function( datasource ) { - if ( datasource.type = 'graphite' ) { - return $http.get( datasource.url + "/metrics/index.json" ) - .then( saveMetricsArray ); - } - } ) ).then( function() { + getFromEachGraphite( '/metrics/index.json', saveMetricsArray ) + .then( function() { $scope.infoText = "Indexing complete!"; - }).then(null, function(err) { + }).then(null, function(err) { $scope.errorText = err; - }); + }); }; + function getFromEachGraphite( request, data_callback, error_callback ) { + return $q.all( _.map( config.datasources, function( datasource ) { + if ( datasource.type = 'graphite' ) { + return $http.get( datasource.url + request ) + .then( data_callback, error_callback ); + } + } ) ); + } + function saveMetricsArray(data, currentIndex) { if (!data && !data.data && data.data.length === 0) { @@ -82,6 +87,7 @@ function (angular, _, config) { }); } + function deleteIndex() { var deferred = $q.defer(); @@ -157,7 +163,6 @@ function (angular, _, config) { function saveMetricKey(metricId) { // Create request with id as title. Rethink this. - console.log( config.grafana_metrics_index, metricId ); var request = $scope.ejs.Document(config.grafana_metrics_index, 'metricKey', metricId).source({ metricPath: metricId }); @@ -175,7 +180,7 @@ function (angular, _, config) { function loadMetricsRecursive(metricPath) { - return $http.get(config.graphiteUrl + '/metrics/find/?query=' + metricPath).then(receiveMetric); + return getFromEachGraphite( '/metrics/find/?query=' + metricPath, receiveMetric ); } });