mirror of https://github.com/grafana/grafana
Alerting: Fix evaluation interval validation (#56115)
Co-authored-by: Gilles De Mey <gilles.de.mey@gmail.com>oneSingleBinary
parent
76868bad04
commit
d945091ff1
@ -0,0 +1,53 @@ |
||||
import { config } from '@grafana/runtime'; |
||||
|
||||
import { checkEvaluationIntervalGlobalLimit } from './config'; |
||||
|
||||
describe('checkEvaluationIntervalGlobalLimit', () => { |
||||
it('should NOT exceed limit if evaluate every is not valid duration', () => { |
||||
config.unifiedAlerting.minInterval = '2m30s'; |
||||
|
||||
const { globalLimit, exceedsLimit } = checkEvaluationIntervalGlobalLimit('123notvalidduration'); |
||||
|
||||
expect(globalLimit).toBe(150 * 1000); |
||||
expect(exceedsLimit).toBe(false); |
||||
}); |
||||
|
||||
it('should NOT exceed limit if config minInterval is not valid duration', () => { |
||||
config.unifiedAlerting.minInterval = '1A8IU3A'; |
||||
|
||||
const { globalLimit, exceedsLimit } = checkEvaluationIntervalGlobalLimit('1m30s'); |
||||
|
||||
expect(globalLimit).toBe(0); |
||||
expect(exceedsLimit).toBe(false); |
||||
}); |
||||
|
||||
it.each([ |
||||
['2m30s', '1m30s'], |
||||
['30s', '10s'], |
||||
['1d2h', '2h'], |
||||
['1y', '90d'], |
||||
])( |
||||
'should exceed limit if config minInterval (%s) is greater than evaluate every (%s)', |
||||
(minInterval, evaluateEvery) => { |
||||
config.unifiedAlerting.minInterval = minInterval; |
||||
|
||||
const { globalLimit, exceedsLimit } = checkEvaluationIntervalGlobalLimit(evaluateEvery); |
||||
|
||||
expect(globalLimit).toBeGreaterThan(0); |
||||
expect(exceedsLimit).toBe(true); |
||||
} |
||||
); |
||||
|
||||
it.each([ |
||||
['1m30s', '2m30s'], |
||||
['30s', '1d'], |
||||
['1m10s', '1h30m15s'], |
||||
])('should NOT exceed limit if config minInterval is lesser than evaluate every', (minInterval, evaluateEvery) => { |
||||
config.unifiedAlerting.minInterval = minInterval; |
||||
|
||||
const { globalLimit, exceedsLimit } = checkEvaluationIntervalGlobalLimit(evaluateEvery); |
||||
|
||||
expect(globalLimit).toBeGreaterThan(0); |
||||
expect(exceedsLimit).toBe(false); |
||||
}); |
||||
}); |
@ -0,0 +1,15 @@ |
||||
import { isValidPrometheusDuration } from './time'; |
||||
|
||||
describe('isValidPrometheusDuration', () => { |
||||
const validDurations = ['20h30m10s45ms', '1m30s', '20s4h', '90s', '10s', '20h20h', '2d4h20m']; |
||||
|
||||
it.each(validDurations)('%s should be valid', (duration) => { |
||||
expect(isValidPrometheusDuration(duration)).toBe(true); |
||||
}); |
||||
|
||||
const invalidDurations = ['20h 30m 10s 45ms', '10Y', 'sample text', 'm']; |
||||
|
||||
it.each(invalidDurations)('%s should NOT be valid', (duration) => { |
||||
expect(isValidPrometheusDuration(duration)).toBe(false); |
||||
}); |
||||
}); |
Loading…
Reference in new issue