feat(slo): use sync delay for burn rate alerting (#148223)

This commit is contained in:
Kevin Delemme 2023-01-04 15:46:02 -05:00 committed by GitHub
parent 312586043b
commit 2f973afd1c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 33 additions and 2 deletions

View file

@ -78,4 +78,25 @@ describe('Duration', () => {
expect(short.isLongerOrEqualThan(new Duration(1, DurationUnit.Year))).toBe(false);
});
});
describe('add', () => {
it('returns the duration result in minute', () => {
const someDuration = new Duration(1, DurationUnit.Minute);
expect(someDuration.add(new Duration(1, DurationUnit.Minute))).toEqual(
new Duration(2, DurationUnit.Minute)
);
expect(someDuration.add(new Duration(1, DurationUnit.Hour))).toEqual(
new Duration(61, DurationUnit.Minute)
);
expect(someDuration.add(new Duration(1, DurationUnit.Day))).toEqual(
new Duration(1441, DurationUnit.Minute)
);
expect(someDuration.add(new Duration(1, DurationUnit.Week))).toEqual(
new Duration(10081, DurationUnit.Minute)
);
expect(someDuration.add(new Duration(1, DurationUnit.Month))).toEqual(
new Duration(43201, DurationUnit.Minute)
);
});
});
});

View file

@ -29,6 +29,16 @@ class Duration {
}
}
add(other: Duration): Duration {
const currentDurationMoment = moment.duration(this.value, toMomentUnitOfTime(this.unit));
const otherDurationMoment = moment.duration(other.value, toMomentUnitOfTime(other.unit));
return new Duration(
currentDurationMoment.add(otherDurationMoment).asMinutes(),
DurationUnit.Minute
);
}
isShorterThan(other: Duration): boolean {
const otherDurationMoment = moment.duration(other.value, toMomentUnitOfTime(other.unit));
const currentDurationMoment = moment.duration(this.value, toMomentUnitOfTime(this.unit));

View file

@ -58,8 +58,8 @@ export const getRuleExecutor = (): LifecycleRuleExecutor<
);
const sliData = await sliClient.fetchSLIDataFrom(slo, [
{ name: LONG_WINDOW, duration: longWindowDuration },
{ name: SHORT_WINDOW, duration: shortWindowDuration },
{ name: LONG_WINDOW, duration: longWindowDuration.add(slo.settings.syncDelay) },
{ name: SHORT_WINDOW, duration: shortWindowDuration.add(slo.settings.syncDelay) },
]);
const longWindowBurnRate = computeBurnRate(slo, sliData[LONG_WINDOW]);