mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Merge pull request #3205 from mtanda/cloudwatch_suggest_fix
(cloudwatch) fix dimension value suggestion
This commit is contained in:
@@ -113,23 +113,28 @@ function (angular, _) {
|
||||
});
|
||||
};
|
||||
|
||||
CloudWatchDatasource.prototype.getDimensionValues = function(region, namespace, metricName, dimensions) {
|
||||
CloudWatchDatasource.prototype.getDimensionValues = function(region, namespace, metricName, dimensionKey, filterDimensions) {
|
||||
var request = {
|
||||
region: templateSrv.replace(region),
|
||||
action: 'ListMetrics',
|
||||
parameters: {
|
||||
namespace: templateSrv.replace(namespace),
|
||||
metricName: templateSrv.replace(metricName),
|
||||
dimensions: convertDimensionFormat(dimensions, {}),
|
||||
dimensions: convertDimensionFormat(filterDimensions, {}),
|
||||
}
|
||||
};
|
||||
|
||||
return this.awsRequest(request).then(function(result) {
|
||||
return _.chain(result.Metrics).map(function(metric) {
|
||||
return _.pluck(metric.Dimensions, 'Value');
|
||||
}).flatten().uniq().sortBy(function(name) {
|
||||
return name;
|
||||
}).map(function(value) {
|
||||
return _.chain(result.Metrics)
|
||||
.pluck('Dimensions')
|
||||
.flatten()
|
||||
.filter(function(dimension) {
|
||||
return dimension.Name === dimensionKey;
|
||||
})
|
||||
.pluck('Value')
|
||||
.uniq()
|
||||
.sortBy()
|
||||
.map(function(value) {
|
||||
return {value: value, text: value};
|
||||
}).value();
|
||||
});
|
||||
@@ -174,25 +179,14 @@ function (angular, _) {
|
||||
return this.getDimensionKeys(dimensionKeysQuery[1]);
|
||||
}
|
||||
|
||||
var dimensionValuesQuery = query.match(/^dimension_values\(([^,]+?),\s?([^,]+?),\s?([^,]+?)(,\s?([^)]*))?\)/);
|
||||
var dimensionValuesQuery = query.match(/^dimension_values\(([^,]+?),\s?([^,]+?),\s?([^,]+?),\s?([^,]+?)\)/);
|
||||
if (dimensionValuesQuery) {
|
||||
region = templateSrv.replace(dimensionValuesQuery[1]);
|
||||
namespace = templateSrv.replace(dimensionValuesQuery[2]);
|
||||
metricName = templateSrv.replace(dimensionValuesQuery[3]);
|
||||
var dimensionPart = templateSrv.replace(dimensionValuesQuery[5]);
|
||||
var dimensionKey = templateSrv.replace(dimensionValuesQuery[4]);
|
||||
|
||||
var dimensions = {};
|
||||
if (!_.isEmpty(dimensionPart)) {
|
||||
_.each(dimensionPart.split(','), function(v) {
|
||||
var t = v.split('=');
|
||||
if (t.length !== 2) {
|
||||
throw new Error('Invalid query format');
|
||||
}
|
||||
dimensions[t[0]] = t[1];
|
||||
});
|
||||
}
|
||||
|
||||
return this.getDimensionValues(region, namespace, metricName, dimensions);
|
||||
return this.getDimensionValues(region, namespace, metricName, dimensionKey, {});
|
||||
}
|
||||
|
||||
var ebsVolumeIdsQuery = query.match(/^ebs_volume_ids\(([^,]+?),\s?([^,]+?)\)/);
|
||||
@@ -222,7 +216,7 @@ function (angular, _) {
|
||||
var metricName = 'EstimatedCharges';
|
||||
var dimensions = {};
|
||||
|
||||
return this.getDimensionValues(region, namespace, metricName, dimensions).then(function () {
|
||||
return this.getDimensionValues(region, namespace, metricName, 'ServiceName', dimensions).then(function () {
|
||||
return { status: 'success', message: 'Data source is working', title: 'Success' };
|
||||
});
|
||||
};
|
||||
|
||||
@@ -76,7 +76,7 @@ function (angular, _) {
|
||||
}
|
||||
};
|
||||
|
||||
$scope.getDimSegments = function(segment) {
|
||||
$scope.getDimSegments = function(segment, $index) {
|
||||
if (segment.type === 'operator') { return $q.when([]); }
|
||||
|
||||
var target = $scope.target;
|
||||
@@ -85,7 +85,8 @@ function (angular, _) {
|
||||
if (segment.type === 'key' || segment.type === 'plus-button') {
|
||||
query = $scope.datasource.getDimensionKeys($scope.target.namespace);
|
||||
} else if (segment.type === 'value') {
|
||||
query = $scope.datasource.getDimensionValues(target.region, target.namespace, target.metricName, {});
|
||||
var dimensionKey = $scope.dimSegments[$index-2].value;
|
||||
query = $scope.datasource.getDimensionValues(target.region, target.namespace, target.metricName, dimensionKey, {});
|
||||
}
|
||||
|
||||
return query.then($scope.transformToSegments(true)).then(function(results) {
|
||||
|
||||
@@ -165,7 +165,7 @@ describe('CloudWatchDatasource', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describeMetricFindQuery('dimension_values(us-east-1,AWS/EC2,CPUUtilization)', scenario => {
|
||||
describeMetricFindQuery('dimension_values(us-east-1,AWS/EC2,CPUUtilization,InstanceId)', scenario => {
|
||||
scenario.setup(() => {
|
||||
scenario.requestResponse = {
|
||||
Metrics: [
|
||||
|
||||
Reference in New Issue
Block a user