-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
feat(ourlogs): Switch needle in haystack to time based #111946
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| import {useCallback, useEffect, useMemo, useState} from 'react'; | ||
| import {useCallback, useEffect, useMemo, useRef, useState} from 'react'; | ||
| import * as Sentry from '@sentry/react'; | ||
| import {logger} from '@sentry/react'; | ||
|
|
||
| import {type ApiResult} from 'sentry/api'; | ||
|
|
@@ -28,6 +29,8 @@ import {SAMPLING_MODE} from 'sentry/views/explore/hooks/useProgressiveQuery'; | |
| import {useTraceItemDetails} from 'sentry/views/explore/hooks/useTraceItemDetails'; | ||
| import { | ||
| AlwaysPresentLogFields, | ||
| FLEX_TIME_INITIAL_SEARCH_DURATION_MS, | ||
| FLEX_TIME_RESUME_SEARCH_DURATION_MS, | ||
| MAX_LOG_INGEST_DELAY, | ||
| MAX_LOGS_INFINITE_QUERY_PAGES, | ||
| QUERY_PAGE_LIMIT, | ||
|
|
@@ -405,12 +408,10 @@ type QueryKey = [ | |
| export function useInfiniteLogsQuery({ | ||
| disabled, | ||
| highFidelity, | ||
| maxAutoFetches = 5, | ||
| referrer, | ||
| }: { | ||
| disabled?: boolean; | ||
| highFidelity?: boolean; | ||
| maxAutoFetches?: number; | ||
| referrer?: string; | ||
| } = {}) { | ||
| const _referrer = referrer ?? 'api.explore.logs-table'; | ||
|
|
@@ -689,15 +690,40 @@ export function useInfiniteLogsQuery({ | |
| const lastPageLength = data?.pages?.[data.pages.length - 1]?.[0]?.data?.length ?? 0; | ||
| const limit = autoRefresh ? QUERY_PAGE_LIMIT_WITH_AUTO_REFRESH : QUERY_PAGE_LIMIT; | ||
|
|
||
| // the original state starts at -1 because we have to count | ||
| // the 1 query made by default outside of the auto fetches | ||
| const [autoFetchesRemaining, setAutoFetchesRemaining] = useState(maxAutoFetches - 1); | ||
| const [autoFetchStartTime, setAutoFetchStartTime] = useState<number>(() => Date.now()); | ||
| const [autoFetchDuration, setAutoFetchDuration] = useState( | ||
| FLEX_TIME_INITIAL_SEARCH_DURATION_MS | ||
| ); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Autofetch timer never resets per new queryMedium Severity
Additional Locations (1) |
||
| const canAutoFetchNextPage = | ||
| !!highFidelity && | ||
| hasNextPage && | ||
| nextPageHasData && | ||
| (lastPageLength === 0 || _data.length < limit); | ||
| const shouldAutoFetchNextPage = canAutoFetchNextPage && autoFetchesRemaining > 0; | ||
| const shouldAutoFetchNextPage = | ||
| canAutoFetchNextPage && Date.now() - autoFetchStartTime < autoFetchDuration; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Time-only autofetch can flood API requestsMedium Severity Replacing Additional Locations (1) |
||
|
|
||
| const autoFetchPageCount = useRef(0); | ||
| const prevShouldAutoFetch = useRef(false); | ||
|
|
||
| useEffect(() => { | ||
| if (shouldAutoFetchNextPage && !prevShouldAutoFetch.current) { | ||
| autoFetchPageCount.current = 0; | ||
| } | ||
|
|
||
| if (!shouldAutoFetchNextPage && prevShouldAutoFetch.current && highFidelity) { | ||
| Sentry.metrics.distribution( | ||
| 'explore.logs.flex_time_pages_before_data', | ||
| autoFetchPageCount.current, | ||
| { | ||
| attributes: { | ||
| found_data: _data.length > 0 ? 'true' : 'false', | ||
| }, | ||
| } | ||
| ); | ||
| } | ||
|
|
||
| prevShouldAutoFetch.current = shouldAutoFetchNextPage; | ||
| }, [shouldAutoFetchNextPage, highFidelity, _data.length]); | ||
|
|
||
| useEffect(() => { | ||
| if (!shouldAutoFetchNextPage) { | ||
|
|
@@ -708,7 +734,7 @@ export function useInfiniteLogsQuery({ | |
| return; | ||
| } | ||
|
|
||
| setAutoFetchesRemaining(remaining => remaining - 1); | ||
| autoFetchPageCount.current += 1; | ||
| _fetchNextPage(); | ||
| }, [shouldAutoFetchNextPage, isFetchingNextPage, _fetchNextPage, nextPageCursor]); | ||
|
|
||
|
|
@@ -741,7 +767,10 @@ export function useInfiniteLogsQuery({ | |
| isFetchingPreviousPage, | ||
| lastPageLength, | ||
| canResumeAutoFetch: canAutoFetchNextPage, | ||
| resumeAutoFetch: () => setAutoFetchesRemaining(maxAutoFetches), | ||
| resumeAutoFetch: () => { | ||
| setAutoFetchStartTime(Date.now()); | ||
| setAutoFetchDuration(FLEX_TIME_RESUME_SEARCH_DURATION_MS); | ||
| }, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Resume duration leaks into later searchesLow Severity
Additional Locations (1) |
||
| dataScanned, | ||
| bytesScanned: totalBytesScanned, | ||
| }; | ||
|
|
||


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.
Bug: The auto-fetch timer state (
autoFetchStartTime,autoFetchDuration) is not reset when the user changes query parameters, preventing or delaying auto-fetching on subsequent searches.Severity: HIGH
Suggested Fix
Use a
useEffecthook that triggers when the query key (queryKeyWithInfinite) changes. Inside this effect, reset theautoFetchStartTimestate toDate.now()and theautoFetchDurationstate to the initial value (FLEX_TIME_INITIAL_SEARCH_DURATION_MS). This will ensure every new, distinct query starts with a fresh auto-fetch timer.Prompt for AI Agent
Did we get this right? 👍 / 👎 to inform future reviews.