-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
feat(tracemetrics): Add progressive loading to metrics page #102100
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
narsaynorath
merged 11 commits into
master
from
narsaynorath/logs-443-add-progressive-querying-to-metrics-querying
Oct 27, 2025
Merged
Changes from 6 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
5e53b10
fix(tracemetrics): Progressively load metrics timeseries
narsaynorath e74ec51
feat(tracemetrics): Add progressive loading to metrics querying
narsaynorath c8dd218
Add querying to aggregate tab hook
narsaynorath 27e5f48
test utils
narsaynorath 0071b31
fix disabling extrapolation
narsaynorath 7a7a6f7
Merge branch 'master' into narsaynorath/logs-443-add-progressive-quer…
narsaynorath a578585
fix name
narsaynorath 0e4e692
Use metric query params provider
narsaynorath 8b3594c
Merge branch 'master' into narsaynorath/logs-443-add-progressive-quer…
narsaynorath d60e0bd
Use multimetrics query params provider and add tracemetric
narsaynorath 0c08647
Use metric util to get query params
narsaynorath 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| import type {ReactNode} from 'react'; | ||
|
|
||
| import {useLocation} from 'sentry/utils/useLocation'; | ||
| import useOrganization from 'sentry/utils/useOrganization'; | ||
| import {QueryParamsContextProvider} from 'sentry/views/explore/queryParams/context'; | ||
| import {getReadableQueryParamsFromLocation} from 'sentry/views/explore/spans/spansQueryParams'; | ||
|
|
||
| export function MockQueryParamsContextWrapper({ | ||
| children, | ||
| }: { | ||
| children: ReactNode; | ||
| extrapolate?: boolean; | ||
| }) { | ||
| const location = useLocation(); | ||
| const organization = useOrganization(); | ||
| const queryParams = getReadableQueryParamsFromLocation(location, organization); | ||
narsaynorath marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return ( | ||
| <QueryParamsContextProvider | ||
| queryParams={queryParams} | ||
| setQueryParams={() => {}} | ||
| isUsingDefaultFields | ||
| shouldManageFields={false} | ||
| > | ||
| {children} | ||
| </QueryParamsContextProvider> | ||
| ); | ||
| } | ||
124 changes: 124 additions & 0 deletions
124
static/app/views/explore/metrics/hooks/useMetricAggregatesTable.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,124 @@ | ||
| import {PageFilterStateFixture} from 'sentry-fixture/pageFilters'; | ||
|
|
||
| import {renderHookWithProviders, waitFor} from 'sentry-test/reactTestingLibrary'; | ||
|
|
||
| import usePageFilters from 'sentry/utils/usePageFilters'; | ||
| import {SAMPLING_MODE} from 'sentry/views/explore/hooks/useProgressiveQuery'; | ||
| import {MockQueryParamsContextWrapper} from 'sentry/views/explore/metrics/hooks/testUtils'; | ||
| import {useMetricAggregatesTable} from 'sentry/views/explore/metrics/hooks/useMetricAggregatesTable'; | ||
|
|
||
| jest.mock('sentry/utils/usePageFilters'); | ||
|
|
||
| describe('useMetricAggregatesTable', () => { | ||
| beforeEach(() => { | ||
| jest.mocked(usePageFilters).mockReturnValue(PageFilterStateFixture()); | ||
| jest.clearAllMocks(); | ||
| }); | ||
|
|
||
| it('triggers the high accuracy request when there is no data and a partial scan', async () => { | ||
| const mockNormalRequestUrl = MockApiClient.addMockResponse({ | ||
| url: '/organizations/org-slug/events/', | ||
| body: { | ||
| data: [], | ||
| meta: { | ||
| dataScanned: 'partial', | ||
| fields: {}, | ||
| }, | ||
| }, | ||
| method: 'GET', | ||
| match: [ | ||
| function (_url: string, options: Record<string, any>) { | ||
| return options.query.sampling === SAMPLING_MODE.NORMAL; | ||
| }, | ||
| ], | ||
| }); | ||
| const mockHighAccuracyRequest = MockApiClient.addMockResponse({ | ||
| url: '/organizations/org-slug/events/', | ||
| match: [ | ||
| function (_url: string, options: Record<string, any>) { | ||
| return options.query.sampling === SAMPLING_MODE.HIGH_ACCURACY; | ||
| }, | ||
| ], | ||
| method: 'GET', | ||
| }); | ||
| renderHookWithProviders( | ||
| () => | ||
| useMetricAggregatesTable({ | ||
| metricName: 'test metric', | ||
| limit: 100, | ||
| enabled: true, | ||
| }), | ||
| { | ||
| additionalWrapper: MockQueryParamsContextWrapper, | ||
| } | ||
| ); | ||
|
|
||
| expect(mockNormalRequestUrl).toHaveBeenCalledTimes(1); | ||
| expect(mockNormalRequestUrl).toHaveBeenCalledWith( | ||
| '/organizations/org-slug/events/', | ||
| expect.objectContaining({ | ||
| query: expect.objectContaining({ | ||
| sampling: SAMPLING_MODE.NORMAL, | ||
| }), | ||
| }) | ||
| ); | ||
|
|
||
| await waitFor(() => { | ||
| expect(mockHighAccuracyRequest).toHaveBeenCalledTimes(1); | ||
| }); | ||
| expect(mockHighAccuracyRequest).toHaveBeenCalledWith( | ||
| '/organizations/org-slug/events/', | ||
| expect.objectContaining({ | ||
| query: expect.objectContaining({ | ||
| sampling: SAMPLING_MODE.HIGH_ACCURACY, | ||
| }), | ||
| }) | ||
| ); | ||
| }); | ||
|
|
||
| it('disables extrapolation', async () => { | ||
narsaynorath marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| const mockNonExtrapolatedRequest = MockApiClient.addMockResponse({ | ||
| url: '/organizations/org-slug/events/', | ||
| match: [ | ||
| function (_url: string, options: Record<string, any>) { | ||
| return ( | ||
| options.query.sampling === SAMPLING_MODE.HIGH_ACCURACY && | ||
| options.query.disableAggregateExtrapolation === '1' | ||
| ); | ||
| }, | ||
| ], | ||
| method: 'GET', | ||
| }); | ||
|
|
||
| renderHookWithProviders( | ||
| () => | ||
| useMetricAggregatesTable({ | ||
| metricName: 'test metric', | ||
| limit: 100, | ||
| enabled: true, | ||
| }), | ||
| { | ||
| additionalWrapper: MockQueryParamsContextWrapper, | ||
| initialRouterConfig: { | ||
| location: { | ||
| pathname: '/organizations/org-slug/explore/metrics/', | ||
| query: { | ||
| extrapolate: '0', | ||
| }, | ||
| }, | ||
| }, | ||
| } | ||
| ); | ||
|
|
||
| await waitFor(() => expect(mockNonExtrapolatedRequest).toHaveBeenCalledTimes(1)); | ||
| expect(mockNonExtrapolatedRequest).toHaveBeenCalledWith( | ||
| '/organizations/org-slug/events/', | ||
| expect.objectContaining({ | ||
| query: expect.objectContaining({ | ||
| disableAggregateExtrapolation: '1', | ||
| sampling: SAMPLING_MODE.HIGH_ACCURACY, | ||
| }), | ||
| }) | ||
| ); | ||
| }); | ||
| }); | ||
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
127 changes: 127 additions & 0 deletions
127
static/app/views/explore/metrics/hooks/useMetricSamplesTable.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,127 @@ | ||
| import {PageFilterStateFixture} from 'sentry-fixture/pageFilters'; | ||
|
|
||
| import {renderHookWithProviders, waitFor} from 'sentry-test/reactTestingLibrary'; | ||
|
|
||
| import usePageFilters from 'sentry/utils/usePageFilters'; | ||
| import {SAMPLING_MODE} from 'sentry/views/explore/hooks/useProgressiveQuery'; | ||
| import {MockQueryParamsContextWrapper} from 'sentry/views/explore/metrics/hooks/testUtils'; | ||
| import {useMetricSamplesTable} from 'sentry/views/explore/metrics/hooks/useMetricSamplesTable'; | ||
|
|
||
| jest.mock('sentry/utils/usePageFilters'); | ||
|
|
||
| describe('useMetricTimeseries', () => { | ||
|
||
| beforeEach(() => { | ||
| jest.mocked(usePageFilters).mockReturnValue(PageFilterStateFixture()); | ||
| jest.clearAllMocks(); | ||
| }); | ||
|
|
||
| it('triggers the high accuracy request when there is no data and a partial scan', async () => { | ||
| const mockNormalRequestUrl = MockApiClient.addMockResponse({ | ||
| url: '/organizations/org-slug/events/', | ||
| body: { | ||
| data: [], | ||
| meta: { | ||
| dataScanned: 'partial', | ||
| fields: {}, | ||
| }, | ||
| }, | ||
| method: 'GET', | ||
| match: [ | ||
| function (_url: string, options: Record<string, any>) { | ||
| return options.query.sampling === SAMPLING_MODE.NORMAL; | ||
| }, | ||
| ], | ||
| }); | ||
| const mockHighAccuracyRequest = MockApiClient.addMockResponse({ | ||
| url: '/organizations/org-slug/events/', | ||
| match: [ | ||
| function (_url: string, options: Record<string, any>) { | ||
| return options.query.sampling === SAMPLING_MODE.HIGH_ACCURACY; | ||
| }, | ||
| ], | ||
| method: 'GET', | ||
| }); | ||
| renderHookWithProviders( | ||
| () => | ||
| useMetricSamplesTable({ | ||
| metricName: 'test metric', | ||
| fields: [], | ||
| limit: 100, | ||
| ingestionDelaySeconds: 0, | ||
| enabled: true, | ||
| }), | ||
| { | ||
| additionalWrapper: MockQueryParamsContextWrapper, | ||
| } | ||
| ); | ||
|
|
||
| expect(mockNormalRequestUrl).toHaveBeenCalledTimes(1); | ||
| expect(mockNormalRequestUrl).toHaveBeenCalledWith( | ||
| '/organizations/org-slug/events/', | ||
| expect.objectContaining({ | ||
| query: expect.objectContaining({ | ||
| sampling: SAMPLING_MODE.NORMAL, | ||
| }), | ||
| }) | ||
| ); | ||
|
|
||
| await waitFor(() => { | ||
| expect(mockHighAccuracyRequest).toHaveBeenCalledTimes(1); | ||
| }); | ||
| expect(mockHighAccuracyRequest).toHaveBeenCalledWith( | ||
| '/organizations/org-slug/events/', | ||
| expect.objectContaining({ | ||
| query: expect.objectContaining({ | ||
| sampling: SAMPLING_MODE.HIGH_ACCURACY, | ||
| }), | ||
| }) | ||
| ); | ||
| }); | ||
|
|
||
| it('disables extrapolation', async () => { | ||
narsaynorath marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| const mockNonExtrapolatedRequest = MockApiClient.addMockResponse({ | ||
| url: '/organizations/org-slug/events/', | ||
| match: [ | ||
| function (_url: string, options: Record<string, any>) { | ||
| return ( | ||
| options.query.sampling === SAMPLING_MODE.HIGH_ACCURACY && | ||
| options.query.disableAggregateExtrapolation === '1' | ||
| ); | ||
| }, | ||
| ], | ||
| method: 'GET', | ||
| }); | ||
|
|
||
| renderHookWithProviders( | ||
| () => | ||
| useMetricSamplesTable({ | ||
| metricName: 'test metric', | ||
| fields: [], | ||
| limit: 100, | ||
| enabled: true, | ||
| }), | ||
| { | ||
| additionalWrapper: MockQueryParamsContextWrapper, | ||
| initialRouterConfig: { | ||
| location: { | ||
| pathname: '/organizations/org-slug/explore/metrics/', | ||
| query: { | ||
| extrapolate: '0', | ||
| }, | ||
| }, | ||
| }, | ||
| } | ||
| ); | ||
|
|
||
| await waitFor(() => expect(mockNonExtrapolatedRequest).toHaveBeenCalledTimes(1)); | ||
| expect(mockNonExtrapolatedRequest).toHaveBeenCalledWith( | ||
| '/organizations/org-slug/events/', | ||
| expect.objectContaining({ | ||
| query: expect.objectContaining({ | ||
| disableAggregateExtrapolation: '1', | ||
| sampling: SAMPLING_MODE.HIGH_ACCURACY, | ||
| }), | ||
| }) | ||
| ); | ||
| }); | ||
| }); | ||
Oops, something went wrong.
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.