Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions static/app/components/events/groupingInfo/groupingInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ export default function GroupingInfo({
projectSlug,
});

const variants = groupInfo
? Object.values(groupInfo).sort((a, b) => {
const variants = groupInfo?.variants
? Object.values(groupInfo.variants).sort((a, b) => {
// Sort contributing variants before non-contributing ones
if (a.contributes && !b.contributes) {
return -1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,59 @@ describe('EventGroupingInfo', () => {
// Should not make grouping-info request
expect(groupingInfoRequest).not.toHaveBeenCalled();
});

it('works with new groupingInfo format', async () => {
groupingInfoRequest = MockApiClient.addMockResponse({
url: `/projects/org-slug/project-slug/events/${event.id}/grouping-info/`,
body: {
grouping_config: 'default:XXXX',
variants: {
app: {
contributes: true,
description: 'variant description',
hash: '123',
hashMismatch: false,
key: 'key',
type: EventGroupVariantType.CHECKSUM,
},
},
},
});
render(<EventGroupingInfoSection {...defaultProps} />);

expect(await screen.findByText('variant description')).toBeInTheDocument();
expect(screen.getByText('123')).toBeInTheDocument();
});
it('gets performance new grouping info from group/event data', async () => {
groupingInfoRequest = MockApiClient.addMockResponse({
url: `/projects/org-slug/project-slug/events/${event.id}/grouping-info/`,
body: {
grouping_config: null,
variants: {
app: {
contributes: true,
description: 'variant description',
hash: '123',
hashMismatch: false,
key: 'key',
type: EventGroupVariantType.CHECKSUM,
},
},
},
});
const perfEvent = EventFixture({
type: 'transaction',
occurrence: {fingerprint: ['123'], evidenceData: {op: 'bad-op'}},
});
const perfGroup = GroupFixture({issueCategory: IssueCategory.PERFORMANCE});

render(
<EventGroupingInfoSection {...defaultProps} event={perfEvent} group={perfGroup} />
);

expect(await screen.findByText('performance problem')).toBeInTheDocument();
expect(screen.getByText('123')).toBeInTheDocument();
// Should not make grouping-info request
expect(groupingInfoRequest).not.toHaveBeenCalled();
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Bug: Unnecessary API Mock in Local Data Test

The test "gets performance new grouping info from group/event data" mocks an API response for grouping info, then asserts the API call isn't made. Since performance grouping data is derived locally, this mock is unnecessary and creates a confusing contradiction in the test.

Fix in Cursor Fix in Web

});
13 changes: 3 additions & 10 deletions static/app/components/events/groupingInfo/groupingSummary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,15 @@ export function GroupInfoSummary({
group,
projectSlug,
});
const groupedBy = groupInfo
? Object.values(groupInfo)
const groupedBy = groupInfo?.variants
? Object.values(groupInfo.variants)
.filter(variant => variant.contributes && variant.description !== null)
.map(variant => variant.description!)
.sort((a, b) => a.toLowerCase().localeCompare(b.toLowerCase()))
.join(', ')
: t('nothing');

const groupingConfig =
showGroupingConfig && groupInfo
? (
Object.values(groupInfo).find(
variant => 'config' in variant && variant.config?.id
) as any
)?.config?.id
: null;
const groupingConfig = showGroupingConfig && groupInfo?.grouping_config;

if (isPending && !hasPerformanceGrouping) {
return (
Expand Down
89 changes: 67 additions & 22 deletions static/app/components/events/groupingInfo/useEventGroupingInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,37 @@ import type {Group} from 'sentry/types/group';
import {useApiQuery} from 'sentry/utils/queryClient';
import useOrganization from 'sentry/utils/useOrganization';

type EventGroupingInfoResponse = Record<string, EventGroupVariant>;
type EventGroupingInfoResponseOld = Record<string, EventGroupVariant>;
type EventGroupingInfoResponse = {
grouping_config: string | null;
variants: Record<string, EventGroupVariant>;
};

// temporary function to convert the old response structure to the new one
function eventGroupingInfoResponseOldToNew(
old: EventGroupingInfoResponseOld | null
): EventGroupingInfoResponse | null {
const grouping_config = old
? (
Object.values(old).find(
variant => 'config' in variant && variant.config?.id
) as any
)?.config?.id
: null;
Copy link
Contributor

Choose a reason for hiding this comment

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

Bug: Config Extraction Fails Without ID Check

The eventGroupingInfoResponseOldToNew function extracts grouping_config by only checking for variant.config, without verifying that the selected config object has an id property. This can lead to grouping_config.id being undefined where other parts of the codebase expect a string or null.

Fix in Cursor Fix in Web

return old
? {
grouping_config,
variants: old,
}
: null;
Comment on lines +21 to +33
Copy link
Member

Choose a reason for hiding this comment

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

Nit, totally not worth changing in this temporary function, but just an option to keep in mind. If you do an early out (if (!old), {return null;} as your first statement), then it'll save you from having to nest so deeply in the rest of the function, which will in turn make it easier to read.

}

// temporary function to check if the respinse is old type
function isOld(
data: EventGroupingInfoResponseOld | EventGroupingInfoResponse | null
): data is EventGroupingInfoResponseOld {
return data ? !('grouping_config' in data) : false;
}

function generatePerformanceGroupInfo({
event,
Expand All @@ -27,21 +57,24 @@ function generatePerformanceGroupInfo({

return group
? {
[group.issueType]: {
contributes: true,
description: t('performance problem'),
hash: event.occurrence?.fingerprint[0] || '',
hashMismatch: false,
hint: null,
key: group.issueType,
type: EventGroupVariantType.PERFORMANCE_PROBLEM,
evidence: {
op: evidenceData?.op,
parent_span_ids: evidenceData?.parentSpanIds,
cause_span_ids: evidenceData?.causeSpanIds,
offender_span_ids: evidenceData?.offenderSpanIds,
desc: t('performance problem'),
fingerprint: hash,
grouping_config: null,
variants: {
[group.issueType]: {
contributes: true,
description: t('performance problem'),
hash: event.occurrence?.fingerprint[0] || '',
hashMismatch: false,
hint: null,
key: group.issueType,
type: EventGroupVariantType.PERFORMANCE_PROBLEM,
evidence: {
op: evidenceData?.op,
parent_span_ids: evidenceData?.parentSpanIds,
cause_span_ids: evidenceData?.causeSpanIds,
offender_span_ids: evidenceData?.offenderSpanIds,
desc: t('performance problem'),
fingerprint: hash,
},
},
},
}
Expand All @@ -61,14 +94,26 @@ export function useEventGroupingInfo({

const hasPerformanceGrouping = event.occurrence && event.type === 'transaction';

const {data, isPending, isError, isSuccess} = useApiQuery<EventGroupingInfoResponse>(
[`/projects/${organization.slug}/${projectSlug}/events/${event.id}/grouping-info/`],
{enabled: !hasPerformanceGrouping, staleTime: Infinity}
);
const {data, isPending, isError, isSuccess} = useApiQuery<
EventGroupingInfoResponseOld | EventGroupingInfoResponse
>([`/projects/${organization.slug}/${projectSlug}/events/${event.id}/grouping-info/`], {
enabled: !hasPerformanceGrouping,
staleTime: Infinity,
});

const groupInfo = hasPerformanceGrouping
const groupInfoRaw = hasPerformanceGrouping
? generatePerformanceGroupInfo({group, event})
: (data ?? null);

return {groupInfo, isPending, isError, isSuccess, hasPerformanceGrouping};
const groupInfo = isOld(groupInfoRaw)
? eventGroupingInfoResponseOldToNew(groupInfoRaw)
: groupInfoRaw;

return {
groupInfo,
isPending,
isError,
isSuccess,
hasPerformanceGrouping,
};
}
Loading