From af0513f22d300e5e3727856744d98471290bf2ba Mon Sep 17 00:00:00 2001 From: Liza K Date: Mon, 6 Apr 2020 21:15:06 +0300 Subject: [PATCH 01/14] move old code to legacy folder --- src/plugins/data/public/search/fetch/index.ts | 2 +- .../{fetch => legacy}/call_client.test.ts | 4 +- .../search/{fetch => legacy}/call_client.ts | 6 +- .../default_search_strategy.test.ts | 4 +- .../default_search_strategy.ts | 5 +- .../{fetch => legacy}/fetch_soon.test.ts | 6 +- .../search/{fetch => legacy}/fetch_soon.ts | 4 +- .../search/legacy/get_msearch_params.test.ts | 66 +++++++++++++++++++ .../search/legacy/get_msearch_params.ts | 29 ++++++++ .../search_strategy/get_search_params.test.ts | 41 +----------- .../search_strategy/get_search_params.ts | 12 +--- .../public/search/search_strategy/index.ts | 4 +- .../search_strategy/no_op_search_strategy.ts | 55 ---------------- 13 files changed, 117 insertions(+), 121 deletions(-) rename src/plugins/data/public/search/{fetch => legacy}/call_client.test.ts (97%) rename src/plugins/data/public/search/{fetch => legacy}/call_client.ts (91%) rename src/plugins/data/public/search/{search_strategy => legacy}/default_search_strategy.test.ts (97%) rename src/plugins/data/public/search/{search_strategy => legacy}/default_search_strategy.ts (93%) rename src/plugins/data/public/search/{fetch => legacy}/fetch_soon.test.ts (96%) rename src/plugins/data/public/search/{fetch => legacy}/fetch_soon.ts (95%) create mode 100644 src/plugins/data/public/search/legacy/get_msearch_params.test.ts create mode 100644 src/plugins/data/public/search/legacy/get_msearch_params.ts delete mode 100644 src/plugins/data/public/search/search_strategy/no_op_search_strategy.ts diff --git a/src/plugins/data/public/search/fetch/index.ts b/src/plugins/data/public/search/fetch/index.ts index 8a80b716add32..7b164f274d540 100644 --- a/src/plugins/data/public/search/fetch/index.ts +++ b/src/plugins/data/public/search/fetch/index.ts @@ -18,5 +18,5 @@ */ export * from './types'; -export { fetchSoon } from './fetch_soon'; +export { fetchSoon } from '../legacy/fetch_soon'; export { RequestFailure } from './errors'; diff --git a/src/plugins/data/public/search/fetch/call_client.test.ts b/src/plugins/data/public/search/legacy/call_client.test.ts similarity index 97% rename from src/plugins/data/public/search/fetch/call_client.test.ts rename to src/plugins/data/public/search/legacy/call_client.test.ts index 7a99b7c064515..63441cfdc0058 100644 --- a/src/plugins/data/public/search/fetch/call_client.test.ts +++ b/src/plugins/data/public/search/legacy/call_client.test.ts @@ -18,8 +18,8 @@ */ import { callClient } from './call_client'; -import { handleResponse } from './handle_response'; -import { FetchHandlers } from './types'; +import { handleResponse } from '../fetch/handle_response'; +import { FetchHandlers } from '../fetch/types'; import { SearchStrategySearchParams, defaultSearchStrategy } from '../search_strategy'; const mockAbortFn = jest.fn(); diff --git a/src/plugins/data/public/search/fetch/call_client.ts b/src/plugins/data/public/search/legacy/call_client.ts similarity index 91% rename from src/plugins/data/public/search/fetch/call_client.ts rename to src/plugins/data/public/search/legacy/call_client.ts index b3c4c682fa60c..21082ffe65d4b 100644 --- a/src/plugins/data/public/search/fetch/call_client.ts +++ b/src/plugins/data/public/search/legacy/call_client.ts @@ -17,10 +17,10 @@ * under the License. */ -import { handleResponse } from './handle_response'; -import { FetchOptions, FetchHandlers } from './types'; +import { handleResponse } from '../fetch/handle_response'; +import { FetchOptions, FetchHandlers } from '../fetch/types'; import { defaultSearchStrategy } from '../search_strategy'; -import { SearchRequest } from '..'; +import { SearchRequest } from '../index'; export function callClient( searchRequests: SearchRequest[], diff --git a/src/plugins/data/public/search/search_strategy/default_search_strategy.test.ts b/src/plugins/data/public/search/legacy/default_search_strategy.test.ts similarity index 97% rename from src/plugins/data/public/search/search_strategy/default_search_strategy.test.ts rename to src/plugins/data/public/search/legacy/default_search_strategy.test.ts index 210a0e5fd1ac7..3a0e68f6f89c5 100644 --- a/src/plugins/data/public/search/search_strategy/default_search_strategy.test.ts +++ b/src/plugins/data/public/search/legacy/default_search_strategy.test.ts @@ -17,8 +17,8 @@ * under the License. */ -import { IUiSettingsClient } from '../../../../../core/public'; -import { SearchStrategySearchParams } from './types'; +import { IUiSettingsClient } from 'kibana/public'; +import { SearchStrategySearchParams } from '../search_strategy/types'; import { defaultSearchStrategy } from './default_search_strategy'; import { searchStartMock } from '../mocks'; diff --git a/src/plugins/data/public/search/search_strategy/default_search_strategy.ts b/src/plugins/data/public/search/legacy/default_search_strategy.ts similarity index 93% rename from src/plugins/data/public/search/search_strategy/default_search_strategy.ts rename to src/plugins/data/public/search/legacy/default_search_strategy.ts index 2bd88f51587a8..b73f08e3cd64a 100644 --- a/src/plugins/data/public/search/search_strategy/default_search_strategy.ts +++ b/src/plugins/data/public/search/legacy/default_search_strategy.ts @@ -17,9 +17,10 @@ * under the License. */ -import { SearchStrategyProvider, SearchStrategySearchParams } from './types'; +import { SearchStrategyProvider, SearchStrategySearchParams } from '../search_strategy/types'; import { isDefault } from '../../index_patterns'; -import { getSearchParams, getMSearchParams, getPreference, getTimeout } from './get_search_params'; +import { getSearchParams, getPreference, getTimeout } from '../search_strategy/get_search_params'; +import { getMSearchParams } from './get_msearch_params'; export const defaultSearchStrategy: SearchStrategyProvider = { id: 'default', diff --git a/src/plugins/data/public/search/fetch/fetch_soon.test.ts b/src/plugins/data/public/search/legacy/fetch_soon.test.ts similarity index 96% rename from src/plugins/data/public/search/fetch/fetch_soon.test.ts rename to src/plugins/data/public/search/legacy/fetch_soon.test.ts index a8d593c8501f6..b2e17798ccc9f 100644 --- a/src/plugins/data/public/search/fetch/fetch_soon.test.ts +++ b/src/plugins/data/public/search/legacy/fetch_soon.test.ts @@ -19,9 +19,9 @@ import { fetchSoon } from './fetch_soon'; import { callClient } from './call_client'; -import { IUiSettingsClient } from '../../../../../core/public'; -import { FetchHandlers, FetchOptions } from './types'; -import { SearchRequest, SearchResponse } from '..'; +import { IUiSettingsClient } from 'kibana/public'; +import { FetchHandlers, FetchOptions } from '../fetch/types'; +import { SearchRequest, SearchResponse } from '../index'; function getConfigStub(config: any = {}) { return { diff --git a/src/plugins/data/public/search/fetch/fetch_soon.ts b/src/plugins/data/public/search/legacy/fetch_soon.ts similarity index 95% rename from src/plugins/data/public/search/fetch/fetch_soon.ts rename to src/plugins/data/public/search/legacy/fetch_soon.ts index b1405747426ee..18fa410a5bef0 100644 --- a/src/plugins/data/public/search/fetch/fetch_soon.ts +++ b/src/plugins/data/public/search/legacy/fetch_soon.ts @@ -18,8 +18,8 @@ */ import { callClient } from './call_client'; -import { FetchHandlers, FetchOptions } from './types'; -import { SearchRequest, SearchResponse } from '..'; +import { FetchHandlers, FetchOptions } from '../fetch/types'; +import { SearchRequest, SearchResponse } from '../index'; /** * This function introduces a slight delay in the request process to allow multiple requests to queue diff --git a/src/plugins/data/public/search/legacy/get_msearch_params.test.ts b/src/plugins/data/public/search/legacy/get_msearch_params.test.ts new file mode 100644 index 0000000000000..9f16d5b408178 --- /dev/null +++ b/src/plugins/data/public/search/legacy/get_msearch_params.test.ts @@ -0,0 +1,66 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { getMSearchParams } from './get_msearch_params'; +import { IUiSettingsClient } from '../../../../../core/public'; + +function getConfigStub(config: any = {}) { + return { + get: key => config[key], + } as IUiSettingsClient; +} + +describe('getMSearchParams', () => { + test('includes rest_total_hits_as_int', () => { + const config = getConfigStub(); + const msearchParams = getMSearchParams(config); + expect(msearchParams.rest_total_hits_as_int).toBe(true); + }); + + test('includes ignore_throttled according to search:includeFrozen', () => { + let config = getConfigStub({ 'search:includeFrozen': true }); + let msearchParams = getMSearchParams(config); + expect(msearchParams.ignore_throttled).toBe(false); + + config = getConfigStub({ 'search:includeFrozen': false }); + msearchParams = getMSearchParams(config); + expect(msearchParams.ignore_throttled).toBe(true); + }); + + test('includes max_concurrent_shard_requests according to courier:maxConcurrentShardRequests if greater than 0', () => { + let config = getConfigStub({ 'courier:maxConcurrentShardRequests': 0 }); + let msearchParams = getMSearchParams(config); + expect(msearchParams.max_concurrent_shard_requests).toBe(undefined); + + config = getConfigStub({ 'courier:maxConcurrentShardRequests': 5 }); + msearchParams = getMSearchParams(config); + expect(msearchParams.max_concurrent_shard_requests).toBe(5); + }); + + test('does not include other search params that are included in the msearch header or body', () => { + const config = getConfigStub({ + 'search:includeFrozen': false, + 'courier:maxConcurrentShardRequests': 5, + }); + const msearchParams = getMSearchParams(config); + expect(msearchParams.hasOwnProperty('ignore_unavailable')).toBe(false); + expect(msearchParams.hasOwnProperty('preference')).toBe(false); + expect(msearchParams.hasOwnProperty('timeout')).toBe(false); + }); +}); diff --git a/src/plugins/data/public/search/legacy/get_msearch_params.ts b/src/plugins/data/public/search/legacy/get_msearch_params.ts new file mode 100644 index 0000000000000..ab5e61c8fcd12 --- /dev/null +++ b/src/plugins/data/public/search/legacy/get_msearch_params.ts @@ -0,0 +1,29 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { IUiSettingsClient } from 'kibana/public'; +import { getIgnoreThrottled, getMaxConcurrentShardRequests } from '../search_strategy'; + +export function getMSearchParams(config: IUiSettingsClient) { + return { + rest_total_hits_as_int: true, + ignore_throttled: getIgnoreThrottled(config), + max_concurrent_shard_requests: getMaxConcurrentShardRequests(config), + }; +} diff --git a/src/plugins/data/public/search/search_strategy/get_search_params.test.ts b/src/plugins/data/public/search/search_strategy/get_search_params.test.ts index 76f3105d7f942..915760c50009a 100644 --- a/src/plugins/data/public/search/search_strategy/get_search_params.test.ts +++ b/src/plugins/data/public/search/search_strategy/get_search_params.test.ts @@ -17,7 +17,7 @@ * under the License. */ -import { getMSearchParams, getSearchParams } from './get_search_params'; +import { getSearchParams } from './get_search_params'; import { IUiSettingsClient } from '../../../../../core/public'; function getConfigStub(config: any = {}) { @@ -26,45 +26,6 @@ function getConfigStub(config: any = {}) { } as IUiSettingsClient; } -describe('getMSearchParams', () => { - test('includes rest_total_hits_as_int', () => { - const config = getConfigStub(); - const msearchParams = getMSearchParams(config); - expect(msearchParams.rest_total_hits_as_int).toBe(true); - }); - - test('includes ignore_throttled according to search:includeFrozen', () => { - let config = getConfigStub({ 'search:includeFrozen': true }); - let msearchParams = getMSearchParams(config); - expect(msearchParams.ignore_throttled).toBe(false); - - config = getConfigStub({ 'search:includeFrozen': false }); - msearchParams = getMSearchParams(config); - expect(msearchParams.ignore_throttled).toBe(true); - }); - - test('includes max_concurrent_shard_requests according to courier:maxConcurrentShardRequests if greater than 0', () => { - let config = getConfigStub({ 'courier:maxConcurrentShardRequests': 0 }); - let msearchParams = getMSearchParams(config); - expect(msearchParams.max_concurrent_shard_requests).toBe(undefined); - - config = getConfigStub({ 'courier:maxConcurrentShardRequests': 5 }); - msearchParams = getMSearchParams(config); - expect(msearchParams.max_concurrent_shard_requests).toBe(5); - }); - - test('does not include other search params that are included in the msearch header or body', () => { - const config = getConfigStub({ - 'search:includeFrozen': false, - 'courier:maxConcurrentShardRequests': 5, - }); - const msearchParams = getMSearchParams(config); - expect(msearchParams.hasOwnProperty('ignore_unavailable')).toBe(false); - expect(msearchParams.hasOwnProperty('preference')).toBe(false); - expect(msearchParams.hasOwnProperty('timeout')).toBe(false); - }); -}); - describe('getSearchParams', () => { test('includes rest_total_hits_as_int', () => { const config = getConfigStub(); diff --git a/src/plugins/data/public/search/search_strategy/get_search_params.ts b/src/plugins/data/public/search/search_strategy/get_search_params.ts index 9fb8f2c728c6f..c0680264830f2 100644 --- a/src/plugins/data/public/search/search_strategy/get_search_params.ts +++ b/src/plugins/data/public/search/search_strategy/get_search_params.ts @@ -21,14 +21,6 @@ import { IUiSettingsClient } from '../../../../../core/public'; const sessionId = Date.now(); -export function getMSearchParams(config: IUiSettingsClient) { - return { - rest_total_hits_as_int: true, - ignore_throttled: getIgnoreThrottled(config), - max_concurrent_shard_requests: getMaxConcurrentShardRequests(config), - }; -} - export function getSearchParams(config: IUiSettingsClient, esShardTimeout: number = 0) { return { rest_total_hits_as_int: true, @@ -40,11 +32,11 @@ export function getSearchParams(config: IUiSettingsClient, esShardTimeout: numbe }; } -function getIgnoreThrottled(config: IUiSettingsClient) { +export function getIgnoreThrottled(config: IUiSettingsClient) { return !config.get('search:includeFrozen'); } -function getMaxConcurrentShardRequests(config: IUiSettingsClient) { +export function getMaxConcurrentShardRequests(config: IUiSettingsClient) { const maxConcurrentShardRequests = config.get('courier:maxConcurrentShardRequests'); return maxConcurrentShardRequests > 0 ? maxConcurrentShardRequests : undefined; } diff --git a/src/plugins/data/public/search/search_strategy/index.ts b/src/plugins/data/public/search/search_strategy/index.ts index e3de2ea46e3ec..d5e406f72698b 100644 --- a/src/plugins/data/public/search/search_strategy/index.ts +++ b/src/plugins/data/public/search/search_strategy/index.ts @@ -21,4 +21,6 @@ export { SearchError, getSearchErrorType } from './search_error'; export { SearchStrategyProvider, SearchStrategySearchParams } from './types'; -export { defaultSearchStrategy } from './default_search_strategy'; +export { defaultSearchStrategy } from '../legacy/default_search_strategy'; + +export { getIgnoreThrottled, getMaxConcurrentShardRequests } from './get_search_params'; diff --git a/src/plugins/data/public/search/search_strategy/no_op_search_strategy.ts b/src/plugins/data/public/search/search_strategy/no_op_search_strategy.ts deleted file mode 100644 index dc7331e614a0e..0000000000000 --- a/src/plugins/data/public/search/search_strategy/no_op_search_strategy.ts +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Licensed to Elasticsearch B.V. under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch B.V. licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import { i18n } from '@kbn/i18n'; -import { SearchError } from './search_error'; -import { SearchStrategyProvider } from './types'; - -export const noOpSearchStrategy: SearchStrategyProvider = { - id: 'noOp', - - search: () => { - const searchError = new SearchError({ - status: '418', // "I'm a teapot" error - title: i18n.translate( - 'data.search.searchSource.noSearchStrategyRegisteredErrorMessageTitle', - { - defaultMessage: 'No search strategy registered', - } - ), - message: i18n.translate( - 'data.search.searchSource.noSearchStrategyRegisteredErrorMessageDescription', - { - defaultMessage: `Couldn't find a search strategy for the search request`, - } - ), - type: 'NO_OP_SEARCH_STRATEGY', - path: '', - }); - - return { - searching: Promise.reject(searchError), - abort: () => {}, - }; - }, - - isViable: () => { - return true; - }, -}; From 9125611a86371748846e5256ef4aeeb7161f9e21 Mon Sep 17 00:00:00 2001 From: Liza K Date: Sun, 12 Apr 2020 13:46:11 +0300 Subject: [PATCH 02/14] Use search service directly from search source --- .../search/search_source/search_source.ts | 59 ++++++++++++++----- 1 file changed, 45 insertions(+), 14 deletions(-) diff --git a/src/plugins/data/public/search/search_source/search_source.ts b/src/plugins/data/public/search/search_source/search_source.ts index c70db7bb82ef7..431d7aad2cbd4 100644 --- a/src/plugins/data/public/search/search_source/search_source.ts +++ b/src/plugins/data/public/search/search_source/search_source.ts @@ -81,6 +81,9 @@ import { fetchSoon, FetchOptions, RequestFailure } from '../fetch'; import { getSearchService, getUiSettings, getInjectedMetadata } from '../../services'; import { getEsQueryConfig, buildEsQuery, Filter } from '../../../common'; import { getHighlightRequest } from '../../../common/field_formats'; +import { handleResponse } from '../fetch/handle_response'; +import { getSearchParams } from '../search_strategy/get_search_params'; +import { ISearchStart } from '../types'; export type ISearchSource = Pick; @@ -184,6 +187,26 @@ export class SearchSource { return this.parent; } + private search(searchRequest: SearchRequest, searchService: ISearchStart, searchParams: any) { + const abortController = new AbortController(); + const { index, indexType, body } = searchRequest; + const params = { + index: index.title || index, + body, + ...searchParams, + }; + const { signal } = abortController; + const promise = searchService + .search({ params, indexType }, { signal }) + .toPromise() + .then(({ rawResponse }) => rawResponse); + + return { + searching: promise, + abort: () => abortController.abort(), + }; + } + /** * Fetch this source and reject the returned Promise on error * @@ -196,18 +219,28 @@ export class SearchSource { this.history = [searchRequest]; const esShardTimeout = getInjectedMetadata().getInjectedVar('esShardTimeout') as number; - const response = await fetchSoon( - searchRequest, - { - ...(this.searchStrategyId && { searchStrategyId: this.searchStrategyId }), - ...options, - }, - { - searchService: getSearchService(), - config: getUiSettings(), - esShardTimeout, - } - ); + const legacySearch = getUiSettings().get('courier:batchSearches'); + let response; + if (legacySearch) { + response = await fetchSoon( + searchRequest, + { + ...(this.searchStrategyId && { searchStrategyId: this.searchStrategyId }), + ...options, + }, + { + searchService: getSearchService(), + config: getUiSettings(), + esShardTimeout, + } + ); + } else { + const searchParams = getSearchParams(getUiSettings(), esShardTimeout); + const { searching, abort } = this.search(searchRequest, getSearchService(), searchParams); + + response = searching.then(result => handleResponse(searchRequest, result)); + if (options.abortSignal) options.abortSignal.addEventListener('abort', abort); + } if (response.error) { throw new RequestFailure(null, response); @@ -246,7 +279,6 @@ export class SearchSource { /** * Called by requests of this search source when they are started - * @param {Courier.Request} request * @param options * @return {Promise} */ @@ -430,7 +462,6 @@ export class SearchSource { * and `kibanaSavedObjectMeta.searchSourceJSON.filter[].meta.index`. * * Using `createSearchSource`, the instance can be re-created. - * @param searchSource The search source to serialize * @public */ public serialize() { const references: SavedObjectReference[] = []; From a3773b9a029cd157ad67a14e1a68ac3483d75c14 Mon Sep 17 00:00:00 2001 From: Liza K Date: Sun, 12 Apr 2020 13:55:57 +0300 Subject: [PATCH 03/14] Move get search params to fetch folder --- .../{search_strategy => fetch}/get_search_params.test.ts | 2 +- .../{search_strategy => fetch}/get_search_params.ts | 2 +- src/plugins/data/public/search/fetch/index.ts | 9 ++++++++- .../data/public/search/legacy/default_search_strategy.ts | 4 ++-- .../data/public/search/legacy/get_msearch_params.ts | 2 +- .../data/public/search/search_source/search_source.ts | 5 ++--- src/plugins/data/public/search/search_strategy/index.ts | 2 -- 7 files changed, 15 insertions(+), 11 deletions(-) rename src/plugins/data/public/search/{search_strategy => fetch}/get_search_params.test.ts (97%) rename src/plugins/data/public/search/{search_strategy => fetch}/get_search_params.ts (96%) diff --git a/src/plugins/data/public/search/search_strategy/get_search_params.test.ts b/src/plugins/data/public/search/fetch/get_search_params.test.ts similarity index 97% rename from src/plugins/data/public/search/search_strategy/get_search_params.test.ts rename to src/plugins/data/public/search/fetch/get_search_params.test.ts index 915760c50009a..edf18405e8ff7 100644 --- a/src/plugins/data/public/search/search_strategy/get_search_params.test.ts +++ b/src/plugins/data/public/search/fetch/get_search_params.test.ts @@ -18,7 +18,7 @@ */ import { getSearchParams } from './get_search_params'; -import { IUiSettingsClient } from '../../../../../core/public'; +import { IUiSettingsClient } from 'kibana/public'; function getConfigStub(config: any = {}) { return { diff --git a/src/plugins/data/public/search/search_strategy/get_search_params.ts b/src/plugins/data/public/search/fetch/get_search_params.ts similarity index 96% rename from src/plugins/data/public/search/search_strategy/get_search_params.ts rename to src/plugins/data/public/search/fetch/get_search_params.ts index c0680264830f2..f0c43bd2e74cd 100644 --- a/src/plugins/data/public/search/search_strategy/get_search_params.ts +++ b/src/plugins/data/public/search/fetch/get_search_params.ts @@ -17,7 +17,7 @@ * under the License. */ -import { IUiSettingsClient } from '../../../../../core/public'; +import { IUiSettingsClient } from 'kibana/public'; const sessionId = Date.now(); diff --git a/src/plugins/data/public/search/fetch/index.ts b/src/plugins/data/public/search/fetch/index.ts index 7b164f274d540..12af09632fe0e 100644 --- a/src/plugins/data/public/search/fetch/index.ts +++ b/src/plugins/data/public/search/fetch/index.ts @@ -18,5 +18,12 @@ */ export * from './types'; -export { fetchSoon } from '../legacy/fetch_soon'; +export { + getSearchParams, + getPreference, + getTimeout, + getIgnoreThrottled, + getMaxConcurrentShardRequests, +} from './get_search_params'; export { RequestFailure } from './errors'; +export { handleResponse } from './handle_response'; diff --git a/src/plugins/data/public/search/legacy/default_search_strategy.ts b/src/plugins/data/public/search/legacy/default_search_strategy.ts index b73f08e3cd64a..4c3d3e0463a07 100644 --- a/src/plugins/data/public/search/legacy/default_search_strategy.ts +++ b/src/plugins/data/public/search/legacy/default_search_strategy.ts @@ -17,9 +17,9 @@ * under the License. */ -import { SearchStrategyProvider, SearchStrategySearchParams } from '../search_strategy/types'; +import { SearchStrategyProvider, SearchStrategySearchParams } from '../search_strategy'; import { isDefault } from '../../index_patterns'; -import { getSearchParams, getPreference, getTimeout } from '../search_strategy/get_search_params'; +import { getSearchParams, getPreference, getTimeout } from '../fetch'; import { getMSearchParams } from './get_msearch_params'; export const defaultSearchStrategy: SearchStrategyProvider = { diff --git a/src/plugins/data/public/search/legacy/get_msearch_params.ts b/src/plugins/data/public/search/legacy/get_msearch_params.ts index ab5e61c8fcd12..48d13903c972f 100644 --- a/src/plugins/data/public/search/legacy/get_msearch_params.ts +++ b/src/plugins/data/public/search/legacy/get_msearch_params.ts @@ -18,7 +18,7 @@ */ import { IUiSettingsClient } from 'kibana/public'; -import { getIgnoreThrottled, getMaxConcurrentShardRequests } from '../search_strategy'; +import { getIgnoreThrottled, getMaxConcurrentShardRequests } from '../fetch'; export function getMSearchParams(config: IUiSettingsClient) { return { diff --git a/src/plugins/data/public/search/search_source/search_source.ts b/src/plugins/data/public/search/search_source/search_source.ts index 431d7aad2cbd4..c2d60e59a91f5 100644 --- a/src/plugins/data/public/search/search_source/search_source.ts +++ b/src/plugins/data/public/search/search_source/search_source.ts @@ -76,14 +76,13 @@ import { filterDocvalueFields } from './filter_docvalue_fields'; import { fieldWildcardFilter } from '../../../../kibana_utils/public'; import { IIndexPattern, SearchRequest } from '../..'; import { SearchSourceOptions, SearchSourceFields } from './types'; -import { fetchSoon, FetchOptions, RequestFailure } from '../fetch'; +import { FetchOptions, RequestFailure, getSearchParams, handleResponse } from '../fetch'; import { getSearchService, getUiSettings, getInjectedMetadata } from '../../services'; import { getEsQueryConfig, buildEsQuery, Filter } from '../../../common'; import { getHighlightRequest } from '../../../common/field_formats'; -import { handleResponse } from '../fetch/handle_response'; -import { getSearchParams } from '../search_strategy/get_search_params'; import { ISearchStart } from '../types'; +import { fetchSoon } from '../legacy/fetch_soon'; export type ISearchSource = Pick; diff --git a/src/plugins/data/public/search/search_strategy/index.ts b/src/plugins/data/public/search/search_strategy/index.ts index d5e406f72698b..f3beb4366b100 100644 --- a/src/plugins/data/public/search/search_strategy/index.ts +++ b/src/plugins/data/public/search/search_strategy/index.ts @@ -22,5 +22,3 @@ export { SearchError, getSearchErrorType } from './search_error'; export { SearchStrategyProvider, SearchStrategySearchParams } from './types'; export { defaultSearchStrategy } from '../legacy/default_search_strategy'; - -export { getIgnoreThrottled, getMaxConcurrentShardRequests } from './get_search_params'; From a7ccef882a79897948a6f8da489d258bfb77a898 Mon Sep 17 00:00:00 2001 From: Liza K Date: Sun, 12 Apr 2020 14:22:28 +0300 Subject: [PATCH 04/14] Delete search strategy folder --- src/plugins/data/public/index.ts | 1 - src/plugins/data/public/search/fetch/index.ts | 4 +- .../fetch/{errors.ts => request_error.ts} | 0 .../search_error.ts | 0 src/plugins/data/public/search/index.ts | 2 +- .../public/search/legacy/call_client.test.ts | 6 +- .../data/public/search/legacy/call_client.ts | 5 +- .../legacy/default_search_strategy.test.ts | 2 +- .../search/legacy/default_search_strategy.ts | 2 +- .../{search_strategy => legacy}/index.ts | 6 +- .../{search_strategy => legacy}/types.ts | 12 +- .../search/search_source/search_source.ts | 2 +- .../public/search/rollup_search_strategy.ts | 104 ------------------ 13 files changed, 19 insertions(+), 127 deletions(-) rename src/plugins/data/public/search/fetch/{errors.ts => request_error.ts} (100%) rename src/plugins/data/public/search/{search_strategy => fetch}/search_error.ts (100%) rename src/plugins/data/public/search/{search_strategy => legacy}/index.ts (78%) rename src/plugins/data/public/search/{search_strategy => legacy}/types.ts (92%) delete mode 100644 x-pack/legacy/plugins/rollup/public/search/rollup_search_strategy.ts diff --git a/src/plugins/data/public/index.ts b/src/plugins/data/public/index.ts index 06a46065baa84..b62b728beca35 100644 --- a/src/plugins/data/public/index.ts +++ b/src/plugins/data/public/index.ts @@ -363,7 +363,6 @@ export { SearchRequest, SearchResponse, SearchError, - SearchStrategyProvider, ISearchSource, SearchSource, createSearchSource, diff --git a/src/plugins/data/public/search/fetch/index.ts b/src/plugins/data/public/search/fetch/index.ts index 12af09632fe0e..39845ec31bfaa 100644 --- a/src/plugins/data/public/search/fetch/index.ts +++ b/src/plugins/data/public/search/fetch/index.ts @@ -25,5 +25,7 @@ export { getIgnoreThrottled, getMaxConcurrentShardRequests, } from './get_search_params'; -export { RequestFailure } from './errors'; + +export { SearchError, getSearchErrorType } from './search_error'; +export { RequestFailure } from './request_error'; export { handleResponse } from './handle_response'; diff --git a/src/plugins/data/public/search/fetch/errors.ts b/src/plugins/data/public/search/fetch/request_error.ts similarity index 100% rename from src/plugins/data/public/search/fetch/errors.ts rename to src/plugins/data/public/search/fetch/request_error.ts diff --git a/src/plugins/data/public/search/search_strategy/search_error.ts b/src/plugins/data/public/search/fetch/search_error.ts similarity index 100% rename from src/plugins/data/public/search/search_strategy/search_error.ts rename to src/plugins/data/public/search/fetch/search_error.ts diff --git a/src/plugins/data/public/search/index.ts b/src/plugins/data/public/search/index.ts index cce973d632f41..939a3d6fee613 100644 --- a/src/plugins/data/public/search/index.ts +++ b/src/plugins/data/public/search/index.ts @@ -46,7 +46,7 @@ export { IKibanaSearchResponse, IKibanaSearchRequest } from '../../common/search export { LegacyApiCaller, SearchRequest, SearchResponse } from './es_client'; -export { SearchError, SearchStrategyProvider, getSearchErrorType } from './search_strategy'; +export { SearchError, getSearchErrorType } from './fetch'; export { ISearchSource, diff --git a/src/plugins/data/public/search/legacy/call_client.test.ts b/src/plugins/data/public/search/legacy/call_client.test.ts index 63441cfdc0058..0d57559fdc32d 100644 --- a/src/plugins/data/public/search/legacy/call_client.test.ts +++ b/src/plugins/data/public/search/legacy/call_client.test.ts @@ -18,9 +18,9 @@ */ import { callClient } from './call_client'; -import { handleResponse } from '../fetch/handle_response'; -import { FetchHandlers } from '../fetch/types'; -import { SearchStrategySearchParams, defaultSearchStrategy } from '../search_strategy'; +import { SearchStrategySearchParams } from './types'; +import { defaultSearchStrategy } from './default_search_strategy'; +import { handleResponse, FetchHandlers } from '../fetch'; const mockAbortFn = jest.fn(); jest.mock('./handle_response', () => ({ diff --git a/src/plugins/data/public/search/legacy/call_client.ts b/src/plugins/data/public/search/legacy/call_client.ts index 21082ffe65d4b..c484c46aa4879 100644 --- a/src/plugins/data/public/search/legacy/call_client.ts +++ b/src/plugins/data/public/search/legacy/call_client.ts @@ -17,9 +17,8 @@ * under the License. */ -import { handleResponse } from '../fetch/handle_response'; -import { FetchOptions, FetchHandlers } from '../fetch/types'; -import { defaultSearchStrategy } from '../search_strategy'; +import { FetchOptions, FetchHandlers, handleResponse } from '../fetch'; +import { defaultSearchStrategy } from './default_search_strategy'; import { SearchRequest } from '../index'; export function callClient( diff --git a/src/plugins/data/public/search/legacy/default_search_strategy.test.ts b/src/plugins/data/public/search/legacy/default_search_strategy.test.ts index 3a0e68f6f89c5..4eaff0b500281 100644 --- a/src/plugins/data/public/search/legacy/default_search_strategy.test.ts +++ b/src/plugins/data/public/search/legacy/default_search_strategy.test.ts @@ -18,9 +18,9 @@ */ import { IUiSettingsClient } from 'kibana/public'; -import { SearchStrategySearchParams } from '../search_strategy/types'; import { defaultSearchStrategy } from './default_search_strategy'; import { searchStartMock } from '../mocks'; +import { SearchStrategySearchParams } from './types'; const { search } = defaultSearchStrategy; diff --git a/src/plugins/data/public/search/legacy/default_search_strategy.ts b/src/plugins/data/public/search/legacy/default_search_strategy.ts index 4c3d3e0463a07..3758f7d3c736c 100644 --- a/src/plugins/data/public/search/legacy/default_search_strategy.ts +++ b/src/plugins/data/public/search/legacy/default_search_strategy.ts @@ -17,10 +17,10 @@ * under the License. */ -import { SearchStrategyProvider, SearchStrategySearchParams } from '../search_strategy'; import { isDefault } from '../../index_patterns'; import { getSearchParams, getPreference, getTimeout } from '../fetch'; import { getMSearchParams } from './get_msearch_params'; +import { SearchStrategyProvider, SearchStrategySearchParams } from './types'; export const defaultSearchStrategy: SearchStrategyProvider = { id: 'default', diff --git a/src/plugins/data/public/search/search_strategy/index.ts b/src/plugins/data/public/search/legacy/index.ts similarity index 78% rename from src/plugins/data/public/search/search_strategy/index.ts rename to src/plugins/data/public/search/legacy/index.ts index f3beb4366b100..74e516f407e8c 100644 --- a/src/plugins/data/public/search/search_strategy/index.ts +++ b/src/plugins/data/public/search/legacy/index.ts @@ -17,8 +17,4 @@ * under the License. */ -export { SearchError, getSearchErrorType } from './search_error'; - -export { SearchStrategyProvider, SearchStrategySearchParams } from './types'; - -export { defaultSearchStrategy } from '../legacy/default_search_strategy'; +export { fetchSoon } from './fetch_soon'; diff --git a/src/plugins/data/public/search/search_strategy/types.ts b/src/plugins/data/public/search/legacy/types.ts similarity index 92% rename from src/plugins/data/public/search/search_strategy/types.ts rename to src/plugins/data/public/search/legacy/types.ts index 764370d8ff649..bb22d05182690 100644 --- a/src/plugins/data/public/search/search_strategy/types.ts +++ b/src/plugins/data/public/search/legacy/types.ts @@ -17,10 +17,14 @@ * under the License. */ -import { IndexPattern } from '../..'; -import { FetchHandlers } from '../fetch/types'; +import { FetchHandlers } from '../fetch'; +import { IndexPattern } from '../../index_patterns'; import { SearchRequest, SearchResponse } from '..'; +export interface SearchStrategySearchParams extends FetchHandlers { + searchRequests: SearchRequest[]; +} + export interface SearchStrategyProvider { id: string; search: (params: SearchStrategySearchParams) => SearchStrategyResponse; @@ -31,7 +35,3 @@ export interface SearchStrategyResponse { searching: Promise; abort: () => void; } - -export interface SearchStrategySearchParams extends FetchHandlers { - searchRequests: SearchRequest[]; -} diff --git a/src/plugins/data/public/search/search_source/search_source.ts b/src/plugins/data/public/search/search_source/search_source.ts index c2d60e59a91f5..b477866549ca1 100644 --- a/src/plugins/data/public/search/search_source/search_source.ts +++ b/src/plugins/data/public/search/search_source/search_source.ts @@ -82,7 +82,7 @@ import { getSearchService, getUiSettings, getInjectedMetadata } from '../../serv import { getEsQueryConfig, buildEsQuery, Filter } from '../../../common'; import { getHighlightRequest } from '../../../common/field_formats'; import { ISearchStart } from '../types'; -import { fetchSoon } from '../legacy/fetch_soon'; +import { fetchSoon } from '../legacy'; export type ISearchSource = Pick; diff --git a/x-pack/legacy/plugins/rollup/public/search/rollup_search_strategy.ts b/x-pack/legacy/plugins/rollup/public/search/rollup_search_strategy.ts deleted file mode 100644 index 4709c0aa498f8..0000000000000 --- a/x-pack/legacy/plugins/rollup/public/search/rollup_search_strategy.ts +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - -import { HttpSetup } from 'src/core/public'; -import { - SearchError, - getSearchErrorType, - IIndexPattern, - SearchStrategyProvider, - SearchResponse, - SearchRequest, -} from '../../../../../../src/plugins/data/public'; - -function serializeFetchParams(searchRequests: SearchRequest[]) { - return JSON.stringify( - searchRequests.map(searchRequestWithFetchParams => { - const indexPattern = - searchRequestWithFetchParams.index.title || searchRequestWithFetchParams.index; - const { - body: { size, aggs, query: _query }, - } = searchRequestWithFetchParams; - - const query = { - size, - aggregations: aggs, - query: _query, - }; - - return { index: indexPattern, query }; - }) - ); -} - -// Rollup search always returns 0 hits, but visualizations expect search responses -// to return hits > 0, otherwise they do not render. We fake the number of hits here -// by counting the number of aggregation buckets/values returned by rollup search. -function shimHitsInFetchResponse(response: SearchResponse[]) { - return response.map(result => { - const buckets = result.aggregations - ? Object.keys(result.aggregations).reduce((allBuckets, agg) => { - return allBuckets.concat( - result.aggregations[agg].buckets || [result.aggregations[agg].value] || [] - ); - }, []) - : []; - return buckets && buckets.length - ? { - ...result, - hits: { - ...result.hits, - total: buckets.length, - }, - } - : result; - }); -} - -export const getRollupSearchStrategy = (fetch: HttpSetup['fetch']): SearchStrategyProvider => ({ - id: 'rollup', - - search: ({ searchRequests }) => { - // Serialize the fetch params into a format suitable for the body of an ES query. - const serializedFetchParams = serializeFetchParams(searchRequests); - - const controller = new AbortController(); - const promise = fetch('../api/rollup/search', { - signal: controller.signal, - method: 'POST', - body: serializedFetchParams, - }); - - return { - searching: promise.then(shimHitsInFetchResponse).catch(error => { - const { - body: { statusCode, error: title, message }, - res: { url }, - } = error; - - // Format fetch error as a SearchError. - const searchError = new SearchError({ - status: statusCode, - title, - message: `Rollup search error: ${message}`, - path: url, - type: getSearchErrorType({ message }) || '', - }); - - return Promise.reject(searchError); - }), - abort: () => controller.abort(), - }; - }, - - isViable: (indexPattern: IIndexPattern) => { - if (!indexPattern) { - return false; - } - - return indexPattern.type === 'rollup'; - }, -}); From 3104896ae3a6041713f81cb1e31a7afc1fa92069 Mon Sep 17 00:00:00 2001 From: Liza K Date: Sun, 12 Apr 2020 14:25:27 +0300 Subject: [PATCH 05/14] Doc update --- .../kibana-plugin-plugins-data-public.md | 1 - ...s-data-public.searchstrategyprovider.id.md | 11 ----- ...-public.searchstrategyprovider.isviable.md | 11 ----- ...gins-data-public.searchstrategyprovider.md | 20 --------- ...ta-public.searchstrategyprovider.search.md | 11 ----- src/plugins/data/public/public.api.md | 45 +++++++------------ 6 files changed, 15 insertions(+), 84 deletions(-) delete mode 100644 docs/development/plugins/data/public/kibana-plugin-plugins-data-public.searchstrategyprovider.id.md delete mode 100644 docs/development/plugins/data/public/kibana-plugin-plugins-data-public.searchstrategyprovider.isviable.md delete mode 100644 docs/development/plugins/data/public/kibana-plugin-plugins-data-public.searchstrategyprovider.md delete mode 100644 docs/development/plugins/data/public/kibana-plugin-plugins-data-public.searchstrategyprovider.search.md diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.md index fc0dab94a0f65..bf29c883e4eb9 100644 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.md +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.md @@ -88,7 +88,6 @@ | [SavedQuery](./kibana-plugin-plugins-data-public.savedquery.md) | | | [SavedQueryService](./kibana-plugin-plugins-data-public.savedqueryservice.md) | | | [SearchSourceFields](./kibana-plugin-plugins-data-public.searchsourcefields.md) | | -| [SearchStrategyProvider](./kibana-plugin-plugins-data-public.searchstrategyprovider.md) | | | [TabbedAggColumn](./kibana-plugin-plugins-data-public.tabbedaggcolumn.md) | \* | | [TabbedTable](./kibana-plugin-plugins-data-public.tabbedtable.md) | \* | | [TimeRange](./kibana-plugin-plugins-data-public.timerange.md) | | diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.searchstrategyprovider.id.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.searchstrategyprovider.id.md deleted file mode 100644 index d60ffba6a05ca..0000000000000 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.searchstrategyprovider.id.md +++ /dev/null @@ -1,11 +0,0 @@ - - -[Home](./index.md) > [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) > [SearchStrategyProvider](./kibana-plugin-plugins-data-public.searchstrategyprovider.md) > [id](./kibana-plugin-plugins-data-public.searchstrategyprovider.id.md) - -## SearchStrategyProvider.id property - -Signature: - -```typescript -id: string; -``` diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.searchstrategyprovider.isviable.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.searchstrategyprovider.isviable.md deleted file mode 100644 index aa8ed49051ee9..0000000000000 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.searchstrategyprovider.isviable.md +++ /dev/null @@ -1,11 +0,0 @@ - - -[Home](./index.md) > [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) > [SearchStrategyProvider](./kibana-plugin-plugins-data-public.searchstrategyprovider.md) > [isViable](./kibana-plugin-plugins-data-public.searchstrategyprovider.isviable.md) - -## SearchStrategyProvider.isViable property - -Signature: - -```typescript -isViable: (indexPattern: IndexPattern) => boolean; -``` diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.searchstrategyprovider.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.searchstrategyprovider.md deleted file mode 100644 index b271a921906a7..0000000000000 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.searchstrategyprovider.md +++ /dev/null @@ -1,20 +0,0 @@ - - -[Home](./index.md) > [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) > [SearchStrategyProvider](./kibana-plugin-plugins-data-public.searchstrategyprovider.md) - -## SearchStrategyProvider interface - -Signature: - -```typescript -export interface SearchStrategyProvider -``` - -## Properties - -| Property | Type | Description | -| --- | --- | --- | -| [id](./kibana-plugin-plugins-data-public.searchstrategyprovider.id.md) | string | | -| [isViable](./kibana-plugin-plugins-data-public.searchstrategyprovider.isviable.md) | (indexPattern: IndexPattern) => boolean | | -| [search](./kibana-plugin-plugins-data-public.searchstrategyprovider.search.md) | (params: SearchStrategySearchParams) => SearchStrategyResponse | | - diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.searchstrategyprovider.search.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.searchstrategyprovider.search.md deleted file mode 100644 index 6e2561c3b0ad0..0000000000000 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.searchstrategyprovider.search.md +++ /dev/null @@ -1,11 +0,0 @@ - - -[Home](./index.md) > [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) > [SearchStrategyProvider](./kibana-plugin-plugins-data-public.searchstrategyprovider.md) > [search](./kibana-plugin-plugins-data-public.searchstrategyprovider.search.md) - -## SearchStrategyProvider.search property - -Signature: - -```typescript -search: (params: SearchStrategySearchParams) => SearchStrategyResponse; -``` diff --git a/src/plugins/data/public/public.api.md b/src/plugins/data/public/public.api.md index cef82b27b1b5b..f43a20aa142d9 100644 --- a/src/plugins/data/public/public.api.md +++ b/src/plugins/data/public/public.api.md @@ -1724,21 +1724,6 @@ export interface SearchSourceFields { version?: boolean; } -// Warning: (ae-missing-release-tag) "SearchStrategyProvider" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) -// -// @public (undocumented) -export interface SearchStrategyProvider { - // (undocumented) - id: string; - // (undocumented) - isViable: (indexPattern: IndexPattern) => boolean; - // Warning: (ae-forgotten-export) The symbol "SearchStrategySearchParams" needs to be exported by the entry point index.d.ts - // Warning: (ae-forgotten-export) The symbol "SearchStrategyResponse" needs to be exported by the entry point index.d.ts - // - // (undocumented) - search: (params: SearchStrategySearchParams) => SearchStrategyResponse; -} - // Warning: (ae-missing-release-tag) "SortDirection" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // // @public (undocumented) @@ -1889,21 +1874,21 @@ export type TSearchStrategyProvider = (context: ISearc // src/plugins/data/public/index.ts:234:27 - (ae-forgotten-export) The symbol "flattenHitWrapper" needs to be exported by the entry point index.d.ts // src/plugins/data/public/index.ts:234:27 - (ae-forgotten-export) The symbol "getRoutes" needs to be exported by the entry point index.d.ts // src/plugins/data/public/index.ts:234:27 - (ae-forgotten-export) The symbol "formatHitProvider" needs to be exported by the entry point index.d.ts -// src/plugins/data/public/index.ts:383:20 - (ae-forgotten-export) The symbol "getRequestInspectorStats" needs to be exported by the entry point index.d.ts -// src/plugins/data/public/index.ts:383:20 - (ae-forgotten-export) The symbol "getResponseInspectorStats" needs to be exported by the entry point index.d.ts -// src/plugins/data/public/index.ts:383:20 - (ae-forgotten-export) The symbol "tabifyAggResponse" needs to be exported by the entry point index.d.ts -// src/plugins/data/public/index.ts:383:20 - (ae-forgotten-export) The symbol "tabifyGetColumns" needs to be exported by the entry point index.d.ts -// src/plugins/data/public/index.ts:388:1 - (ae-forgotten-export) The symbol "CidrMask" needs to be exported by the entry point index.d.ts -// src/plugins/data/public/index.ts:389:1 - (ae-forgotten-export) The symbol "convertDateRangeToString" needs to be exported by the entry point index.d.ts -// src/plugins/data/public/index.ts:391:1 - (ae-forgotten-export) The symbol "dateHistogramInterval" needs to be exported by the entry point index.d.ts -// src/plugins/data/public/index.ts:400:1 - (ae-forgotten-export) The symbol "InvalidEsCalendarIntervalError" needs to be exported by the entry point index.d.ts -// src/plugins/data/public/index.ts:401:1 - (ae-forgotten-export) The symbol "InvalidEsIntervalFormatError" needs to be exported by the entry point index.d.ts -// src/plugins/data/public/index.ts:402:1 - (ae-forgotten-export) The symbol "isDateHistogramBucketAggConfig" needs to be exported by the entry point index.d.ts -// src/plugins/data/public/index.ts:405:1 - (ae-forgotten-export) The symbol "isValidEsInterval" needs to be exported by the entry point index.d.ts -// src/plugins/data/public/index.ts:406:1 - (ae-forgotten-export) The symbol "isValidInterval" needs to be exported by the entry point index.d.ts -// src/plugins/data/public/index.ts:409:1 - (ae-forgotten-export) The symbol "parseInterval" needs to be exported by the entry point index.d.ts -// src/plugins/data/public/index.ts:410:1 - (ae-forgotten-export) The symbol "propFilter" needs to be exported by the entry point index.d.ts -// src/plugins/data/public/index.ts:413:1 - (ae-forgotten-export) The symbol "toAbsoluteDates" needs to be exported by the entry point index.d.ts +// src/plugins/data/public/index.ts:382:20 - (ae-forgotten-export) The symbol "getRequestInspectorStats" needs to be exported by the entry point index.d.ts +// src/plugins/data/public/index.ts:382:20 - (ae-forgotten-export) The symbol "getResponseInspectorStats" needs to be exported by the entry point index.d.ts +// src/plugins/data/public/index.ts:382:20 - (ae-forgotten-export) The symbol "tabifyAggResponse" needs to be exported by the entry point index.d.ts +// src/plugins/data/public/index.ts:382:20 - (ae-forgotten-export) The symbol "tabifyGetColumns" needs to be exported by the entry point index.d.ts +// src/plugins/data/public/index.ts:387:1 - (ae-forgotten-export) The symbol "CidrMask" needs to be exported by the entry point index.d.ts +// src/plugins/data/public/index.ts:388:1 - (ae-forgotten-export) The symbol "convertDateRangeToString" needs to be exported by the entry point index.d.ts +// src/plugins/data/public/index.ts:390:1 - (ae-forgotten-export) The symbol "dateHistogramInterval" needs to be exported by the entry point index.d.ts +// src/plugins/data/public/index.ts:399:1 - (ae-forgotten-export) The symbol "InvalidEsCalendarIntervalError" needs to be exported by the entry point index.d.ts +// src/plugins/data/public/index.ts:400:1 - (ae-forgotten-export) The symbol "InvalidEsIntervalFormatError" needs to be exported by the entry point index.d.ts +// src/plugins/data/public/index.ts:401:1 - (ae-forgotten-export) The symbol "isDateHistogramBucketAggConfig" needs to be exported by the entry point index.d.ts +// src/plugins/data/public/index.ts:404:1 - (ae-forgotten-export) The symbol "isValidEsInterval" needs to be exported by the entry point index.d.ts +// src/plugins/data/public/index.ts:405:1 - (ae-forgotten-export) The symbol "isValidInterval" needs to be exported by the entry point index.d.ts +// src/plugins/data/public/index.ts:408:1 - (ae-forgotten-export) The symbol "parseInterval" needs to be exported by the entry point index.d.ts +// src/plugins/data/public/index.ts:409:1 - (ae-forgotten-export) The symbol "propFilter" needs to be exported by the entry point index.d.ts +// src/plugins/data/public/index.ts:412:1 - (ae-forgotten-export) The symbol "toAbsoluteDates" needs to be exported by the entry point index.d.ts // src/plugins/data/public/query/state_sync/connect_to_query_state.ts:33:33 - (ae-forgotten-export) The symbol "FilterStateStore" needs to be exported by the entry point index.d.ts // src/plugins/data/public/query/state_sync/connect_to_query_state.ts:37:1 - (ae-forgotten-export) The symbol "QueryStateChange" needs to be exported by the entry point index.d.ts // src/plugins/data/public/types.ts:52:5 - (ae-forgotten-export) The symbol "createFiltersFromEvent" needs to be exported by the entry point index.d.ts From 8ee5e012e094a1aa62213215617196fc5eb860cc Mon Sep 17 00:00:00 2001 From: Liza K Date: Sun, 12 Apr 2020 14:30:14 +0300 Subject: [PATCH 06/14] Minor cleanups --- .../public/search/search_source/search_source.ts | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/plugins/data/public/search/search_source/search_source.ts b/src/plugins/data/public/search/search_source/search_source.ts index b477866549ca1..f4b3f8220edd8 100644 --- a/src/plugins/data/public/search/search_source/search_source.ts +++ b/src/plugins/data/public/search/search_source/search_source.ts @@ -81,7 +81,6 @@ import { FetchOptions, RequestFailure, getSearchParams, handleResponse } from '. import { getSearchService, getUiSettings, getInjectedMetadata } from '../../services'; import { getEsQueryConfig, buildEsQuery, Filter } from '../../../common'; import { getHighlightRequest } from '../../../common/field_formats'; -import { ISearchStart } from '../types'; import { fetchSoon } from '../legacy'; export type ISearchSource = Pick; @@ -186,17 +185,17 @@ export class SearchSource { return this.parent; } - private search(searchRequest: SearchRequest, searchService: ISearchStart, searchParams: any) { + private runSearch(searchRequest: SearchRequest, esShardTimeout: number) { + const searchParams = getSearchParams(getUiSettings(), esShardTimeout); const abortController = new AbortController(); - const { index, indexType, body } = searchRequest; const params = { - index: index.title || index, - body, + index: searchRequest.index.title || searchRequest.index, + body: searchRequest.body, ...searchParams, }; const { signal } = abortController; - const promise = searchService - .search({ params, indexType }, { signal }) + const promise = getSearchService() + .search({ params, indexType: searchRequest.indexType }, { signal }) .toPromise() .then(({ rawResponse }) => rawResponse); @@ -234,8 +233,7 @@ export class SearchSource { } ); } else { - const searchParams = getSearchParams(getUiSettings(), esShardTimeout); - const { searching, abort } = this.search(searchRequest, getSearchService(), searchParams); + const { searching, abort } = this.runSearch(searchRequest, esShardTimeout); response = searching.then(result => handleResponse(searchRequest, result)); if (options.abortSignal) options.abortSignal.addEventListener('abort', abort); From 3e43cf4d3017933d4bf7bf30e29413d4f95109a9 Mon Sep 17 00:00:00 2001 From: Liza K Date: Sun, 12 Apr 2020 14:39:41 +0300 Subject: [PATCH 07/14] Moved es client to legacy folder --- .../lib/get_indices.test.ts | 2 +- src/plugins/data/public/search/fetch/types.ts | 3 +++ src/plugins/data/public/search/index.ts | 12 +++++++----- .../search/{ => legacy}/es_client/get_es_client.ts | 0 .../public/search/{ => legacy}/es_client/index.ts | 2 +- .../public/search/{ => legacy}/es_client/types.ts | 3 +-- src/plugins/data/public/search/legacy/index.ts | 1 + src/plugins/data/public/search/search_service.ts | 6 +++--- src/plugins/data/public/search/types.ts | 11 +---------- 9 files changed, 18 insertions(+), 22 deletions(-) rename src/plugins/data/public/search/{ => legacy}/es_client/get_es_client.ts (100%) rename src/plugins/data/public/search/{ => legacy}/es_client/index.ts (91%) rename src/plugins/data/public/search/{ => legacy}/es_client/types.ts (94%) diff --git a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/create_index_pattern_wizard/lib/get_indices.test.ts b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/create_index_pattern_wizard/lib/get_indices.test.ts index 40583af7177fe..b1500f8303b66 100644 --- a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/create_index_pattern_wizard/lib/get_indices.test.ts +++ b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/create_index_pattern_wizard/lib/get_indices.test.ts @@ -20,7 +20,7 @@ import { getIndices } from './get_indices'; import { IndexPatternCreationConfig } from '../../../../../../../../../plugins/index_pattern_management/public'; // eslint-disable-next-line @kbn/eslint/no-restricted-paths -import { LegacyApiCaller } from '../../../../../../../../../plugins/data/public/search'; +import { LegacyApiCaller } from '../../../../../../../../../plugins/data/public/search/legacy'; export const successfulResponse = { hits: { diff --git a/src/plugins/data/public/search/fetch/types.ts b/src/plugins/data/public/search/fetch/types.ts index e8de0576b8a72..475b2abbc019f 100644 --- a/src/plugins/data/public/search/fetch/types.ts +++ b/src/plugins/data/public/search/fetch/types.ts @@ -20,6 +20,9 @@ import { IUiSettingsClient } from '../../../../../core/public'; import { ISearchStart } from '../types'; +export type SearchRequest = any; +export type SearchResponse = any; + export interface FetchOptions { abortSignal?: AbortSignal; searchStrategyId?: string; diff --git a/src/plugins/data/public/search/index.ts b/src/plugins/data/public/search/index.ts index 939a3d6fee613..75c0eb8b6f022 100644 --- a/src/plugins/data/public/search/index.ts +++ b/src/plugins/data/public/search/index.ts @@ -44,9 +44,13 @@ export { esSearchStrategyProvider, getEsPreference } from './es_search'; export { IKibanaSearchResponse, IKibanaSearchRequest } from '../../common/search'; -export { LegacyApiCaller, SearchRequest, SearchResponse } from './es_client'; - -export { SearchError, getSearchErrorType } from './fetch'; +export { + SearchError, + FetchOptions, + SearchRequest, + SearchResponse, + getSearchErrorType, +} from './fetch'; export { ISearchSource, @@ -59,5 +63,3 @@ export { export { SearchInterceptor } from './search_interceptor'; export { RequestTimeoutError } from './request_timeout_error'; - -export { FetchOptions } from './fetch'; diff --git a/src/plugins/data/public/search/es_client/get_es_client.ts b/src/plugins/data/public/search/legacy/es_client/get_es_client.ts similarity index 100% rename from src/plugins/data/public/search/es_client/get_es_client.ts rename to src/plugins/data/public/search/legacy/es_client/get_es_client.ts diff --git a/src/plugins/data/public/search/es_client/index.ts b/src/plugins/data/public/search/legacy/es_client/index.ts similarity index 91% rename from src/plugins/data/public/search/es_client/index.ts rename to src/plugins/data/public/search/legacy/es_client/index.ts index b1e0ce3116824..78ac83af642d8 100644 --- a/src/plugins/data/public/search/es_client/index.ts +++ b/src/plugins/data/public/search/legacy/es_client/index.ts @@ -18,4 +18,4 @@ */ export { getEsClient } from './get_es_client'; -export { SearchRequest, SearchResponse, LegacyApiCaller } from './types'; +export { LegacyApiCaller } from './types'; diff --git a/src/plugins/data/public/search/es_client/types.ts b/src/plugins/data/public/search/legacy/es_client/types.ts similarity index 94% rename from src/plugins/data/public/search/es_client/types.ts rename to src/plugins/data/public/search/legacy/es_client/types.ts index 3ca0513a14238..7a56b9b0cb00a 100644 --- a/src/plugins/data/public/search/es_client/types.ts +++ b/src/plugins/data/public/search/legacy/es_client/types.ts @@ -17,8 +17,7 @@ * under the License. */ -export type SearchRequest = any; -export type SearchResponse = any; +import { SearchRequest, SearchResponse } from '../../fetch'; export interface LegacyApiCaller { search: (searchRequest: SearchRequest) => LegacyApiCallerResponse; diff --git a/src/plugins/data/public/search/legacy/index.ts b/src/plugins/data/public/search/legacy/index.ts index 74e516f407e8c..e2ae72824f3f4 100644 --- a/src/plugins/data/public/search/legacy/index.ts +++ b/src/plugins/data/public/search/legacy/index.ts @@ -18,3 +18,4 @@ */ export { fetchSoon } from './fetch_soon'; +export { getEsClient, LegacyApiCaller } from './es_client'; diff --git a/src/plugins/data/public/search/search_service.ts b/src/plugins/data/public/search/search_service.ts index 6124682184821..a8e2feb1af31f 100644 --- a/src/plugins/data/public/search/search_service.ts +++ b/src/plugins/data/public/search/search_service.ts @@ -22,12 +22,12 @@ import { Plugin, CoreSetup, CoreStart, PackageInfo } from '../../../../core/publ import { SYNC_SEARCH_STRATEGY, syncSearchStrategyProvider } from './sync_search_strategy'; import { ISearchSetup, ISearchStart, TSearchStrategyProvider, TSearchStrategiesMap } from './types'; import { TStrategyTypes } from './strategy_types'; -import { getEsClient, LegacyApiCaller } from './es_client'; +import { getEsClient, LegacyApiCaller } from './legacy'; import { ES_SEARCH_STRATEGY, DEFAULT_SEARCH_STRATEGY } from '../../common/search'; -import { esSearchStrategyProvider } from './es_search/es_search_strategy'; +import { esSearchStrategyProvider } from './es_search'; import { IndexPatternsContract } from '../index_patterns/index_patterns'; import { createSearchSource } from './search_source'; -import { QuerySetup } from '../query/query_service'; +import { QuerySetup } from '../query'; import { GetInternalStartServicesFn } from '../types'; import { SearchInterceptor } from './search_interceptor'; import { diff --git a/src/plugins/data/public/search/types.ts b/src/plugins/data/public/search/types.ts index ba6e44f47b75e..2122e4e82ec1d 100644 --- a/src/plugins/data/public/search/types.ts +++ b/src/plugins/data/public/search/types.ts @@ -22,7 +22,7 @@ import { createSearchSource } from './search_source'; import { SearchAggsSetup, SearchAggsStart, SearchAggsStartLegacy } from './aggs'; import { ISearch, ISearchGeneric } from './i_search'; import { TStrategyTypes } from './strategy_types'; -import { LegacyApiCaller } from './es_client'; +import { LegacyApiCaller } from './legacy/es_client'; import { SearchInterceptor } from './search_interceptor'; export interface ISearchContext { @@ -38,15 +38,6 @@ export interface ISearchStrategy { search: ISearch; } -/** - * Search strategy provider creates an instance of a search strategy with the request - * handler context bound to it. This way every search strategy can use - * whatever information they require from the request context. - */ -export type TSearchStrategyProviderEnhanced = ( - search: ISearchGeneric -) => Promise>; - export type TSearchStrategiesMap = { [K in TStrategyTypes]?: TSearchStrategyProvider; }; From 2b8610dc8b9af53ad08e1456f3e99404fad8861d Mon Sep 17 00:00:00 2001 From: Liza K Date: Sun, 12 Apr 2020 14:52:41 +0300 Subject: [PATCH 08/14] Clean up some unused code (isViable, old search function) --- .../search/legacy/default_search_strategy.ts | 37 ++----------------- .../data/public/search/legacy/types.ts | 3 +- .../search/search_source/search_source.ts | 1 - 3 files changed, 4 insertions(+), 37 deletions(-) diff --git a/src/plugins/data/public/search/legacy/default_search_strategy.ts b/src/plugins/data/public/search/legacy/default_search_strategy.ts index 3758f7d3c736c..1552410f9090c 100644 --- a/src/plugins/data/public/search/legacy/default_search_strategy.ts +++ b/src/plugins/data/public/search/legacy/default_search_strategy.ts @@ -17,24 +17,19 @@ * under the License. */ -import { isDefault } from '../../index_patterns'; -import { getSearchParams, getPreference, getTimeout } from '../fetch'; +import { getPreference, getTimeout } from '../fetch'; import { getMSearchParams } from './get_msearch_params'; import { SearchStrategyProvider, SearchStrategySearchParams } from './types'; +// @deprecated export const defaultSearchStrategy: SearchStrategyProvider = { id: 'default', search: params => { - return params.config.get('courier:batchSearches') ? msearch(params) : search(params); - }, - - isViable: indexPattern => { - return indexPattern && isDefault(indexPattern); + return msearch(params); }, }; -// @deprecated function msearch({ searchRequests, searchService, @@ -66,29 +61,3 @@ function msearch({ abort: searching.abort, }; } - -function search({ - searchRequests, - searchService, - config, - esShardTimeout, -}: SearchStrategySearchParams) { - const abortController = new AbortController(); - const searchParams = getSearchParams(config, esShardTimeout); - const promises = searchRequests.map(({ index, indexType, body }) => { - const params = { - index: index.title || index, - body, - ...searchParams, - }; - const { signal } = abortController; - return searchService - .search({ params, indexType }, { signal }) - .toPromise() - .then(({ rawResponse }) => rawResponse); - }); - return { - searching: Promise.all(promises), - abort: () => abortController.abort(), - }; -} diff --git a/src/plugins/data/public/search/legacy/types.ts b/src/plugins/data/public/search/legacy/types.ts index bb22d05182690..3812cec7a2aa2 100644 --- a/src/plugins/data/public/search/legacy/types.ts +++ b/src/plugins/data/public/search/legacy/types.ts @@ -18,17 +18,16 @@ */ import { FetchHandlers } from '../fetch'; -import { IndexPattern } from '../../index_patterns'; import { SearchRequest, SearchResponse } from '..'; export interface SearchStrategySearchParams extends FetchHandlers { searchRequests: SearchRequest[]; } +// @deprecated export interface SearchStrategyProvider { id: string; search: (params: SearchStrategySearchParams) => SearchStrategyResponse; - isViable: (indexPattern: IndexPattern) => boolean; } export interface SearchStrategyResponse { diff --git a/src/plugins/data/public/search/search_source/search_source.ts b/src/plugins/data/public/search/search_source/search_source.ts index f4b3f8220edd8..7ba04ff9810f2 100644 --- a/src/plugins/data/public/search/search_source/search_source.ts +++ b/src/plugins/data/public/search/search_source/search_source.ts @@ -234,7 +234,6 @@ export class SearchSource { ); } else { const { searching, abort } = this.runSearch(searchRequest, esShardTimeout); - response = searching.then(result => handleResponse(searchRequest, result)); if (options.abortSignal) options.abortSignal.addEventListener('abort', abort); } From 3ffe1d6b79299d56873ff80d8fb605bf818d0bc2 Mon Sep 17 00:00:00 2001 From: Liza K Date: Sun, 12 Apr 2020 16:12:21 +0300 Subject: [PATCH 09/14] Updated tests --- .../aggs/test_helpers/mock_data_services.ts | 11 +++- .../legacy/default_search_strategy.test.ts | 20 ------- .../search_source/search_source.test.ts | 57 ++++++++++++++++++- 3 files changed, 63 insertions(+), 25 deletions(-) diff --git a/src/plugins/data/public/search/aggs/test_helpers/mock_data_services.ts b/src/plugins/data/public/search/aggs/test_helpers/mock_data_services.ts index d1d591771743c..e807e084c683a 100644 --- a/src/plugins/data/public/search/aggs/test_helpers/mock_data_services.ts +++ b/src/plugins/data/public/search/aggs/test_helpers/mock_data_services.ts @@ -18,8 +18,8 @@ */ // eslint-disable-next-line @kbn/eslint/no-restricted-paths -import { coreMock } from '../../../../../../../src/core/public/mocks'; -import { dataPluginMock } from '../../../../public/mocks'; +import { coreMock } from '../../../../../../core/public/mocks'; +import { dataPluginMock } from '../../../mocks'; import { setFieldFormats, setIndexPatterns, @@ -29,7 +29,7 @@ import { setQueryService, setSearchService, setUiSettings, -} from '../../../../public/services'; +} from '../../../services'; /** * Testing helper which calls all of the service setters used in the @@ -49,4 +49,9 @@ export function mockDataServices() { setQueryService(data.query); setSearchService(data.search); setUiSettings(core.uiSettings); + + return { + core, + data, + }; } diff --git a/src/plugins/data/public/search/legacy/default_search_strategy.test.ts b/src/plugins/data/public/search/legacy/default_search_strategy.test.ts index 4eaff0b500281..835b02b3cd5c7 100644 --- a/src/plugins/data/public/search/legacy/default_search_strategy.test.ts +++ b/src/plugins/data/public/search/legacy/default_search_strategy.test.ts @@ -38,12 +38,6 @@ const searchMockResponse: any = Promise.resolve([]); searchMockResponse.abort = jest.fn(); const searchMock = jest.fn().mockReturnValue(searchMockResponse); -const newSearchMockResponse: any = Promise.resolve([]); -newSearchMockResponse.abort = jest.fn(); -const newSearchMock = jest.fn().mockReturnValue({ - toPromise: () => searchMockResponse, -}); - describe('defaultSearchStrategy', function() { describe('search', function() { let searchArgs: MockedKeys>; @@ -58,7 +52,6 @@ describe('defaultSearchStrategy', function() { const searchService = searchStartMock; searchService.aggs.calculateAutoTimeExpression = jest.fn().mockReturnValue('1d'); - searchService.search = newSearchMock; searchService.__LEGACY.esClient.search = searchMock; searchService.__LEGACY.esClient.msearch = msearchMock; @@ -112,18 +105,5 @@ describe('defaultSearchStrategy', function() { search({ ...searchArgs, config }).abort(); expect(msearchMockResponse.abort).toHaveBeenCalled(); }); - - test('should call new search service', () => { - const config = getConfigStub(); - search({ ...searchArgs, config }); - expect(newSearchMock).toHaveBeenCalledTimes(1); - }); - - test('should properly abort with new search service', async () => { - const abortSpy = jest.spyOn(AbortController.prototype, 'abort'); - const config = getConfigStub({}); - search({ ...searchArgs, config }).abort(); - expect(abortSpy).toHaveBeenCalled(); - }); }); }); diff --git a/src/plugins/data/public/search/search_source/search_source.test.ts b/src/plugins/data/public/search/search_source/search_source.test.ts index 6bad093d31402..fbbc2bbce2b42 100644 --- a/src/plugins/data/public/search/search_source/search_source.test.ts +++ b/src/plugins/data/public/search/search_source/search_source.test.ts @@ -20,8 +20,28 @@ import { SearchSource } from './search_source'; import { IndexPattern, SortDirection } from '../..'; import { mockDataServices } from '../aggs/test_helpers'; +import { setSearchService } from '../../services'; +import { searchStartMock } from '../mocks'; +import { fetchSoon } from '../legacy'; +import { CoreStart } from 'kibana/public'; -jest.mock('../fetch', () => ({ +// Setup search service mock +searchStartMock.search = jest.fn(() => { + return { + toPromise: () => { + return new Promise(resolve => { + setTimeout(() => { + resolve({ + rawResponse: '', + }); + }, 100); + }); + }, + }; +}) as any; +setSearchService(searchStartMock); + +jest.mock('../legacy', () => ({ fetchSoon: jest.fn().mockResolvedValue({}), })); @@ -44,8 +64,11 @@ const indexPattern2 = ({ } as unknown) as IndexPattern; describe('SearchSource', function() { + let uiSettingsMock: jest.Mocked; beforeEach(() => { - mockDataServices(); + const { core } = mockDataServices(); + uiSettingsMock = core.uiSettings; + jest.clearAllMocks(); }); describe('#setField()', function() { @@ -151,6 +174,36 @@ describe('SearchSource', function() { }); }); + describe('#legacy fetch()', () => { + beforeEach(() => { + uiSettingsMock.get.mockImplementation(() => { + return true; // batchSearches = true + }); + }); + + afterEach(() => { + uiSettingsMock.get.mockImplementation(() => { + return false; // batchSearches = false + }); + }); + + it('should call msearch', async () => { + const searchSource = new SearchSource({ index: indexPattern }); + const options = {}; + await searchSource.fetch(options); + expect(fetchSoon).toBeCalledTimes(1); + }); + }); + + describe('#search service fetch()', () => { + it('should call msearch', async () => { + const searchSource = new SearchSource({ index: indexPattern }); + const options = {}; + await searchSource.fetch(options); + expect(searchStartMock.search).toBeCalledTimes(1); + }); + }); + describe('#serialize', function() { it('should reference index patterns', () => { const indexPattern123 = { id: '123' } as IndexPattern; From e3f9d10e932ddfcc0073d3cf97df9ebbea108964 Mon Sep 17 00:00:00 2001 From: Liza K Date: Sun, 12 Apr 2020 17:51:17 +0300 Subject: [PATCH 10/14] strings update --- x-pack/plugins/translations/translations/ja-JP.json | 8 +++----- x-pack/plugins/translations/translations/zh-CN.json | 8 +++----- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/x-pack/plugins/translations/translations/ja-JP.json b/x-pack/plugins/translations/translations/ja-JP.json index fe0c58e83e544..a555e4979708e 100644 --- a/x-pack/plugins/translations/translations/ja-JP.json +++ b/x-pack/plugins/translations/translations/ja-JP.json @@ -851,8 +851,6 @@ "data.search.searchSource.indexPatternIdDescription": "{kibanaIndexPattern} インデックス内の ID です。", "data.search.searchSource.indexPatternIdLabel": "インデックスパターン ID", "data.search.searchSource.indexPatternLabel": "インデックスパターン", - "data.search.searchSource.noSearchStrategyRegisteredErrorMessageDescription": "検索リクエストの検索方法が見つかりませんでした", - "data.search.searchSource.noSearchStrategyRegisteredErrorMessageTitle": "検索方法が登録されていません", "data.search.searchSource.queryTimeDescription": "クエリの処理の所要時間です。リクエストの送信やブラウザでのパースの時間は含まれません。", "data.search.searchSource.queryTimeLabel": "クエリ時間", "data.search.searchSource.queryTimeValue": "{queryTime}ms", @@ -2511,13 +2509,13 @@ "management.breadcrumb": "管理", "management.connectDataDisplayName": "データに接続", "management.displayName": "管理", + "management.nav.label": "管理", + "management.nav.menu": "管理メニュー", + "management.stackManagement.managementDescription": "Elastic Stack の管理を行うセンターコンソールです。", "indexPatternManagement.editIndexPattern.createIndex.defaultButtonDescription": "すべてのデータに完全集約を実行", "indexPatternManagement.editIndexPattern.createIndex.defaultButtonText": "標準インデックスパターン", "indexPatternManagement.editIndexPattern.createIndex.defaultTypeName": "インデックスパターン", "indexPatternManagement.editIndexPattern.list.defaultIndexPatternListName": "デフォルト", - "management.nav.label": "管理", - "management.nav.menu": "管理メニュー", - "management.stackManagement.managementDescription": "Elastic Stack の管理を行うセンターコンソールです。", "newsfeed.emptyPrompt.noNewsText": "Kibanaインスタンスがインターネットにアクセスできない場合、管理者にこの機能を無効にするように依頼してください。そうでない場合は、ニュースを取り込み続けます。", "newsfeed.emptyPrompt.noNewsTitle": "ニュースがない場合", "newsfeed.flyoutList.closeButtonLabel": "閉じる", diff --git a/x-pack/plugins/translations/translations/zh-CN.json b/x-pack/plugins/translations/translations/zh-CN.json index fd2a92c2c402f..7fd1fab08603c 100644 --- a/x-pack/plugins/translations/translations/zh-CN.json +++ b/x-pack/plugins/translations/translations/zh-CN.json @@ -852,8 +852,6 @@ "data.search.searchSource.indexPatternIdDescription": "{kibanaIndexPattern} 索引中的 ID。", "data.search.searchSource.indexPatternIdLabel": "索引模式 ID", "data.search.searchSource.indexPatternLabel": "索引模式", - "data.search.searchSource.noSearchStrategyRegisteredErrorMessageDescription": "无法为该搜索请求找到搜索策略", - "data.search.searchSource.noSearchStrategyRegisteredErrorMessageTitle": "未注册任何搜索策略", "data.search.searchSource.queryTimeDescription": "处理查询所花费的时间。不包括发送请求或在浏览器中解析它的时间。", "data.search.searchSource.queryTimeLabel": "查询时间", "data.search.searchSource.queryTimeValue": "{queryTime}ms", @@ -2512,13 +2510,13 @@ "management.breadcrumb": "管理", "management.connectDataDisplayName": "连接数据", "management.displayName": "管理", + "management.nav.label": "管理", + "management.nav.menu": "管理菜单", + "management.stackManagement.managementDescription": "您用于管理 Elastic Stack 的中心控制台。", "indexPatternManagement.editIndexPattern.createIndex.defaultButtonDescription": "对任何数据执行完全聚合", "indexPatternManagement.editIndexPattern.createIndex.defaultButtonText": "标准索引模式", "indexPatternManagement.editIndexPattern.createIndex.defaultTypeName": "索引模式", "indexPatternManagement.editIndexPattern.list.defaultIndexPatternListName": "默认值", - "management.nav.label": "管理", - "management.nav.menu": "管理菜单", - "management.stackManagement.managementDescription": "您用于管理 Elastic Stack 的中心控制台。", "newsfeed.emptyPrompt.noNewsText": "如果您的 Kibana 实例没有 Internet 连接,请让您的管理员禁用此功能。否则,我们将不断尝试获取新闻。", "newsfeed.emptyPrompt.noNewsTitle": "无新闻?", "newsfeed.flyoutList.closeButtonLabel": "鍏抽棴", From 2a1d42a858db2b05f55ba4b249584a88504c1d73 Mon Sep 17 00:00:00 2001 From: Liza K Date: Mon, 13 Apr 2020 11:08:17 +0300 Subject: [PATCH 11/14] Fix jest test --- src/plugins/data/public/search/legacy/call_client.test.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/plugins/data/public/search/legacy/call_client.test.ts b/src/plugins/data/public/search/legacy/call_client.test.ts index 0d57559fdc32d..f919187d46784 100644 --- a/src/plugins/data/public/search/legacy/call_client.test.ts +++ b/src/plugins/data/public/search/legacy/call_client.test.ts @@ -20,14 +20,15 @@ import { callClient } from './call_client'; import { SearchStrategySearchParams } from './types'; import { defaultSearchStrategy } from './default_search_strategy'; -import { handleResponse, FetchHandlers } from '../fetch'; +import { FetchHandlers } from '../fetch'; +import { handleResponse } from '../fetch/handle_response'; const mockAbortFn = jest.fn(); -jest.mock('./handle_response', () => ({ +jest.mock('../fetch/handle_response', () => ({ handleResponse: jest.fn((request, response) => response), })); -jest.mock('../search_strategy', () => { +jest.mock('./default_search_strategy', () => { return { defaultSearchStrategy: { search: jest.fn(({ searchRequests }: SearchStrategySearchParams) => { From 30a87a6c39d1adced727f89b7b9da69cb4178f16 Mon Sep 17 00:00:00 2001 From: Liza K Date: Mon, 13 Apr 2020 11:32:07 +0300 Subject: [PATCH 12/14] re-arrange runSearch function --- .../search/search_source/search_source.ts | 28 +++++++++++-------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/src/plugins/data/public/search/search_source/search_source.ts b/src/plugins/data/public/search/search_source/search_source.ts index 7ba04ff9810f2..032efa67ba303 100644 --- a/src/plugins/data/public/search/search_source/search_source.ts +++ b/src/plugins/data/public/search/search_source/search_source.ts @@ -185,24 +185,32 @@ export class SearchSource { return this.parent; } - private runSearch(searchRequest: SearchRequest, esShardTimeout: number) { - const searchParams = getSearchParams(getUiSettings(), esShardTimeout); + /** + * Run a search using the search service + * @return {Promise>} + */ + private runSearch( + searchRequest: SearchRequest, + esShardTimeout: number, + abortSignal?: AbortSignal + ) { const abortController = new AbortController(); + const { signal } = abortController; + const searchParams = getSearchParams(getUiSettings(), esShardTimeout); const params = { index: searchRequest.index.title || searchRequest.index, body: searchRequest.body, ...searchParams, }; - const { signal } = abortController; - const promise = getSearchService() + const searching = getSearchService() .search({ params, indexType: searchRequest.indexType }, { signal }) .toPromise() .then(({ rawResponse }) => rawResponse); - return { - searching: promise, - abort: () => abortController.abort(), - }; + const response = searching.then(result => handleResponse(searchRequest, result)); + if (abortSignal) abortSignal.addEventListener('abort', () => abortController.abort()); + + return response; } /** @@ -233,9 +241,7 @@ export class SearchSource { } ); } else { - const { searching, abort } = this.runSearch(searchRequest, esShardTimeout); - response = searching.then(result => handleResponse(searchRequest, result)); - if (options.abortSignal) options.abortSignal.addEventListener('abort', abort); + response = this.runSearch(searchRequest, esShardTimeout, options.abortSignal); } if (response.error) { From 92a7f999c957116c6e21dd8927cf306c2b3e842a Mon Sep 17 00:00:00 2001 From: Liza K Date: Thu, 16 Apr 2020 14:59:28 +0300 Subject: [PATCH 13/14] re-arrange runSearch function --- .../search/search_source/search_source.ts | 60 +++++++++---------- 1 file changed, 28 insertions(+), 32 deletions(-) diff --git a/src/plugins/data/public/search/search_source/search_source.ts b/src/plugins/data/public/search/search_source/search_source.ts index 032efa67ba303..9d2bb889953cf 100644 --- a/src/plugins/data/public/search/search_source/search_source.ts +++ b/src/plugins/data/public/search/search_source/search_source.ts @@ -70,6 +70,7 @@ */ import _ from 'lodash'; +import { map } from 'rxjs/operators'; import { SavedObjectReference } from 'kibana/public'; import { normalizeSortRequest } from './normalize_sort_request'; import { filterDocvalueFields } from './filter_docvalue_fields'; @@ -187,32 +188,40 @@ export class SearchSource { /** * Run a search using the search service - * @return {Promise>} + * @return {Observable>} */ - private runSearch( - searchRequest: SearchRequest, - esShardTimeout: number, - abortSignal?: AbortSignal - ) { - const abortController = new AbortController(); - const { signal } = abortController; + private fetch$(searchRequest: SearchRequest, signal?: AbortSignal) { + const esShardTimeout = getInjectedMetadata().getInjectedVar('esShardTimeout') as number; const searchParams = getSearchParams(getUiSettings(), esShardTimeout); const params = { index: searchRequest.index.title || searchRequest.index, body: searchRequest.body, ...searchParams, }; - const searching = getSearchService() + return getSearchService() .search({ params, indexType: searchRequest.indexType }, { signal }) - .toPromise() - .then(({ rawResponse }) => rawResponse); - - const response = searching.then(result => handleResponse(searchRequest, result)); - if (abortSignal) abortSignal.addEventListener('abort', () => abortController.abort()); - - return response; + .pipe(map(({ rawResponse }) => handleResponse(searchRequest, rawResponse))); } + /** + * Run a search using the search service + * @return {Promise>} + */ + private async legacyFetch(searchRequest: SearchRequest, options: FetchOptions) { + const esShardTimeout = getInjectedMetadata().getInjectedVar('esShardTimeout') as number; + return await fetchSoon( + searchRequest, + { + ...(this.searchStrategyId && { searchStrategyId: this.searchStrategyId }), + ...options, + }, + { + searchService: getSearchService(), + config: getUiSettings(), + esShardTimeout, + } + ); + } /** * Fetch this source and reject the returned Promise on error * @@ -224,24 +233,11 @@ export class SearchSource { const searchRequest = await this.flatten(); this.history = [searchRequest]; - const esShardTimeout = getInjectedMetadata().getInjectedVar('esShardTimeout') as number; - const legacySearch = getUiSettings().get('courier:batchSearches'); let response; - if (legacySearch) { - response = await fetchSoon( - searchRequest, - { - ...(this.searchStrategyId && { searchStrategyId: this.searchStrategyId }), - ...options, - }, - { - searchService: getSearchService(), - config: getUiSettings(), - esShardTimeout, - } - ); + if (getUiSettings().get('courier:batchSearches')) { + response = await this.legacyFetch(searchRequest, options); } else { - response = this.runSearch(searchRequest, esShardTimeout, options.abortSignal); + response = this.fetch$(searchRequest, options.abortSignal).toPromise(); } if (response.error) { From 584f7c685b5e902f6757bd87b501df577650cc0b Mon Sep 17 00:00:00 2001 From: Liza K Date: Thu, 16 Apr 2020 18:23:09 +0300 Subject: [PATCH 14/14] fix jest tests --- .../search/search_source/search_source.test.ts | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/plugins/data/public/search/search_source/search_source.test.ts b/src/plugins/data/public/search/search_source/search_source.test.ts index fbbc2bbce2b42..6e878844664ad 100644 --- a/src/plugins/data/public/search/search_source/search_source.test.ts +++ b/src/plugins/data/public/search/search_source/search_source.test.ts @@ -24,20 +24,18 @@ import { setSearchService } from '../../services'; import { searchStartMock } from '../mocks'; import { fetchSoon } from '../legacy'; import { CoreStart } from 'kibana/public'; +import { Observable } from 'rxjs'; // Setup search service mock searchStartMock.search = jest.fn(() => { - return { - toPromise: () => { - return new Promise(resolve => { - setTimeout(() => { - resolve({ - rawResponse: '', - }); - }, 100); + return new Observable(subscriber => { + setTimeout(() => { + subscriber.next({ + rawResponse: '', }); - }, - }; + subscriber.complete(); + }, 100); + }); }) as any; setSearchService(searchStartMock);