fix CloudWatch dimension value suggestion

This commit is contained in:
Mitsuhiro Tanda 2015-11-10 19:25:59 +09:00
parent 4da99d14e6
commit ef4bec1c6d
3 changed files with 33 additions and 11 deletions

View File

@ -124,13 +124,7 @@ function (angular, _) {
};
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 {value: value, text: value};
}).value();
return _.pluck(result.Metrics, 'Dimensions');
});
};
@ -191,7 +185,20 @@ function (angular, _) {
});
}
return this.getDimensionValues(region, namespace, metricName, dimensions);
return this.getDimensionValues(region, namespace, metricName, dimensions).then(function(result) {
return _.map(result, function(dimensions) {
var values = _.chain(dimensions)
.sortBy(function(dimension) {
return dimension.Name;
})
.map(function(dimension) {
return dimension.Name + '=' + dimension.Value;
})
.value().join(',');
return { text: values };
});
});
}
var ebsVolumeIdsQuery = query.match(/^ebs_volume_ids\(([^,]+?),\s?([^,]+?)\)/);

View File

@ -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;
@ -88,7 +88,22 @@ function (angular, _) {
query = $scope.datasource.getDimensionValues(target.region, target.namespace, target.metricName, {});
}
return query.then($scope.transformToSegments(true)).then(function(results) {
return query.then(function(results) {
if (segment.type === 'value') {
results = _.chain(results)
.flatten(true)
.filter(function(dimension) {
return dimension.Name === templateSrv.replace($scope.dimSegments[$index-2].value);
})
.pluck('Value')
.uniq()
.map(function(value) {
return {value: value, text: value};
})
.value();
}
return $scope.transformToSegments(true)(results);
}).then(function(results) {
if (segment.type === 'key') {
results.splice(0, 0, angular.copy($scope.removeDimSegment));
}

View File

@ -165,7 +165,7 @@ describe('CloudWatchDatasource', function() {
});
it('should call __ListMetrics and return result', () => {
expect(scenario.result[0].text).to.be('i-12345678');
expect(scenario.result[0].text).to.be('InstanceId=i-12345678');
expect(scenario.request.data.action).to.be('ListMetrics');
});
});