From 3641b28e844549dfbed71bfc7ef40039e137dcb5 Mon Sep 17 00:00:00 2001 From: Matias Chomicki Date: Wed, 15 Jan 2025 22:08:19 +0000 Subject: [PATCH] Explore: fix logs no results and scanning states (#98605) --- public/app/features/explore/Logs/Logs.tsx | 63 ++++++++++--------- .../app/features/explore/state/query.test.ts | 19 +++++- public/app/features/explore/state/query.ts | 8 ++- 3 files changed, 59 insertions(+), 31 deletions(-) diff --git a/public/app/features/explore/Logs/Logs.tsx b/public/app/features/explore/Logs/Logs.tsx index a82f30e196b..57a69022712 100644 --- a/public/app/features/explore/Logs/Logs.tsx +++ b/public/app/features/explore/Logs/Logs.tsx @@ -968,13 +968,13 @@ const UnthemedLogs: React.FunctionComponent = (props: Props) => { /> )} - {visualisationType === 'logs' && ( -
- {hasData && ( + {visualisationType === 'logs' && hasData && ( + <> +
= (props: Props) => { renderPreview /> - )} -
+
+ + )} {!loading && !hasData && !scanning && ( -
+
No logs found. -
)} {scanning && ( -
+
{scanText} -
)} -
@@ -1067,10 +1067,17 @@ export const Logs = withTheme2(UnthemedLogs); const getStyles = (theme: GrafanaTheme2, wrapLogMessage: boolean, tableHeight: number) => { return { + noDataWrapper: css({ + display: 'flex', + justifyContent: 'center', + width: '100%', + paddingBottom: theme.spacing(2), + }), noData: css({ - '& > *': { - marginLeft: '0.5em', - }, + display: 'inline-block', + }), + scanButton: css({ + marginLeft: theme.spacing(1), }), logOptions: css({ display: 'flex', diff --git a/public/app/features/explore/state/query.test.ts b/public/app/features/explore/state/query.test.ts index eb84d558a84..a3e55f10d80 100644 --- a/public/app/features/explore/state/query.test.ts +++ b/public/app/features/explore/state/query.test.ts @@ -323,7 +323,7 @@ describe('running queries', () => { cleanSupplementaryQueryAction({ exploreId, type: SupplementaryQueryType.LogsSample }), ]); }); - it('should cancel running query when a new query is issued', async () => { + it('should cancel running queries when a new query is issued', async () => { const initialState = { ...makeExplorePaneState(), }; @@ -333,6 +333,23 @@ describe('running queries', () => { expect(dispatchedActions).toContainEqual(cancelQueriesAction({ exploreId })); }); + it('should not cancel running queries when scanning', async () => { + const initialState = { + ...makeExplorePaneState(), + explore: { + panes: { + [exploreId]: { + scanning: true, + }, + }, + }, + }; + const dispatchedActions = await thunkTester(initialState) + .givenThunk(runQueries) + .whenThunkIsDispatched({ exploreId }); + + expect(dispatchedActions).not.toContainEqual(cancelQueriesAction({ exploreId })); + }); }); describe('changeQueries', () => { diff --git a/public/app/features/explore/state/query.ts b/public/app/features/explore/state/query.ts index 88181538dcd..e8ee7a86b44 100644 --- a/public/app/features/explore/state/query.ts +++ b/public/app/features/explore/state/query.ts @@ -528,7 +528,10 @@ interface RunQueriesOptions { export const runQueries = createAsyncThunk( 'explore/runQueries', async ({ exploreId, preserveCache }, { dispatch, getState }) => { - dispatch(cancelQueries(exploreId)); + // Running cancel queries when Explore is scanning will cancel the scanning state + if (!getState().explore?.panes[exploreId]?.scanning) { + dispatch(cancelQueries(exploreId)); + } const { defaultCorrelationEditorDatasource, scopedVars, showCorrelationEditorLinks } = await getCorrelationsData( getState(), @@ -658,11 +661,12 @@ export const runQueries = createAsyncThunk( // Keep scanning for results if this was the last scanning transaction if (exploreState!.scanning) { + console.log(data.series); if (data.state === LoadingState.Done && data.series.length === 0) { const range = getShiftedTimeRange(-1, exploreState!.range); dispatch(updateTime({ exploreId, absoluteRange: range })); dispatch(runQueries({ exploreId })); - } else { + } else if (data.series[0]?.length > 0 || data.state === LoadingState.Done) { // We can stop scanning if we have a result dispatch(scanStopAction({ exploreId })); }