mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
feat(cloudwatch): restored dimension keys lookup
This commit is contained in:
@@ -104,8 +104,12 @@ function (angular, _) {
|
||||
};
|
||||
|
||||
CloudWatchDatasource.prototype.getDimensionKeys = function(namespace) {
|
||||
namespace = templateSrv.replace(namespace);
|
||||
return $q.when(this.supportedDimensions[namespace] || []);
|
||||
return this.awsRequest({
|
||||
action: '__GetDimensions',
|
||||
parameters: {
|
||||
namespace: templateSrv.replace(namespace)
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
CloudWatchDatasource.prototype.getDimensionValues = function(region, namespace, metricName, dimensions) {
|
||||
@@ -120,6 +124,7 @@ function (angular, _) {
|
||||
};
|
||||
|
||||
return this.awsRequest(request).then(function(result) {
|
||||
console.log(result);
|
||||
return _.chain(result.Metrics).map(function(metric) {
|
||||
return _.pluck(metric.Dimensions, 'Value');
|
||||
}).flatten().uniq().sortBy(function(name) {
|
||||
@@ -167,8 +172,7 @@ function (angular, _) {
|
||||
|
||||
var dimensionKeysQuery = query.match(/^dimension_keys\(([^\)]+?)\)/);
|
||||
if (dimensionKeysQuery) {
|
||||
namespace = templateSrv.replace(dimensionKeysQuery[1]);
|
||||
return this.getDimensionKeys(namespace).then(transformSuggestData);
|
||||
return this.getDimensionKeys(dimensionKeysQuery[1]);
|
||||
}
|
||||
|
||||
var dimensionValuesQuery = query.match(/^dimension_values\(([^,]+?),\s?([^,]+?),\s?([^,]+?)(,\s?([^)]*))?\)/);
|
||||
|
||||
@@ -82,7 +82,7 @@ function (angular, _) {
|
||||
|
||||
$scope.suggestDimensionKeys = function(query, callback) { // jshint unused:false
|
||||
$scope.datasource.getDimensionKeys($scope.target.namespace).then(function(result) {
|
||||
callback(result);
|
||||
callback(_.pluck(result, 'text'));
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -138,25 +138,39 @@ describe('CloudWatchDatasource', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('When performing metricFindQuery', function() {
|
||||
// it('should return suggest list for dimension_keys()', function(done) {
|
||||
// var query = 'dimension_keys(AWS/EC2)';
|
||||
// ctx.ds.metricFindQuery(query).then(function(result) {
|
||||
// result = result.map(function(v) { return v.text; });
|
||||
// expect(result).to.contain('InstanceId');
|
||||
// done();
|
||||
// });
|
||||
// ctx.$rootScope.$apply();
|
||||
// });
|
||||
//
|
||||
// it('should return suggest list for dimension_values()', function(done) {
|
||||
// var query = 'dimension_values(us-east-1,AWS/EC2,CPUUtilization)';
|
||||
// ctx.ds.metricFindQuery(query).then(function(result) {
|
||||
// result = result.map(function(v) { return v.text; });
|
||||
// expect(result).to.eql(['i-12345678']);
|
||||
// done();
|
||||
// });
|
||||
// ctx.$rootScope.$apply();
|
||||
// });
|
||||
describeMetricFindQuery('dimension_keys(AWS/EC2)', scenario => {
|
||||
scenario.setup(() => {
|
||||
scenario.requestResponse = [{text: 'InstanceId'}];
|
||||
});
|
||||
|
||||
it('should call __GetDimensions and return result', () => {
|
||||
expect(scenario.result[0].text).to.be('InstanceId');
|
||||
expect(scenario.request.data.action).to.be('__GetDimensions');
|
||||
});
|
||||
});
|
||||
|
||||
describeMetricFindQuery('dimension_values(us-east-1,AWS/EC2,CPUUtilization)', scenario => {
|
||||
scenario.setup(() => {
|
||||
scenario.requestResponse = {
|
||||
Metrics: [
|
||||
{
|
||||
Namespace: 'AWS/EC2',
|
||||
MetricName: 'CPUUtilization',
|
||||
Dimensions: [
|
||||
{
|
||||
Name: 'InstanceId',
|
||||
Value: 'i-12345678'
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
};
|
||||
});
|
||||
|
||||
it('should call __GetMetrics and return result', () => {
|
||||
expect(scenario.result[0].text).to.be('i-12345678');
|
||||
expect(scenario.request.data.action).to.be('ListMetrics');
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user