Skip to content

Commit

Permalink
feat: add alertSettings.parallelRunFailureTreshold to CLI [sc-19200] (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
maxigimenez committed Feb 8, 2024
1 parent fd4c60d commit bfc68da
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions packages/cli/src/constructs/alert-escalation-policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ export type Reminders = {
interval?: number
}

export type ParallelRunFailureThreshold = {
enabled?: boolean,
percentage?: number,
}

export interface AlertEscalation {
escalationType?: AlertEscalationType,
runBasedEscalation?: {
Expand All @@ -18,31 +23,43 @@ export interface AlertEscalation {
minutesFailingThreshold?: number
},
reminders?: Reminders
parallelRunFailureThreshold?: ParallelRunFailureThreshold
}

export type AlertEscalationOptions = Pick<AlertEscalation, 'runBasedEscalation' | 'timeBasedEscalation' | 'reminders'>
export type AlertEscalationOptions = Pick<AlertEscalation, 'runBasedEscalation' | 'timeBasedEscalation' | 'reminders' | 'parallelRunFailureThreshold'>

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 }
private static DEFAULT_PARALLEL_RUN_FAILURE_THRESHOLD = { enabled: false, percentage: 10 }

static runBasedEscalation (failedRunThreshold: number, reminders?: Reminders) {
static runBasedEscalation (
failedRunThreshold: number,
reminders?: Reminders,
parallelRunFailureThreshold?: ParallelRunFailureThreshold,
) {
const options: AlertEscalationOptions = {
runBasedEscalation: {
failedRunThreshold,
},
reminders,
parallelRunFailureThreshold,
}
return this.alertEscalation(AlertEscalationType.RUN, options)
}

static timeBasedEscalation (minutesFailingThreshold: number, reminders?: Reminders) {
static timeBasedEscalation (
minutesFailingThreshold: number,
reminders?: Reminders,
parallelRunFailureThreshold?: ParallelRunFailureThreshold,
) {
const options: AlertEscalationOptions = {
timeBasedEscalation: {
minutesFailingThreshold,
},
reminders,
parallelRunFailureThreshold,
}
return this.alertEscalation(AlertEscalationType.TIME, options)
}
Expand All @@ -54,6 +71,7 @@ export class AlertEscalationBuilder {
runBasedEscalation: options.runBasedEscalation ?? this.DEFAULT_RUN_BASED_ESCALATION,
timeBasedEscalation: options.timeBasedEscalation ?? this.DEFAULT_TIME_BASED_ESCALATION,
reminders: options.reminders ?? this.DEFAULT_REMINDERS,
parallelRunFailureThreshold: options.parallelRunFailureThreshold ?? this.DEFAULT_PARALLEL_RUN_FAILURE_THRESHOLD,
}
}
}

0 comments on commit bfc68da

Please sign in to comment.