Explore: fix logs no results and scanning states (#98605)

This commit is contained in:
Matias Chomicki 2025-01-15 22:08:19 +00:00 committed by GitHub
parent d025523a8b
commit 3641b28e84
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 59 additions and 31 deletions

View File

@ -968,13 +968,13 @@ const UnthemedLogs: React.FunctionComponent<Props> = (props: Props) => {
/> />
</div> </div>
)} )}
{visualisationType === 'logs' && ( {visualisationType === 'logs' && hasData && (
<div <>
className={config.featureToggles.logsInfiniteScrolling ? styles.scrollableLogRows : styles.logRows} <div
data-testid="logRows" className={config.featureToggles.logsInfiniteScrolling ? styles.scrollableLogRows : styles.logRows}
ref={logsContainerRef} data-testid="logRows"
> ref={logsContainerRef}
{hasData && ( >
<InfiniteScroll <InfiniteScroll
loading={loading} loading={loading}
loadMoreLogs={infiniteScrollAvailable ? loadMoreLogs : undefined} loadMoreLogs={infiniteScrollAvailable ? loadMoreLogs : undefined}
@ -1022,41 +1022,41 @@ const UnthemedLogs: React.FunctionComponent<Props> = (props: Props) => {
renderPreview renderPreview
/> />
</InfiniteScroll> </InfiniteScroll>
)} </div>
</div> <LogsNavigation
logsSortOrder={logsSortOrder}
visibleRange={navigationRange ?? absoluteRange}
absoluteRange={absoluteRange}
timeZone={timeZone}
onChangeTime={onChangeTime}
loading={loading}
queries={logsQueries ?? []}
scrollToTopLogs={scrollToTopLogs}
addResultsToCache={addResultsToCache}
clearCache={clearCache}
/>
</>
)} )}
{!loading && !hasData && !scanning && ( {!loading && !hasData && !scanning && (
<div className={styles.logRows}> <div className={styles.noDataWrapper}>
<div className={styles.noData}> <div className={styles.noData}>
<Trans i18nKey="explore.logs.no-logs-found">No logs found.</Trans> <Trans i18nKey="explore.logs.no-logs-found">No logs found.</Trans>
<Button size="sm" variant="secondary" onClick={onClickScan}> <Button size="sm" variant="secondary" className={styles.scanButton} onClick={onClickScan}>
<Trans i18nKey="explore.logs.scan-for-older-logs">Scan for older logs</Trans> <Trans i18nKey="explore.logs.scan-for-older-logs">Scan for older logs</Trans>
</Button> </Button>
</div> </div>
</div> </div>
)} )}
{scanning && ( {scanning && (
<div className={styles.logRows}> <div className={styles.noDataWrapper}>
<div className={styles.noData}> <div className={styles.noData}>
<span>{scanText}</span> <span>{scanText}</span>
<Button size="sm" variant="secondary" onClick={onClickStopScan}> <Button size="sm" variant="secondary" className={styles.scanButton} onClick={onClickStopScan}>
<Trans i18nKey="explore.logs.stop-scan">Stop scan</Trans> <Trans i18nKey="explore.logs.stop-scan">Stop scan</Trans>
</Button> </Button>
</div> </div>
</div> </div>
)} )}
<LogsNavigation
logsSortOrder={logsSortOrder}
visibleRange={navigationRange ?? absoluteRange}
absoluteRange={absoluteRange}
timeZone={timeZone}
onChangeTime={onChangeTime}
loading={loading}
queries={logsQueries ?? []}
scrollToTopLogs={scrollToTopLogs}
addResultsToCache={addResultsToCache}
clearCache={clearCache}
/>
</div> </div>
</PanelChrome> </PanelChrome>
</> </>
@ -1067,10 +1067,17 @@ export const Logs = withTheme2(UnthemedLogs);
const getStyles = (theme: GrafanaTheme2, wrapLogMessage: boolean, tableHeight: number) => { const getStyles = (theme: GrafanaTheme2, wrapLogMessage: boolean, tableHeight: number) => {
return { return {
noDataWrapper: css({
display: 'flex',
justifyContent: 'center',
width: '100%',
paddingBottom: theme.spacing(2),
}),
noData: css({ noData: css({
'& > *': { display: 'inline-block',
marginLeft: '0.5em', }),
}, scanButton: css({
marginLeft: theme.spacing(1),
}), }),
logOptions: css({ logOptions: css({
display: 'flex', display: 'flex',

View File

@ -323,7 +323,7 @@ describe('running queries', () => {
cleanSupplementaryQueryAction({ exploreId, type: SupplementaryQueryType.LogsSample }), 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 = { const initialState = {
...makeExplorePaneState(), ...makeExplorePaneState(),
}; };
@ -333,6 +333,23 @@ describe('running queries', () => {
expect(dispatchedActions).toContainEqual(cancelQueriesAction({ exploreId })); 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', () => { describe('changeQueries', () => {

View File

@ -528,7 +528,10 @@ interface RunQueriesOptions {
export const runQueries = createAsyncThunk<void, RunQueriesOptions>( export const runQueries = createAsyncThunk<void, RunQueriesOptions>(
'explore/runQueries', 'explore/runQueries',
async ({ exploreId, preserveCache }, { dispatch, getState }) => { 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( const { defaultCorrelationEditorDatasource, scopedVars, showCorrelationEditorLinks } = await getCorrelationsData(
getState(), getState(),
@ -658,11 +661,12 @@ export const runQueries = createAsyncThunk<void, RunQueriesOptions>(
// Keep scanning for results if this was the last scanning transaction // Keep scanning for results if this was the last scanning transaction
if (exploreState!.scanning) { if (exploreState!.scanning) {
console.log(data.series);
if (data.state === LoadingState.Done && data.series.length === 0) { if (data.state === LoadingState.Done && data.series.length === 0) {
const range = getShiftedTimeRange(-1, exploreState!.range); const range = getShiftedTimeRange(-1, exploreState!.range);
dispatch(updateTime({ exploreId, absoluteRange: range })); dispatch(updateTime({ exploreId, absoluteRange: range }));
dispatch(runQueries({ exploreId })); dispatch(runQueries({ exploreId }));
} else { } else if (data.series[0]?.length > 0 || data.state === LoadingState.Done) {
// We can stop scanning if we have a result // We can stop scanning if we have a result
dispatch(scanStopAction({ exploreId })); dispatch(scanStopAction({ exploreId }));
} }