Commit 5c556175 by Torkel Ödegaard

refactor: polishing OpenTSDB related PR #1646, added caching of aggregators…

refactor: polishing OpenTSDB related PR #1646, added caching of aggregators request so only one call is made
parent 0e0caabf
......@@ -175,14 +175,17 @@ function (angular, _, dateMath) {
});
};
OpenTSDBDatasource.prototype.performAggregatorsQuery = function() {
return this._get('/api/aggregators', {}).then(function(result) {
if (result.data instanceof Array) {
var aggregatorsPromise = null;
OpenTSDBDatasource.prototype.getAggregators = function() {
if (aggregatorsPromise) { return aggregatorsPromise; }
aggregatorsPromise = this._get('/api/aggregators').then(function(result) {
if (result.data && _.isArray(result.data)) {
return result.data.sort();
} else {
return result.data;
}
return [];
});
return aggregatorsPromise;
};
function transformMetricData(md, groupByTags, target, options) {
......
......@@ -14,12 +14,6 @@ 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';
}
......@@ -27,6 +21,10 @@ function (angular, _, kbn) {
if (!$scope.target.downsampleAggregator) {
$scope.target.downsampleAggregator = 'avg';
}
$scope.datasource.getAggregators().then(function(aggs) {
$scope.aggregators = aggs;
});
};
$scope.targetBlur = function() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment