-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for determining error priority
- Loading branch information
Nicholas Smith
committed
Sep 7, 2021
1 parent
19580ee
commit f29f991
Showing
7 changed files
with
166 additions
and
41 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,5 @@ | ||
import { ErrorGroup, ErrorPriority } from '../models'; | ||
|
||
export interface PrioritizationProviderInterface { | ||
determinePriority(errorGroup: ErrorGroup): Promise<ErrorPriority>; | ||
} |
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export * from './AlertProviderInterface'; | ||
export * from './CacheProviderInterface'; | ||
export * from './ErrorProviderInterface'; | ||
export * from './PrioritizationProviderInterface'; | ||
export * from './TicketProviderInterface'; |
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,57 @@ | ||
import { ErrorGroup, ErrorPriority } from '../models'; | ||
import { PrioritizationProviderInterface } from '../interfaces'; | ||
|
||
export type ErrorCountPrioritizationProviderThreshold = { | ||
threshold: number, | ||
priority: ErrorPriority, | ||
label: string, | ||
}; | ||
|
||
export type ErrorCountPrioritizationProviderConfig = { | ||
thresholds: ErrorCountPrioritizationProviderThreshold[], | ||
}; | ||
|
||
export const DefaultErrorCountPrioritizationProviderConfig = { | ||
thresholds: [{ | ||
// affecting zero users | ||
threshold: 1, | ||
priority: ErrorPriority.P5, | ||
label: '0', | ||
}, { | ||
// affecting [1, 10) users | ||
threshold: 10, | ||
priority: ErrorPriority.P4, | ||
label: '>= 1 and < 10', | ||
}, { | ||
// affecting [10, 30) users | ||
threshold: 30, | ||
priority: ErrorPriority.P3, | ||
label: '>= 10 and < 30', | ||
}, { | ||
// affecting [30, 90) users | ||
threshold: 90, | ||
priority: ErrorPriority.P2, | ||
label: '>= 30 and < 90', | ||
}, { | ||
// affecting [90, infinity) users | ||
threshold: Number.MAX_SAFE_INTEGER, | ||
priority: ErrorPriority.P1, | ||
label: '>= 90', | ||
}], | ||
}; | ||
|
||
export class ErrorCountPrioritizationProvider implements PrioritizationProviderInterface { | ||
private config: ErrorCountPrioritizationProviderConfig; | ||
|
||
public constructor(config?: ErrorCountPrioritizationProviderConfig) { | ||
this.config = config ?? DefaultErrorCountPrioritizationProviderConfig; | ||
} | ||
|
||
public async determinePriority(errorGroup: ErrorGroup): Promise<ErrorPriority> { | ||
for (const threshold of this.config.thresholds) { | ||
if (errorGroup.count < threshold.threshold) { | ||
return threshold.priority; | ||
} | ||
} | ||
} | ||
} |
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