From 081218e97520672d2d746a0c8bb99e7022944fdc Mon Sep 17 00:00:00 2001 From: Eric Date: Wed, 8 Nov 2023 21:29:52 +0000 Subject: [PATCH] Revert "[Explorer] Supports session for s3 direct query (#1178) (#1183)" This reverts commit d50047fa6a4872339a4a017dd3e404cbafc49f7a. --- common/constants/data_sources.ts | 5 --- common/constants/shared.ts | 4 -- common/types/explorer.ts | 7 --- common/utils/query_session_utils.ts | 16 ------- common/utils/shared.ts | 8 ---- .../components/common/search/sql_search.tsx | 29 +++++------- .../datasources/datasources_selection.tsx | 44 +------------------ public/services/requests/sql.ts | 11 ++++- .../routes/datasources/datasources_router.ts | 1 - 9 files changed, 21 insertions(+), 104 deletions(-) delete mode 100644 common/utils/query_session_utils.ts delete mode 100644 common/utils/shared.ts diff --git a/common/constants/data_sources.ts b/common/constants/data_sources.ts index ad5c0cfdf4..aa596ad108 100644 --- a/common/constants/data_sources.ts +++ b/common/constants/data_sources.ts @@ -14,8 +14,3 @@ export const enum QUERY_LANGUAGE { SQL = 'SQL', DQL = 'DQL', } -export enum DATA_SOURCE_TYPES { - DEFAULT_CLUSTER_TYPE = DEFAULT_DATA_SOURCE_TYPE, - SPARK = 'spark', - S3Glue = 's3glue', -} diff --git a/common/constants/shared.ts b/common/constants/shared.ts index 2116454852..198ce05a33 100644 --- a/common/constants/shared.ts +++ b/common/constants/shared.ts @@ -246,7 +246,3 @@ export const VISUALIZATION_ERROR = { }; export const S3_DATASOURCE_TYPE = 'S3_DATASOURCE'; - -export const ASYNC_QUERY_SESSION_ID = 'async-query-session-id'; - -export const DIRECT_DUMMY_QUERY = 'select 1'; diff --git a/common/types/explorer.ts b/common/types/explorer.ts index 9daf690743..a36dd81a8d 100644 --- a/common/types/explorer.ts +++ b/common/types/explorer.ts @@ -427,10 +427,3 @@ export enum DirectQueryLoadingStatus { SCHEDULED = 'SCHEDULED', CANCELED = 'CANCELED', } - -export interface DirectQueryRequest { - query: string; - lang: string; - datasource: string; - sessionId?: string; -} diff --git a/common/utils/query_session_utils.ts b/common/utils/query_session_utils.ts deleted file mode 100644 index ad0e0a1afb..0000000000 --- a/common/utils/query_session_utils.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * Copyright OpenSearch Contributors - * SPDX-License-Identifier: Apache-2.0 - */ - -import { ASYNC_QUERY_SESSION_ID } from '../constants/shared'; - -export const setAsyncSessionId = (value: string | null) => { - if (value !== null) { - sessionStorage.setItem(ASYNC_QUERY_SESSION_ID, value); - } -}; - -export const getAsyncSessionId = () => { - return sessionStorage.getItem(ASYNC_QUERY_SESSION_ID); -}; diff --git a/common/utils/shared.ts b/common/utils/shared.ts deleted file mode 100644 index a6f226a6dd..0000000000 --- a/common/utils/shared.ts +++ /dev/null @@ -1,8 +0,0 @@ -/* - * Copyright OpenSearch Contributors - * SPDX-License-Identifier: Apache-2.0 - */ - -export function get(obj: Record, path: string, defaultValue?: T): T { - return path.split('.').reduce((acc: any, part: string) => acc && acc[part], obj) || defaultValue; -} diff --git a/public/components/common/search/sql_search.tsx b/public/components/common/search/sql_search.tsx index 0ba84061d4..5a0b18ae73 100644 --- a/public/components/common/search/sql_search.tsx +++ b/public/components/common/search/sql_search.tsx @@ -18,11 +18,11 @@ import { EuiPopoverFooter, EuiToolTip, } from '@elastic/eui'; -import { isEqual } from 'lodash'; +import { isEqual, lowerCase } from 'lodash'; import React, { useEffect, useState } from 'react'; import { batch, useDispatch, useSelector } from 'react-redux'; import { APP_ANALYTICS_TAB_ID_REGEX, RAW_QUERY } from '../../../../common/constants/explorer'; -import { DirectQueryLoadingStatus, DirectQueryRequest } from '../../../../common/types/explorer'; +import { DirectQueryLoadingStatus } from '../../../../common/types/explorer'; import { PPL_NEWLINE_REGEX, PPL_SPAN_REGEX } from '../../../../common/constants/shared'; import { uiSettingsService } from '../../../../common/utils'; import { useFetchEvents } from '../../../components/event_analytics/hooks'; @@ -38,8 +38,6 @@ import { PPLReferenceFlyout } from '../helpers'; import { Autocomplete } from './autocomplete'; import { changeQuery } from '../../../components/event_analytics/redux/slices/query_slice'; import { QUERY_LANGUAGE } from '../../../../common/constants/data_sources'; -import { getAsyncSessionId, setAsyncSessionId } from '../../../../common/utils/query_session_utils'; -import { get as getObjValue } from '../../../../common/utils/shared'; export interface IQueryBarProps { query: string; tempQuery: string; @@ -103,7 +101,7 @@ export const DirectSearch = (props: any) => { stopPolling, } = usePolling((params) => { return sqlService.fetchWithJobId(params); - }, 2000); + }, 5000); const requestParams = { tabId }; const { dispatchOnGettingHis } = useFetchEvents({ @@ -192,21 +190,13 @@ export const DirectSearch = (props: any) => { ); }); dispatch(updateSearchMetaData({ tabId, data: { isPolling: true, lang } })); - const sessionId = getAsyncSessionId(); - const requestPayload = { - lang: lang.toLowerCase(), - query: tempQuery || query, - datasource: explorerSearchMetadata.datasources[0].label, - } as DirectQueryRequest; - - if (sessionId) { - requestPayload.sessionId = sessionId; - } - sqlService - .fetch(requestPayload) + .fetch({ + lang: lowerCase(lang), + query: tempQuery || query, + datasource: explorerSearchMetadata.datasources[0].name, + }) .then((result) => { - setAsyncSessionId(getObjValue(result, 'sessionId', null)); if (result.queryId) { startPolling({ queryId: result.queryId, @@ -218,7 +208,8 @@ export const DirectSearch = (props: any) => { .catch((e) => { setIsQueryRunning(false); console.error(e); - }); + }) + .finally(() => {}); }; useEffect(() => { diff --git a/public/components/event_analytics/explorer/datasources/datasources_selection.tsx b/public/components/event_analytics/explorer/datasources/datasources_selection.tsx index 3c6e34df1f..bbea0a6282 100644 --- a/public/components/event_analytics/explorer/datasources/datasources_selection.tsx +++ b/public/components/event_analytics/explorer/datasources/datasources_selection.tsx @@ -23,7 +23,7 @@ import { reset as resetQueryResults } from '../../redux/slices/query_result_slic import { reset as resetVisualization } from '../../redux/slices/visualization_slice'; import { reset as resetVisConfig } from '../../redux/slices/viualization_config_slice'; import { reset as resetQuery } from '../../redux/slices/query_slice'; -import { DirectQueryRequest, SelectedDataSource } from '../../../../../common/types/explorer'; +import { SelectedDataSource } from '../../../../../common/types/explorer'; import { ObservabilityDefaultDataSource } from '../../../../framework/datasources/obs_opensearch_datasource'; import { DATA_SOURCE_TYPE_URL_PARAM_KEY, @@ -32,16 +32,7 @@ import { DEFAULT_DATA_SOURCE_TYPE, DEFAULT_DATA_SOURCE_TYPE_NAME, DEFAULT_DATA_SOURCE_OBSERVABILITY_DISPLAY_NAME, - DATA_SOURCE_TYPES, - QUERY_LANGUAGE, } from '../../../../../common/constants/data_sources'; -import { SQLService } from '../../../../services/requests/sql'; -import { get as getObjValue } from '../../../../../common/utils/shared'; -import { - setAsyncSessionId, - getAsyncSessionId, -} from '../../../../../common/utils/query_session_utils'; -import { DIRECT_DUMMY_QUERY } from '../../../../../common/constants/shared'; const getDataSourceState = (selectedSourceState: SelectedDataSource[]) => { if (selectedSourceState.length === 0) return []; @@ -79,8 +70,7 @@ const removeDataSourceFromURLParams = (currURL: string) => { }; export const DataSourceSelection = ({ tabId }: { tabId: string }) => { - const { dataSources, http } = coreRefs; - const sqlService = new SQLService(http!); + const { dataSources } = coreRefs; const dispatch = useDispatch(); const routerContext = useContext(LogExplorerRouterContext); const explorerSearchMetadata = useSelector(selectSearchMetaData)[tabId]; @@ -119,23 +109,6 @@ export const DataSourceSelection = ({ tabId }: { tabId: string }) => { setSelectedSources(selectedSource); }; - const runDummyQuery = (dataSource: string) => { - const requestPayload = { - lang: QUERY_LANGUAGE.SQL.toLowerCase(), - query: DIRECT_DUMMY_QUERY, - datasource: dataSource, - } as DirectQueryRequest; - - sqlService - .fetch(requestPayload) - .then((result) => { - setAsyncSessionId(getObjValue(result, 'sessionId', null)); - }) - .catch((e) => { - console.error(e); - }); - }; - useEffect(() => { setSelectedSources(getDataSourceState(explorerSearchMetadata.datasources)); }, [explorerSearchMetadata.datasources]); @@ -193,19 +166,6 @@ export const DataSourceSelection = ({ tabId }: { tabId: string }) => { } }, []); - useEffect(() => { - // Execute a dummy query to initialize the cluster and obtain a sessionId for subsequent queries. - const dsType = explorerSearchMetadata.datasources?.[0]?.type; - const dsName = explorerSearchMetadata.datasources?.[0]?.label; - if ( - !getAsyncSessionId() && - [DATA_SOURCE_TYPES.SPARK, DATA_SOURCE_TYPES.S3Glue].includes(dsType) && - dsName - ) { - runDummyQuery(dsName); - } - }, [explorerSearchMetadata.datasources]); - /** * Process the data source options to display different than discover's group names. * Temporary solution for version 2.11. diff --git a/public/services/requests/sql.ts b/public/services/requests/sql.ts index 2073804ad8..e87d4d7267 100644 --- a/public/services/requests/sql.ts +++ b/public/services/requests/sql.ts @@ -4,7 +4,7 @@ */ import { CoreStart } from '../../../../../src/core/public'; -import { DirectQueryRequest } from '../../../common/types/explorer'; +import { PPL_BASE, PPL_SEARCH } from '../../../common/constants/shared'; export class SQLService { private http; @@ -12,7 +12,14 @@ export class SQLService { this.http = http; } - fetch = async (params: DirectQueryRequest, errorHandler?: (error: any) => void) => { + fetch = async ( + params: { + query: string; + lang: string; + datasource: string; + }, + errorHandler?: (error: any) => void + ) => { return this.http .post('/api/observability/query/jobs', { body: JSON.stringify(params), diff --git a/server/routes/datasources/datasources_router.ts b/server/routes/datasources/datasources_router.ts index 45279ccf76..eb8d6a635c 100644 --- a/server/routes/datasources/datasources_router.ts +++ b/server/routes/datasources/datasources_router.ts @@ -16,7 +16,6 @@ export function registerDatasourcesRoute(router: IRouter) { query: schema.string(), lang: schema.string(), datasource: schema.string(), - sessionId: schema.maybe(schema.string()), }), }, },