Skip to content

Commit 875d80a

Browse files
committed
feat(cloudwatch): refactoring cloudwatch datasource code, grafana#684
1 parent af8d121 commit 875d80a

File tree

1 file changed

+13
-21
lines changed

1 file changed

+13
-21
lines changed

public/app/plugins/datasource/cloudwatch/datasource.js

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -246,23 +246,20 @@ function (angular, _) {
246246
return d.promise;
247247
}
248248

249-
var allQueryPromise = _.map(queries, _.bind(function(query) {
249+
var allQueryPromise = _.map(queries, function(query) {
250250
return this.performTimeSeriesQuery(query, start, end);
251-
}, this));
252-
253-
return $q.all(allQueryPromise)
254-
.then(function(allResponse) {
255-
var result = [];
251+
}, this);
256252

257-
_.each(allResponse, function(response, index) {
258-
var metrics = transformMetricData(response, options.targets[index]);
259-
_.each(metrics, function(m) {
260-
result.push(m);
261-
});
262-
});
253+
return $q.all(allQueryPromise).then(function(allResponse) {
254+
var result = [];
263255

264-
return { data: result };
256+
_.each(allResponse, function(response, index) {
257+
var metrics = transformMetricData(response.data, options.targets[index]);
258+
result = result.concat(metrics);
265259
});
260+
261+
return { data: result };
262+
});
266263
};
267264

268265
CloudWatchDatasource.prototype.performTimeSeriesQuery = function(query, start, end) {
@@ -305,23 +302,18 @@ function (angular, _) {
305302
metricName = templateSrv.replace(metricName);
306303

307304
var cloudwatch = this.getAwsClient(region, 'CloudWatch');
305+
var params = {Namespace: namespace, MetricName: metricName};
308306

309-
var params = {
310-
Namespace: namespace,
311-
MetricName: metricName
312-
};
313307
if (!_.isEmpty(dimensions)) {
314308
params.Dimensions = convertDimensionFormat(dimensions);
315309
}
316310

317-
return cloudwatch.listMetrics(params).then(function(data) {
318-
var suggestData = _.chain(data.Metrics).map(function(metric) {
311+
return cloudwatch.listMetrics(params).then(function(result) {
312+
return _.chain(result.data.Metrics).map(function(metric) {
319313
return metric.Dimensions;
320314
}).reject(function(metric) {
321315
return _.isEmpty(metric);
322316
}).value();
323-
324-
return suggestData;
325317
});
326318
};
327319

0 commit comments

Comments
 (0)