Skip to content

Commit

Permalink
Revert "Support cancellation of async queries (opensearch-project#1177)…
Browse files Browse the repository at this point in the history
… (opensearch-project#1186)"

This reverts commit 6b495f3.
  • Loading branch information
mengweieric committed Nov 8, 2023
1 parent 1f63d69 commit fe770e3
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 91 deletions.
11 changes: 5 additions & 6 deletions public/components/common/search/sql_search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,11 @@ 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 { 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';
import { PPL_NEWLINE_REGEX, PPL_SPAN_REGEX } from '../../../../common/constants/shared';
import { uiSettingsService } from '../../../../common/utils';
import { getAsyncSessionId, setAsyncSessionId } from '../../../../common/utils/query_session_utils';
import { get as getObjValue } from '../../../../common/utils/shared';
import { useFetchEvents } from '../../../components/event_analytics/hooks';
import { changeQuery } from '../../../components/event_analytics/redux/slices/query_slice';
import { usePolling } from '../../../components/hooks/use_polling';
import { coreRefs } from '../../../framework/core_refs';
import { SQLService } from '../../../services/requests/sql';
Expand All @@ -40,6 +36,10 @@ import {
} from '../../event_analytics/redux/slices/search_meta_data_slice';
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;
Expand Down Expand Up @@ -208,7 +208,6 @@ export const DirectSearch = (props: any) => {
.then((result) => {
setAsyncSessionId(getObjValue(result, 'sessionId', null));
if (result.queryId) {
dispatch(updateSearchMetaData({ tabId, data: { queryId: result.queryId } }));
startPolling({
queryId: result.queryId,
});
Expand Down
42 changes: 15 additions & 27 deletions public/components/event_analytics/explorer/direct_query_running.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,18 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { EuiButton, EuiEmptyPrompt, EuiProgress, EuiSpacer, EuiText } from '@elastic/eui';
import React from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { DirectQueryLoadingStatus } from '../../../../common/types/explorer';
import { coreRefs } from '../../../framework/core_refs';
import { SQLService } from '../../../services/requests/sql';
import { EuiProgress, EuiEmptyPrompt, EuiButton, EuiText, EuiSpacer } from '@elastic/eui';
import {
selectSearchMetaData,
update as updateSearchMetaData,
} from '../redux/slices/search_meta_data_slice';
import { DirectQueryLoadingStatus } from '../../../../common/types/explorer';

export const DirectQueryRunning = ({ tabId }: { tabId: string }) => {
const explorerSearchMeta = useSelector(selectSearchMetaData)[tabId] || {};
const dispatch = useDispatch();
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,
},
})
);
});
}
};

return (
<EuiEmptyPrompt
icon={<EuiProgress size="xs" color="accent" />}
Expand All @@ -49,7 +25,19 @@ export const DirectQueryRunning = ({ tabId }: { tabId: string }) => {
Status: {explorerSearchMeta.status ?? DirectQueryLoadingStatus.SCHEDULED}
</EuiText>
<EuiSpacer size="s" />
<EuiButton color="success" onClick={cancelQuery}>
<EuiButton
color="success"
onClick={() => {
dispatch(
updateSearchMetaData({
tabId,
data: {
isPolling: false,
},
})
);
}}
>
Cancel
</EuiButton>
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { PayloadAction, createSelector, createSlice } from '@reduxjs/toolkit';
import { createSlice, createSelector, PayloadAction } from '@reduxjs/toolkit';
import { initialTabId } from '../../../../framework/redux/store/shared_state';
import { REDUX_EXPL_SLICE_SEARCH_META_DATA } from '../../../../../common/constants/explorer';
import { DirectQueryLoadingStatus, SelectedDataSource } from '../../../../../common/types/explorer';
import { initialTabId } from '../../../../framework/redux/store/shared_state';

const searchMetaInitialState = {
lang: 'PPL',
datasources: [],
queryId: '',
isPolling: false,
};

Expand All @@ -25,7 +24,6 @@ interface SearchMetaData {
lang: string;
datasources: SelectedDataSource[];
isPolling: boolean;
queryId: string;
status: DirectQueryLoadingStatus;
}

Expand Down
9 changes: 0 additions & 9 deletions public/services/requests/sql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import { CoreStart } from '../../../../../src/core/public';
import { DirectQueryRequest } from '../../../common/types/explorer';


export class SQLService {
private http;
constructor(http: CoreStart['http']) {
Expand All @@ -32,12 +31,4 @@ export class SQLService {
throw error;
});
};

deleteWithJobId = async (params: { queryId: string }, errorHandler?: (error: any) => void) => {
return this.http.delete(`/api/observability/query/jobs/${params.queryId}`).catch((error) => {
console.error('delete error: ', error.body);
if (errorHandler) errorHandler(error);
throw error;
});
};
}
16 changes: 0 additions & 16 deletions server/adaptors/opensearch_observability_plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ export function OpenSearchObservabilityPlugin(Client: any, config: any, componen
method: 'DELETE',
});

// Get async job status
observability.getJobStatus = clientAction({
url: {
fmt: `${JOBS_ENDPOINT_BASE}/<%=queryId%>`,
Expand All @@ -131,21 +130,6 @@ export function OpenSearchObservabilityPlugin(Client: any, config: any, componen
method: 'GET',
});

// Delete async job
observability.deleteJob = clientAction({
url: {
fmt: `${JOBS_ENDPOINT_BASE}/<%=queryId%>`,
req: {
queryId: {
type: 'string',
required: true,
},
},
},
method: 'DELETE',
});

// Run async job
observability.runDirectQuery = clientAction({
url: {
fmt: `${JOBS_ENDPOINT_BASE}`,
Expand Down
29 changes: 0 additions & 29 deletions server/routes/datasources/datasources_router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,33 +71,4 @@ export function registerDatasourcesRoute(router: IRouter) {
}
}
);

router.delete(
{
path: `${OBSERVABILITY_BASE}${JOBS_BASE}/{queryId}`,
validate: {
params: schema.object({
queryId: schema.string(),
}),
},
},
async (context, request, response): Promise<any> => {
try {
const res = await context.observability_plugin.observabilityClient
.asScoped(request)
.callAsCurrentUser('observability.deleteJob', {
queryId: request.params.queryId,
});
return response.ok({
body: res,
});
} catch (error: any) {
console.error('Error in deleting job:', error);
return response.custom({
statusCode: error.statusCode || 500,
body: error.message,
});
}
}
);
}

0 comments on commit fe770e3

Please sign in to comment.