Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,73 @@ describe('MetricDetectorTriggeredSection', () => {
await screen.findByRole('link', {name: 'RequestError'});
});

it('filters contributing issues by environment when set on detector', async () => {
const startDate = '2023-12-31T23:58:00.000Z';

const dataSourceWithEnv = SnubaQueryDataSourceFixture({
queryObj: {
id: '1',
status: 1,
subscription: '1',
snubaQuery: {
aggregate: 'count()',
dataset: Dataset.ERRORS,
id: '',
query: 'is:unresolved',
timeWindow: 60,
eventTypes: [EventTypes.ERROR],
environment: 'production',
},
},
});

const contributingIssuesMock = MockApiClient.addMockResponse({
url: '/organizations/org-slug/issues/',
body: [GroupFixture()],
});

const event = EventFixture({
dateCreated: openPeriodStartDate,
eventID: 'event-1',
groupID: '123',
occurrence: {
id: '1',
eventId: 'event-1',
fingerprint: ['fingerprint'],
issueTitle: 'Test Issue',
subtitle: 'Subtitle',
resourceId: 'resource-1',
evidenceData: {
conditions: [condition],
dataSources: [dataSourceWithEnv],
value: 150,
},
evidenceDisplay: [],
type: 8001,
detectionTime: '2024-01-01T00:00:00Z',
},
});

render(<MetricDetectorTriggeredSection {...defaultProps} event={event} />);

await waitFor(() => {
expect(contributingIssuesMock).toHaveBeenCalledWith(
expect.anything(),
expect.objectContaining({
query: expect.objectContaining({
query: 'issue.type:error event.type:error is:unresolved',
start: startDate,
end: openPeriodEndDate,
environment: 'production',
}),
})
);
});

expect(screen.getByRole('cell', {name: 'Environment'})).toBeInTheDocument();
expect(screen.getByRole('cell', {name: 'production'})).toBeInTheDocument();
});

it('renders contributing issues section for crash free rate (releases) dataset', async () => {
const startDate = '2023-12-31T23:58:00.000Z';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ function isMetricDetectorEvidenceData(
interface RelatedIssuesProps {
aggregate: string;
end: string;
environment: string | undefined;
eventDateCreated: string | undefined;
projectId: string | number;
query: string;
Expand Down Expand Up @@ -235,6 +236,7 @@ function ContributingIssues({
eventDateCreated,
aggregate,
end,
environment,
start,
}: RelatedIssuesProps) {
const organization = useOrganization();
Expand Down Expand Up @@ -262,6 +264,7 @@ function ContributingIssues({
query: `issue.type:error ${query}`,
start,
end,
...(environment ? {environment} : {}),
limit: 5,
sort: aggregate === 'count_unique(user)' ? 'user' : 'freq',
groupStatsPeriod: 'auto',
Expand All @@ -277,6 +280,7 @@ function ContributingIssues({
dataset: SavedQueryDatasets.ERRORS,
start,
end,
...(environment ? {environment} : {}),
},
};

Expand Down Expand Up @@ -445,6 +449,15 @@ function TriggeredConditionDetails({
value: datasetConfig.fromApiAggregate(snubaQuery.aggregate),
subject: t('Aggregate'),
},
...(snubaQuery.environment
? [
{
key: 'environment',
value: snubaQuery.environment,
subject: t('Environment'),
},
]
: []),
...(snubaQuery.query
? [
{
Expand Down Expand Up @@ -509,6 +522,7 @@ function TriggeredConditionDetails({
query={issueSearchQuery}
eventDateCreated={eventDateCreated}
aggregate={snubaQuery.aggregate}
environment={snubaQuery.environment}
start={startDate}
end={endDate}
/>
Expand Down
Loading