mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
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:
parent
c03764ff8a
commit
9b50c9038b
@ -39,6 +39,14 @@ export default class CloudWatchDatasource {
|
|||||||
item.dimensions = this.convertDimensionFormat(item.dimensions, options.scopedVars);
|
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
|
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(
|
return _.extend(
|
||||||
{
|
{
|
||||||
refId: item.refId,
|
refId: item.refId,
|
||||||
|
@ -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) {
|
it('should return series list', function(done) {
|
||||||
ctx.ds.query(query).then(function(result) {
|
ctx.ds.query(query).then(function(result) {
|
||||||
expect(result.data[0].target).toBe(response.results.A.series[0].name);
|
expect(result.data[0].target).toBe(response.results.A.series[0].name);
|
||||||
|
Loading…
Reference in New Issue
Block a user