mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
refactor: polishing OpenTSDB related PR #1646, added caching of aggregators request so only one call is made
This commit is contained in:
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user