Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Alerting: Fix evaluation interval validation (#56115)
Co-authored-by: Gilles De Mey <gilles.de.mey@gmail.com> (cherry picked from commit d945091)
- Loading branch information
1 parent
34e7d48
commit e0a6257
Showing
7 changed files
with
197 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters