-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
chore(alerts): Dont use legacy alerts endpoint in metric issue details #117482
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
Open
ceorourke
wants to merge
1
commit into
master
Choose a base branch
from
ceorourke/ISWF-2854
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+264
−49
Open
Changes from all commits
Commits
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
157 changes: 157 additions & 0 deletions
157
static/app/views/issueDetails/metricIssues/metricIssuesSection.spec.tsx
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,157 @@ | ||
| import { | ||
| MetricDetectorFixture, | ||
| SnubaQueryDataSourceFixture, | ||
| } from 'sentry-fixture/detectors'; | ||
| import {EventFixture} from 'sentry-fixture/event'; | ||
| import {GroupFixture} from 'sentry-fixture/group'; | ||
| import {OrganizationFixture} from 'sentry-fixture/organization'; | ||
| import {ProjectFixture} from 'sentry-fixture/project'; | ||
|
|
||
| import {render, screen} from 'sentry-test/reactTestingLibrary'; | ||
|
|
||
| import {IssueCategory, IssueType} from 'sentry/types/group'; | ||
| import {Dataset} from 'sentry/views/alerts/rules/metric/types'; | ||
| import {IssueDetailsContext} from 'sentry/views/issueDetails/context'; | ||
| import {MetricIssuesSection} from 'sentry/views/issueDetails/metricIssues/metricIssuesSection'; | ||
| import {getDetectorDetails} from 'sentry/views/issueDetails/sidebar/detectorSection'; | ||
|
|
||
| describe('MetricIssuesSection', () => { | ||
| const organization = OrganizationFixture(); | ||
| const project = ProjectFixture({organization}); | ||
| const group = GroupFixture({ | ||
| project, | ||
| issueCategory: IssueCategory.METRIC, | ||
| issueType: IssueType.METRIC_ISSUE, | ||
| }); | ||
|
|
||
| const baseIssueDetailsContext = { | ||
| sectionData: {}, | ||
| detectorDetails: {}, | ||
| isSidebarOpen: true, | ||
| navScrollMargin: 0, | ||
| eventCount: 0, | ||
| dispatch: jest.fn(), | ||
| }; | ||
|
|
||
| const detector = MetricDetectorFixture({projectId: project.id}); | ||
| const event = EventFixture({ | ||
| occurrence: { | ||
| evidenceData: {detectorId: detector.id}, | ||
| type: 8001, | ||
| }, | ||
| }); | ||
|
|
||
| beforeEach(() => { | ||
| MockApiClient.clearMockResponses(); | ||
| MockApiClient.addMockResponse({ | ||
| url: `/organizations/${organization.slug}/open-periods/`, | ||
| body: [], | ||
| }); | ||
| // Endpoints fired by the correlated issues/transactions tables | ||
| MockApiClient.addMockResponse({ | ||
| url: `/organizations/${organization.slug}/issues/`, | ||
| body: [], | ||
| }); | ||
| MockApiClient.addMockResponse({ | ||
| url: `/organizations/${organization.slug}/events/`, | ||
| body: {data: [], meta: {}}, | ||
| }); | ||
| MockApiClient.addMockResponse({ | ||
| url: `/organizations/${organization.slug}/users/`, | ||
| body: [], | ||
| }); | ||
| MockApiClient.addMockResponse({ | ||
| url: `/organizations/${organization.slug}/members/`, | ||
| body: [], | ||
| }); | ||
| }); | ||
|
|
||
| function renderSection( | ||
| detectorDetails = getDetectorDetails({event, organization, project}) | ||
| ) { | ||
| return render( | ||
| <IssueDetailsContext value={{...baseIssueDetailsContext, detectorDetails}}> | ||
| <MetricIssuesSection | ||
| organization={organization} | ||
| group={group} | ||
| project={project} | ||
| /> | ||
| </IssueDetailsContext>, | ||
| {organization} | ||
| ); | ||
| } | ||
|
|
||
| it('fetches the detector and renders correlated issues for an error dataset', async () => { | ||
| const mockDetector = MockApiClient.addMockResponse({ | ||
| url: `/organizations/${organization.slug}/detectors/${detector.id}/`, | ||
| body: detector, | ||
| }); | ||
| const mockIssues = MockApiClient.addMockResponse({ | ||
| url: `/organizations/${organization.slug}/issues/`, | ||
| body: [], | ||
| }); | ||
|
|
||
| renderSection(); | ||
|
|
||
| expect(await screen.findByText('Correlated Issues')).toBeInTheDocument(); | ||
| expect(mockDetector).toHaveBeenCalled(); | ||
| // The detector's snuba query flows through to the correlated issues request | ||
| expect(mockIssues).toHaveBeenCalledWith( | ||
| expect.anything(), | ||
| expect.objectContaining({ | ||
| query: expect.objectContaining({ | ||
| query: expect.stringContaining('is:unresolved'), | ||
| }), | ||
| }) | ||
| ); | ||
| }); | ||
|
|
||
| it('renders correlated transactions for a transaction dataset detector', async () => { | ||
| const transactionDetector = MetricDetectorFixture({ | ||
| projectId: project.id, | ||
| dataSources: [ | ||
| SnubaQueryDataSourceFixture({ | ||
| queryObj: { | ||
| id: '1', | ||
| status: 1, | ||
| subscription: '1', | ||
| snubaQuery: { | ||
| id: '', | ||
| aggregate: 'count()', | ||
| dataset: Dataset.TRANSACTIONS, | ||
| query: '', | ||
| timeWindow: 60, | ||
| eventTypes: [], | ||
| }, | ||
| }, | ||
| }), | ||
| ], | ||
| }); | ||
| MockApiClient.addMockResponse({ | ||
| url: `/organizations/${organization.slug}/detectors/${detector.id}/`, | ||
| body: transactionDetector, | ||
| }); | ||
|
|
||
| renderSection(); | ||
|
|
||
| expect(await screen.findByText('Correlated Transactions')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('renders nothing and never hits the legacy alert-rules endpoint without a metric detector', () => { | ||
| const alertRulesMock = MockApiClient.addMockResponse({ | ||
| url: `/organizations/${organization.slug}/alert-rules/123/`, | ||
| body: {}, | ||
| }); | ||
| const detectorMock = MockApiClient.addMockResponse({ | ||
| url: `/organizations/${organization.slug}/detectors/${detector.id}/`, | ||
| body: detector, | ||
| }); | ||
|
|
||
| renderSection({}); | ||
|
|
||
| expect(screen.queryByText('Correlated Issues')).not.toBeInTheDocument(); | ||
| expect(screen.queryByText('Correlated Transactions')).not.toBeInTheDocument(); | ||
| expect(alertRulesMock).not.toHaveBeenCalled(); | ||
| expect(detectorMock).not.toHaveBeenCalled(); | ||
| }); | ||
| }); | ||
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,57 @@ | ||
| import { | ||
| MetricDetectorFixture, | ||
| SnubaQueryDataSourceFixture, | ||
| } from 'sentry-fixture/detectors'; | ||
| import {ProjectFixture} from 'sentry-fixture/project'; | ||
|
|
||
| import {Dataset, EventTypes} from 'sentry/views/alerts/rules/metric/types'; | ||
| import {getMetricRuleFromDetector} from 'sentry/views/issueDetails/metricIssues/utils'; | ||
|
|
||
| describe('getMetricRuleFromDetector', () => { | ||
| const project = ProjectFixture(); | ||
|
|
||
| it('maps a metric detector snuba query into a MetricRule', () => { | ||
| const detector = MetricDetectorFixture({ | ||
| config: {detectionType: 'static'}, | ||
| dataSources: [ | ||
| SnubaQueryDataSourceFixture({ | ||
| queryObj: { | ||
| id: '1', | ||
| status: 1, | ||
| subscription: '1', | ||
| snubaQuery: { | ||
| id: '', | ||
| aggregate: 'count_unique(user)', | ||
| dataset: Dataset.ERRORS, | ||
| query: 'is:unresolved', | ||
| // seconds; should be converted to minutes | ||
| timeWindow: 3600, | ||
| eventTypes: [EventTypes.ERROR], | ||
| environment: 'prod', | ||
| }, | ||
| }, | ||
| }), | ||
| ], | ||
| }); | ||
|
|
||
| const rule = getMetricRuleFromDetector(detector, project); | ||
|
|
||
| expect(rule.aggregate).toBe('count_unique(user)'); | ||
| expect(rule.dataset).toBe(Dataset.ERRORS); | ||
| expect(rule.query).toBe('is:unresolved'); | ||
| expect(rule.eventTypes).toEqual([EventTypes.ERROR]); | ||
| expect(rule.environment).toBe('prod'); | ||
| expect(rule.projects).toEqual([project.slug]); | ||
| expect(rule.detectionType).toBe('static'); | ||
| // 3600s -> 60m | ||
| expect(rule.timeWindow).toBe(60); | ||
| }); | ||
|
|
||
| it('defaults environment to null when the snuba query has none', () => { | ||
| const detector = MetricDetectorFixture(); | ||
|
|
||
| const rule = getMetricRuleFromDetector(detector, project); | ||
|
|
||
| expect(rule.environment).toBeNull(); | ||
| }); | ||
| }); |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
idk how necessary this test is 🤔