Skip to content

Commit 99048b9

Browse files
Zylphrexshashjar
authored andcommitted
feat(logs): Add better loading state for flex time strategy (#102104)
Previously, the flex time strategy could result in a really long loading state. This change shows a live progress with the bytes scanned in the loading state to indicate we're still working on it. Closes LOGS-438
1 parent 12b02ec commit 99048b9

File tree

6 files changed

+62
-4
lines changed

6 files changed

+62
-4
lines changed

static/app/utils/discover/eventView.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ export type MetaType = Record<string, any> & {
6969
export type EventsMetaType = {fields: Record<string, ColumnType>} & {
7070
units: Record<string, string>;
7171
} & {
72+
bytesScanned?: number | null;
7273
dataScanned?: 'full' | 'partial';
7374
discoverSplitDecision?: WidgetType;
7475
isMetricsData?: boolean;

static/app/views/explore/logs/tables/logsInfiniteTable.tsx

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type {CSSProperties} from 'react';
12
import {Fragment, useCallback, useEffect, useMemo, useRef, useState} from 'react';
23
import {useTheme} from '@emotion/react';
34
import styled from '@emotion/styled';
@@ -8,6 +9,7 @@ import {Button} from 'sentry/components/core/button';
89
import {ExternalLink} from 'sentry/components/core/link';
910
import {Tooltip} from 'sentry/components/core/tooltip';
1011
import EmptyStateWarning from 'sentry/components/emptyStateWarning';
12+
import FileSize from 'sentry/components/fileSize';
1113
import LoadingIndicator from 'sentry/components/loadingIndicator';
1214
import JumpButtons from 'sentry/components/replays/jumpButtons';
1315
import useJumpButtons from 'sentry/components/replays/useJumpButtons';
@@ -106,6 +108,7 @@ export function LogsInfiniteTable({
106108
const {infiniteLogsQueryResult} = useLogsPageData();
107109
const lastFetchTime = useRef<number | null>(null);
108110
const {
111+
bytesScanned,
109112
isPending,
110113
isEmpty,
111114
meta,
@@ -385,7 +388,7 @@ export function LogsInfiniteTable({
385388
</TableRow>
386389
)}
387390
{/* Only render these in table for non-replay contexts */}
388-
{!hasReplay && isPending && <LoadingRenderer />}
391+
{!hasReplay && isPending && <LoadingRenderer bytesScanned={bytesScanned} />}
389392
{!hasReplay && isError && <ErrorRenderer />}
390393
{!hasReplay && isEmpty && (emptyRenderer ? emptyRenderer() : <EmptyRenderer />)}
391394
{!autoRefresh && !isPending && isFetchingPreviousPage && (
@@ -573,14 +576,41 @@ function ErrorRenderer() {
573576
);
574577
}
575578

576-
export function LoadingRenderer({size}: {size?: number}) {
579+
export function LoadingRenderer({bytesScanned}: {bytesScanned?: number | null}) {
577580
return (
578-
<TableStatus size={size}>
579-
<LoadingIndicator size={size} />
581+
<TableStatus>
582+
<LoadingStateContainer>
583+
<EmptyStateText size="md" textAlign="center">
584+
<StyledLoadingIndicator margin="1em auto" />
585+
{defined(bytesScanned) && bytesScanned > 0 && (
586+
<Fragment>
587+
{t('Searching for a needle in a haystack. This could take a while.')}
588+
<br />
589+
<span>
590+
{tct('[bytesScanned] scanned', {
591+
bytesScanned: <FileSize bytes={bytesScanned} base={2} />,
592+
})}
593+
</span>
594+
</Fragment>
595+
)}
596+
</EmptyStateText>
597+
</LoadingStateContainer>
580598
</TableStatus>
581599
);
582600
}
583601

602+
const LoadingStateContainer = styled('div')`
603+
display: flex;
604+
flex-direction: column;
605+
align-items: center;
606+
`;
607+
608+
const StyledLoadingIndicator = styled(LoadingIndicator)<{
609+
margin: CSSProperties['margin'];
610+
}>`
611+
${p => p.margin && `margin: ${p.margin}`};
612+
`;
613+
584614
function HoveringRowLoadingRenderer({
585615
position,
586616
isEmbedded,

static/app/views/explore/logs/useLogsQuery.tsx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,27 @@ export function useInfiniteLogsQuery({
584584

585585
const {virtualStreamedTimestamp} = useVirtualStreaming({data, highFidelity});
586586

587+
// Due to the way we prune empty pages, we cannot simply compute the sum of bytes scanned
588+
// for all pages as most empty pages would have been evicted already.
589+
//
590+
// Instead, we watch the last page loaded, and keep a running sum that is reset when
591+
// the last page is falsey which corresponds to a query change.
592+
const [totalBytesScanned, setTotalBytesScanned] = useState(0);
593+
const lastPage = data?.pages?.[data?.pages?.length - 1];
594+
useEffect(() => {
595+
if (!lastPage) {
596+
setTotalBytesScanned(0);
597+
return;
598+
}
599+
600+
const bytesScanned = lastPage[0].meta?.bytesScanned;
601+
if (!defined(bytesScanned)) {
602+
return;
603+
}
604+
605+
setTotalBytesScanned(previousBytesScanned => previousBytesScanned + bytesScanned);
606+
}, [lastPage]);
607+
587608
const _data = useMemo(() => {
588609
const usedRowIds = new Set();
589610
const filteredData =
@@ -694,6 +715,7 @@ export function useInfiniteLogsQuery({
694715
isFetchingNextPage: _data.length > 0 && (waitingToAutoFetch || isFetchingNextPage),
695716
isFetchingPreviousPage,
696717
lastPageLength,
718+
bytesScanned: totalBytesScanned,
697719
};
698720
}
699721

static/app/views/explore/logs/useLogsTimeseries.spec.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ describe('useLogsTimeseries', () => {
100100
isFetchingNextPage: false,
101101
isFetchingPreviousPage: false,
102102
lastPageLength: 0,
103+
bytesScanned: 0,
103104
},
104105
}),
105106
{additionalWrapper: Wrapper}

static/app/views/explore/logs/useStreamingTimeseriesResult.spec.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ describe('useStreamingTimeseriesResult', () => {
101101
isFetchingNextPage: false,
102102
isFetchingPreviousPage: false,
103103
lastPageLength: logFixtures.length,
104+
bytesScanned: 0,
104105
} as UseInfiniteLogsQueryResult;
105106
}
106107

static/app/views/explore/tables/tracesTable/styles.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type {CSSProperties} from 'react';
12
import {css} from '@emotion/react';
23
import styled from '@emotion/styled';
34

@@ -89,10 +90,12 @@ export const BreakdownPanelItem = styled(StyledPanelItem)<{highlightedSliceName:
8990

9091
export const EmptyStateText = styled('div')<{
9192
size: 'xl' | 'md';
93+
textAlign?: CSSProperties['textAlign'];
9294
}>`
9395
color: ${p => p.theme.subText};
9496
font-size: ${p => p.theme.fontSize[p.size]};
9597
padding-bottom: ${space(1)};
98+
${p => p.textAlign && `text-align: ${p.textAlign}`};
9699
`;
97100

98101
export const EmptyValueContainer = styled('span')`

0 commit comments

Comments
 (0)