Merge pull request #3249 from mtanda/cloudwatch_null_pointmode

(cloudwatch) support null point mode
This commit is contained in:
Torkel Ödegaard 2015-11-17 14:03:48 +01:00
commit e008473e47
2 changed files with 33 additions and 7 deletions

View File

@ -25,6 +25,7 @@ function (angular, _) {
var end = convertToCloudWatchTime(options.range.to);
var queries = [];
options = _.clone(options);
_.each(options.targets, _.bind(function(target) {
if (target.hide || !target.namespace || !target.metricName || _.isEmpty(target.statistics)) {
return;
@ -38,11 +39,11 @@ function (angular, _) {
query.statistics = target.statistics;
var range = end - start;
query.period = parseInt(target.period, 10) || 60;
query.period = parseInt(target.period, 10) || (query.namespace === 'AWS/EC2' ? 300 : 60);
if (range / query.period >= 1440) {
query.period = Math.ceil(range / 1440 / 60) * 60;
}
target.period = query.period;
queries.push(query);
}, this));
@ -252,13 +253,22 @@ function (angular, _) {
};
_.extend(aliasData, options.dimensions);
var periodMs = options.period * 1000;
return _.map(options.statistics, function(stat) {
var dps = _.chain(md.Datapoints).map(function(dp) {
return [dp[stat], new Date(dp.Timestamp).getTime()];
})
var dps = [];
var lastTimestamp = null;
_.chain(md.Datapoints)
.sortBy(function(dp) {
return dp[1];
}).value();
return dp.Timestamp;
})
.each(function(dp) {
var timestamp = new Date(dp.Timestamp).getTime();
if (lastTimestamp && (timestamp - lastTimestamp) > periodMs * 2) {
dps.push([null, lastTimestamp + periodMs]);
}
lastTimestamp = timestamp;
dps.push([dp[stat], timestamp]);
});
aliasData.stat = stat;
var seriesName = aliasPattern.replace(aliasRegex, function(match, g1) {

View File

@ -48,6 +48,14 @@ describe('CloudWatchDatasource', function() {
{
Average: 1,
Timestamp: 'Wed Dec 31 1969 16:00:00 GMT-0800 (PST)'
},
{
Average: 2,
Timestamp: 'Wed Dec 31 1969 16:05:00 GMT-0800 (PST)'
},
{
Average: 5,
Timestamp: 'Wed Dec 31 1969 16:20:00 GMT-0800 (PST)'
}
],
Label: 'CPUUtilization'
@ -82,6 +90,14 @@ describe('CloudWatchDatasource', function() {
});
ctx.$rootScope.$apply();
});
it('should return null for missing data point', function(done) {
ctx.ds.query(query).then(function(result) {
expect(result.data[0].datapoints[2][0]).to.be(null);
done();
});
ctx.$rootScope.$apply();
});
});
function describeMetricFindQuery(query, func) {