skip backend request if extended statistics is invalid. (#12495)

* check extended statistics pattern

* check extended statistics pattern

* Revert "check extended statistics pattern"

This reverts commit 52c7b1a972636d5f5729e64ae5e00e6fae329257.

* add test

* fix test
This commit is contained in:
Mitsuhiro Tanda 2018-07-12 03:23:38 +09:00 committed by Torkel Ödegaard
parent c03764ff8a
commit 9b50c9038b
2 changed files with 28 additions and 0 deletions

View File

@ -39,6 +39,14 @@ export default class CloudWatchDatasource {
item.dimensions = this.convertDimensionFormat(item.dimensions, options.scopedVars);
item.period = String(this.getPeriod(item, options)); // use string format for period in graph query, and alerting
// valid ExtendedStatistics is like p90.00, check the pattern
let hasInvalidStatistics = item.statistics.some(s => {
return s.indexOf('p') === 0 && !/p\d{2}\.\d{2}/.test(s);
});
if (hasInvalidStatistics) {
throw { message: 'Invalid extended statistics' };
}
return _.extend(
{
refId: item.refId,

View File

@ -121,6 +121,26 @@ describe('CloudWatchDatasource', function() {
});
});
it('should cancel query for invalid extended statistics', function () {
var query = {
range: { from: 'now-1h', to: 'now' },
rangeRaw: { from: 1483228800, to: 1483232400 },
targets: [
{
region: 'us-east-1',
namespace: 'AWS/EC2',
metricName: 'CPUUtilization',
dimensions: {
InstanceId: 'i-12345678',
},
statistics: ['pNN.NN'],
period: '60s',
},
],
};
expect(ctx.ds.query.bind(ctx.ds, query)).toThrow(/Invalid extended statistics/);
});
it('should return series list', function(done) {
ctx.ds.query(query).then(function(result) {
expect(result.data[0].target).toBe(response.results.A.series[0].name);