Skip to content

Commit

Permalink
Flint bug fix explorer failure (opensearch-project#1476)
Browse files Browse the repository at this point in the history
* rename direct query search file

Signed-off-by: Paul Sebastian <paulstn@amazon.com>

* updated import for rename

Signed-off-by: Paul Sebastian <paulstn@amazon.com>

* aforementioned direct query changes

Signed-off-by: Paul Sebastian <paulstn@amazon.com>

* fixed error message handling

Signed-off-by: Paul Sebastian <paulstn@amazon.com>

* using notifications from corerefs instead of props

Signed-off-by: Paul Sebastian <paulstn@amazon.com>

---------

Signed-off-by: Paul Sebastian <paulstn@amazon.com>
  • Loading branch information
paulstn authored Mar 4, 2024
1 parent 187b112 commit e9690a6
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 29 deletions.
10 changes: 5 additions & 5 deletions common/types/explorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -424,11 +424,11 @@ export interface GridSortingColumn {
}

export enum DirectQueryLoadingStatus {
SUCCESS = 'SUCCESS',
FAILED = 'FAILED',
RUNNING = 'RUNNING',
SCHEDULED = 'SCHEDULED',
CANCELED = 'CANCELED',
SUCCESS = 'success',
FAILED = 'failed',
RUNNING = 'running',
SCHEDULED = 'scheduled',
CANCELED = 'canceled',
}

export interface DirectQueryRequest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,20 @@ import { DirectQueryLoadingStatus, DirectQueryRequest } from '../../../../common
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 { useFetchEvents } from '../../event_analytics/hooks';
import { changeQuery } from '../../event_analytics/redux/slices/query_slice';
import { usePolling } from '../../hooks/use_polling';
import { coreRefs } from '../../../framework/core_refs';
import { SQLService } from '../../../services/requests/sql';
import { SavePanel } from '../../event_analytics/explorer/save_panel';
import {
selectSearchMetaData,
update as updateSearchMetaData,
} from '../../event_analytics/redux/slices/search_meta_data_slice';
import { reset as resetResults } from '../../event_analytics/redux/slices/query_result_slice';
import { PPLReferenceFlyout } from '../helpers';
import { Autocomplete } from './autocomplete';
import { formatError } from '../../event_analytics/utils';
export interface IQueryBarProps {
query: string;
tempQuery: string;
Expand Down Expand Up @@ -179,13 +181,33 @@ export const DirectSearch = (props: any) => {
</EuiButton>
);

const stopPollingWithStatus = (status: DirectQueryLoadingStatus | undefined) => {
stopPolling();
setIsQueryRunning(false);
dispatch(
updateSearchMetaData({
tabId,
data: {
isPolling: false,
status,
},
})
);
};

const onQuerySearch = (lang: string) => {
setIsQueryRunning(true);
batch(() => {
dispatch(resetResults({ tabId })); // reset results
dispatch(
changeQuery({ tabId, query: { [RAW_QUERY]: tempQuery.replaceAll(PPL_NEWLINE_REGEX, '') } })
);
dispatch(updateSearchMetaData({ tabId, data: { isPolling: true, lang } }));
dispatch(
updateSearchMetaData({
tabId,
data: { isPolling: true, lang, status: DirectQueryLoadingStatus.SCHEDULED },
})
);
});
const sessionId = getAsyncSessionId();
const requestPayload = {
Expand All @@ -212,39 +234,48 @@ export const DirectSearch = (props: any) => {
}
})
.catch((e) => {
setIsQueryRunning(false);
stopPollingWithStatus(DirectQueryLoadingStatus.FAILED);
const formattedError = formatError(
'',
'The query failed to execute and the operation could not be complete.',
e.body.message
);
coreRefs.core?.notifications.toasts.addError(formattedError, {
title: 'Query Failed',
});
console.error(e);
});
};

useEffect(() => {
// cancel direct query
if (!pollingResult) return;
const { status, datarows } = pollingResult;
const { status: anyCaseStatus, datarows, error } = pollingResult;
const status = anyCaseStatus?.toLowerCase();

if (status === DirectQueryLoadingStatus.SUCCESS || datarows) {
// stop polling
stopPolling();
setIsQueryRunning(false);
stopPollingWithStatus(status);
// update page with data
dispatchOnGettingHis(pollingResult, '');
} else if (status === DirectQueryLoadingStatus.FAILED) {
stopPollingWithStatus(status);
// send in a toast with error message
const formattedError = formatError(
'',
'The query failed to execute and the operation could not be complete.',
error
);
coreRefs.core?.notifications.toasts.addError(formattedError, {
title: 'Query Failed',
});
} else {
dispatch(
updateSearchMetaData({
tabId,
data: {
isPolling: false,
status: undefined,
},
data: { status },
})
);
// update page with data
dispatchOnGettingHis(pollingResult, '');
return;
}
dispatch(
updateSearchMetaData({
tabId,
data: { status },
})
);
}, [pollingResult, pollingError]);

useEffect(() => {
Expand Down
2 changes: 1 addition & 1 deletion public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ import {
uiSettingsService,
} from '../common/utils';
import { Search } from './components/common/search/search';
import { DirectSearch } from './components/common/search/sql_search';
import { DirectSearch } from './components/common/search/direct_search';
import { convertLegacyNotebooksUrl } from './components/notebooks/components/helpers/legacy_route_helpers';
import { convertLegacyTraceAnalyticsUrl } from './components/trace_analytics/components/common/legacy_route_helpers';
import { registerAsssitantDependencies } from './dependencies/register_assistant';
Expand Down
2 changes: 1 addition & 1 deletion server/routes/datasources/datasources_router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export function registerDatasourcesRoute(router: IRouter) {
console.error('Error in running direct query:', error);
return response.custom({
statusCode: error.statusCode || 500,
body: error.message,
body: error.body,
});
}
}
Expand Down

0 comments on commit e9690a6

Please sign in to comment.