Skip to content
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

[Backport 2.x] [Explorer] Fixes for cancel button and saved object loading #1200

Merged
merged 1 commit into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions common/constants/data_sources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ export enum DATA_SOURCE_TYPES {
SPARK = 'spark',
S3Glue = 's3glue',
}
export const ASYNC_POLLING_INTERVAL = 2000;
4 changes: 2 additions & 2 deletions public/components/common/search/sql_search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
import { isEqual } from 'lodash';
import React, { useEffect, useState } from 'react';
import { batch, useDispatch, useSelector } from 'react-redux';
import { QUERY_LANGUAGE } from '../../../../common/constants/data_sources';
import { ASYNC_POLLING_INTERVAL, QUERY_LANGUAGE } from '../../../../common/constants/data_sources';
import { APP_ANALYTICS_TAB_ID_REGEX, RAW_QUERY } from '../../../../common/constants/explorer';
import { PPL_NEWLINE_REGEX, PPL_SPAN_REGEX } from '../../../../common/constants/shared';
import { DirectQueryLoadingStatus, DirectQueryRequest } from '../../../../common/types/explorer';
Expand Down Expand Up @@ -103,7 +103,7 @@ export const DirectSearch = (props: any) => {
stopPolling,
} = usePolling<any, any>((params) => {
return sqlService.fetchWithJobId(params);
}, 2000);
}, ASYNC_POLLING_INTERVAL);

const requestParams = { tabId };
const { dispatchOnGettingHis } = useFetchEvents({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,22 @@ export const DirectQueryRunning = ({ tabId }: { tabId: string }) => {
const sqlService = new SQLService(coreRefs.http);

const cancelQuery = () => {
if (explorerSearchMeta.queryId !== '') {
sqlService
.deleteWithJobId({ queryId: explorerSearchMeta.queryId })
.catch((e) => {
console.error(e);
})
.finally(() => {
dispatch(
updateSearchMetaData({
tabId,
data: {
isPolling: false,
},
})
);
});
if (explorerSearchMeta.queryId) {
sqlService.deleteWithJobId({ queryId: explorerSearchMeta.queryId }).catch((e) => {
console.error(e);
});
}

// reset isPolling flag to remove loading page and queryId to empty
dispatch(
updateSearchMetaData({
tabId,
data: {
isPolling: false,
queryId: '',
},
})
);
};

return (
Expand Down
23 changes: 13 additions & 10 deletions public/components/event_analytics/home/home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -229,16 +229,6 @@ const EventAnalyticsHome = (props: IHomeProps) => {
>
Delete
</EuiContextMenuItem>,
<EuiContextMenuItem
key="redirect"
onClick={() => {
setIsActionsPopoverOpen(false);
history.push(`/explorer`);
}}
data-test-subj="eventHomeAction__explorer"
>
Event Explorer
</EuiContextMenuItem>,
<EuiContextMenuItem
key="addSample"
onClick={() => {
Expand Down Expand Up @@ -294,6 +284,19 @@ const EventAnalyticsHome = (props: IHomeProps) => {
<EuiContextMenuPanel items={popoverItems} />
</EuiPopover>
</EuiFlexItem>
<EuiFlexItem>
<EuiButton
key="redirect"
onClick={() => {
setIsActionsPopoverOpen(false);
history.push(`/explorer`);
}}
data-test-subj="eventHomeAction__explorer"
fill
>
Event Explorer
</EuiButton>
</EuiFlexItem>
</EuiFlexGroup>
</EuiPageContentHeaderSection>
</EuiPageContentHeader>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
import { QueryManager } from '../../../../common/query_manager';
import { statsChunk } from '../../../../common/query_manager/ast/types/stats';
import {
DirectQueryRequest,
IField,
SavedQuery,
SavedVisualization,
Expand All @@ -43,6 +44,9 @@ import { PollingConfigurations } from '../../../components/hooks';
import { SQLService } from '../../requests/sql';
import { coreRefs } from '../../../framework/core_refs';
import { UsePolling } from '../../../components/hooks/use_polling';
import { getAsyncSessionId, setAsyncSessionId } from '../../../../common/utils/query_session_utils';
import { get as getObjValue } from '../../../../common/utils/shared';
import { ASYNC_POLLING_INTERVAL } from '../../../../common/constants/data_sources';

enum DIRECT_DATA_SOURCE_TYPES {
DEFAULT_INDEX_PATTERNS = 'DEFAULT_INDEX_PATTERNS',
Expand Down Expand Up @@ -300,6 +304,12 @@ export class ExplorerSavedObjectLoader extends SavedObjectLoaderBase implements
dispatchOnGettingHis(pollingResult, '');
return true;
}
dispatch(
updateSearchMetaData({
tabId,
data: { status: pollingResult.status },
})
);
return false;
};

Expand All @@ -316,13 +326,23 @@ export class ExplorerSavedObjectLoader extends SavedObjectLoaderBase implements
loadSparkGlue = ({ objectData, dataSources, tabId }) => {
const { dispatch } = this.dispatchers;
const sqlService = new SQLService(coreRefs.http);
const sessionId = getAsyncSessionId();
const requestPayload = {
lang: objectData.query_lang.toLowerCase(),
query: objectData.query,
datasource: dataSources[0].label,
} as DirectQueryRequest;

if (sessionId) {
requestPayload.sessionId = sessionId;
}

// Create an instance of UsePolling
const polling = new UsePolling<any, any>(
(params) => {
return sqlService.fetchWithJobId(params);
},
5000,
ASYNC_POLLING_INTERVAL,
this.handleDirectQuerySuccess,
this.handleDirectQueryError,
{ tabId }
Expand All @@ -343,13 +363,11 @@ export class ExplorerSavedObjectLoader extends SavedObjectLoaderBase implements
);

sqlService
.fetch({
lang: objectData.query_lang.toLowerCase(),
query: objectData.query,
datasource: dataSources[0].label,
})
.fetch(requestPayload)
.then((result) => {
setAsyncSessionId(getObjValue(result, 'sessionId', null));
if (result.queryId) {
dispatch(updateSearchMetaData({ tabId, data: { queryId: result.queryId } }));
startPolling({ queryId: result.queryId });
} else {
console.log('no query id found in response');
Expand Down
Loading