Skip to content

Commit 6d001f1

Browse files
authored
fix(metric-issues): Filter contributing issues by detector environment (#117367)
The metric issue details wasn't handling monitors with an environment very well. It didn't show it in the 'Triggered condition' table, and it didn't query with that environment in the contributing issues section.
1 parent 08fca61 commit 6d001f1

2 files changed

Lines changed: 81 additions & 0 deletions

File tree

static/app/views/issueDetails/sidebar/metricDetectorTriggeredSection.spec.tsx

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,73 @@ describe('MetricDetectorTriggeredSection', () => {
275275
await screen.findByRole('link', {name: 'RequestError'});
276276
});
277277

278+
it('filters contributing issues by environment when set on detector', async () => {
279+
const startDate = '2023-12-31T23:58:00.000Z';
280+
281+
const dataSourceWithEnv = SnubaQueryDataSourceFixture({
282+
queryObj: {
283+
id: '1',
284+
status: 1,
285+
subscription: '1',
286+
snubaQuery: {
287+
aggregate: 'count()',
288+
dataset: Dataset.ERRORS,
289+
id: '',
290+
query: 'is:unresolved',
291+
timeWindow: 60,
292+
eventTypes: [EventTypes.ERROR],
293+
environment: 'production',
294+
},
295+
},
296+
});
297+
298+
const contributingIssuesMock = MockApiClient.addMockResponse({
299+
url: '/organizations/org-slug/issues/',
300+
body: [GroupFixture()],
301+
});
302+
303+
const event = EventFixture({
304+
dateCreated: openPeriodStartDate,
305+
eventID: 'event-1',
306+
groupID: '123',
307+
occurrence: {
308+
id: '1',
309+
eventId: 'event-1',
310+
fingerprint: ['fingerprint'],
311+
issueTitle: 'Test Issue',
312+
subtitle: 'Subtitle',
313+
resourceId: 'resource-1',
314+
evidenceData: {
315+
conditions: [condition],
316+
dataSources: [dataSourceWithEnv],
317+
value: 150,
318+
},
319+
evidenceDisplay: [],
320+
type: 8001,
321+
detectionTime: '2024-01-01T00:00:00Z',
322+
},
323+
});
324+
325+
render(<MetricDetectorTriggeredSection {...defaultProps} event={event} />);
326+
327+
await waitFor(() => {
328+
expect(contributingIssuesMock).toHaveBeenCalledWith(
329+
expect.anything(),
330+
expect.objectContaining({
331+
query: expect.objectContaining({
332+
query: 'issue.type:error event.type:error is:unresolved',
333+
start: startDate,
334+
end: openPeriodEndDate,
335+
environment: 'production',
336+
}),
337+
})
338+
);
339+
});
340+
341+
expect(screen.getByRole('cell', {name: 'Environment'})).toBeInTheDocument();
342+
expect(screen.getByRole('cell', {name: 'production'})).toBeInTheDocument();
343+
});
344+
278345
it('renders contributing issues section for crash free rate (releases) dataset', async () => {
279346
const startDate = '2023-12-31T23:58:00.000Z';
280347

static/app/views/issueDetails/sidebar/metricDetectorTriggeredSection.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ function isMetricDetectorEvidenceData(
9999
interface RelatedIssuesProps {
100100
aggregate: string;
101101
end: string;
102+
environment: string | undefined;
102103
eventDateCreated: string | undefined;
103104
projectId: string | number;
104105
query: string;
@@ -235,6 +236,7 @@ function ContributingIssues({
235236
eventDateCreated,
236237
aggregate,
237238
end,
239+
environment,
238240
start,
239241
}: RelatedIssuesProps) {
240242
const organization = useOrganization();
@@ -262,6 +264,7 @@ function ContributingIssues({
262264
query: `issue.type:error ${query}`,
263265
start,
264266
end,
267+
...(environment ? {environment} : {}),
265268
limit: 5,
266269
sort: aggregate === 'count_unique(user)' ? 'user' : 'freq',
267270
groupStatsPeriod: 'auto',
@@ -277,6 +280,7 @@ function ContributingIssues({
277280
dataset: SavedQueryDatasets.ERRORS,
278281
start,
279282
end,
283+
...(environment ? {environment} : {}),
280284
},
281285
};
282286

@@ -445,6 +449,15 @@ function TriggeredConditionDetails({
445449
value: datasetConfig.fromApiAggregate(snubaQuery.aggregate),
446450
subject: t('Aggregate'),
447451
},
452+
...(snubaQuery.environment
453+
? [
454+
{
455+
key: 'environment',
456+
value: snubaQuery.environment,
457+
subject: t('Environment'),
458+
},
459+
]
460+
: []),
448461
...(snubaQuery.query
449462
? [
450463
{
@@ -509,6 +522,7 @@ function TriggeredConditionDetails({
509522
query={issueSearchQuery}
510523
eventDateCreated={eventDateCreated}
511524
aggregate={snubaQuery.aggregate}
525+
environment={snubaQuery.environment}
512526
start={startDate}
513527
end={endDate}
514528
/>

0 commit comments

Comments
 (0)