-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
feat(metric-issues): Add "correlated issues" section #83353
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
Merged
Merged
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
6c64337
Hide tags section
snigdhas 30c2a98
Add correlated issues section
snigdhas 03100c7
Rename componentg
snigdhas eea5901
Update static/app/views/issueDetails/correlatedIssues.tsx
snigdhas 79b4e3a
:hammer_and_wrench: apply pre-commit fixes
getsantry[bot] 2cc6c24
Switch to useApiQuery and update issues query
snigdhas f3de6ca
Return early for unsupported datasets
snigdhas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,131 @@ | ||
import {Fragment, useEffect, useState} from 'react'; | ||
import moment from 'moment-timezone'; | ||
|
||
import {LinkButton} from 'sentry/components/button'; | ||
import {DateTime} from 'sentry/components/dateTime'; | ||
import {t} from 'sentry/locale'; | ||
import type {Event} from 'sentry/types/event'; | ||
import type {Group} from 'sentry/types/group'; | ||
import type {Organization} from 'sentry/types/organization'; | ||
import type {Project} from 'sentry/types/project'; | ||
import type {TimePeriodType} from 'sentry/views/alerts/rules/metric/details/constants'; | ||
import RelatedIssues from 'sentry/views/alerts/rules/metric/details/relatedIssues'; | ||
import {Dataset, TimePeriod} from 'sentry/views/alerts/rules/metric/types'; | ||
import {extractEventTypeFilterFromRule} from 'sentry/views/alerts/rules/metric/utils/getEventTypeFilter'; | ||
import {isCrashFreeAlert} from 'sentry/views/alerts/rules/metric/utils/isCrashFreeAlert'; | ||
import {fetchAlertRule} from 'sentry/views/alerts/utils/apiCalls'; | ||
import {SectionKey} from 'sentry/views/issueDetails/streamline/context'; | ||
import {InterimSection} from 'sentry/views/issueDetails/streamline/interimSection'; | ||
|
||
interface CorrelatedIssuesProps { | ||
event: Event; | ||
group: Group; | ||
organization: Organization; | ||
project: Project; | ||
} | ||
|
||
export default function CorrelatedIssues({ | ||
organization, | ||
event, | ||
group, | ||
project, | ||
}: CorrelatedIssuesProps) { | ||
const [rule, setRule] = useState<any>(null); | ||
const ruleId = event.contexts?.metric_alert?.alert_rule_id; | ||
useEffect(() => { | ||
async function getRuleData() { | ||
if (!ruleId) { | ||
return; | ||
} | ||
const ruleData = await fetchAlertRule(organization.slug, ruleId, { | ||
expand: 'latestIncident', | ||
}); | ||
setRule(ruleData); | ||
} | ||
getRuleData(); | ||
}, [ruleId, organization.slug]); | ||
|
||
const openPeriod = group.openPeriods?.[0]; | ||
if (!ruleId || !openPeriod) { | ||
return null; | ||
} | ||
|
||
const start = openPeriod.start; | ||
let end = openPeriod.end; | ||
if (!end) { | ||
end = moment().toISOString(); | ||
} | ||
const getTimePeriod = (): TimePeriodType => { | ||
return { | ||
start, | ||
end, | ||
period: TimePeriod.SEVEN_DAYS, | ||
usingPeriod: false, | ||
label: t('Custom time'), | ||
display: ( | ||
<Fragment> | ||
<DateTime date={moment.utc(start)} /> | ||
{' — '} | ||
<DateTime date={moment.utc(end)} /> | ||
</Fragment> | ||
), | ||
custom: true, | ||
}; | ||
}; | ||
|
||
const timePeriod = getTimePeriod(); | ||
snigdhas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
if (!rule || !timePeriod) { | ||
return null; | ||
} | ||
|
||
const {dataset, query} = rule; | ||
|
||
const queryParams = { | ||
start, | ||
end, | ||
groupStatsPeriod: 'auto', | ||
limit: 5, | ||
...(rule.environment ? {environment: rule.environment} : {}), | ||
sort: rule.aggregate === 'count_unique(user)' ? 'user' : 'freq', | ||
query, | ||
project: [project.id], | ||
snigdhas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}; | ||
const issueSearch = { | ||
pathname: `/organizations/${organization.slug}/issues/`, | ||
query: queryParams, | ||
}; | ||
|
||
const actions = ( | ||
<LinkButton data-test-id="issues-open" size="xs" to={issueSearch}> | ||
{t('Open in Issues')} | ||
</LinkButton> | ||
); | ||
|
||
return ( | ||
<InterimSection | ||
title={t('Correlated Issues')} | ||
type={SectionKey.CORRELATED_ISSUES} | ||
help={t('A list of issues that are correlated with this event')} | ||
actions={actions} | ||
> | ||
{[Dataset.METRICS, Dataset.SESSIONS, Dataset.ERRORS].includes(dataset) && ( | ||
snigdhas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
<RelatedIssues | ||
organization={organization} | ||
rule={rule} | ||
projects={[project]} | ||
timePeriod={timePeriod} | ||
query={ | ||
dataset === Dataset.ERRORS | ||
? // Not using (query) AND (event.type:x) because issues doesn't support it yet | ||
`${extractEventTypeFilterFromRule(rule)} ${query}`.trim() | ||
: isCrashFreeAlert(dataset) | ||
? `${query} error.unhandled:true`.trim() | ||
: undefined | ||
} | ||
skipHeader | ||
/> | ||
)} | ||
</InterimSection> | ||
); | ||
} |
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.