From 068aef82bcd127c1a6b11f9e6b463bfb9e0b845a Mon Sep 17 00:00:00 2001 From: Jason Stoltzfus Date: Mon, 28 Jun 2021 18:45:48 -0400 Subject: [PATCH] [App Search] Remove analytics tracking from the entire dashboard (#103534) --- .../relevance_tuning_logic.test.ts | 30 ++++++-------- .../relevance_tuning_logic.ts | 2 +- .../sample_response/sample_response_logic.ts | 8 +++- .../components/search/search_logic.test.ts | 6 +-- .../components/search/search_logic.ts | 2 +- .../server/routes/app_search/curations.ts | 17 -------- .../routes/app_search/result_settings.test.ts | 28 ------------- .../routes/app_search/result_settings.ts | 14 ------- .../server/routes/app_search/search.test.ts | 2 +- .../server/routes/app_search/search.ts | 20 ++++----- .../routes/app_search/search_settings.test.ts | 41 ------------------- .../routes/app_search/search_settings.ts | 17 -------- 12 files changed, 32 insertions(+), 155 deletions(-) diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/relevance_tuning/relevance_tuning_logic.test.ts b/x-pack/plugins/enterprise_search/public/applications/app_search/components/relevance_tuning/relevance_tuning_logic.test.ts index 147a3d38add1..4233a7b300d1 100644 --- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/relevance_tuning/relevance_tuning_logic.test.ts +++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/relevance_tuning/relevance_tuning_logic.test.ts @@ -387,15 +387,12 @@ describe('RelevanceTuningLogic', () => { await nextTick(); expect(RelevanceTuningLogic.actions.setResultsLoading).toHaveBeenCalledWith(true); - expect(http.post).toHaveBeenCalledWith( - '/api/app_search/engines/test-engine/search_settings_search', - { - body: JSON.stringify(searchSettingsWithoutNewBoostProp), - query: { - query: 'foo', - }, - } - ); + expect(http.post).toHaveBeenCalledWith('/api/app_search/engines/test-engine/search', { + body: JSON.stringify(searchSettingsWithoutNewBoostProp), + query: { + query: 'foo', + }, + }); expect(RelevanceTuningLogic.actions.setSearchResults).toHaveBeenCalledWith(searchResults); expect(clearFlashMessages).toHaveBeenCalled(); }); @@ -420,15 +417,12 @@ describe('RelevanceTuningLogic', () => { jest.runAllTimers(); await nextTick(); - expect(http.post).toHaveBeenCalledWith( - '/api/app_search/engines/test-engine/search_settings_search', - { - body: '{}', - query: { - query: 'foo', - }, - } - ); + expect(http.post).toHaveBeenCalledWith('/api/app_search/engines/test-engine/search', { + body: '{}', + query: { + query: 'foo', + }, + }); }); it('will call clearSearchResults if there is no query', async () => { diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/relevance_tuning/relevance_tuning_logic.ts b/x-pack/plugins/enterprise_search/public/applications/app_search/components/relevance_tuning/relevance_tuning_logic.ts index 45f56c1ef36b..743bb1aa1502 100644 --- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/relevance_tuning/relevance_tuning_logic.ts +++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/relevance_tuning/relevance_tuning_logic.ts @@ -268,7 +268,7 @@ export const RelevanceTuningLogic = kea< const { engineName } = EngineLogic.values; const { http } = HttpLogic.values; const { search_fields: searchFields, boosts } = removeBoostStateProps(values.searchSettings); - const url = `/api/app_search/engines/${engineName}/search_settings_search`; + const url = `/api/app_search/engines/${engineName}/search`; actions.setResultsLoading(true); diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/result_settings/sample_response/sample_response_logic.ts b/x-pack/plugins/enterprise_search/public/applications/app_search/components/result_settings/sample_response/sample_response_logic.ts index c64cb3465b31..4f0461220e54 100644 --- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/result_settings/sample_response/sample_response_logic.ts +++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/result_settings/sample_response/sample_response_logic.ts @@ -68,12 +68,16 @@ export const SampleResponseLogic = kea { afterAll(() => jest.useRealTimers()); it('should make a GET API call with a search query', async () => { - http.get.mockReturnValueOnce(Promise.resolve(MOCK_SEARCH_RESPONSE)); + http.post.mockReturnValueOnce(Promise.resolve(MOCK_SEARCH_RESPONSE)); const logic = mountLogic(); jest.spyOn(logic.actions, 'onSearch'); @@ -90,14 +90,14 @@ describe('SearchLogic', () => { jest.runAllTimers(); await nextTick(); - expect(http.get).toHaveBeenCalledWith('/api/app_search/engines/some-engine/search', { + expect(http.post).toHaveBeenCalledWith('/api/app_search/engines/some-engine/search', { query: { query: 'hello world' }, }); expect(logic.actions.onSearch).toHaveBeenCalledWith(MOCK_SEARCH_RESPONSE); }); it('handles errors', async () => { - http.get.mockReturnValueOnce(Promise.reject('error')); + http.post.mockReturnValueOnce(Promise.reject('error')); const logic = mountLogic(); logic.actions.search('test'); diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/search/search_logic.ts b/x-pack/plugins/enterprise_search/public/applications/app_search/components/search/search_logic.ts index d9b7d575ae0e..52aedc165968 100644 --- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/search/search_logic.ts +++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/search/search_logic.ts @@ -61,7 +61,7 @@ export const SearchLogic = kea>({ const { engineName } = EngineLogic.values; try { - const response = await http.get(`/api/app_search/engines/${engineName}/search`, { + const response = await http.post(`/api/app_search/engines/${engineName}/search`, { query: { query }, }); actions.onSearch(response); diff --git a/x-pack/plugins/enterprise_search/server/routes/app_search/curations.ts b/x-pack/plugins/enterprise_search/server/routes/app_search/curations.ts index 4811ceeac408..3cacab96d196 100644 --- a/x-pack/plugins/enterprise_search/server/routes/app_search/curations.ts +++ b/x-pack/plugins/enterprise_search/server/routes/app_search/curations.ts @@ -115,21 +115,4 @@ export function registerCurationsRoutes({ path: '/as/engines/:engineName/curations/find_or_create', }) ); - - router.get( - { - path: '/api/app_search/engines/{engineName}/curation_search', - validate: { - params: schema.object({ - engineName: schema.string(), - }), - query: schema.object({ - query: schema.string(), - }), - }, - }, - enterpriseSearchRequestHandler.createRequest({ - path: '/api/as/v1/engines/:engineName/search.json', - }) - ); } diff --git a/x-pack/plugins/enterprise_search/server/routes/app_search/result_settings.test.ts b/x-pack/plugins/enterprise_search/server/routes/app_search/result_settings.test.ts index eab4acd1ea4e..58f69e4abf96 100644 --- a/x-pack/plugins/enterprise_search/server/routes/app_search/result_settings.test.ts +++ b/x-pack/plugins/enterprise_search/server/routes/app_search/result_settings.test.ts @@ -72,32 +72,4 @@ describe('result settings routes', () => { }); }); }); - - describe('POST /api/app_search/engines/{name}/sample_response_search', () => { - const mockRouter = new MockRouter({ - method: 'post', - path: '/api/app_search/engines/{engineName}/sample_response_search', - }); - - beforeEach(() => { - registerResultSettingsRoutes({ - ...mockDependencies, - router: mockRouter.router, - }); - }); - - it('creates a request to enterprise search', () => { - mockRouter.callRoute({ - params: { engineName: 'some-engine' }, - body: { - query: 'test', - result_fields: resultFields, - }, - }); - - expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({ - path: '/as/engines/:engineName/sample_response_search', - }); - }); - }); }); diff --git a/x-pack/plugins/enterprise_search/server/routes/app_search/result_settings.ts b/x-pack/plugins/enterprise_search/server/routes/app_search/result_settings.ts index 9a81b8a9f590..d02844090817 100644 --- a/x-pack/plugins/enterprise_search/server/routes/app_search/result_settings.ts +++ b/x-pack/plugins/enterprise_search/server/routes/app_search/result_settings.ts @@ -42,18 +42,4 @@ export function registerResultSettingsRoutes({ path: '/as/engines/:engineName/result_settings', }) ); - - router.post( - skipBodyValidation({ - path: '/api/app_search/engines/{engineName}/sample_response_search', - validate: { - params: schema.object({ - engineName: schema.string(), - }), - }, - }), - enterpriseSearchRequestHandler.createRequest({ - path: '/as/engines/:engineName/sample_response_search', - }) - ); } diff --git a/x-pack/plugins/enterprise_search/server/routes/app_search/search.test.ts b/x-pack/plugins/enterprise_search/server/routes/app_search/search.test.ts index 9262dd9e574a..7c81d20334a5 100644 --- a/x-pack/plugins/enterprise_search/server/routes/app_search/search.test.ts +++ b/x-pack/plugins/enterprise_search/server/routes/app_search/search.test.ts @@ -28,7 +28,7 @@ describe('search routes', () => { it('creates a request handler', () => { expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({ - path: '/api/as/v1/engines/:engineName/search.json', + path: '/as/engines/:engineName/dashboard_search', }); }); }); diff --git a/x-pack/plugins/enterprise_search/server/routes/app_search/search.ts b/x-pack/plugins/enterprise_search/server/routes/app_search/search.ts index 216bffc68326..551ad8938abb 100644 --- a/x-pack/plugins/enterprise_search/server/routes/app_search/search.ts +++ b/x-pack/plugins/enterprise_search/server/routes/app_search/search.ts @@ -22,8 +22,8 @@ export function registerSearchRoutes({ router, enterpriseSearchRequestHandler, }: RouteDependencies) { - router.get( - { + router.post( + skipBodyValidation({ path: '/api/app_search/engines/{engineName}/search', validate: { params: schema.object({ @@ -33,19 +33,15 @@ export function registerSearchRoutes({ query: schema.string(), }), }, - }, + }), enterpriseSearchRequestHandler.createRequest({ - path: '/api/as/v1/engines/:engineName/search.json', + path: '/as/engines/:engineName/dashboard_search', }) ); - // For the Search UI routes below, Search UI always uses the full API path, like: - // "/api/as/v1/engines/{engineName}/search.json". We only have control over the base path - // in Search UI, so we created a common basepath of "/api/app_search/search-ui" here that - // Search UI can use. - // - // Search UI *also* uses the click tracking and query suggestion endpoints, however, since the - // App Search plugin doesn't use that portion of Search UI, we only set up a proxy for the search endpoint below. + // Search UI always posts it's requests to {some_configured_base_url}/api/as/v1/engines/{engineName}/search.json + // For that reason, we have to create a proxy url with that same suffix below, so that we can proxy Search UI + // requests through Kibana's server. router.post( skipBodyValidation({ path: '/api/app_search/search-ui/api/as/v1/engines/{engineName}/search.json', @@ -56,7 +52,7 @@ export function registerSearchRoutes({ }, }), enterpriseSearchRequestHandler.createRequest({ - path: '/api/as/v1/engines/:engineName/search.json', + path: '/as/engines/:engineName/dashboard_search', }) ); } diff --git a/x-pack/plugins/enterprise_search/server/routes/app_search/search_settings.test.ts b/x-pack/plugins/enterprise_search/server/routes/app_search/search_settings.test.ts index 0c11a10ea10f..7ea533af5da7 100644 --- a/x-pack/plugins/enterprise_search/server/routes/app_search/search_settings.test.ts +++ b/x-pack/plugins/enterprise_search/server/routes/app_search/search_settings.test.ts @@ -132,45 +132,4 @@ describe('search settings routes', () => { }); }); }); - - describe('POST /api/app_search/engines/{name}/search_settings_search', () => { - const mockRouter = new MockRouter({ - method: 'post', - path: '/api/app_search/engines/{engineName}/search_settings_search', - }); - - beforeEach(() => { - registerSearchSettingsRoutes({ - ...mockDependencies, - router: mockRouter.router, - }); - }); - - it('creates a request to enterprise search', () => { - mockRouter.callRoute({ - params: { engineName: 'some-engine' }, - body: searchSettings, - }); - - expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({ - path: '/as/engines/:engineName/search_settings_search', - }); - }); - - describe('validates query', () => { - it('correctly', () => { - const request = { - query: { - query: 'foo', - }, - }; - mockRouter.shouldValidate(request); - }); - - it('missing required fields', () => { - const request = { query: {} }; - mockRouter.shouldThrow(request); - }); - }); - }); }); diff --git a/x-pack/plugins/enterprise_search/server/routes/app_search/search_settings.ts b/x-pack/plugins/enterprise_search/server/routes/app_search/search_settings.ts index c8801d608973..31a8cc09ed83 100644 --- a/x-pack/plugins/enterprise_search/server/routes/app_search/search_settings.ts +++ b/x-pack/plugins/enterprise_search/server/routes/app_search/search_settings.ts @@ -56,21 +56,4 @@ export function registerSearchSettingsRoutes({ path: '/as/engines/:engineName/search_settings', }) ); - - router.post( - skipBodyValidation({ - path: '/api/app_search/engines/{engineName}/search_settings_search', - validate: { - params: schema.object({ - engineName: schema.string(), - }), - query: schema.object({ - query: schema.string(), - }), - }, - }), - enterpriseSearchRequestHandler.createRequest({ - path: '/as/engines/:engineName/search_settings_search', - }) - ); }