diff --git a/common/index.ts b/common/index.ts index a670499d..5260db3b 100644 --- a/common/index.ts +++ b/common/index.ts @@ -14,3 +14,7 @@ export enum ServiceEndpoints { } export const SEARCH_API = '/_search'; + +//Query1 for the left search and Query2 for the right search page +export const QUERY_NUMBER_ONE = '1'; +export const QUERY_NUMBER_TWO = '2'; diff --git a/opensearch_dashboards.json b/opensearch_dashboards.json index ec878b3a..8dcc712c 100644 --- a/opensearch_dashboards.json +++ b/opensearch_dashboards.json @@ -6,5 +6,6 @@ "ui": true, "requiredPlugins": [ "navigation" - ] + ], + "optionalPlugins": ["dataSource","dataSourceManagement"] } \ No newline at end of file diff --git a/public/application.tsx b/public/application.tsx index deec7abf..51be4f7e 100644 --- a/public/application.tsx +++ b/public/application.tsx @@ -6,13 +6,15 @@ import React from 'react'; import ReactDOM from 'react-dom'; import { AppMountParameters, CoreStart } from '../../../src/core/public'; -import { AppPluginStartDependencies } from './types'; +import { DataSourceManagementPluginSetup } from '../../../src/plugins/data_source_management/public'; import { SearchRelevanceApp } from './components/app'; +import { AppPluginStartDependencies } from './types'; export const renderApp = ( - { notifications, http, chrome }: CoreStart, - { navigation }: AppPluginStartDependencies, - { element }: AppMountParameters + { notifications, http, chrome, savedObjects }: CoreStart, + { navigation, dataSource }: AppPluginStartDependencies, + { element, setHeaderActionMenu }: AppMountParameters, + dataSourceManagement: DataSourceManagementPluginSetup ) => { ReactDOM.render( , element ); diff --git a/public/components/app.tsx b/public/components/app.tsx index 3d91dda9..469d9b19 100644 --- a/public/components/app.tsx +++ b/public/components/app.tsx @@ -3,22 +3,26 @@ * SPDX-License-Identifier: Apache-2.0 */ -import React from 'react'; +import { EuiGlobalToastList } from '@elastic/eui'; import { I18nProvider } from '@osd/i18n/react'; +import React, { useState } from 'react'; import { HashRouter, Route, Switch } from 'react-router-dom'; -import { useState } from 'react'; -import { EuiGlobalToastList } from '@elastic/eui'; -import { CoreStart, Toast } from '../../../../src/core/public'; +import { CoreStart, MountPoint, Toast } from '../../../../src/core/public'; +import { DataSourceManagementPluginSetup } from '../../../../src/plugins/data_source_management/public'; import { NavigationPublicPluginStart } from '../../../../src/plugins/navigation/public'; -import { Home as QueryCompareHome } from './query_compare/home'; import { PLUGIN_NAME } from '../../common'; import { SearchRelevanceContextProvider } from '../contexts'; +import { Home as QueryCompareHome } from './query_compare/home'; interface SearchRelevanceAppDeps { notifications: CoreStart['notifications']; http: CoreStart['http']; navigation: NavigationPublicPluginStart; chrome: CoreStart['chrome']; + savedObjects: CoreStart['savedObjects']; + dataSourceEnabled: boolean; + dataSourceManagement: DataSourceManagementPluginSetup; + setActionMenu: (menuMount: MountPoint | undefined) => void; } export const SearchRelevanceApp = ({ @@ -26,6 +30,10 @@ export const SearchRelevanceApp = ({ http, navigation, chrome, + savedObjects, + dataSourceEnabled, + setActionMenu, + dataSourceManagement, }: SearchRelevanceAppDeps) => { const [toasts, setToasts] = useState([]); const [toastRightSide, setToastRightSide] = useState(true); @@ -64,6 +72,10 @@ export const SearchRelevanceApp = ({ setBreadcrumbs={chrome.setBreadcrumbs} setToast={setToast} chrome={chrome} + savedObjects={savedObjects} + dataSourceEnabled={dataSourceEnabled} + dataSourceManagement={dataSourceManagement} + setActionMenu={setActionMenu} /> ); }} diff --git a/public/components/query_compare/home.tsx b/public/components/query_compare/home.tsx index 0ef866c0..55c65135 100644 --- a/public/components/query_compare/home.tsx +++ b/public/components/query_compare/home.tsx @@ -3,27 +3,33 @@ * SPDX-License-Identifier: Apache-2.0 */ -import React, { useEffect } from 'react'; +import React, { useEffect, useMemo, useState } from 'react'; +import { ChromeBreadcrumb, CoreStart, MountPoint, NotificationsStart } from '../../../../../src/core/public'; +import { DataSourceAggregatedViewConfig, DataSourceManagementPluginSetup } from '../../../../../src/plugins/data_source_management/public'; import { NavigationPublicPluginStart } from '../../../../../src/plugins/navigation/public'; -import { CoreStart, ChromeBreadcrumb } from '../../../../../src/core/public'; +import { QUERY_NUMBER_ONE, QUERY_NUMBER_TWO, ServiceEndpoints } from '../../../common'; import '../../ace-themes/sql_console'; -import { CreateIndex } from './create_index'; -import { SearchResult } from './search_result'; import { useSearchRelevanceContext } from '../../contexts'; import { DocumentsIndex } from '../../types/index'; -import { ServiceEndpoints } from '../../../common'; import { Flyout } from '../common/flyout'; +import { CreateIndex } from './create_index'; +import { SearchResult } from './search_result'; +import { DataSourceOption } from '../../../../../src/plugins/data_source_management/public/components/data_source_selector/data_source_selector'; import './home.scss'; interface QueryExplorerProps { parentBreadCrumbs: ChromeBreadcrumb[]; - notifications: CoreStart['notifications']; + notifications: NotificationsStart; http: CoreStart['http']; navigation: NavigationPublicPluginStart; setBreadcrumbs: (newBreadcrumbs: ChromeBreadcrumb[]) => void; setToast: (title: string, color?: string, text?: any, side?: string) => void; chrome: CoreStart['chrome']; + savedObjects: CoreStart['savedObjects']; + dataSourceEnabled: boolean + dataSourceManagement: DataSourceManagementPluginSetup; + setActionMenu: (menuMount: MountPoint | undefined) => void; } export const Home = ({ parentBreadCrumbs, @@ -33,33 +39,136 @@ export const Home = ({ setBreadcrumbs, setToast, chrome, + savedObjects, + dataSourceEnabled, + dataSourceManagement, + setActionMenu, }: QueryExplorerProps) => { const { - documentsIndexes, - setDocumentsIndexes, - pipelines, - setPipelines, showFlyout, + documentsIndexes1, + documentsIndexes2, + setDocumentsIndexes1, + setDocumentsIndexes2, + datasource1, + datasource2, + setFetchedPipelines1, + setFetchedPipelines2, } = useSearchRelevanceContext(); useEffect(() => { setBreadcrumbs([...parentBreadCrumbs]); }, [setBreadcrumbs, parentBreadCrumbs]); + const [dataSourceOptions, setDataSourceOptions] = useState([]); + const fetchIndexes = (dataConnectionId: string, queryNumber: string) => { + if(dataConnectionId){ + http.get(`${ServiceEndpoints.GetIndexes}/${dataConnectionId}`).then((res: DocumentsIndex[]) => { + if(queryNumber == QUERY_NUMBER_ONE){ + setDocumentsIndexes1(res) + } + else{ + setDocumentsIndexes2(res) + } + }).catch((err) => { + if(queryNumber === QUERY_NUMBER_ONE){ + setDocumentsIndexes1([]) + } + else{ + setDocumentsIndexes2([]) + } + console.log(err) + }); + } + else{ + http.get(ServiceEndpoints.GetIndexes).then((res: DocumentsIndex[]) => { + if(queryNumber == QUERY_NUMBER_ONE){ + setDocumentsIndexes1(res) + } + else{ + setDocumentsIndexes2(res) + } + }).catch((err) => { + if(queryNumber === QUERY_NUMBER_ONE){ + setDocumentsIndexes1([]) + } + else{ + setDocumentsIndexes2([]) + } + console.log(err) + }); + } + } + const fetchPipelines = (dataConnectionId: string, queryNumber: string) => { + if(dataConnectionId){ + http.get(`${ServiceEndpoints.GetPipelines}/${dataConnectionId}`).then((res: {}) => { + if(queryNumber === QUERY_NUMBER_ONE){ + console.log(res) + setFetchedPipelines1(res) + } + else{ + setFetchedPipelines2(res) + } + }).catch((err) => { + if(queryNumber === QUERY_NUMBER_ONE){ + setFetchedPipelines1('') + } + else{ + setFetchedPipelines2('') + } + console.log(err) + }); + } + else{ + http.get(ServiceEndpoints.GetPipelines).then((res: {}) => { + if(queryNumber === QUERY_NUMBER_ONE){ + console.log(res) + setFetchedPipelines1(res) + } + else{ + setFetchedPipelines2(res) + } + }).catch((err) => { + if(queryNumber === QUERY_NUMBER_ONE){ + setFetchedPipelines1('') + } + else{ + setFetchedPipelines2('') + } + console.log(err) + }); + } + } + const DataSourceMenu = dataSourceManagement.ui.getDataSourceMenu(); // Get Indexes and Pipelines useEffect(() => { - http.get(ServiceEndpoints.GetIndexes).then((res: DocumentsIndex[]) => { - setDocumentsIndexes(res); - }); - http.get(ServiceEndpoints.GetPipelines).then((res: {}) => { - setPipelines(res); - }); - }, [http, setDocumentsIndexes, setPipelines]); + fetchIndexes(datasource1,QUERY_NUMBER_ONE) + fetchIndexes(datasource2,QUERY_NUMBER_TWO) + fetchPipelines(datasource1,QUERY_NUMBER_ONE) + fetchPipelines(datasource2,QUERY_NUMBER_TWO) + + }, [http, setDocumentsIndexes1, setDocumentsIndexes2, setFetchedPipelines1, setFetchedPipelines2, datasource1, datasource2]); + + const dataSourceMenuComponent = useMemo(() => { + return ( + + ); + }, [setActionMenu, savedObjects.client, notifications, datasource1, datasource2]); return ( <> + {dataSourceEnabled && dataSourceMenuComponent}
- {documentsIndexes.length ? : } + {documentsIndexes1.length || documentsIndexes2.length ? : }
{showFlyout && } diff --git a/public/components/query_compare/search_result/index.tsx b/public/components/query_compare/search_result/index.tsx index 7e6de1ad..b71fa546 100644 --- a/public/components/query_compare/search_result/index.tsx +++ b/public/components/query_compare/search_result/index.tsx @@ -3,31 +3,41 @@ * SPDX-License-Identifier: Apache-2.0 */ -import React, { useState } from 'react'; import { EuiPageContentBody } from '@elastic/eui'; +import React, { useState } from 'react'; -import { CoreStart } from '../../../../../../src/core/public'; -import { SearchConfigsPanel } from './search_components/search_configs/search_configs'; -import { SearchInputBar } from './search_components/search_bar'; +import { CoreStart, MountPoint } from '../../../../../../src/core/public'; +import { DataSourceManagementPluginSetup } from '../../../../../../src/plugins/data_source_management/public'; +import { DataSourceOption } from '../../../../../../src/plugins/data_source_management/public/components/data_source_selector/data_source_selector'; +import { NavigationPublicPluginStart } from '../../../../../../src/plugins/navigation/public'; import { ServiceEndpoints } from '../../../../common'; -import { Header } from '../../common/header'; +import { useSearchRelevanceContext } from '../../../contexts'; import { - SearchResults, QueryError, QueryStringError, + SearchResults, SelectIndexError, initialQueryErrorState, } from '../../../types/index'; +import { Header } from '../../common/header'; import { ResultComponents } from './result_components/result_components'; -import { useSearchRelevanceContext } from '../../../contexts'; +import { SearchInputBar } from './search_components/search_bar'; +import { SearchConfigsPanel } from './search_components/search_configs/search_configs'; const DEFAULT_QUERY = '{}'; interface SearchResultProps { http: CoreStart['http']; + savedObjects: CoreStart['savedObjects']; + dataSourceEnabled: boolean + navigation: NavigationPublicPluginStart; + setActionMenu: (menuMount: MountPoint | undefined) => void; + dataSourceManagement: DataSourceManagementPluginSetup; + dataSourceOptions: DataSourceOption[] + notifications: NotificationsStart } -export const SearchResult = ({ http }: SearchResultProps) => { +export const SearchResult = ({ http, savedObjects, dataSourceEnabled, dataSourceManagement, setActionMenu, navigation, dataSourceOptions, notifications}: SearchResultProps) => { const [queryString1, setQueryString1] = useState(DEFAULT_QUERY); const [queryString2, setQueryString2] = useState(DEFAULT_QUERY); const [queryResult1, setQueryResult1] = useState({} as any); @@ -35,7 +45,6 @@ export const SearchResult = ({ http }: SearchResultProps) => { const [queryError1, setQueryError1] = useState(initialQueryErrorState); const [queryError2, setQueryError2] = useState(initialQueryErrorState); const [searchBarValue, setSearchBarValue] = useState(''); - const { updateComparedResult1, updateComparedResult2, @@ -43,6 +52,8 @@ export const SearchResult = ({ http }: SearchResultProps) => { selectedIndex2, pipeline1, pipeline2, + datasource1, + datasource2 } = useSearchRelevanceContext(); const onClickSearch = () => { @@ -92,7 +103,7 @@ export const SearchResult = ({ http }: SearchResultProps) => { jsonQuery: any, updateComparedResult: (result: SearchResults) => void, setQueryResult: React.Dispatch>, - setQueryError: React.Dispatch> + setQueryError: React.Dispatch>, ) => { if (queryError.queryString.length || queryError.selectIndex.length) { setQueryError(queryError); @@ -105,64 +116,75 @@ export const SearchResult = ({ http }: SearchResultProps) => { }; const handleSearch = (jsonQueries: any, queryErrors: QueryError[]) => { - const requestBody = { - query1: handleQuery( + const requestBody1 = handleQuery( queryErrors[0], selectedIndex1, pipeline1, jsonQueries[0], updateComparedResult1, setQueryResult1, - setQueryError1 - ), - query2: handleQuery( + setQueryError1, + ); + + const requestBody2 = handleQuery( queryErrors[1], selectedIndex2, pipeline2, jsonQueries[1], updateComparedResult2, setQueryResult2, - setQueryError2 - ), - }; - if (Object.keys(requestBody).length !== 0) { - http - .post(ServiceEndpoints.GetSearchResults, { - body: JSON.stringify(requestBody), - }) - .then((res) => { - if (res.result1) { - setQueryResult1(res.result1); - updateComparedResult1(res.result1); - } - - if (res.result2) { - setQueryResult2(res.result2); - updateComparedResult2(res.result2); - } - - if (res.errorMessage1) { - setQueryError1((error: QueryError) => ({ - ...error, - queryString: res.errorMessage1, - errorResponse: res.errorMessage1, - })); - } - - if (res.errorMessage2) { - setQueryError2((error: QueryError) => ({ - ...error, - queryString: res.errorMessage2, - errorResponse: res.errorMessage2, - })); - } - }) - .catch((error: Error) => { - // eslint-disable-next-line no-console - console.error(error); - }); + setQueryError2, + ); + if (Object.keys(requestBody1).length !== 0 || Object.keys(requestBody2).length !== 0) { + // First Query + if (Object.keys(requestBody1).length !== 0) { + http.post(ServiceEndpoints.GetSearchResults, { + body: JSON.stringify({ query1: requestBody1, dataSourceId1: datasource1? datasource1: '' }), + }) + .then((res) => { + if (res.result1) { + setQueryResult1(res.result1); + updateComparedResult1(res.result1); + } + + if (res.errorMessage1) { + setQueryError1((error: QueryError) => ({ + ...error, + queryString: res.errorMessage1, + errorResponse: res.errorMessage1, + })); + } + }) + .catch((error: Error) => { + console.error(error); + }); + } + + // Second Query + if (Object.keys(requestBody2).length !== 0) { + http.post(ServiceEndpoints.GetSearchResults, { + body: JSON.stringify({ query2: requestBody2, dataSourceId2: datasource2? datasource2: '' }), + }) + .then((res) => { + if (res.result2) { + setQueryResult2(res.result2); + updateComparedResult2(res.result2); + } + + if (res.errorMessage2) { + setQueryError2((error: QueryError) => ({ + ...error, + queryString: res.errorMessage2, + errorResponse: res.errorMessage2, + })); + } + }) + .catch((error: Error) => { + console.error(error); + }); + } } - }; +}; return ( <> @@ -181,8 +203,15 @@ export const SearchResult = ({ http }: SearchResultProps) => { setQueryString2={setQueryString2} queryError1={queryError1} queryError2={queryError2} + dataSourceManagement={dataSourceManagement} setQueryError1={setQueryError1} setQueryError2={setQueryError2} + dataSourceEnabled={dataSourceEnabled} + savedObjects={savedObjects} + navigation={navigation} + setActionMenu={setActionMenu} + dataSourceOptions={dataSourceOptions} + notifications={notifications} /> + +

+ Query + 1 +

+
+ +
+ + +
+ +
+ +
+
+ + + +
+
+ + +
+
+ + + + +
+ + + + + +
+
+
+
+
+
+
+
+
+
+
+ +
+ +
+
+ + + +
+
+ +
+ + +
+
+
+ +
+ +
+
+ +
+ +
+ + + +
+
+
+
+ + +
+ + +
+ Optional +
+
+
+
+ +
+ +
+ + + Enter a query in + + + OpenSearch Query DSL + + . Use %SearchText% to refer to the text in the search bar +

+ } + isInvalid={false} + label="Query" + labelAppend={ + + + Help + + + } + labelType="label" + > +
+
+ + + + + +
+ + + +
+
+
+
+ +
+ + +
+ +
+ + +
+

+ Enter a query in + + + OpenSearch Query DSL + + . Use %SearchText% to refer to the text in the search bar +

+
+
+
+
+ + + +`; + +exports[`Flyout component Renders flyout component when multi-datasource is enabled 1`] = ` + + , + }, + } + } + pipeline="" + queryError={ + Object { + "errorResponse": Object { + "body": "", + "statusCode": 200, + }, + "queryString": "", + "selectIndex": "", + } + } + queryNumber={1} + queryString="{}" + selectedIndex="" + setPipeline={ + [MockFunction] { + "calls": Array [ + Array [ + "", + ], + ], + "results": Array [ + Object { + "type": "return", + "value": undefined, + }, + ], + } + } setQueryError={[MockFunction]} setQueryString={[MockFunction]} - setSelectedIndex={[MockFunction]} + setSelectedIndex={ + [MockFunction] { + "calls": Array [ + Array [ + "", + ], + ], + "results": Array [ + Object { + "type": "return", + "value": undefined, + }, + ], + } + } > , + }, + } + } queryError1={ Object { "errorResponse": Object { @@ -51,6 +58,13 @@ exports[`Flyout component Renders flyout component 1`] = ` className="euiFlexItem search-relevance-config" > , + }, + } + } pipeline="" queryError={ Object { @@ -65,6 +79,7 @@ exports[`Flyout component Renders flyout component 1`] = ` queryNumber={1} queryString="{}" selectedIndex="" + setDataSource={[Function]} setPipeline={[Function]} setQueryError={[Function]} setQueryString={[Function]} @@ -810,6 +825,13 @@ exports[`Flyout component Renders flyout component 1`] = ` className="euiFlexItem search-relevance-config" > , + }, + } + } pipeline="" queryError={ Object { @@ -824,6 +846,7 @@ exports[`Flyout component Renders flyout component 1`] = ` queryNumber={2} queryString="{}" selectedIndex="" + setDataSource={[Function]} setPipeline={[Function]} setQueryError={[Function]} setQueryString={[Function]} @@ -1569,3 +1592,1582 @@ exports[`Flyout component Renders flyout component 1`] = ` `; + +exports[`Flyout component Renders flyout component when multi dataSource enabled 1`] = ` + + + +
+ +
+ +
+ + +

+ Query + 1 +

+
+ +
+ + +
+ +
+ +
+
+ + + +
+
+ + +
+
+ + + + +
+ + + + + +
+
+
+
+
+
+
+
+
+
+
+ +
+ +
+
+ + + +
+
+ +
+ + +
+
+
+ +
+ +
+
+ +
+ +
+ + + +
+
+
+
+ + +
+ + +
+ Optional +
+
+
+
+ +
+ +
+ + + Enter a query in + + + OpenSearch Query DSL + + . Use %SearchText% to refer to the text in the search bar +

+ } + isInvalid={false} + label="Query" + labelAppend={ + + + Help + + + } + labelType="label" + > +
+
+ + + + + +
+ + + +
+
+
+
+ +
+ + +
+ +
+ + +
+

+ Enter a query in + + + OpenSearch Query DSL + + . Use %SearchText% to refer to the text in the search bar +

+
+
+
+
+ + +
+
+ +
+ + +

+ Query + 2 +

+
+ +
+ + +
+ +
+ +
+
+ + + +
+
+ + +
+
+ + + + +
+ + + + + +
+
+
+
+
+
+
+
+
+
+
+ +
+ +
+
+ + + +
+
+ +
+ + +
+
+
+ +
+ +
+
+ +
+ +
+ + + +
+
+
+
+ + +
+ + +
+ Optional +
+
+
+
+ +
+ +
+ + + Enter a query in + + + OpenSearch Query DSL + + . Use %SearchText% to refer to the text in the search bar +

+ } + isInvalid={false} + label="Query" + labelAppend={ + + + Help + + + } + labelType="label" + > +
+
+ + + + + +
+ + + +
+
+
+
+ +
+ + +
+ +
+ + +
+

+ Enter a query in + + + OpenSearch Query DSL + + . Use %SearchText% to refer to the text in the search bar +

+
+
+
+
+ + +
+
+
+
+
+ + + +`; diff --git a/public/components/query_compare/search_result/search_components/__tests__/search_config.test.tsx b/public/components/query_compare/search_result/search_components/__tests__/search_config.test.tsx index 4cc69a7a..76d47451 100644 --- a/public/components/query_compare/search_result/search_components/__tests__/search_config.test.tsx +++ b/public/components/query_compare/search_result/search_components/__tests__/search_config.test.tsx @@ -3,23 +3,64 @@ * SPDX-License-Identifier: Apache-2.0 */ +import { waitFor } from '@testing-library/react'; import { configure, mount } from 'enzyme'; import Adapter from 'enzyme-adapter-react-16'; import React from 'react'; -import { waitFor } from '@testing-library/react'; -import { SearchConfig } from '../search_configs/search_config'; -import { SearchRelevanceContextProvider } from '../../../../../contexts'; -import { TEST_QUERY_STRING } from '../../../../../../test/constants'; import { initialQueryErrorState } from '../../../../../../public/types/index'; +import { TEST_QUERY_STRING } from '../../../../../../test/constants'; +import { SearchRelevanceContextProvider } from '../../../../../contexts'; +import { SearchConfig } from '../search_configs/search_config'; describe('Flyout component', () => { configure({ adapter: new Adapter() }); + it('Renders flyout component when multi-datasource is enabled', async () => { + const setQueryString = jest.fn(); + const setSelectedIndex = jest.fn(); + const setPipeline = jest.fn(); + const setQueryError = jest.fn(); + const setDataSourceManagement = jest.fn(); + const wrapper = mount( + + } }} + /> + + ); + + wrapper.update(); + await waitFor(() => { + expect(wrapper).toMatchSnapshot(); + wrapper.find('EuiCodeEditor').prop('onChange')?.({ target: { value: '' } }); + wrapper.find('EuiSelect').prop('onChange')?.({ target: {} }); + wrapper.find('EuiSelect').prop('onBlur')?.({ target: {} }); + wrapper.find('EuiComboBox').prop('onChange')?.({ target: { selectedPipelineOptions: [] } }); + wrapper.find('EuiComboBox').prop('onChange')?.({ + target: { selectedPipelineOptions: [{ label: '_none' }] }, + }); + }); + expect(setQueryString).toHaveBeenCalledTimes(1); + expect(setSelectedIndex).toHaveBeenCalledTimes(2); + expect(setPipeline).toHaveBeenCalledTimes(3); + expect(setQueryError).toHaveBeenCalledTimes(3); + }); + it('Renders flyout component', async () => { const setQueryString = jest.fn(); const setSelectedIndex = jest.fn(); const setPipeline = jest.fn(); const setQueryError = jest.fn(); + const setDataSourceManagement = jest.fn(); const wrapper = mount( { setPipeline={setPipeline} queryError={initialQueryErrorState} setQueryError={setQueryError} + dataSourceEnabled={false} /> ); @@ -48,8 +90,8 @@ describe('Flyout component', () => { }); }); expect(setQueryString).toHaveBeenCalledTimes(1); - expect(setSelectedIndex).toHaveBeenCalledTimes(1); - expect(setPipeline).toHaveBeenCalledTimes(2); + expect(setSelectedIndex).toHaveBeenCalledTimes(2); + expect(setPipeline).toHaveBeenCalledTimes(3); expect(setQueryError).toHaveBeenCalledTimes(3); }); }); diff --git a/public/components/query_compare/search_result/search_components/__tests__/search_configs.test.tsx b/public/components/query_compare/search_result/search_components/__tests__/search_configs.test.tsx index 1efb59d3..d18ffad0 100644 --- a/public/components/query_compare/search_result/search_components/__tests__/search_configs.test.tsx +++ b/public/components/query_compare/search_result/search_components/__tests__/search_configs.test.tsx @@ -3,14 +3,14 @@ * SPDX-License-Identifier: Apache-2.0 */ +import { waitFor } from '@testing-library/react'; import { configure, mount } from 'enzyme'; import Adapter from 'enzyme-adapter-react-16'; import React from 'react'; -import { waitFor } from '@testing-library/react'; -import { SearchConfigsPanel } from '../search_configs/search_configs'; -import { SearchRelevanceContextProvider } from '../../../../../contexts'; -import { TEST_QUERY_STRING } from '../../../../../../test/constants'; import { initialQueryErrorState } from '../../../../../../public/types/index'; +import { TEST_QUERY_STRING } from '../../../../../../test/constants'; +import { SearchRelevanceContextProvider } from '../../../../../contexts'; +import { SearchConfigsPanel } from '../search_configs/search_configs'; describe('Flyout component', () => { configure({ adapter: new Adapter() }); @@ -27,6 +27,30 @@ describe('Flyout component', () => { queryError2={initialQueryErrorState} setQueryError1={() => {}} setQueryError2={() => {}} + dataSourceManagement={{ ui: { DataSourceSelector: <> } }} + /> + + ); + + wrapper.update(); + + await waitFor(() => { + expect(wrapper).toMatchSnapshot(); + }); + }); + it('Renders flyout component when multi dataSource enabled', async () => { + const wrapper = mount( + + {}} + setQueryString2={() => {}} + queryError1={initialQueryErrorState} + queryError2={initialQueryErrorState} + setQueryError1={() => {}} + setQueryError2={() => {}} + dataSourceEnabled={false} /> ); diff --git a/public/components/query_compare/search_result/search_components/search_configs/search_config.tsx b/public/components/query_compare/search_result/search_components/search_configs/search_config.tsx index 654ad012..252db819 100644 --- a/public/components/query_compare/search_result/search_components/search_configs/search_config.tsx +++ b/public/components/query_compare/search_result/search_components/search_configs/search_config.tsx @@ -3,23 +3,39 @@ * SPDX-License-Identifier: Apache-2.0 */ -import React, { FunctionComponent } from 'react'; import { - EuiTitle, - EuiSpacer, - EuiFormRow, - EuiSelect, - EuiCodeEditor, - EuiText, EuiButtonEmpty, + EuiCodeEditor, + EuiComboBox, EuiFlexGroup, EuiFlexItem, - EuiComboBox, + EuiFormRow, + EuiSelect, + EuiSpacer, + EuiText, + EuiTitle, } from '@elastic/eui'; +import React, { FunctionComponent, useEffect } from 'react'; +import { AppMountParameters, CoreStart, MountPoint, NotificationsStart, SavedObjectsStart, ToastsStart } from '../../../../../../../../src/core/public'; +import { DataSourceManagementPluginSetup } from '../../../../../../../../src/plugins/data_source_management/public'; +import { DataSourceOption } from '../../../../../../../../src/plugins/data_source_management/public/components/data_source_selector/data_source_selector'; +import { NavigationPublicPluginStart } from '../../../../../../../../src/plugins/navigation/public'; import { useSearchRelevanceContext } from '../../../../../contexts'; import { QueryError, QueryStringError, SelectIndexError } from '../../../../../types/index'; +export interface SearchRelevanceServices extends CoreStart { + setHeaderActionMenu: AppMountParameters['setHeaderActionMenu']; + appBasePath: AppMountParameters['history']; + element: AppMountParameters['element']; + navigation: NavigationPublicPluginStart; + toastNotifications: ToastsStart; + history: AppMountParameters['history']; + overlays: CoreStart['overlays']; + chrome: CoreStart['chrome']; + uiSettings: CoreStart['uiSettings']; +} + interface SearchConfigProps { queryNumber: 1 | 2; queryString: string; @@ -30,6 +46,14 @@ interface SearchConfigProps { setQueryError: React.Dispatch>; pipeline: string; setPipeline: React.Dispatch>; + dataSourceEnabled: boolean; + notifications: NotificationsStart; + savedObjects: SavedObjectsStart; + setDataSource: React.Dispatch>; + dataSourceManagement: DataSourceManagementPluginSetup; + navigation: NavigationPublicPluginStart; + setActionMenu: (menuMount: MountPoint | undefined) => void; + dataSourceOptions: DataSourceOption[] } export const SearchConfig: FunctionComponent = ({ @@ -42,8 +66,15 @@ export const SearchConfig: FunctionComponent = ({ setQueryError, pipeline, setPipeline, + dataSourceEnabled, + savedObjects, + notifications, + dataSourceManagement, + navigation, + setActionMenu, + dataSourceOptions, }) => { - const { documentsIndexes, pipelines, setShowFlyout } = useSearchRelevanceContext(); + const { documentsIndexes1, setDataSource1, setDataSource2, documentsIndexes2, fetchedPipelines1, fetchedPipelines2, setShowFlyout, datasource1, datasource2} = useSearchRelevanceContext(); // On select index const onChangeSelectedIndex: React.ChangeEventHandler = (e) => { setSelectedIndex(e.target.value); @@ -53,7 +84,10 @@ export const SearchConfig: FunctionComponent = ({ selectIndex: '', })); }; - + + const documentIndex = queryNumber === 1? documentsIndexes1: documentsIndexes2 + console.log(fetchedPipelines1) + const pipelines = queryNumber === 1? fetchedPipelines1: fetchedPipelines2 // Sort search pipelines based off of each individual pipeline name. const sortedPipelines = [...Object.keys(pipelines)] .sort((a, b) => a.localeCompare(b)) @@ -102,7 +136,26 @@ export const SearchConfig: FunctionComponent = ({ })); } }; + const onSelectedDataSource = (e) => { + const dataConnectionId = e[0] ? e[0].id : undefined; + if(queryNumber == 1){ + setDataSource1(dataConnectionId) + } + else{ + setDataSource2(dataConnectionId) + } + setPipeline('') + } + useEffect(() => { + setSelectedIndex('') + setPipeline('') + }, [datasource1, datasource2]); + + let DataSourceSelector; + if (dataSourceEnabled) { + DataSourceSelector = dataSourceManagement.ui.DataSourceSelector; + } return ( <> @@ -110,6 +163,23 @@ export const SearchConfig: FunctionComponent = ({ + {dataSourceEnabled && ( + + + + + )} = ({ > ({ + options={documentIndex.map(({ index }) => ({ value: index, text: index, }))} diff --git a/public/components/query_compare/search_result/search_components/search_configs/search_configs.tsx b/public/components/query_compare/search_result/search_components/search_configs/search_configs.tsx index f214ddb6..3b244189 100644 --- a/public/components/query_compare/search_result/search_components/search_configs/search_configs.tsx +++ b/public/components/query_compare/search_result/search_components/search_configs/search_configs.tsx @@ -3,15 +3,19 @@ * SPDX-License-Identifier: Apache-2.0 */ +import { EuiFlexGroup, EuiFlexItem, EuiPanel } from '@elastic/eui'; import React from 'react'; -import { EuiPanel, EuiFlexGroup, EuiFlexItem } from '@elastic/eui'; import '../../../../../ace-themes/sql_console'; -import { SearchConfig } from './search_config'; import { useSearchRelevanceContext } from '../../../../../contexts'; +import { SearchConfig } from './search_config'; -import './search_configs.scss'; +import { CoreStart, MountPoint } from '../../../../../../../../src/core/public'; +import { DataSourceManagementPluginSetup } from '../../../../../../../../src/plugins/data_source_management/public'; +import { DataSourceOption } from '../../../../../../../../src/plugins/data_source_management/public/components/data_source_selector/data_source_selector'; +import { NavigationPublicPluginStart } from '../../../../../../../../src/plugins/navigation/public'; import { QueryError } from '../../../../../../public/types/index'; +import './search_configs.scss'; interface SearchConfigsPanelProps { queryString1: string; @@ -22,6 +26,13 @@ interface SearchConfigsPanelProps { queryError2: QueryError; setQueryError1: React.Dispatch>; setQueryError2: React.Dispatch>; + dataSourceEnabled: boolean; + savedObjects: CoreStart['savedObjects']; + notifications: CoreStart['notifications']; + dataSourceManagement: DataSourceManagementPluginSetup; + navigation: NavigationPublicPluginStart; + setActionMenu: (menuMount: MountPoint | undefined) => void; + dataSourceOptions: DataSourceOption[]; } export const SearchConfigsPanel = ({ @@ -33,6 +44,13 @@ export const SearchConfigsPanel = ({ queryError2, setQueryError1, setQueryError2, + dataSourceEnabled, + savedObjects, + dataSourceManagement, + setActionMenu, + navigation, + dataSourceOptions, + notifications }: SearchConfigsPanelProps) => { const { selectedIndex1, @@ -43,6 +61,10 @@ export const SearchConfigsPanel = ({ setPipeline1, pipeline2, setPipeline2, + datasource1, + setDataSource1, + datasource2, + setDataSource2, } = useSearchRelevanceContext(); return ( @@ -65,6 +87,14 @@ export const SearchConfigsPanel = ({ setQueryError={setQueryError1} pipeline={pipeline1} setPipeline={setPipeline1} + setDataSource={setDataSource1} + dataSourceEnabled={dataSourceEnabled} + savedObjects={savedObjects} + dataSourceManagement={dataSourceManagement} + navigation={navigation} + setActionMenu={setActionMenu} + dataSourceOptions={dataSourceOptions} + notifications={notifications} /> @@ -78,6 +108,14 @@ export const SearchConfigsPanel = ({ setQueryError={setQueryError2} pipeline={pipeline2} setPipeline={setPipeline2} + setDataSource={setDataSource2} + dataSourceEnabled={dataSourceEnabled} + savedObjects={savedObjects} + dataSourceManagement={dataSourceManagement} + navigation={navigation} + setActionMenu={setActionMenu} + dataSourceOptions={dataSourceOptions} + notifications={notifications} /> diff --git a/public/contexts/index.tsx b/public/contexts/index.tsx index d0fd077f..22eb54d7 100644 --- a/public/contexts/index.tsx +++ b/public/contexts/index.tsx @@ -5,12 +5,17 @@ import React, { createContext, useContext, useState } from 'react'; +import { DataSourceOption } from '../../../../src/plugins/data_source_management/public/components/data_source_selector/data_source_selector'; import { DocumentsIndex, SearchResults } from '../types/index'; -import { getDocumentRank, DocumentRank } from './utils'; +import { DocumentRank, getDocumentRank } from './utils'; export interface SearchRelevanceContextProps { documentsIndexes: DocumentsIndex[]; setDocumentsIndexes: React.Dispatch>; + documentsIndexes1: DocumentsIndex[]; + setDocumentsIndexes1: React.Dispatch>; + documentsIndexes2: DocumentsIndex[]; + setDocumentsIndexes2: React.Dispatch>; showFlyout: boolean; setShowFlyout: React.Dispatch>; comparedResult1: DocumentRank; @@ -27,6 +32,18 @@ export interface SearchRelevanceContextProps { setPipeline1: React.Dispatch>; pipeline2: string; setPipeline2: React.Dispatch>; + datasource1: string; + setDataSource1: React.Dispatch>; + datasource2: string; + setDataSource2: React.Dispatch>; + datasourceItems: {} + setDatasourceItems: React.Dispatch>; + fetchedPipelines1: {}; + setFetchedPipelines1: React.Dispatch>; + fetchedPipelines2: {}; + setFetchedPipelines2: React.Dispatch>; + dataSourceOptions: DataSourceOption[] + setDataSourceOptions: React.Dispatch>; } export const SearchRelevanceContext = createContext(null); @@ -42,7 +59,10 @@ export const useSearchRelevanceContext = () => { }; export const SearchRelevanceContextProvider = ({ children }: { children: React.ReactNode }) => { + const [documentsIndexes, setDocumentsIndexes] = useState([]); + const [documentsIndexes1, setDocumentsIndexes1] = useState([]); + const [documentsIndexes2, setDocumentsIndexes2] = useState([]); const [showFlyout, setShowFlyout] = useState(false); const [comparedResult1, setComparedResult1] = useState({}); const [comparedResult2, setComparedResult2] = useState({}); @@ -51,6 +71,11 @@ export const SearchRelevanceContextProvider = ({ children }: { children: React.R const [pipelines, setPipelines] = useState<{}>({}); const [pipeline1, setPipeline1] = useState(''); const [pipeline2, setPipeline2] = useState(''); + const [datasource1, setDataSource1] = useState(''); + const [datasource2, setDataSource2] = useState(''); + const [fetchedPipelines1, setFetchedPipelines1] = useState<{}>({}); + const [fetchedPipelines2, setFetchedPipelines2] = useState<{}>({}); + const [dataSourceOptions, setDataSourceOptions] = useState([]) const updateComparedResult1 = (result: SearchResults) => { setComparedResult1(getDocumentRank(result?.hits?.hits)); @@ -65,6 +90,10 @@ export const SearchRelevanceContextProvider = ({ children }: { children: React.R value={{ documentsIndexes, setDocumentsIndexes, + documentsIndexes1, + setDocumentsIndexes1, + documentsIndexes2, + setDocumentsIndexes2, showFlyout, setShowFlyout, comparedResult1, @@ -81,6 +110,16 @@ export const SearchRelevanceContextProvider = ({ children }: { children: React.R setPipeline1, pipeline2, setPipeline2, + datasource1, + setDataSource1, + datasource2, + setDataSource2, + fetchedPipelines1, + setFetchedPipelines1, + fetchedPipelines2, + setFetchedPipelines2, + dataSourceOptions, + setDataSourceOptions }} > {children} diff --git a/public/plugin.ts b/public/plugin.ts index 6998757f..2c5bc55f 100644 --- a/public/plugin.ts +++ b/public/plugin.ts @@ -5,16 +5,27 @@ import { i18n } from '@osd/i18n'; import { AppMountParameters, CoreSetup, CoreStart, Plugin } from '../../../src/core/public'; +import { DataSourcePluginSetup, DataSourcePluginStart } from '../../../src/plugins/data_source/public'; +import { DataSourceManagementPluginSetup } from '../../../src/plugins/data_source_management/public'; +import { PLUGIN_ID, PLUGIN_NAME } from '../common'; import { + AppPluginStartDependencies, SearchRelevancePluginSetup, SearchRelevancePluginStart, - AppPluginStartDependencies, } from './types'; -import { PLUGIN_NAME, PLUGIN_ID } from '../common'; + +export interface SearchRelevancePluginSetupDependencies { + dataSource: DataSourcePluginSetup; + dataSourceManagement: DataSourceManagementPluginSetup +} + +export interface SearchRelevanceStartDependencies { + dataSource: DataSourcePluginStart; +} export class SearchRelevancePlugin implements Plugin { - public setup(core: CoreSetup): SearchRelevancePluginSetup { + public setup(core: CoreSetup, {dataSource, dataSourceManagement} : SearchRelevancePluginSetupDependencies): SearchRelevancePluginSetup { // Register an application into the side navigation menu core.application.register({ id: PLUGIN_ID, @@ -30,7 +41,7 @@ export class SearchRelevancePlugin // Get start services as specified in opensearch_dashboards.json const [coreStart, depsStart] = await core.getStartServices(); // Render the application - return renderApp(coreStart, depsStart as AppPluginStartDependencies, params); + return renderApp(coreStart, depsStart as AppPluginStartDependencies, params, dataSourceManagement); }, }); @@ -47,7 +58,7 @@ export class SearchRelevancePlugin }; } - public start(core: CoreStart): SearchRelevancePluginStart { + public start(core: CoreStart, {dataSource}: SearchRelevanceStartDependencies): SearchRelevancePluginStart { return {}; } diff --git a/public/types.ts b/public/types.ts index 8db98969..4e94ca24 100644 --- a/public/types.ts +++ b/public/types.ts @@ -3,6 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ +import { DataSourcePluginStart } from '../../../src/plugins/data_source/public/types'; import { NavigationPublicPluginStart } from '../../../src/plugins/navigation/public'; export interface SearchRelevancePluginSetup { @@ -13,4 +14,5 @@ export interface SearchRelevancePluginStart {} export interface AppPluginStartDependencies { navigation: NavigationPublicPluginStart; + dataSource: DataSourcePluginStart; } diff --git a/public/types/index.ts b/public/types/index.ts index d6100158..16dcd1ac 100644 --- a/public/types/index.ts +++ b/public/types/index.ts @@ -74,3 +74,9 @@ export const initialQueryErrorState: QueryError = { statusCode: 200, }, }; + +export interface datasourceElements { + index : DocumentsIndex [], + dataConnectionId: string, + pipeline: {} +} \ No newline at end of file diff --git a/server/plugin.ts b/server/plugin.ts index 2e58b481..41240359 100644 --- a/server/plugin.ts +++ b/server/plugin.ts @@ -7,21 +7,26 @@ import { Observable } from 'rxjs'; import { first } from 'rxjs/operators'; import { - PluginInitializerContext, CoreSetup, CoreStart, - IContextProvider, + ILegacyClusterClient, Logger, Plugin, - ILegacyClusterClient, - RequestHandler, + PluginInitializerContext } from '../../../src/core/server'; import { defineRoutes } from './routes'; -import { MetricsService, MetricsServiceSetup } from './metrics/metrics_service'; +import { DataSourcePluginSetup } from '../../../src/plugins/data_source/server/types'; +import { DataSourceManagementPlugin } from '../../../src/plugins/data_source_management/public/plugin'; import { SearchRelevancePluginConfigType } from '../config'; +import { MetricsService, MetricsServiceSetup } from './metrics/metrics_service'; import { SearchRelevancePluginSetup, SearchRelevancePluginStart } from './types'; +export interface SearchRelevancePluginSetupDependencies { + dataSourceManagement: ReturnType; + dataSource: DataSourcePluginSetup; +} + export class SearchRelevancePlugin implements Plugin { @@ -35,7 +40,9 @@ export class SearchRelevancePlugin this.metricsService = new MetricsService(this.logger.get('metrics-service')); } - public async setup(core: CoreSetup) { + public async setup(core: CoreSetup, {dataSource}: SearchRelevancePluginSetupDependencies) { + + const dataSourceEnabled = !!dataSource; this.logger.debug('SearchRelevance: Setup'); const config: SearchRelevancePluginConfigType = await this.config$.pipe(first()).toPromise(); @@ -47,8 +54,10 @@ export class SearchRelevancePlugin const router = core.http.createRouter(); - const opensearchSearchRelevanceClient: ILegacyClusterClient = - core.opensearch.legacy.createClient('opensearch_search_relevance'); + let opensearchSearchRelevanceClient: ILegacyClusterClient | undefined = undefined; + opensearchSearchRelevanceClient = core.opensearch.legacy.createClient( + 'opensearch_search_relevance', + ) // @ts-ignore core.http.registerRouteHandlerContext('searchRelevance', (context, request) => { @@ -60,7 +69,7 @@ export class SearchRelevancePlugin }); // Register server side APIs - defineRoutes(router); + defineRoutes(router,core.opensearch,dataSourceEnabled); return {}; } diff --git a/server/routes/dsl_route.ts b/server/routes/dsl_route.ts index 94671f8c..ee65f456 100644 --- a/server/routes/dsl_route.ts +++ b/server/routes/dsl_route.ts @@ -3,12 +3,12 @@ * SPDX-License-Identifier: Apache-2.0 */ -import { schema } from '@osd/config-schema'; import { RequestParams } from '@opensearch-project/opensearch'; +import { schema } from '@osd/config-schema'; -import { IRouter } from '../../../../src/core/server'; -import { METRIC_NAME, METRIC_ACTION } from '../metrics'; -import { ServiceEndpoints, SEARCH_API } from '../../common'; +import { ILegacyScopedClusterClient, IRouter, OpenSearchServiceSetup } from '../../../../src/core/server'; +import { SEARCH_API, ServiceEndpoints } from '../../common'; +import { METRIC_ACTION, METRIC_NAME } from '../metrics'; interface SearchResultsResponse { result1?: Object; @@ -19,14 +19,14 @@ interface SearchResultsResponse { const performance = require('perf_hooks').performance; -export function registerDslRoute(router: IRouter) { +export function registerDslRoute(router: IRouter, openSearchServiceSetup: OpenSearchServiceSetup, dataSourceEnabled: boolean) { router.post( { path: ServiceEndpoints.GetSearchResults, validate: { body: schema.any() }, }, async (context, request, response) => { - const { query1, query2 } = request.body; + const { query1, dataSourceId1, query2, dataSourceId2 } = request.body; const actionName = query1 && query2 ? METRIC_ACTION.COMPARISON_SEARCH : METRIC_ACTION.SINGLE_SEARCH; const resBody: SearchResultsResponse = {}; @@ -46,13 +46,19 @@ export function registerDslRoute(router: IRouter) { size, body: rest, }; - const start = performance.now(); try { - const resp = await context.core.opensearch.legacy.client.callAsCurrentUser( - 'search', - params - ); + let resp; + if(dataSourceEnabled && dataSourceId1){ + const client = context.dataSource.opensearch.legacy.getClient(dataSourceId1); + resp = await client.callAPI('search', params); + } + else{ + resp = await context.core.opensearch.legacy.client.callAsCurrentUser( + 'search', + params + ); + } const end = performance.now(); context.searchRelevance.metricsService.addMetric( METRIC_NAME.SEARCH_RELEVANCE, @@ -100,10 +106,17 @@ export function registerDslRoute(router: IRouter) { const start = performance.now(); try { - const resp = await context.core.opensearch.legacy.client.callAsCurrentUser( - 'search', - params - ); + let resp; + if(dataSourceEnabled && dataSourceId2){ + const client = context.dataSource.opensearch.legacy.getClient(dataSourceId2); + resp = await client.callAPI('search', params); + } + else{ + resp = await context.core.opensearch.legacy.client.callAsCurrentUser( + 'search', + params + ); + } const end = performance.now(); context.searchRelevance.metricsService.addMetric( METRIC_NAME.SEARCH_RELEVANCE, @@ -141,8 +154,12 @@ export function registerDslRoute(router: IRouter) { // Get Indices router.get( { - path: ServiceEndpoints.GetIndexes, - validate: {}, + path: `${ServiceEndpoints.GetIndexes}/{dataSourceId?}`, + validate: { + params: schema.object({ + dataSourceId: schema.maybe(schema.string({ defaultValue: '' })) + }), + }, }, async (context, request, response) => { const params = { @@ -150,10 +167,14 @@ export function registerDslRoute(router: IRouter) { }; const start = performance.now(); try { - const resp = await context.core.opensearch.legacy.client.callAsCurrentUser( - 'cat.indices', - params - ); + const dataSourceId = request.params.dataSourceId; + let callApi: ILegacyScopedClusterClient['callAsCurrentUser']; + if(dataSourceEnabled && dataSourceId){ + callApi = context.dataSource.opensearch.legacy.getClient(dataSourceId).callAPI; + } else { + callApi = context.core.opensearch.legacy.client.callAsCurrentUser; + } + const resp = await callApi('cat.indices', params); const end = performance.now(); context.searchRelevance.metricsService.addMetric( METRIC_NAME.SEARCH_RELEVANCE, @@ -184,18 +205,37 @@ export function registerDslRoute(router: IRouter) { // Get Pipelines router.get( { - path: ServiceEndpoints.GetPipelines, - validate: {}, + path: `${ServiceEndpoints.GetPipelines}/{dataSourceId?}`, + validate: { + params: schema.object({ + dataSourceId: schema.maybe(schema.string({ defaultValue: '' })) + }), + }, }, async (context, request, response) => { + const params = { + format: 'json', + }; const start = performance.now(); let resBody: any = {}; + let resp; try { - const resp = await context.core.opensearch.client.asCurrentUser.transport.request({ - method: 'GET', - path: `${SEARCH_API}/pipeline`, - }); + const dataSourceId = request.params.dataSourceId; + if(dataSourceEnabled && dataSourceId){ + resp = (await context.dataSource.opensearch.getClient(dataSourceId)).transport + resp = await resp.request({ + method: 'GET', + path: `${SEARCH_API}/pipeline`, + }) + } + else{ + resp = await context.core.opensearch.client.asCurrentUser.transport.request({ + method: 'GET', + path: `${SEARCH_API}/pipeline`, + }); + } resBody = resp.body; + console.log('inside pipleine',resBody) const end = performance.now(); context.searchRelevance.metricsService.addMetric( METRIC_NAME.SEARCH_RELEVANCE, @@ -215,9 +255,10 @@ export function registerDslRoute(router: IRouter) { end - start ); if (error.statusCode !== 404) console.error(error); - return response.custom({ - statusCode: error.statusCode || 500, - body: error.message, + console.log(error,'inside error') + return response.customError({ + statusCode: 404, + body: error, }); } } diff --git a/server/routes/index.ts b/server/routes/index.ts index aae28f4b..b83ff531 100644 --- a/server/routes/index.ts +++ b/server/routes/index.ts @@ -3,11 +3,11 @@ * SPDX-License-Identifier: Apache-2.0 */ -import { ILegacyClusterClient, IRouter } from '../../../../src/core/server'; +import { IRouter, OpenSearchServiceSetup } from '../../../../src/core/server'; import { registerDslRoute } from './dsl_route'; import { registerMetricsRoute } from './metrics_route'; -export function defineRoutes(router: IRouter) { - registerDslRoute(router); +export function defineRoutes(router: IRouter, openSearchServiceSetup: OpenSearchServiceSetup, dataSourceEnabled: boolean) { + registerDslRoute(router, openSearchServiceSetup, dataSourceEnabled); registerMetricsRoute(router); }