Alerting: Fix invalid duration that causes Grafana to crash (#63753)

* Alerting: fix invalid alert duration

* Return empty string from intervalToAbbreviatedDurationString

* Alerting: add tests for invalid duration

* tests intervalToAbbreviatedDurationString

* Alerting: add missing isAfter import 

* durationutils.ts
This commit is contained in:
Fábio Silva
2023-03-01 11:45:41 -10:00
committed by GitHub
parent 9160f608b4
commit afc9925dbf
2 changed files with 13 additions and 1 deletions
@@ -13,6 +13,12 @@ describe('Duration util', () => {
const endDate = addDurationToDate(startDate, { months: 1, weeks: 1, days: 1, hours: 1, minutes: 1, seconds: 1 });
expect(intervalToAbbreviatedDurationString({ start: startDate, end: endDate })).toEqual('1M 8d 1h 1m 1s');
});
it('should return an empty string if start date is after end date', () => {
const endDate = new Date();
const startDate = addDurationToDate(endDate, { minutes: 1 });
expect(intervalToAbbreviatedDurationString({ start: startDate, end: endDate })).toEqual('');
});
});
describe('parseDuration', () => {