-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add alert escalation policy as part of the check/config (#922)
- Loading branch information
1 parent
fdc09c7
commit 1857918
Showing
7 changed files
with
87 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// eslint-disable-next-line no-restricted-syntax | ||
enum AlertEscalationType { | ||
RUN = 'RUN_BASED', | ||
TIME = 'TIME_BASED' | ||
} | ||
|
||
export type Reminders = { | ||
amount?: number, | ||
interval?: number | ||
} | ||
|
||
export interface AlertEscalation { | ||
escalationType?: AlertEscalationType, | ||
runBasedEscalation?: { | ||
failedRunThreshold?: number | ||
}, | ||
timeBasedEscalation?: { | ||
minutesFailingThreshold?: number | ||
}, | ||
reminders?: Reminders | ||
} | ||
|
||
export type AlertEscalationOptions = Pick<AlertEscalation, 'runBasedEscalation' | 'timeBasedEscalation' | 'reminders'> | ||
|
||
export class AlertEscalationBuilder { | ||
private static DEFAULT_RUN_BASED_ESCALATION = { failedRunThreshold: 1 } | ||
private static DEFAULT_TIME_BASED_ESCALATION = { minutesFailingThreshold: 5 } | ||
private static DEFAULT_REMINDERS = { amount: 0, interval: 5 } | ||
|
||
static runBasedEscalation (failedRunThreshold: number, reminders?: Reminders) { | ||
const options: AlertEscalationOptions = { | ||
runBasedEscalation: { | ||
failedRunThreshold, | ||
}, | ||
reminders, | ||
} | ||
return this.alertEscalation(AlertEscalationType.RUN, options) | ||
} | ||
|
||
static timeBasedEscalation (minutesFailingThreshold: number, reminders?: Reminders) { | ||
const options: AlertEscalationOptions = { | ||
timeBasedEscalation: { | ||
minutesFailingThreshold, | ||
}, | ||
reminders, | ||
} | ||
return this.alertEscalation(AlertEscalationType.TIME, options) | ||
} | ||
|
||
private static alertEscalation (escalationType: AlertEscalationType, | ||
options: AlertEscalationOptions): AlertEscalation { | ||
return { | ||
escalationType, | ||
runBasedEscalation: options.runBasedEscalation ?? this.DEFAULT_RUN_BASED_ESCALATION, | ||
timeBasedEscalation: options.timeBasedEscalation ?? this.DEFAULT_TIME_BASED_ESCALATION, | ||
reminders: options.reminders ?? this.DEFAULT_REMINDERS, | ||
} | ||
} | ||
} |
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