mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
change behavior of dimension value suggestion
This commit is contained in:
@@ -271,7 +271,7 @@ function (angular, _, kbn) {
|
|||||||
return this.supportedDimensions[namespace] || [];
|
return this.supportedDimensions[namespace] || [];
|
||||||
};
|
};
|
||||||
|
|
||||||
CloudWatchDatasource.prototype.performSuggestDimensionValues = function(region, namespace, metricName, dimensions, targetDimensionKey) {
|
CloudWatchDatasource.prototype.performSuggestDimensionValues = function(region, namespace, metricName, dimensions) {
|
||||||
var cloudwatch = this.getCloudWatchClient(region);
|
var cloudwatch = this.getCloudWatchClient(region);
|
||||||
|
|
||||||
var params = {
|
var params = {
|
||||||
@@ -298,15 +298,6 @@ function (angular, _, kbn) {
|
|||||||
.map(function(metric) {
|
.map(function(metric) {
|
||||||
return metric.Dimensions;
|
return metric.Dimensions;
|
||||||
})
|
})
|
||||||
.flatten(true)
|
|
||||||
.filter(function(dimension) {
|
|
||||||
return dimension.Name === targetDimensionKey;
|
|
||||||
})
|
|
||||||
.map(function(metric) {
|
|
||||||
return metric;
|
|
||||||
})
|
|
||||||
.pluck('Value')
|
|
||||||
.uniq()
|
|
||||||
.value();
|
.value();
|
||||||
|
|
||||||
return d.resolve(suggestData);
|
return d.resolve(suggestData);
|
||||||
@@ -319,7 +310,6 @@ function (angular, _, kbn) {
|
|||||||
var region;
|
var region;
|
||||||
var namespace;
|
var namespace;
|
||||||
var metricName;
|
var metricName;
|
||||||
var dimensions;
|
|
||||||
|
|
||||||
var transformSuggestData = function(suggestData) {
|
var transformSuggestData = function(suggestData) {
|
||||||
return _.map(suggestData, function(v) {
|
return _.map(suggestData, function(v) {
|
||||||
@@ -355,16 +345,28 @@ function (angular, _, kbn) {
|
|||||||
return d.promise;
|
return d.promise;
|
||||||
}
|
}
|
||||||
|
|
||||||
var dimensionValuesQuery = query.match(/^dimension_values\(([^,]+?),\s?([^,]+?),\s?([^,]+?),\s?([^,]+?)\)/);
|
var dimensionValuesQuery = query.match(/^dimension_values\(([^,]+?),\s?([^,]+?),\s?([^,]+?)\)/);
|
||||||
if (dimensionValuesQuery) {
|
if (dimensionValuesQuery) {
|
||||||
region = dimensionValuesQuery[1];
|
region = dimensionValuesQuery[1];
|
||||||
namespace = dimensionValuesQuery[2];
|
namespace = dimensionValuesQuery[2];
|
||||||
metricName = dimensionValuesQuery[3];
|
metricName = dimensionValuesQuery[3];
|
||||||
dimensions = {};
|
var dimensions = {};
|
||||||
var targetDimensionKey = dimensionValuesQuery[4];
|
|
||||||
|
|
||||||
return this.performSuggestDimensionValues(region, namespace, metricName, dimensions, targetDimensionKey)
|
return this.performSuggestDimensionValues(region, namespace, metricName, dimensions)
|
||||||
.then(transformSuggestData);
|
.then(function(suggestData) {
|
||||||
|
return _.map(suggestData, function(dimensions) {
|
||||||
|
var result = _.chain(dimensions)
|
||||||
|
.sortBy(function(dimension) {
|
||||||
|
return dimension.Name;
|
||||||
|
})
|
||||||
|
.map(function(dimension) {
|
||||||
|
return dimension.Name + '=' + dimension.Value;
|
||||||
|
})
|
||||||
|
.value().join(',');
|
||||||
|
|
||||||
|
return { text: result };
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return $q.when([]);
|
return $q.when([]);
|
||||||
@@ -376,9 +378,8 @@ function (angular, _, kbn) {
|
|||||||
var namespace = 'AWS/Billing';
|
var namespace = 'AWS/Billing';
|
||||||
var metricName = 'EstimatedCharges';
|
var metricName = 'EstimatedCharges';
|
||||||
var dimensions = {};
|
var dimensions = {};
|
||||||
var targetDimensionKey = 'ServiceName';
|
|
||||||
|
|
||||||
return this.performSuggestDimensionValues(region, namespace, metricName, dimensions, targetDimensionKey).then(function () {
|
return this.performSuggestDimensionValues(region, namespace, metricName, dimensions).then(function () {
|
||||||
return { status: 'success', message: 'Data source is working', title: 'Success' };
|
return { status: 'success', message: 'Data source is working', title: 'Success' };
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -64,11 +64,19 @@ function (angular, _) {
|
|||||||
$scope.target.region,
|
$scope.target.region,
|
||||||
$scope.target.namespace,
|
$scope.target.namespace,
|
||||||
$scope.target.metricName,
|
$scope.target.metricName,
|
||||||
$scope.target.dimensions,
|
$scope.target.dimensions
|
||||||
$scope.target.currentDimensionKey
|
|
||||||
)
|
)
|
||||||
.then(function(result) {
|
.then(function(result) {
|
||||||
callback(result);
|
var suggestData = _.chain(result)
|
||||||
|
.flatten(true)
|
||||||
|
.filter(function(dimension) {
|
||||||
|
return dimension.Name === $scope.target.currentDimensionKey;
|
||||||
|
})
|
||||||
|
.pluck('Value')
|
||||||
|
.uniq()
|
||||||
|
.value();
|
||||||
|
|
||||||
|
callback(suggestData);
|
||||||
}, function() {
|
}, function() {
|
||||||
callback([]);
|
callback([]);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user