-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
feat(aci): redirect incidents to metric issue details #104001
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| import {lazy} from 'react'; | ||
|
|
||
| import {withOpenPeriodRedirect} from 'sentry/views/alerts/workflowEngineRedirects'; | ||
|
|
||
| const AlertWizardProjectProvider = lazy( | ||
| () => import('sentry/views/alerts/incidentRedirect') | ||
| ); | ||
|
|
||
| export default withOpenPeriodRedirect(AlertWizardProjectProvider); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| import LoadingIndicator from 'sentry/components/loadingIndicator'; | ||
| import Redirect from 'sentry/components/redirect'; | ||
| import {useApiQuery} from 'sentry/utils/queryClient'; | ||
| import {useLocation} from 'sentry/utils/useLocation'; | ||
| import useOrganization from 'sentry/utils/useOrganization'; | ||
| import {useParams} from 'sentry/utils/useParams'; | ||
| import {useUser} from 'sentry/utils/useUser'; | ||
|
|
@@ -26,6 +27,13 @@ interface AlertRuleDetector { | |
| ruleId: string | null; | ||
| } | ||
|
|
||
| interface IncidentGroupOpenPeriod { | ||
| groupId: string; | ||
| incidentId: string | null; | ||
| incidentIdentifier: string; | ||
| openPeriodId: string; | ||
| } | ||
|
|
||
| /** | ||
| * HoC that wraps a component to handle workflow engine | ||
| * redirects for issue alert rules. Fetches workflow data if needed and | ||
|
|
@@ -137,10 +145,86 @@ export const withAutomationEditRedirect = <P extends Record<string, any>>( | |
|
|
||
| export const withDetectorDetailsRedirect = <P extends Record<string, any>>( | ||
| Component: React.ComponentType<P> | ||
| ) => | ||
| withAlertRuleRedirect(Component, (detectorId, orgSlug) => | ||
| makeMonitorDetailsPathname(orgSlug, detectorId) | ||
| ); | ||
| ) => { | ||
| return function WorkflowEngineRedirectWrapper(props: P) { | ||
| const user = useUser(); | ||
| const organization = useOrganization(); | ||
| const {ruleId, detectorId} = useParams(); | ||
| const location = useLocation(); | ||
| const alertId = location.query.alert as string | undefined; | ||
|
|
||
| const shouldRedirect = | ||
| !user.isStaff && organization.features.includes('workflow-engine-ui'); | ||
|
|
||
| // Check for incident open period if alertId is present | ||
| const {data: incidentGroupOpenPeriod, isPending: isOpenPeriodPending} = | ||
| useApiQuery<IncidentGroupOpenPeriod>( | ||
| [ | ||
| `/organizations/${organization.slug}/incident-groupopenperiod/`, | ||
| {query: {incident_identifier: alertId}}, | ||
| ], | ||
| { | ||
| staleTime: 0, | ||
| enabled: shouldRedirect && !!alertId, | ||
| retry: false, | ||
| } | ||
| ); | ||
|
|
||
| // Check for detector if no alertId | ||
| const {data: alertRuleDetector, isPending: isDetectorPending} = | ||
| useApiQuery<AlertRuleDetector>( | ||
| [ | ||
| `/organizations/${organization.slug}/alert-rule-detector/`, | ||
| {query: {alert_rule_id: ruleId}}, | ||
| ], | ||
| { | ||
| staleTime: 0, | ||
| enabled: shouldRedirect && !!ruleId && !detectorId && !alertId, | ||
| retry: false, | ||
| } | ||
| ); | ||
|
|
||
| if (shouldRedirect) { | ||
| // If alertId is provided, redirect to metric issue | ||
| if (alertId) { | ||
| if (isOpenPeriodPending) { | ||
| return <LoadingIndicator />; | ||
| } | ||
| if (incidentGroupOpenPeriod) { | ||
| return ( | ||
| <Redirect | ||
| to={`/organizations/${organization.slug}/issues/${incidentGroupOpenPeriod.groupId}`} | ||
| /> | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| // If detectorId is provided, redirect to monitor details | ||
| if (detectorId) { | ||
| return ( | ||
| <Redirect to={makeMonitorDetailsPathname(organization.slug, detectorId)} /> | ||
| ); | ||
| } | ||
|
|
||
| // If alertRuleId is provided, fetch detector and redirect | ||
| if (isDetectorPending) { | ||
| return <LoadingIndicator />; | ||
| } | ||
| if (alertRuleDetector) { | ||
| return ( | ||
| <Redirect | ||
| to={makeMonitorDetailsPathname( | ||
| organization.slug, | ||
| alertRuleDetector.detectorId | ||
| )} | ||
| /> | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| return <Component {...(props as any)} />; | ||
| }; | ||
| }; | ||
|
|
||
| export const withDetectorEditRedirect = <P extends Record<string, any>>( | ||
| Component: React.ComponentType<P> | ||
|
|
@@ -183,3 +267,44 @@ export function withDetectorCreateRedirect<P extends Record<string, any>>( | |
| return <Component {...(props as any)} />; | ||
| }; | ||
| } | ||
|
|
||
| export function withOpenPeriodRedirect<P extends Record<string, any>>( | ||
| Component: React.ComponentType<P> | ||
| ) { | ||
| return function OpenPeriodRedirectWrapper(props: P) { | ||
| const user = useUser(); | ||
| const organization = useOrganization(); | ||
| const {alertId} = useParams(); | ||
|
|
||
| const shouldRedirect = | ||
| !user.isStaff && organization.features.includes('workflow-engine-ui'); | ||
|
|
||
| const {data: incidentGroupOpenPeriod, isPending} = | ||
| useApiQuery<IncidentGroupOpenPeriod>( | ||
| [ | ||
| `/organizations/${organization.slug}/incident-groupopenperiod/`, | ||
| {query: {incident_identifier: alertId}}, | ||
| ], | ||
| { | ||
| staleTime: 0, | ||
| enabled: shouldRedirect && !!alertId, | ||
|
Comment on lines
+283
to
+290
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: 🔍 Detailed AnalysisThe 💡 Suggested FixAdd an 🤖 Prompt for AI AgentDid we get this right? 👍 / 👎 to inform future reviews. |
||
| retry: false, | ||
| } | ||
| ); | ||
|
|
||
| if (shouldRedirect) { | ||
| if (isPending) { | ||
| return <LoadingIndicator />; | ||
| } | ||
| if (incidentGroupOpenPeriod) { | ||
| return ( | ||
| <Redirect | ||
| to={`/organizations/${organization.slug}/issues/${incidentGroupOpenPeriod.groupId}`} | ||
ameliahsu marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| /> | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| return <Component {...(props as any)} />; | ||
| }; | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.