Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(integrations): custom pagerduty + opsgenie metric alert priorities FE #66929

Merged
merged 3 commits into from
Mar 14, 2024

Conversation

cathteng
Copy link
Member

@cathteng cathteng commented Mar 13, 2024

Completes custom metric alert priority work for Pagerduty and Opsgenie. The (feature flagged) frontend allows for settings these values, and defaults to the original logic:

  • Pagerduty: critical status => critical severity, warning => warning severity
  • Opsgenie: critical status => P1 priority, warning => P2 priority
Screen.Recording.2024-03-13.at.14.51.31.mov

Note that we don't show the priority in the description of the action unless it has been explicitly set to something.

For #58830
For #54921

@github-actions github-actions bot added the Scope: Frontend Automatically applied to PRs that change frontend components label Mar 13, 2024
@cathteng cathteng force-pushed the cathy/opsgenie-pagerduty/metric-alert-priorities-FE branch from 26803fb to f035e4e Compare March 14, 2024 17:13
@cathteng cathteng marked this pull request as ready for review March 14, 2024 17:14
@cathteng cathteng requested a review from a team as a code owner March 14, 2024 17:14
@cathteng cathteng requested a review from vartec March 14, 2024 17:14
Comment on lines +194 to +197
export const DefaultPriorities = {
[ActionType.PAGERDUTY]: {[0]: 'critical', [1]: 'warning'},
[ActionType.OPSGENIE]: {[0]: 'P1', [1]: 'P2'},
};
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these are placeholders. maybe we should prefix them with severity for Pagerduty or priority for Opsgenie

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

default pagerduty severities:

severity = "info"
if new_status == IncidentStatus.CRITICAL:
severity = "critical"
elif new_status == IncidentStatus.WARNING:
severity = "warning"
elif new_status == IncidentStatus.CLOSED:
severity = "info"

default opsgenie priorities:

priority = "P1"
if new_status == IncidentStatus.WARNING:
priority = "P2"

Copy link
Contributor

@saponifi3d saponifi3d left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

generally LGTM - comments are mostly just nitpicks / minor improvements to the TS :)

Comment on lines +462 to +465
{hasPriorityFlag &&
availableAction &&
(availableAction.type === 'opsgenie' ||
availableAction.type === 'pagerduty') ? (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: might be nice to make this a const before the render, for readability for the html

const isSelectEnabled = hasPriorityFlag &&  availableAction &&
  (availableAction.type === 'opsgenie' || availableAction.type === 'pagerduty');

...

{isSelectEnabled && <SelectControl .... />}

actionIdx
)}
/>
) : null}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: no need to add null here

Suggested change
) : null}
)}

@@ -185,6 +185,17 @@ export const TargetLabel = {
[TargetType.TEAM]: t('Team'),
};

export const PriorityOptions = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
export const PriorityOptions = {
export const PriorityOptions: Record<ActionType, string[]> = {

@@ -185,6 +185,17 @@ export const TargetLabel = {
[TargetType.TEAM]: t('Team'),
};

export const PriorityOptions = {
[ActionType.PAGERDUTY]: ['critical', 'warning', 'error', 'info'],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might be nice to move these priorities to an enum rather than a inlining them

export enum PagerDutyPriorities {
  CRITICAL = 'critical',
  WARNING = 'warning',
  ERROR = 'error',
  INFO = 'info',
};

export enum OpsGeniePriorities {
  P1: 'P1',
  P2: 'P2',
  ...
}

This is also nice since you're using these strings later in DefaultPriories too.

export const DefaultPriorities = {
  [ActionType.PAGERDUTY]: {[0]: PagerDutyPriorities.CRITICAL, [1]: PagerDutyPriorities.WARNING},
  [ActionType.OPSGENIE]: {[0]:  OpsGeniePriorties.P1, [1]: OpsGeniePriorties.P2},
};

Comment on lines +464 to +465
(availableAction.type === 'opsgenie' ||
availableAction.type === 'pagerduty') ? (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
(availableAction.type === 'opsgenie' ||
availableAction.type === 'pagerduty') ? (
(availableAction.type === 'opsgenie' ||
availableAction.type === 'pagerduty') ? (

also suggest moving these opsgenie and pagerduty to constants at the top of the file:

const OPSGENIE = 'opsgenie';
const PAGERDUTY = 'pagerduty';

Comment on lines +194 to +196
export const DefaultPriorities = {
[ActionType.PAGERDUTY]: {[0]: 'critical', [1]: 'warning'},
[ActionType.OPSGENIE]: {[0]: 'P1', [1]: 'P2'},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd recommend adding some typing to this, then changing the data structure from an object to an array.

Suggested change
export const DefaultPriorities = {
[ActionType.PAGERDUTY]: {[0]: 'critical', [1]: 'warning'},
[ActionType.OPSGENIE]: {[0]: 'P1', [1]: 'P2'},
export const DefaultPriorities: Record<ActionType, string[]> = {
[ActionType.PAGERDUTY]: ['critical', 'warning'],
[ActionType.OPSGENIE]: ['P1', 'P2'],

@cathteng cathteng merged commit 6491d48 into master Mar 14, 2024
40 checks passed
@cathteng cathteng deleted the cathy/opsgenie-pagerduty/metric-alert-priorities-FE branch March 14, 2024 21:49
@github-actions github-actions bot locked and limited conversation to collaborators Mar 30, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Scope: Frontend Automatically applied to PRs that change frontend components
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants