From b01b121a4b573eff975b33bfe239044459c392db Mon Sep 17 00:00:00 2001 From: Mike Kobyakov Date: Wed, 25 Mar 2015 14:32:26 -0700 Subject: [PATCH 1/4] Instead of hard-coding the OpenTsdb aggregators list, pull the supported aggregators from the datasource directly. --- .../app/plugins/datasource/opentsdb/datasource.js | 14 ++++++++++++++ .../app/plugins/datasource/opentsdb/queryCtrl.js | 6 ++++++ 2 files changed, 20 insertions(+) diff --git a/public/app/plugins/datasource/opentsdb/datasource.js b/public/app/plugins/datasource/opentsdb/datasource.js index cd0c83b7c1d..8e59b71c551 100644 --- a/public/app/plugins/datasource/opentsdb/datasource.js +++ b/public/app/plugins/datasource/opentsdb/datasource.js @@ -90,6 +90,20 @@ function (angular, _, kbn) { }); }; + OpenTSDBDatasource.prototype.performAggregatorsQuery = function() { + var options = { + method: 'GET', + url: this.url + '/api/aggregators' + }; + return $http(options).then(function(result) { + if (result.data instanceof Array) { + return result.data.sort(); + } else { + return result.data; + } + }); + }; + function transformMetricData(md, groupByTags, options) { var metricLabel = createMetricLabel(md, options, groupByTags); var dps = []; diff --git a/public/app/plugins/datasource/opentsdb/queryCtrl.js b/public/app/plugins/datasource/opentsdb/queryCtrl.js index 576517a50b6..f62165e997a 100644 --- a/public/app/plugins/datasource/opentsdb/queryCtrl.js +++ b/public/app/plugins/datasource/opentsdb/queryCtrl.js @@ -14,6 +14,12 @@ function (angular, _, kbn) { $scope.target.errors = validateTarget($scope.target); $scope.aggregators = ['avg', 'sum', 'min', 'max', 'dev', 'zimsum', 'mimmin', 'mimmax']; + $scope.datasource.performAggregatorsQuery().then(function(result) { + if (result) { + $scope.aggregators = result; + } + }); + if (!$scope.target.aggregator) { $scope.target.aggregator = 'sum'; } From e395211654a8ca2a258b04d23dd6e7ff2d2792fd Mon Sep 17 00:00:00 2001 From: Mike Kobyakov Date: Wed, 25 Mar 2015 14:32:26 -0700 Subject: [PATCH 2/4] Instead of hard-coding the OpenTsdb aggregators list, pull the supported aggregators from the datasource directly. --- .../app/plugins/datasource/opentsdb/datasource.js | 14 ++++++++++++++ .../app/plugins/datasource/opentsdb/queryCtrl.js | 6 ++++++ 2 files changed, 20 insertions(+) diff --git a/public/app/plugins/datasource/opentsdb/datasource.js b/public/app/plugins/datasource/opentsdb/datasource.js index 936500be0f0..5fe53c59e17 100644 --- a/public/app/plugins/datasource/opentsdb/datasource.js +++ b/public/app/plugins/datasource/opentsdb/datasource.js @@ -90,6 +90,20 @@ function (angular, _, kbn) { }); }; + OpenTSDBDatasource.prototype.performAggregatorsQuery = function() { + var options = { + method: 'GET', + url: this.url + '/api/aggregators' + }; + return $http(options).then(function(result) { + if (result.data instanceof Array) { + return result.data.sort(); + } else { + return result.data; + } + }); + }; + function transformMetricData(md, groupByTags, options) { var metricLabel = createMetricLabel(md, options, groupByTags); var dps = []; diff --git a/public/app/plugins/datasource/opentsdb/queryCtrl.js b/public/app/plugins/datasource/opentsdb/queryCtrl.js index 576517a50b6..f62165e997a 100644 --- a/public/app/plugins/datasource/opentsdb/queryCtrl.js +++ b/public/app/plugins/datasource/opentsdb/queryCtrl.js @@ -14,6 +14,12 @@ function (angular, _, kbn) { $scope.target.errors = validateTarget($scope.target); $scope.aggregators = ['avg', 'sum', 'min', 'max', 'dev', 'zimsum', 'mimmin', 'mimmax']; + $scope.datasource.performAggregatorsQuery().then(function(result) { + if (result) { + $scope.aggregators = result; + } + }); + if (!$scope.target.aggregator) { $scope.target.aggregator = 'sum'; } From eb88a532231923cf099d4c3625773b7524675f29 Mon Sep 17 00:00:00 2001 From: Mike Kobyakov Date: Fri, 10 Jul 2015 16:09:08 -0700 Subject: [PATCH 3/4] fix for a change in datasource object --- public/app/plugins/datasource/opentsdb/datasource.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/public/app/plugins/datasource/opentsdb/datasource.js b/public/app/plugins/datasource/opentsdb/datasource.js index 9ac32802d46..2a5ca425ea3 100644 --- a/public/app/plugins/datasource/opentsdb/datasource.js +++ b/public/app/plugins/datasource/opentsdb/datasource.js @@ -173,11 +173,7 @@ function (angular, _, kbn) { }; OpenTSDBDatasource.prototype.performAggregatorsQuery = function() { - var options = { - method: 'GET', - url: this.url + '/api/aggregators' - }; - return $http(options).then(function(result) { + return this._get('/api/aggregators', {}).then(function(result) { if (result.data instanceof Array) { return result.data.sort(); } else { From f76374cd8f59caf08fd7cf581710317e1b2be6b4 Mon Sep 17 00:00:00 2001 From: Mike Kobyakov Date: Wed, 15 Jul 2015 12:03:22 -0700 Subject: [PATCH 4/4] fix testDatasource, which was calling performSuggestQuery instead of _performSuggestQuery --- public/app/plugins/datasource/opentsdb/datasource.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/app/plugins/datasource/opentsdb/datasource.js b/public/app/plugins/datasource/opentsdb/datasource.js index 2a5ca425ea3..bac88117204 100644 --- a/public/app/plugins/datasource/opentsdb/datasource.js +++ b/public/app/plugins/datasource/opentsdb/datasource.js @@ -167,7 +167,7 @@ function (angular, _, kbn) { }; OpenTSDBDatasource.prototype.testDatasource = function() { - return this.performSuggestQuery('cpu', 'metrics').then(function () { + return this._performSuggestQuery('cpu', 'metrics').then(function () { return { status: "success", message: "Data source is working", title: "Success" }; }); };