From b5f724d83fe04cab05885865fb68a34076190a29 Mon Sep 17 00:00:00 2001 From: Lukas Olson Date: Fri, 5 Jun 2020 14:23:32 -0700 Subject: [PATCH 01/21] [search] Refactor the way search strategies are registered/retrieved on the server --- src/plugins/data/server/plugin.ts | 2 +- .../data/server/search/search_service.ts | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/plugins/data/server/plugin.ts b/src/plugins/data/server/plugin.ts index bcf1f4f8ab60b..c7bcd0c148858 100644 --- a/src/plugins/data/server/plugin.ts +++ b/src/plugins/data/server/plugin.ts @@ -91,11 +91,11 @@ export class DataServerPlugin implements Plugin { @@ -35,7 +36,13 @@ export class SearchService implements Plugin { constructor(private initializerContext: PluginInitializerContext) {} public setup(core: CoreSetup): ISearchSetup { - this.registerSearchStrategy( + core.savedObjects.registerType(searchSavedObjectType); + + const registerSearchStrategy: TRegisterSearchStrategy = async (name, strategy) => { + this.searchStrategies[name] = await strategy; + }; + + registerSearchStrategy( ES_SEARCH_STRATEGY, esSearchStrategyProvider(this.initializerContext.config.legacy.globalConfig$) ); @@ -49,6 +56,16 @@ export class SearchService implements Plugin { return { getSearchStrategy: this.getSearchStrategy }; } + public start(): ISearchStart { + const getSearchStrategy: TGetSearchStrategy = (name) => { + if (!this.searchStrategies.hasOwnProperty(name)) { + throw new Error('No strategy registered for `${name}`.'); + } + return this.searchStrategies[name]; + }; + + return { getSearchStrategy }; + } public stop() {} private registerSearchStrategy: TRegisterSearchStrategy = (name, strategy) => { From e01bc6a3d746021f80be17a508c77fb137c78f6d Mon Sep 17 00:00:00 2001 From: Lukas Olson Date: Mon, 8 Jun 2020 17:06:10 -0700 Subject: [PATCH 02/21] Fix types and tests and update docs --- .../data/server/search/search_service.test.ts | 5 ++ .../data/server/search/search_service.ts | 16 +------ src/plugins/data/server/server.api.md | 48 +++++++++---------- .../kbn_tp_run_pipeline/public/index.ts | 10 +--- 4 files changed, 32 insertions(+), 47 deletions(-) diff --git a/src/plugins/data/server/search/search_service.test.ts b/src/plugins/data/server/search/search_service.test.ts index 25143fa09e6bf..c455fba4eaa2c 100644 --- a/src/plugins/data/server/search/search_service.test.ts +++ b/src/plugins/data/server/search/search_service.test.ts @@ -23,6 +23,11 @@ import { SearchService } from './search_service'; import { CoreSetup } from '../../../../core/server'; import { DataPluginStart } from '../plugin'; +const mockSearchApi = { search: jest.fn() }; +jest.mock('./create_api', () => ({ + createApi: () => mockSearchApi, +})); + describe('Search service', () => { let plugin: SearchService; let mockCoreSetup: MockedKeys>; diff --git a/src/plugins/data/server/search/search_service.ts b/src/plugins/data/server/search/search_service.ts index d503247cce0ca..df809b425eb9e 100644 --- a/src/plugins/data/server/search/search_service.ts +++ b/src/plugins/data/server/search/search_service.ts @@ -38,11 +38,7 @@ export class SearchService implements Plugin { public setup(core: CoreSetup): ISearchSetup { core.savedObjects.registerType(searchSavedObjectType); - const registerSearchStrategy: TRegisterSearchStrategy = async (name, strategy) => { - this.searchStrategies[name] = await strategy; - }; - - registerSearchStrategy( + this.registerSearchStrategy( ES_SEARCH_STRATEGY, esSearchStrategyProvider(this.initializerContext.config.legacy.globalConfig$) ); @@ -56,16 +52,6 @@ export class SearchService implements Plugin { return { getSearchStrategy: this.getSearchStrategy }; } - public start(): ISearchStart { - const getSearchStrategy: TGetSearchStrategy = (name) => { - if (!this.searchStrategies.hasOwnProperty(name)) { - throw new Error('No strategy registered for `${name}`.'); - } - return this.searchStrategies[name]; - }; - - return { getSearchStrategy }; - } public stop() {} private registerSearchStrategy: TRegisterSearchStrategy = (name, strategy) => { diff --git a/src/plugins/data/server/server.api.md b/src/plugins/data/server/server.api.md index f029609cbf7ec..c0a907ed92ec3 100644 --- a/src/plugins/data/server/server.api.md +++ b/src/plugins/data/server/server.api.md @@ -802,30 +802,30 @@ export const UI_SETTINGS: { // src/plugins/data/server/index.ts:40:23 - (ae-forgotten-export) The symbol "buildFilter" needs to be exported by the entry point index.d.ts // src/plugins/data/server/index.ts:71:21 - (ae-forgotten-export) The symbol "getEsQueryConfig" needs to be exported by the entry point index.d.ts // src/plugins/data/server/index.ts:71:21 - (ae-forgotten-export) The symbol "buildEsQuery" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/index.ts:102:26 - (ae-forgotten-export) The symbol "FieldFormatsRegistry" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/index.ts:102:26 - (ae-forgotten-export) The symbol "FieldFormat" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/index.ts:102:26 - (ae-forgotten-export) The symbol "BoolFormat" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/index.ts:102:26 - (ae-forgotten-export) The symbol "BytesFormat" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/index.ts:102:26 - (ae-forgotten-export) The symbol "ColorFormat" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/index.ts:102:26 - (ae-forgotten-export) The symbol "DateNanosFormat" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/index.ts:102:26 - (ae-forgotten-export) The symbol "DurationFormat" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/index.ts:102:26 - (ae-forgotten-export) The symbol "IpFormat" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/index.ts:102:26 - (ae-forgotten-export) The symbol "NumberFormat" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/index.ts:102:26 - (ae-forgotten-export) The symbol "PercentFormat" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/index.ts:102:26 - (ae-forgotten-export) The symbol "RelativeDateFormat" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/index.ts:102:26 - (ae-forgotten-export) The symbol "SourceFormat" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/index.ts:102:26 - (ae-forgotten-export) The symbol "StaticLookupFormat" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/index.ts:102:26 - (ae-forgotten-export) The symbol "UrlFormat" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/index.ts:102:26 - (ae-forgotten-export) The symbol "StringFormat" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/index.ts:102:26 - (ae-forgotten-export) The symbol "TruncateFormat" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/index.ts:129:27 - (ae-forgotten-export) The symbol "isFilterable" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/index.ts:129:27 - (ae-forgotten-export) The symbol "isNestedField" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/index.ts:184:1 - (ae-forgotten-export) The symbol "dateHistogramInterval" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/index.ts:185:1 - (ae-forgotten-export) The symbol "InvalidEsCalendarIntervalError" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/index.ts:186:1 - (ae-forgotten-export) The symbol "InvalidEsIntervalFormatError" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/index.ts:187:1 - (ae-forgotten-export) The symbol "isValidEsInterval" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/index.ts:188:1 - (ae-forgotten-export) The symbol "isValidInterval" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/index.ts:191:1 - (ae-forgotten-export) The symbol "toAbsoluteDates" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index.ts:103:26 - (ae-forgotten-export) The symbol "FieldFormatsRegistry" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index.ts:103:26 - (ae-forgotten-export) The symbol "FieldFormat" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index.ts:103:26 - (ae-forgotten-export) The symbol "BoolFormat" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index.ts:103:26 - (ae-forgotten-export) The symbol "BytesFormat" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index.ts:103:26 - (ae-forgotten-export) The symbol "ColorFormat" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index.ts:103:26 - (ae-forgotten-export) The symbol "DateNanosFormat" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index.ts:103:26 - (ae-forgotten-export) The symbol "DurationFormat" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index.ts:103:26 - (ae-forgotten-export) The symbol "IpFormat" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index.ts:103:26 - (ae-forgotten-export) The symbol "NumberFormat" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index.ts:103:26 - (ae-forgotten-export) The symbol "PercentFormat" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index.ts:103:26 - (ae-forgotten-export) The symbol "RelativeDateFormat" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index.ts:103:26 - (ae-forgotten-export) The symbol "SourceFormat" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index.ts:103:26 - (ae-forgotten-export) The symbol "StaticLookupFormat" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index.ts:103:26 - (ae-forgotten-export) The symbol "UrlFormat" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index.ts:103:26 - (ae-forgotten-export) The symbol "StringFormat" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index.ts:103:26 - (ae-forgotten-export) The symbol "TruncateFormat" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index.ts:131:27 - (ae-forgotten-export) The symbol "isFilterable" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index.ts:131:27 - (ae-forgotten-export) The symbol "isNestedField" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index.ts:186:1 - (ae-forgotten-export) The symbol "dateHistogramInterval" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index.ts:187:1 - (ae-forgotten-export) The symbol "InvalidEsCalendarIntervalError" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index.ts:188:1 - (ae-forgotten-export) The symbol "InvalidEsIntervalFormatError" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index.ts:189:1 - (ae-forgotten-export) The symbol "isValidEsInterval" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index.ts:190:1 - (ae-forgotten-export) The symbol "isValidInterval" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index.ts:193:1 - (ae-forgotten-export) The symbol "toAbsoluteDates" needs to be exported by the entry point index.d.ts // (No @packageDocumentation comment for this package) diff --git a/test/interpreter_functional/plugins/kbn_tp_run_pipeline/public/index.ts b/test/interpreter_functional/plugins/kbn_tp_run_pipeline/public/index.ts index d7a764b581c01..368575b705c90 100644 --- a/test/interpreter_functional/plugins/kbn_tp_run_pipeline/public/index.ts +++ b/test/interpreter_functional/plugins/kbn_tp_run_pipeline/public/index.ts @@ -17,12 +17,6 @@ * under the License. */ -import { PluginInitializer, PluginInitializerContext } from 'src/core/public'; -import { Plugin, StartDeps } from './plugin'; -export { StartDeps }; +import { DemoDataPlugin } from './plugin'; -export const plugin: PluginInitializer = ( - initializerContext: PluginInitializerContext -) => { - return new Plugin(initializerContext); -}; +export const plugin = () => new DemoDataPlugin(); From 9f471cba0c1064bbaccfd15eaa5909f6111f08e9 Mon Sep 17 00:00:00 2001 From: Lukas Olson Date: Tue, 9 Jun 2020 15:56:44 -0700 Subject: [PATCH 03/21] Fix failing test --- src/plugins/data/server/search/search_service.test.ts | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/plugins/data/server/search/search_service.test.ts b/src/plugins/data/server/search/search_service.test.ts index c455fba4eaa2c..25143fa09e6bf 100644 --- a/src/plugins/data/server/search/search_service.test.ts +++ b/src/plugins/data/server/search/search_service.test.ts @@ -23,11 +23,6 @@ import { SearchService } from './search_service'; import { CoreSetup } from '../../../../core/server'; import { DataPluginStart } from '../plugin'; -const mockSearchApi = { search: jest.fn() }; -jest.mock('./create_api', () => ({ - createApi: () => mockSearchApi, -})); - describe('Search service', () => { let plugin: SearchService; let mockCoreSetup: MockedKeys>; From ad2fe4764a3ed482bdc0467af07887095394bf28 Mon Sep 17 00:00:00 2001 From: Liza K Date: Tue, 16 Jun 2020 23:25:47 +0300 Subject: [PATCH 04/21] Move strategy name into options --- src/plugins/data/public/search/search_interceptor.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/plugins/data/public/search/search_interceptor.ts b/src/plugins/data/public/search/search_interceptor.ts index 8edbfd94deb38..f077d2ced79b7 100644 --- a/src/plugins/data/public/search/search_interceptor.ts +++ b/src/plugins/data/public/search/search_interceptor.ts @@ -24,6 +24,7 @@ import { getCombinedSignal, AbortError } from '../../common/utils'; import { IEsSearchRequest, IEsSearchResponse } from '../../common/search'; import { ISearchOptions } from './types'; import { getLongQueryNotification } from './long_query_notification'; +import { TStrategyTypes } from './strategy_types'; const LONG_QUERY_NOTIFICATION_DELAY = 10000; From a032ed5a1a525710ac27fae83e5b16e49c8a66b3 Mon Sep 17 00:00:00 2001 From: Liza K Date: Thu, 18 Jun 2020 21:39:55 +0300 Subject: [PATCH 05/21] Remove FE strategies --- src/plugins/data/public/search/search_interceptor.ts | 1 - src/plugins/data/public/search/search_service.ts | 3 +++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/plugins/data/public/search/search_interceptor.ts b/src/plugins/data/public/search/search_interceptor.ts index f077d2ced79b7..8edbfd94deb38 100644 --- a/src/plugins/data/public/search/search_interceptor.ts +++ b/src/plugins/data/public/search/search_interceptor.ts @@ -24,7 +24,6 @@ import { getCombinedSignal, AbortError } from '../../common/utils'; import { IEsSearchRequest, IEsSearchResponse } from '../../common/search'; import { ISearchOptions } from './types'; import { getLongQueryNotification } from './long_query_notification'; -import { TStrategyTypes } from './strategy_types'; const LONG_QUERY_NOTIFICATION_DELAY = 10000; diff --git a/src/plugins/data/public/search/search_service.ts b/src/plugins/data/public/search/search_service.ts index a27eba21714bb..f10e8635035fb 100644 --- a/src/plugins/data/public/search/search_service.ts +++ b/src/plugins/data/public/search/search_service.ts @@ -36,6 +36,9 @@ import { AggConfigs, getCalculateAutoTimeExpression, } from './aggs'; +import { + z + } from '../field_formats'; import { ISearchGeneric } from './types'; interface SearchServiceSetupDependencies { From 92b35b389dedc3c7926492d29582077482d5e534 Mon Sep 17 00:00:00 2001 From: Liza K Date: Sun, 28 Jun 2020 23:57:45 +0300 Subject: [PATCH 06/21] TypeScript of hell delete search explorer --- src/plugins/data/public/search/search_service.ts | 2 +- .../plugins/data_enhanced/public/search/search_interceptor.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/plugins/data/public/search/search_service.ts b/src/plugins/data/public/search/search_service.ts index f10e8635035fb..21ebcfe95e0d5 100644 --- a/src/plugins/data/public/search/search_service.ts +++ b/src/plugins/data/public/search/search_service.ts @@ -136,7 +136,7 @@ export class SearchService implements Plugin { }, types: aggTypesStart, }, - search, + search: this.searchInterceptor.search, searchSource: { create: createSearchSource(dependencies.indexPatterns, searchSourceDependencies), createEmpty: () => { diff --git a/x-pack/plugins/data_enhanced/public/search/search_interceptor.ts b/x-pack/plugins/data_enhanced/public/search/search_interceptor.ts index c0e2a6bd113eb..3cfd49fa91661 100644 --- a/x-pack/plugins/data_enhanced/public/search/search_interceptor.ts +++ b/x-pack/plugins/data_enhanced/public/search/search_interceptor.ts @@ -85,7 +85,7 @@ export class EnhancedSearchInterceptor extends SearchInterceptor { } // If the response indicates it is complete, stop polling and complete the observable - if (!response.is_running) return EMPTY; + if (!isRunning) return EMPTY; id = response.id; // Delay by the given poll interval From 718b0294bd7a0c498f4f805da8b5e34e5bef27a3 Mon Sep 17 00:00:00 2001 From: Liza K Date: Mon, 29 Jun 2020 18:08:59 +0300 Subject: [PATCH 07/21] Fix search interceptor OSS tests --- src/plugins/data/public/search/search_interceptor.test.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/plugins/data/public/search/search_interceptor.test.ts b/src/plugins/data/public/search/search_interceptor.test.ts index f4c5de2bcaf31..87cc8f221bec7 100644 --- a/src/plugins/data/public/search/search_interceptor.test.ts +++ b/src/plugins/data/public/search/search_interceptor.test.ts @@ -134,12 +134,15 @@ describe('SearchInterceptor', () => { const response = searchInterceptor.search(mockRequest, { signal: abort.signal }); abort.abort(); + const next = jest.fn(); const error = (e: any) => { + expect(next).not.toBeCalled(); expect(e).toBeInstanceOf(AbortError); expect(mockCoreStart.http.fetch).not.toBeCalled(); done(); }; - response.subscribe({ error }); + response.subscribe({ next, error }); + setTimeout(() => abortController.abort(), 200); }); }); From 5b3c73f6f447606e9dabfef5f7887b0d6d64611d Mon Sep 17 00:00:00 2001 From: Liza K Date: Tue, 30 Jun 2020 19:20:22 +0300 Subject: [PATCH 08/21] test cleanup --- .../plugins/data_enhanced/public/search/search_interceptor.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/plugins/data_enhanced/public/search/search_interceptor.ts b/x-pack/plugins/data_enhanced/public/search/search_interceptor.ts index 3cfd49fa91661..c0e2a6bd113eb 100644 --- a/x-pack/plugins/data_enhanced/public/search/search_interceptor.ts +++ b/x-pack/plugins/data_enhanced/public/search/search_interceptor.ts @@ -85,7 +85,7 @@ export class EnhancedSearchInterceptor extends SearchInterceptor { } // If the response indicates it is complete, stop polling and complete the observable - if (!isRunning) return EMPTY; + if (!response.is_running) return EMPTY; id = response.id; // Delay by the given poll interval From 3883eddf1b52993e43bfc2f64364b32590c85f41 Mon Sep 17 00:00:00 2001 From: Liza K Date: Tue, 30 Jun 2020 22:21:36 +0300 Subject: [PATCH 09/21] fix --- src/plugins/data/public/search/search_service.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/plugins/data/public/search/search_service.ts b/src/plugins/data/public/search/search_service.ts index 21ebcfe95e0d5..741397ca32b90 100644 --- a/src/plugins/data/public/search/search_service.ts +++ b/src/plugins/data/public/search/search_service.ts @@ -25,7 +25,6 @@ import { createSearchSource, SearchSource, SearchSourceDependencies } from './se import { getEsClient, LegacyApiCaller } from './legacy'; import { getForceNow } from '../query/timefilter/lib/get_force_now'; import { calculateBounds, TimeRange } from '../../common/query'; - import { IndexPatternsContract } from '../index_patterns/index_patterns'; import { GetInternalStartServicesFn } from '../types'; import { SearchInterceptor } from './search_interceptor'; From 284da6eee69944fc808c80e78e669fa78d74eab0 Mon Sep 17 00:00:00 2001 From: Liza K Date: Tue, 30 Jun 2020 23:04:11 +0300 Subject: [PATCH 10/21] return search wrapper --- src/plugins/data/public/search/search_service.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/data/public/search/search_service.ts b/src/plugins/data/public/search/search_service.ts index 741397ca32b90..0f5755eba5968 100644 --- a/src/plugins/data/public/search/search_service.ts +++ b/src/plugins/data/public/search/search_service.ts @@ -135,7 +135,7 @@ export class SearchService implements Plugin { }, types: aggTypesStart, }, - search: this.searchInterceptor.search, + search, searchSource: { create: createSearchSource(dependencies.indexPatterns, searchSourceDependencies), createEmpty: () => { From 4dde888d5cad5a7ca25596173d1843f0cbeb3160 Mon Sep 17 00:00:00 2001 From: Liza K Date: Wed, 1 Jul 2020 15:39:23 +0300 Subject: [PATCH 11/21] initial api --- .../search/es_search/es_search_strategy.ts | 4 +-- src/plugins/data/server/search/routes.ts | 6 ++-- .../data/server/search/search_service.ts | 31 +++++++++++++++---- src/plugins/data/server/search/types.ts | 5 +++ .../server/search/es_search_strategy.ts | 10 ++++-- 5 files changed, 43 insertions(+), 13 deletions(-) diff --git a/src/plugins/data/server/search/es_search/es_search_strategy.ts b/src/plugins/data/server/search/es_search/es_search_strategy.ts index db08ddf920818..0a1eb50226e3c 100644 --- a/src/plugins/data/server/search/es_search/es_search_strategy.ts +++ b/src/plugins/data/server/search/es_search/es_search_strategy.ts @@ -17,7 +17,7 @@ * under the License. */ import { first } from 'rxjs/operators'; -import { RequestHandlerContext, SharedGlobalConfig } from 'kibana/server'; +import { SharedGlobalConfig } from 'kibana/server'; import { SearchResponse } from 'elasticsearch'; import { Observable } from 'rxjs'; import { ES_SEARCH_STRATEGY } from '../../../common/search'; @@ -27,7 +27,7 @@ export const esSearchStrategyProvider = ( config$: Observable ): ISearchStrategy => { return { - search: async (context: RequestHandlerContext, request, options) => { + search: async (context, request, options) => { const config = await config$.pipe(first()).toPromise(); const defaultParams = getDefaultSearchParams(config); diff --git a/src/plugins/data/server/search/routes.ts b/src/plugins/data/server/search/routes.ts index 7b6c045b0908c..bf1982a1f7fb2 100644 --- a/src/plugins/data/server/search/routes.ts +++ b/src/plugins/data/server/search/routes.ts @@ -42,10 +42,12 @@ export function registerSearchRoute(core: CoreSetup): v const signal = getRequestAbortedSignal(request.events.aborted$); const [, , selfStart] = await core.getStartServices(); - const searchStrategy = selfStart.search.getSearchStrategy(strategy); try { - const response = await searchStrategy.search(context, searchRequest, { signal }); + const response = await selfStart.search.search(context, searchRequest, { + signal, + strategy, + }); return res.ok({ body: response }); } catch (err) { return res.customError({ diff --git a/src/plugins/data/server/search/search_service.ts b/src/plugins/data/server/search/search_service.ts index df809b425eb9e..7c8c01f75581d 100644 --- a/src/plugins/data/server/search/search_service.ts +++ b/src/plugins/data/server/search/search_service.ts @@ -17,7 +17,12 @@ * under the License. */ -import { Plugin, PluginInitializerContext, CoreSetup } from '../../../../core/server'; +import { + Plugin, + PluginInitializerContext, + CoreSetup, + RequestHandlerContext, +} from '../../../../core/server'; import { ISearchSetup, ISearchStart, @@ -29,6 +34,7 @@ import { registerSearchRoute } from './routes'; import { ES_SEARCH_STRATEGY, esSearchStrategyProvider } from './es_search'; import { searchSavedObjectType } from '../saved_objects'; import { DataPluginStart } from '../plugin'; +import { IEsSearchRequest } from '../../common'; export class SearchService implements Plugin { private searchStrategies: TSearchStrategiesMap = {}; @@ -38,18 +44,31 @@ export class SearchService implements Plugin { public setup(core: CoreSetup): ISearchSetup { core.savedObjects.registerType(searchSavedObjectType); - this.registerSearchStrategy( - ES_SEARCH_STRATEGY, - esSearchStrategyProvider(this.initializerContext.config.legacy.globalConfig$) - ); + core.getStartServices().then(([coreStart]) => { + this.registerSearchStrategy( + ES_SEARCH_STRATEGY, + esSearchStrategyProvider(this.initializerContext.config.legacy.globalConfig$) + ); + }); registerSearchRoute(core); return { registerSearchStrategy: this.registerSearchStrategy }; } + private search(context: RequestHandlerContext, searchRequest: IEsSearchRequest, options: any) { + return this.getSearchStrategy(options.strategy || ES_SEARCH_STRATEGY).search( + context, + searchRequest, + { signal: options.signal } + ); + } + public start(): ISearchStart { - return { getSearchStrategy: this.getSearchStrategy }; + return { + getSearchStrategy: this.getSearchStrategy, + search: this.search, + }; } public stop() {} diff --git a/src/plugins/data/server/search/types.ts b/src/plugins/data/server/search/types.ts index dea325cc063bb..b241074bd29d2 100644 --- a/src/plugins/data/server/search/types.ts +++ b/src/plugins/data/server/search/types.ts @@ -35,6 +35,11 @@ export interface ISearchStart { * already-registered ES search strategy, it can use this function to accomplish that. */ getSearchStrategy: TGetSearchStrategy; + search: ( + context: RequestHandlerContext, + request: IKibanaSearchRequest, + options: any + ) => Promise; } export interface ISearchOptions { diff --git a/x-pack/plugins/data_enhanced/server/search/es_search_strategy.ts b/x-pack/plugins/data_enhanced/server/search/es_search_strategy.ts index 7c1001697421f..2b4e46fc7c080 100644 --- a/x-pack/plugins/data_enhanced/server/search/es_search_strategy.ts +++ b/x-pack/plugins/data_enhanced/server/search/es_search_strategy.ts @@ -8,7 +8,11 @@ import { first } from 'rxjs/operators'; import { mapKeys, snakeCase } from 'lodash'; import { SearchResponse } from 'elasticsearch'; import { Observable } from 'rxjs'; -import { LegacyAPICaller, SharedGlobalConfig } from '../../../../../src/core/server'; +import { + LegacyAPICaller, + SharedGlobalConfig, + RequestHandlerContext, +} from '../../../../../src/core/server'; import { ES_SEARCH_STRATEGY } from '../../../../../src/plugins/data/common'; import { ISearch, @@ -32,12 +36,12 @@ export const enhancedEsSearchStrategyProvider = ( config$: Observable ): ISearchStrategy => { const search: ISearch = async ( - context, + context: RequestHandlerContext, request: IEnhancedEsSearchRequest, options ) => { const config = await config$.pipe(first()).toPromise(); - const caller = context.core.elasticsearch.legacy.client.callAsCurrentUser; + const caller = context.core.elasticsearch.legacy.client.asScoped(request).callAsCurrentUser; const defaultParams = getDefaultSearchParams(config); const params = { ...defaultParams, ...request.params }; From ab6feb513308482297b9fea047f2f5faa9f153f5 Mon Sep 17 00:00:00 2001 From: Liza K Date: Wed, 1 Jul 2020 16:54:40 +0300 Subject: [PATCH 12/21] Shiny happy cleanup --- src/plugins/data/server/index.ts | 7 +- .../search/es_search/es_search_strategy.ts | 3 +- src/plugins/data/server/search/index.ts | 12 +-- src/plugins/data/server/search/mocks.ts | 1 + .../data/server/search/search_service.ts | 18 ++--- src/plugins/data/server/search/types.ts | 73 +++---------------- .../server/search/es_search_strategy.ts | 13 ++-- 7 files changed, 27 insertions(+), 100 deletions(-) diff --git a/src/plugins/data/server/index.ts b/src/plugins/data/server/index.ts index 6a4eb38b552ff..61c06e521075f 100644 --- a/src/plugins/data/server/index.ts +++ b/src/plugins/data/server/index.ts @@ -165,15 +165,10 @@ import { export { ParsedInterval } from '../common'; export { - ISearch, - ISearchCancel, + ISearchStrategy, ISearchOptions, - IRequestTypesMap, - IResponseTypesMap, ISearchSetup, ISearchStart, - TStrategyTypes, - ISearchStrategy, getDefaultSearchParams, getTotalLoaded, } from './search'; diff --git a/src/plugins/data/server/search/es_search/es_search_strategy.ts b/src/plugins/data/server/search/es_search/es_search_strategy.ts index 0a1eb50226e3c..82f8ef21ebb38 100644 --- a/src/plugins/data/server/search/es_search/es_search_strategy.ts +++ b/src/plugins/data/server/search/es_search/es_search_strategy.ts @@ -20,12 +20,11 @@ import { first } from 'rxjs/operators'; import { SharedGlobalConfig } from 'kibana/server'; import { SearchResponse } from 'elasticsearch'; import { Observable } from 'rxjs'; -import { ES_SEARCH_STRATEGY } from '../../../common/search'; import { ISearchStrategy, getDefaultSearchParams, getTotalLoaded } from '..'; export const esSearchStrategyProvider = ( config$: Observable -): ISearchStrategy => { +): ISearchStrategy => { return { search: async (context, request, options) => { const config = await config$.pipe(first()).toPromise(); diff --git a/src/plugins/data/server/search/index.ts b/src/plugins/data/server/search/index.ts index 882f56e83d4ca..67789fcbf56b4 100644 --- a/src/plugins/data/server/search/index.ts +++ b/src/plugins/data/server/search/index.ts @@ -17,16 +17,6 @@ * under the License. */ -export { - ISearch, - ISearchCancel, - ISearchOptions, - IRequestTypesMap, - IResponseTypesMap, - ISearchSetup, - ISearchStart, - TStrategyTypes, - ISearchStrategy, -} from './types'; +export { ISearchStrategy, ISearchOptions, ISearchSetup, ISearchStart } from './types'; export { getDefaultSearchParams, getTotalLoaded } from './es_search'; diff --git a/src/plugins/data/server/search/mocks.ts b/src/plugins/data/server/search/mocks.ts index 0aab466a9a0d9..b210df3c55db9 100644 --- a/src/plugins/data/server/search/mocks.ts +++ b/src/plugins/data/server/search/mocks.ts @@ -26,5 +26,6 @@ export function createSearchSetupMock() { export function createSearchStartMock() { return { getSearchStrategy: jest.fn(), + search: jest.fn(), }; } diff --git a/src/plugins/data/server/search/search_service.ts b/src/plugins/data/server/search/search_service.ts index 7c8c01f75581d..ebea5b6cef1ed 100644 --- a/src/plugins/data/server/search/search_service.ts +++ b/src/plugins/data/server/search/search_service.ts @@ -23,21 +23,19 @@ import { CoreSetup, RequestHandlerContext, } from '../../../../core/server'; -import { - ISearchSetup, - ISearchStart, - TSearchStrategiesMap, - TRegisterSearchStrategy, - TGetSearchStrategy, -} from './types'; +import { ISearchSetup, ISearchStart, ISearchStrategy } from './types'; import { registerSearchRoute } from './routes'; import { ES_SEARCH_STRATEGY, esSearchStrategyProvider } from './es_search'; import { searchSavedObjectType } from '../saved_objects'; import { DataPluginStart } from '../plugin'; import { IEsSearchRequest } from '../../common'; +interface StrategyMap { + [name: string]: ISearchStrategy; +} + export class SearchService implements Plugin { - private searchStrategies: TSearchStrategiesMap = {}; + private searchStrategies: StrategyMap = {}; constructor(private initializerContext: PluginInitializerContext) {} @@ -73,11 +71,11 @@ export class SearchService implements Plugin { public stop() {} - private registerSearchStrategy: TRegisterSearchStrategy = (name, strategy) => { + private registerSearchStrategy = (name: string, strategy: ISearchStrategy) => { this.searchStrategies[name] = strategy; }; - private getSearchStrategy: TGetSearchStrategy = (name) => { + private getSearchStrategy = (name: string): ISearchStrategy => { const strategy = this.searchStrategies[name]; if (!strategy) { throw new Error(`Search strategy ${name} not found`); diff --git a/src/plugins/data/server/search/types.ts b/src/plugins/data/server/search/types.ts index b241074bd29d2..509b18f6ce014 100644 --- a/src/plugins/data/server/search/types.ts +++ b/src/plugins/data/server/search/types.ts @@ -19,14 +19,14 @@ import { RequestHandlerContext } from '../../../../core/server'; import { IKibanaSearchResponse, IKibanaSearchRequest } from '../../common/search'; -import { ES_SEARCH_STRATEGY, IEsSearchRequest, IEsSearchResponse } from './es_search'; +import { IEsSearchRequest, IEsSearchResponse } from './es_search'; export interface ISearchSetup { /** * Extension point exposed for other plugins to register their own search * strategies. */ - registerSearchStrategy: TRegisterSearchStrategy; + registerSearchStrategy: (name: string, strategy: ISearchStrategy) => void; } export interface ISearchStart { @@ -34,7 +34,7 @@ export interface ISearchStart { * Get other registered search strategies. For example, if a new strategy needs to use the * already-registered ES search strategy, it can use this function to accomplish that. */ - getSearchStrategy: TGetSearchStrategy; + getSearchStrategy: (name: string) => ISearchStrategy; search: ( context: RequestHandlerContext, request: IKibanaSearchRequest, @@ -49,68 +49,15 @@ export interface ISearchOptions { signal?: AbortSignal; } -/** - * Contains all known strategy type identifiers that will be used to map to - * request and response shapes. Plugins that wish to add their own custom search - * strategies should extend this type via: - * - * const MY_STRATEGY = 'MY_STRATEGY'; - * - * declare module 'src/plugins/search/server' { - * export interface IRequestTypesMap { - * [MY_STRATEGY]: IMySearchRequest; - * } - * - * export interface IResponseTypesMap { - * [MY_STRATEGY]: IMySearchResponse - * } - * } - */ -export type TStrategyTypes = typeof ES_SEARCH_STRATEGY | string; - -/** - * The map of search strategy IDs to the corresponding request type definitions. - */ -export interface IRequestTypesMap { - [ES_SEARCH_STRATEGY]: IEsSearchRequest; - [key: string]: IKibanaSearchRequest; -} - -/** - * The map of search strategy IDs to the corresponding response type definitions. - */ -export interface IResponseTypesMap { - [ES_SEARCH_STRATEGY]: IEsSearchResponse; - [key: string]: IKibanaSearchResponse; -} - -export type ISearch = ( - context: RequestHandlerContext, - request: IRequestTypesMap[T], - options?: ISearchOptions -) => Promise; - -export type ISearchCancel = ( - context: RequestHandlerContext, - id: string -) => Promise; - /** * Search strategy interface contains a search method that takes in a request and returns a promise * that resolves to a response. */ -export interface ISearchStrategy { - search: ISearch; - cancel?: ISearchCancel; +export interface ISearchStrategy { + search: ( + context: RequestHandlerContext, + request: IEsSearchRequest, + options?: ISearchOptions + ) => Promise; + cancel?: (context: RequestHandlerContext, id: string) => Promise; } - -export type TRegisterSearchStrategy = ( - name: T, - searchStrategy: ISearchStrategy -) => void; - -export type TGetSearchStrategy = (name: T) => ISearchStrategy; - -export type TSearchStrategiesMap = { - [K in TStrategyTypes]?: ISearchStrategy; -}; diff --git a/x-pack/plugins/data_enhanced/server/search/es_search_strategy.ts b/x-pack/plugins/data_enhanced/server/search/es_search_strategy.ts index 2b4e46fc7c080..7b29117495a67 100644 --- a/x-pack/plugins/data_enhanced/server/search/es_search_strategy.ts +++ b/x-pack/plugins/data_enhanced/server/search/es_search_strategy.ts @@ -13,11 +13,8 @@ import { SharedGlobalConfig, RequestHandlerContext, } from '../../../../../src/core/server'; -import { ES_SEARCH_STRATEGY } from '../../../../../src/plugins/data/common'; import { - ISearch, ISearchOptions, - ISearchCancel, getDefaultSearchParams, getTotalLoaded, ISearchStrategy, @@ -34,14 +31,14 @@ export interface AsyncSearchResponse { export const enhancedEsSearchStrategyProvider = ( config$: Observable -): ISearchStrategy => { - const search: ISearch = async ( +): ISearchStrategy => { + const search = async ( context: RequestHandlerContext, request: IEnhancedEsSearchRequest, - options + options?: ISearchOptions ) => { const config = await config$.pipe(first()).toPromise(); - const caller = context.core.elasticsearch.legacy.client.asScoped(request).callAsCurrentUser; + const caller = context.core.elasticsearch.legacy.client.callAsCurrentUser; const defaultParams = getDefaultSearchParams(config); const params = { ...defaultParams, ...request.params }; @@ -50,7 +47,7 @@ export const enhancedEsSearchStrategyProvider = ( : asyncSearch(caller, { ...request, params }, options); }; - const cancel: ISearchCancel = async (context, id) => { + const cancel = async (context: RequestHandlerContext, id: string) => { const method = 'DELETE'; const path = encodeURI(`/_async_search/${id}`); await context.core.elasticsearch.legacy.client.callAsCurrentUser('transport.request', { From d0121fade77c54e69e5f3d164a89678a8f39efd7 Mon Sep 17 00:00:00 2001 From: Liza K Date: Wed, 1 Jul 2020 17:01:17 +0300 Subject: [PATCH 13/21] docs --- ...plugins-data-server.irequesttypesmap.es.md | 11 ---- ...in-plugins-data-server.irequesttypesmap.md | 20 ------ ...lugins-data-server.iresponsetypesmap.es.md | 11 ---- ...n-plugins-data-server.iresponsetypesmap.md | 20 ------ ...bana-plugin-plugins-data-server.isearch.md | 11 ---- ...lugin-plugins-data-server.isearchcancel.md | 11 ---- ...plugin-plugins-data-server.isearchsetup.md | 2 +- ...ver.isearchsetup.registersearchstrategy.md | 2 +- ...a-server.isearchstart.getsearchstrategy.md | 2 +- ...plugin-plugins-data-server.isearchstart.md | 3 +- ...plugins-data-server.isearchstart.search.md | 11 ++++ ...gins-data-server.isearchstrategy.cancel.md | 2 +- ...gin-plugins-data-server.isearchstrategy.md | 6 +- ...gins-data-server.isearchstrategy.search.md | 2 +- .../kibana-plugin-plugins-data-server.md | 5 -- ...ugin-plugins-data-server.tstrategytypes.md | 19 ------ src/plugins/data/server/server.api.md | 66 ++++--------------- 17 files changed, 35 insertions(+), 169 deletions(-) delete mode 100644 docs/development/plugins/data/server/kibana-plugin-plugins-data-server.irequesttypesmap.es.md delete mode 100644 docs/development/plugins/data/server/kibana-plugin-plugins-data-server.irequesttypesmap.md delete mode 100644 docs/development/plugins/data/server/kibana-plugin-plugins-data-server.iresponsetypesmap.es.md delete mode 100644 docs/development/plugins/data/server/kibana-plugin-plugins-data-server.iresponsetypesmap.md delete mode 100644 docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearch.md delete mode 100644 docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchcancel.md create mode 100644 docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchstart.search.md delete mode 100644 docs/development/plugins/data/server/kibana-plugin-plugins-data-server.tstrategytypes.md diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.irequesttypesmap.es.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.irequesttypesmap.es.md deleted file mode 100644 index 9cebff05dc9db..0000000000000 --- a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.irequesttypesmap.es.md +++ /dev/null @@ -1,11 +0,0 @@ - - -[Home](./index.md) > [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) > [IRequestTypesMap](./kibana-plugin-plugins-data-server.irequesttypesmap.md) > [es](./kibana-plugin-plugins-data-server.irequesttypesmap.es.md) - -## IRequestTypesMap.es property - -Signature: - -```typescript -[ES_SEARCH_STRATEGY]: IEsSearchRequest; -``` diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.irequesttypesmap.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.irequesttypesmap.md deleted file mode 100644 index 3f5e4ba0f7799..0000000000000 --- a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.irequesttypesmap.md +++ /dev/null @@ -1,20 +0,0 @@ - - -[Home](./index.md) > [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) > [IRequestTypesMap](./kibana-plugin-plugins-data-server.irequesttypesmap.md) - -## IRequestTypesMap interface - -The map of search strategy IDs to the corresponding request type definitions. - -Signature: - -```typescript -export interface IRequestTypesMap -``` - -## Properties - -| Property | Type | Description | -| --- | --- | --- | -| [es](./kibana-plugin-plugins-data-server.irequesttypesmap.es.md) | IEsSearchRequest | | - diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.iresponsetypesmap.es.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.iresponsetypesmap.es.md deleted file mode 100644 index 1154fc141d6c7..0000000000000 --- a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.iresponsetypesmap.es.md +++ /dev/null @@ -1,11 +0,0 @@ - - -[Home](./index.md) > [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) > [IResponseTypesMap](./kibana-plugin-plugins-data-server.iresponsetypesmap.md) > [es](./kibana-plugin-plugins-data-server.iresponsetypesmap.es.md) - -## IResponseTypesMap.es property - -Signature: - -```typescript -[ES_SEARCH_STRATEGY]: IEsSearchResponse; -``` diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.iresponsetypesmap.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.iresponsetypesmap.md deleted file mode 100644 index 629ab4347eda8..0000000000000 --- a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.iresponsetypesmap.md +++ /dev/null @@ -1,20 +0,0 @@ - - -[Home](./index.md) > [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) > [IResponseTypesMap](./kibana-plugin-plugins-data-server.iresponsetypesmap.md) - -## IResponseTypesMap interface - -The map of search strategy IDs to the corresponding response type definitions. - -Signature: - -```typescript -export interface IResponseTypesMap -``` - -## Properties - -| Property | Type | Description | -| --- | --- | --- | -| [es](./kibana-plugin-plugins-data-server.iresponsetypesmap.es.md) | IEsSearchResponse | | - diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearch.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearch.md deleted file mode 100644 index 96991579c1716..0000000000000 --- a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearch.md +++ /dev/null @@ -1,11 +0,0 @@ - - -[Home](./index.md) > [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) > [ISearch](./kibana-plugin-plugins-data-server.isearch.md) - -## ISearch type - -Signature: - -```typescript -export declare type ISearch = (context: RequestHandlerContext, request: IRequestTypesMap[T], options?: ISearchOptions) => Promise; -``` diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchcancel.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchcancel.md deleted file mode 100644 index b5a687d1b19d8..0000000000000 --- a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchcancel.md +++ /dev/null @@ -1,11 +0,0 @@ - - -[Home](./index.md) > [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) > [ISearchCancel](./kibana-plugin-plugins-data-server.isearchcancel.md) - -## ISearchCancel type - -Signature: - -```typescript -export declare type ISearchCancel = (context: RequestHandlerContext, id: string) => Promise; -``` diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchsetup.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchsetup.md index 93e253b2e98a3..ca8ad8fdc06ea 100644 --- a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchsetup.md +++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchsetup.md @@ -14,5 +14,5 @@ export interface ISearchSetup | Property | Type | Description | | --- | --- | --- | -| [registerSearchStrategy](./kibana-plugin-plugins-data-server.isearchsetup.registersearchstrategy.md) | TRegisterSearchStrategy | Extension point exposed for other plugins to register their own search strategies. | +| [registerSearchStrategy](./kibana-plugin-plugins-data-server.isearchsetup.registersearchstrategy.md) | (name: string, strategy: ISearchStrategy) => void | Extension point exposed for other plugins to register their own search strategies. | diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchsetup.registersearchstrategy.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchsetup.registersearchstrategy.md index c06b8b00806bf..73c575e7095ed 100644 --- a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchsetup.registersearchstrategy.md +++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchsetup.registersearchstrategy.md @@ -9,5 +9,5 @@ Extension point exposed for other plugins to register their own search strategie Signature: ```typescript -registerSearchStrategy: TRegisterSearchStrategy; +registerSearchStrategy: (name: string, strategy: ISearchStrategy) => void; ``` diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchstart.getsearchstrategy.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchstart.getsearchstrategy.md index 0ba4bf578d6cc..970b2811a574b 100644 --- a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchstart.getsearchstrategy.md +++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchstart.getsearchstrategy.md @@ -9,5 +9,5 @@ Get other registered search strategies. For example, if a new strategy needs to Signature: ```typescript -getSearchStrategy: TGetSearchStrategy; +getSearchStrategy: (name: string) => ISearchStrategy; ``` diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchstart.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchstart.md index abe72396f61e1..be64eeb39c117 100644 --- a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchstart.md +++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchstart.md @@ -14,5 +14,6 @@ export interface ISearchStart | Property | Type | Description | | --- | --- | --- | -| [getSearchStrategy](./kibana-plugin-plugins-data-server.isearchstart.getsearchstrategy.md) | TGetSearchStrategy | Get other registered search strategies. For example, if a new strategy needs to use the already-registered ES search strategy, it can use this function to accomplish that. | +| [getSearchStrategy](./kibana-plugin-plugins-data-server.isearchstart.getsearchstrategy.md) | (name: string) => ISearchStrategy | Get other registered search strategies. For example, if a new strategy needs to use the already-registered ES search strategy, it can use this function to accomplish that. | +| [search](./kibana-plugin-plugins-data-server.isearchstart.search.md) | (context: RequestHandlerContext, request: IKibanaSearchRequest, options: any) => Promise<IKibanaSearchResponse> | | diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchstart.search.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchstart.search.md new file mode 100644 index 0000000000000..b0fa0d6d0b1fe --- /dev/null +++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchstart.search.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) > [ISearchStart](./kibana-plugin-plugins-data-server.isearchstart.md) > [search](./kibana-plugin-plugins-data-server.isearchstart.search.md) + +## ISearchStart.search property + +Signature: + +```typescript +search: (context: RequestHandlerContext, request: IKibanaSearchRequest, options: any) => Promise; +``` diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchstrategy.cancel.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchstrategy.cancel.md index c1e0c3d9f2330..34903697090ea 100644 --- a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchstrategy.cancel.md +++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchstrategy.cancel.md @@ -7,5 +7,5 @@ Signature: ```typescript -cancel?: ISearchCancel; +cancel?: (context: RequestHandlerContext, id: string) => Promise; ``` diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchstrategy.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchstrategy.md index 167c6ab6e5a16..d54e027c4b847 100644 --- a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchstrategy.md +++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchstrategy.md @@ -9,13 +9,13 @@ Search strategy interface contains a search method that takes in a request and r Signature: ```typescript -export interface ISearchStrategy +export interface ISearchStrategy ``` ## Properties | Property | Type | Description | | --- | --- | --- | -| [cancel](./kibana-plugin-plugins-data-server.isearchstrategy.cancel.md) | ISearchCancel<T> | | -| [search](./kibana-plugin-plugins-data-server.isearchstrategy.search.md) | ISearch<T> | | +| [cancel](./kibana-plugin-plugins-data-server.isearchstrategy.cancel.md) | (context: RequestHandlerContext, id: string) => Promise<void> | | +| [search](./kibana-plugin-plugins-data-server.isearchstrategy.search.md) | (context: RequestHandlerContext, request: IEsSearchRequest, options?: ISearchOptions) => Promise<IEsSearchResponse> | | diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchstrategy.search.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchstrategy.search.md index 34a17ca87807a..1a225d0c9aeab 100644 --- a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchstrategy.search.md +++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchstrategy.search.md @@ -7,5 +7,5 @@ Signature: ```typescript -search: ISearch; +search: (context: RequestHandlerContext, request: IEsSearchRequest, options?: ISearchOptions) => Promise; ``` diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.md index c80112fb17dde..9adefda718338 100644 --- a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.md +++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.md @@ -40,8 +40,6 @@ | [IIndexPattern](./kibana-plugin-plugins-data-server.iindexpattern.md) | | | [IndexPatternAttributes](./kibana-plugin-plugins-data-server.indexpatternattributes.md) | Use data plugin interface instead | | [IndexPatternFieldDescriptor](./kibana-plugin-plugins-data-server.indexpatternfielddescriptor.md) | | -| [IRequestTypesMap](./kibana-plugin-plugins-data-server.irequesttypesmap.md) | The map of search strategy IDs to the corresponding request type definitions. | -| [IResponseTypesMap](./kibana-plugin-plugins-data-server.iresponsetypesmap.md) | The map of search strategy IDs to the corresponding response type definitions. | | [ISearchOptions](./kibana-plugin-plugins-data-server.isearchoptions.md) | | | [ISearchSetup](./kibana-plugin-plugins-data-server.isearchsetup.md) | | | [ISearchStart](./kibana-plugin-plugins-data-server.isearchstart.md) | | @@ -73,8 +71,5 @@ | --- | --- | | [FieldFormatsGetConfigFn](./kibana-plugin-plugins-data-server.fieldformatsgetconfigfn.md) | | | [IFieldFormatsRegistry](./kibana-plugin-plugins-data-server.ifieldformatsregistry.md) | | -| [ISearch](./kibana-plugin-plugins-data-server.isearch.md) | | -| [ISearchCancel](./kibana-plugin-plugins-data-server.isearchcancel.md) | | | [ParsedInterval](./kibana-plugin-plugins-data-server.parsedinterval.md) | | -| [TStrategyTypes](./kibana-plugin-plugins-data-server.tstrategytypes.md) | Contains all known strategy type identifiers that will be used to map to request and response shapes. Plugins that wish to add their own custom search strategies should extend this type via:const MY\_STRATEGY = 'MY\_STRATEGY';declare module 'src/plugins/search/server' { export interface IRequestTypesMap { \[MY\_STRATEGY\]: IMySearchRequest; }export interface IResponseTypesMap { \[MY\_STRATEGY\]: IMySearchResponse } } | diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.tstrategytypes.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.tstrategytypes.md deleted file mode 100644 index 443d8d1b424d0..0000000000000 --- a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.tstrategytypes.md +++ /dev/null @@ -1,19 +0,0 @@ - - -[Home](./index.md) > [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) > [TStrategyTypes](./kibana-plugin-plugins-data-server.tstrategytypes.md) - -## TStrategyTypes type - -Contains all known strategy type identifiers that will be used to map to request and response shapes. Plugins that wish to add their own custom search strategies should extend this type via: - -const MY\_STRATEGY = 'MY\_STRATEGY'; - -declare module 'src/plugins/search/server' { export interface IRequestTypesMap { \[MY\_STRATEGY\]: IMySearchRequest; } - -export interface IResponseTypesMap { \[MY\_STRATEGY\]: IMySearchResponse } } - -Signature: - -```typescript -export declare type TStrategyTypes = typeof ES_SEARCH_STRATEGY | string; -``` diff --git a/src/plugins/data/server/server.api.md b/src/plugins/data/server/server.api.md index c0a907ed92ec3..f0c6c0b8ffc62 100644 --- a/src/plugins/data/server/server.api.md +++ b/src/plugins/data/server/server.api.md @@ -508,46 +508,6 @@ export class IndexPatternsFetcher { }): Promise; } -// Warning: (ae-missing-release-tag) "IRequestTypesMap" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) -// -// @public -export interface IRequestTypesMap { - // Warning: (ae-forgotten-export) The symbol "IKibanaSearchRequest" needs to be exported by the entry point index.d.ts - // - // (undocumented) - [key: string]: IKibanaSearchRequest; - // Warning: (ae-forgotten-export) The symbol "ES_SEARCH_STRATEGY" needs to be exported by the entry point index.d.ts - // Warning: (ae-forgotten-export) The symbol "IEsSearchRequest" needs to be exported by the entry point index.d.ts - // - // (undocumented) - [ES_SEARCH_STRATEGY]: IEsSearchRequest; -} - -// Warning: (ae-missing-release-tag) "IResponseTypesMap" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) -// -// @public -export interface IResponseTypesMap { - // Warning: (ae-forgotten-export) The symbol "IKibanaSearchResponse" needs to be exported by the entry point index.d.ts - // - // (undocumented) - [key: string]: IKibanaSearchResponse; - // Warning: (ae-forgotten-export) The symbol "IEsSearchResponse" needs to be exported by the entry point index.d.ts - // - // (undocumented) - [ES_SEARCH_STRATEGY]: IEsSearchResponse; -} - -// Warning: (ae-forgotten-export) The symbol "RequestHandlerContext" needs to be exported by the entry point index.d.ts -// Warning: (ae-missing-release-tag) "ISearch" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) -// -// @public (undocumented) -export type ISearch = (context: RequestHandlerContext, request: IRequestTypesMap[T], options?: ISearchOptions) => Promise; - -// Warning: (ae-missing-release-tag) "ISearchCancel" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) -// -// @public (undocumented) -export type ISearchCancel = (context: RequestHandlerContext, id: string) => Promise; - // Warning: (ae-missing-release-tag) "ISearchOptions" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // // @public (undocumented) @@ -559,26 +519,33 @@ export interface ISearchOptions { // // @public (undocumented) export interface ISearchSetup { - // Warning: (ae-forgotten-export) The symbol "TRegisterSearchStrategy" needs to be exported by the entry point index.d.ts - registerSearchStrategy: TRegisterSearchStrategy; + registerSearchStrategy: (name: string, strategy: ISearchStrategy) => void; } // Warning: (ae-missing-release-tag) "ISearchStart" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // // @public (undocumented) export interface ISearchStart { - // Warning: (ae-forgotten-export) The symbol "TGetSearchStrategy" needs to be exported by the entry point index.d.ts - getSearchStrategy: TGetSearchStrategy; + getSearchStrategy: (name: string) => ISearchStrategy; + // Warning: (ae-forgotten-export) The symbol "RequestHandlerContext" needs to be exported by the entry point index.d.ts + // Warning: (ae-forgotten-export) The symbol "IKibanaSearchRequest" needs to be exported by the entry point index.d.ts + // Warning: (ae-forgotten-export) The symbol "IKibanaSearchResponse" needs to be exported by the entry point index.d.ts + // + // (undocumented) + search: (context: RequestHandlerContext, request: IKibanaSearchRequest, options: any) => Promise; } // Warning: (ae-missing-release-tag) "ISearchStrategy" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // // @public -export interface ISearchStrategy { +export interface ISearchStrategy { // (undocumented) - cancel?: ISearchCancel; + cancel?: (context: RequestHandlerContext, id: string) => Promise; + // Warning: (ae-forgotten-export) The symbol "IEsSearchRequest" needs to be exported by the entry point index.d.ts + // Warning: (ae-forgotten-export) The symbol "IEsSearchResponse" needs to be exported by the entry point index.d.ts + // // (undocumented) - search: ISearch; + search: (context: RequestHandlerContext, request: IEsSearchRequest, options?: ISearchOptions) => Promise; } // @public (undocumented) @@ -757,11 +724,6 @@ export interface TimeRange { to: string; } -// Warning: (ae-missing-release-tag) "TStrategyTypes" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) -// -// @public -export type TStrategyTypes = typeof ES_SEARCH_STRATEGY | string; - // Warning: (ae-missing-release-tag) "UI_SETTINGS" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // // @public (undocumented) From 1b02297e4800d4efcd024c82685ac178734b8455 Mon Sep 17 00:00:00 2001 From: Liza K Date: Thu, 2 Jul 2020 16:19:25 +0300 Subject: [PATCH 14/21] fix jest test --- src/plugins/data/server/search/routes.test.ts | 22 +++++++++---------- 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/plugins/data/server/search/routes.test.ts b/src/plugins/data/server/search/routes.test.ts index 4ef67de93e454..167bd5af5d51d 100644 --- a/src/plugins/data/server/search/routes.test.ts +++ b/src/plugins/data/server/search/routes.test.ts @@ -33,9 +33,8 @@ describe('Search service', () => { }); it('handler calls context.search.search with the given request and strategy', async () => { - const mockSearch = jest.fn().mockResolvedValue('yay'); - mockDataStart.search.getSearchStrategy.mockReturnValueOnce({ search: mockSearch }); - + const response = { id: 'yay' }; + mockDataStart.search.search.mockResolvedValue(response); const mockContext = {}; const mockBody = { params: {} }; const mockParams = { strategy: 'foo' }; @@ -51,21 +50,21 @@ describe('Search service', () => { const handler = mockRouter.post.mock.calls[0][1]; await handler((mockContext as unknown) as RequestHandlerContext, mockRequest, mockResponse); - expect(mockDataStart.search.getSearchStrategy.mock.calls[0][0]).toBe(mockParams.strategy); - expect(mockSearch).toBeCalled(); - expect(mockSearch.mock.calls[0][1]).toStrictEqual(mockBody); + expect(mockDataStart.search.search).toBeCalled(); + expect(mockDataStart.search.search.mock.calls[0][1]).toStrictEqual(mockBody); expect(mockResponse.ok).toBeCalled(); - expect(mockResponse.ok.mock.calls[0][0]).toEqual({ body: 'yay' }); + expect(mockResponse.ok.mock.calls[0][0]).toEqual({ + body: response, + }); }); it('handler throws an error if the search throws an error', async () => { - const mockSearch = jest.fn().mockRejectedValue({ + mockDataStart.search.search.mockRejectedValue({ message: 'oh no', body: { error: 'oops', }, }); - mockDataStart.search.getSearchStrategy.mockReturnValueOnce({ search: mockSearch }); const mockContext = {}; const mockBody = { params: {} }; @@ -82,9 +81,8 @@ describe('Search service', () => { const handler = mockRouter.post.mock.calls[0][1]; await handler((mockContext as unknown) as RequestHandlerContext, mockRequest, mockResponse); - expect(mockDataStart.search.getSearchStrategy.mock.calls[0][0]).toBe(mockParams.strategy); - expect(mockSearch).toBeCalled(); - expect(mockSearch.mock.calls[0][1]).toStrictEqual(mockBody); + expect(mockDataStart.search.search).toBeCalled(); + expect(mockDataStart.search.search.mock.calls[0][1]).toStrictEqual(mockBody); expect(mockResponse.customError).toBeCalled(); const error: any = mockResponse.customError.mock.calls[0][0]; expect(error.body.message).toBe('oh no'); From 696215b2a8ae75ccaaa3f578e09374d4c724d768 Mon Sep 17 00:00:00 2001 From: Liza K Date: Sun, 5 Jul 2020 14:45:07 +0300 Subject: [PATCH 15/21] simplify strategy registration --- src/plugins/data/server/search/search_service.ts | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/plugins/data/server/search/search_service.ts b/src/plugins/data/server/search/search_service.ts index ebea5b6cef1ed..950cdf6cefc3e 100644 --- a/src/plugins/data/server/search/search_service.ts +++ b/src/plugins/data/server/search/search_service.ts @@ -42,12 +42,10 @@ export class SearchService implements Plugin { public setup(core: CoreSetup): ISearchSetup { core.savedObjects.registerType(searchSavedObjectType); - core.getStartServices().then(([coreStart]) => { - this.registerSearchStrategy( - ES_SEARCH_STRATEGY, - esSearchStrategyProvider(this.initializerContext.config.legacy.globalConfig$) - ); - }); + this.registerSearchStrategy( + ES_SEARCH_STRATEGY, + esSearchStrategyProvider(this.initializerContext.config.legacy.globalConfig$) + ); registerSearchRoute(core); From 873eb48e71ac42e7975338082411e91ea345545e Mon Sep 17 00:00:00 2001 From: Liza K Date: Wed, 8 Jul 2020 01:07:10 +0300 Subject: [PATCH 16/21] fix rebase --- .../public/search/search_interceptor.test.ts | 196 ++++++------------ .../data/public/search/search_service.ts | 60 ++++-- src/plugins/data/server/plugin.ts | 2 +- .../kbn_tp_run_pipeline/public/index.ts | 10 +- 4 files changed, 125 insertions(+), 143 deletions(-) diff --git a/src/plugins/data/public/search/search_interceptor.test.ts b/src/plugins/data/public/search/search_interceptor.test.ts index 87cc8f221bec7..bd056271688c1 100644 --- a/src/plugins/data/public/search/search_interceptor.test.ts +++ b/src/plugins/data/public/search/search_interceptor.test.ts @@ -17,172 +17,114 @@ * under the License. */ +import { Observable, Subject } from 'rxjs'; import { CoreStart } from '../../../../core/public'; import { coreMock } from '../../../../core/public/mocks'; -import { IEsSearchRequest } from '../../common/search'; +import { IKibanaSearchRequest } from '../../common/search'; +import { RequestTimeoutError } from './request_timeout_error'; import { SearchInterceptor } from './search_interceptor'; -import { AbortError } from '../../common'; +jest.useFakeTimers(); + +const mockSearch = jest.fn(); let searchInterceptor: SearchInterceptor; let mockCoreStart: MockedKeys; -const flushPromises = () => new Promise((resolve) => setImmediate(resolve)); -jest.useFakeTimers(); - describe('SearchInterceptor', () => { beforeEach(() => { mockCoreStart = coreMock.createStart(); + mockSearch.mockClear(); searchInterceptor = new SearchInterceptor( - { - toasts: mockCoreStart.notifications.toasts, - application: mockCoreStart.application, - uiSettings: mockCoreStart.uiSettings, - http: mockCoreStart.http, - }, + mockCoreStart.notifications.toasts, + mockCoreStart.application, 1000 ); }); describe('search', () => { - test('Observable should resolve if fetch is successful', async () => { - const mockResponse: any = { result: 200 }; - mockCoreStart.http.fetch.mockResolvedValueOnce(mockResponse); - const mockRequest: IEsSearchRequest = { - params: {}, - }; - const response = searchInterceptor.search(mockRequest); - - const result = await response.toPromise(); - expect(result).toBe(mockResponse); + test('should invoke `search` with the request', () => { + const mockResponse = new Subject(); + mockSearch.mockReturnValue(mockResponse.asObservable()); + const mockRequest: IKibanaSearchRequest = {}; + const response = searchInterceptor.search(mockSearch, mockRequest); + mockResponse.complete(); + + response.subscribe(); + expect(mockSearch.mock.calls[0][0]).toBe(mockRequest); }); - test('Observable should fail if fetch has an error', async () => { - const mockResponse: any = { result: 500 }; - mockCoreStart.http.fetch.mockRejectedValueOnce(mockResponse); - const mockRequest: IEsSearchRequest = { - params: {}, - }; - const response = searchInterceptor.search(mockRequest); - - try { - await response.toPromise(); - } catch (e) { - expect(e).toBe(mockResponse); - } - }); + test('should mirror the observable to completion if the request does not time out', () => { + const mockResponse = new Subject(); + mockSearch.mockReturnValue(mockResponse.asObservable()); + const response = searchInterceptor.search(mockSearch, {}); - test('Observable should fail if fetch times out (test merged signal)', async () => { - mockCoreStart.http.fetch.mockImplementationOnce((options: any) => { - return new Promise((resolve, reject) => { - options.signal.addEventListener('abort', () => { - reject(new AbortError()); - }); - - setTimeout(resolve, 5000); - }); - }); - const mockRequest: IEsSearchRequest = { - params: {}, - }; - const response = searchInterceptor.search(mockRequest); + setTimeout(() => mockResponse.next('hi'), 250); + setTimeout(() => mockResponse.complete(), 500); const next = jest.fn(); - const error = (e: any) => { - expect(next).not.toBeCalled(); - expect(e).toBeInstanceOf(AbortError); - }; - response.subscribe({ next, error }); + const complete = jest.fn(); + response.subscribe({ next, complete }); - jest.advanceTimersByTime(5000); + jest.advanceTimersByTime(1000); - await flushPromises(); + expect(next).toHaveBeenCalledWith('hi'); + expect(complete).toHaveBeenCalled(); }); - test('Observable should fail if user aborts (test merged signal)', async () => { - const abortController = new AbortController(); - mockCoreStart.http.fetch.mockImplementationOnce((options: any) => { - return new Promise((resolve, reject) => { - options.signal.addEventListener('abort', () => { - reject(new AbortError()); - }); - - setTimeout(resolve, 500); - }); - }); - const mockRequest: IEsSearchRequest = { - params: {}, - }; - const response = searchInterceptor.search(mockRequest, { signal: abortController.signal }); + test('should mirror the observable to error if the request does not time out', () => { + const mockResponse = new Subject(); + mockSearch.mockReturnValue(mockResponse.asObservable()); + const response = searchInterceptor.search(mockSearch, {}); + + setTimeout(() => mockResponse.next('hi'), 250); + setTimeout(() => mockResponse.error('error'), 500); const next = jest.fn(); - const error = (e: any) => { - expect(next).not.toBeCalled(); - expect(e).toBeInstanceOf(AbortError); - }; + const error = jest.fn(); response.subscribe({ next, error }); - setTimeout(() => abortController.abort(), 200); - jest.advanceTimersByTime(5000); - await flushPromises(); + jest.advanceTimersByTime(1000); + + expect(next).toHaveBeenCalledWith('hi'); + expect(error).toHaveBeenCalledWith('error'); }); - test('Immediatelly aborts if passed an aborted abort signal', async (done) => { - const abort = new AbortController(); - const mockRequest: IEsSearchRequest = { - params: {}, - }; - const response = searchInterceptor.search(mockRequest, { signal: abort.signal }); - abort.abort(); + test('should return a `RequestTimeoutError` if the request times out', () => { + mockSearch.mockReturnValue(new Observable()); + const response = searchInterceptor.search(mockSearch, {}); - const next = jest.fn(); - const error = (e: any) => { - expect(next).not.toBeCalled(); - expect(e).toBeInstanceOf(AbortError); - expect(mockCoreStart.http.fetch).not.toBeCalled(); - done(); - }; - response.subscribe({ next, error }); - setTimeout(() => abortController.abort(), 200); + const error = jest.fn(); + response.subscribe({ error }); + + jest.advanceTimersByTime(1000); + + expect(error).toHaveBeenCalled(); + expect(error.mock.calls[0][0] instanceof RequestTimeoutError).toBe(true); }); }); describe('getPendingCount$', () => { test('should observe the number of pending requests', () => { - const pendingCount$ = searchInterceptor.getPendingCount$(); - const pendingNext = jest.fn(); - pendingCount$.subscribe(pendingNext); - - const mockResponse: any = { result: 200 }; - mockCoreStart.http.fetch.mockResolvedValue(mockResponse); - const mockRequest: IEsSearchRequest = { - params: {}, - }; - const response = searchInterceptor.search(mockRequest); - - response.subscribe({ - complete: () => { - expect(pendingNext.mock.calls).toEqual([[0], [1], [0]]); - }, - }); - }); + let i = 0; + const mockResponses = [new Subject(), new Subject()]; + mockSearch.mockImplementation(() => mockResponses[i++]); - test('should observe the number of pending requests on error', () => { const pendingCount$ = searchInterceptor.getPendingCount$(); - const pendingNext = jest.fn(); - pendingCount$.subscribe(pendingNext); - - const mockResponse: any = { result: 500 }; - mockCoreStart.http.fetch.mockRejectedValue(mockResponse); - const mockRequest: IEsSearchRequest = { - params: {}, - }; - const response = searchInterceptor.search(mockRequest); - - response.subscribe({ - complete: () => { - expect(pendingNext.mock.calls).toEqual([[0], [1], [0]]); - }, - }); + + const next = jest.fn(); + pendingCount$.subscribe(next); + + const error = jest.fn(); + searchInterceptor.search(mockSearch, {}).subscribe({ error }); + searchInterceptor.search(mockSearch, {}).subscribe({ error }); + + setTimeout(() => mockResponses[0].complete(), 250); + setTimeout(() => mockResponses[1].error('error'), 500); + + jest.advanceTimersByTime(500); + + expect(next).toHaveBeenCalled(); + expect(next.mock.calls).toEqual([[0], [1], [2], [1], [0]]); }); }); }); diff --git a/src/plugins/data/public/search/search_service.ts b/src/plugins/data/public/search/search_service.ts index 0f5755eba5968..134dc89c2421a 100644 --- a/src/plugins/data/public/search/search_service.ts +++ b/src/plugins/data/public/search/search_service.ts @@ -18,13 +18,17 @@ */ import { Plugin, CoreSetup, CoreStart, PackageInfo } from '../../../../core/public'; -import { ISearchSetup, ISearchStart } from './types'; +import { SYNC_SEARCH_STRATEGY, syncSearchStrategyProvider } from './sync_search_strategy'; +import { ISearchSetup, ISearchStart, TSearchStrategiesMap, ISearchStrategy } from './types'; import { ExpressionsSetup } from '../../../../plugins/expressions/public'; import { createSearchSource, SearchSource, SearchSourceDependencies } from './search_source'; +import { TStrategyTypes } from './strategy_types'; import { getEsClient, LegacyApiCaller } from './legacy'; import { getForceNow } from '../query/timefilter/lib/get_force_now'; import { calculateBounds, TimeRange } from '../../common/query'; +import { ES_SEARCH_STRATEGY, DEFAULT_SEARCH_STRATEGY } from '../../common/search'; +import { esSearchStrategyProvider } from './es_search'; import { IndexPatternsContract } from '../index_patterns/index_patterns'; import { GetInternalStartServicesFn } from '../types'; import { SearchInterceptor } from './search_interceptor'; @@ -35,10 +39,7 @@ import { AggConfigs, getCalculateAutoTimeExpression, } from './aggs'; -import { - z - } from '../field_formats'; -import { ISearchGeneric } from './types'; +import { ISearchGeneric } from './i_search'; interface SearchServiceSetupDependencies { expressions: ExpressionsSetup; @@ -50,11 +51,38 @@ interface SearchServiceStartDependencies { indexPatterns: IndexPatternsContract; } +/** + * The search plugin exposes a method `registerSearchStrategy` for other plugins + * to add their own custom search strategies. + * + * It also comes with two search strategy implementations - SYNC_SEARCH_STRATEGY and ES_SEARCH_STRATEGY. + */ export class SearchService implements Plugin { + /** + * A mapping of search strategies keyed by a unique identifier. Plugins can use this unique identifier + * to override certain strategy implementations. + */ + private searchStrategies: TSearchStrategiesMap = {}; + private esClient?: LegacyApiCaller; private readonly aggTypesRegistry = new AggTypesRegistry(); private searchInterceptor!: SearchInterceptor; + private registerSearchStrategy = ( + name: T, + strategy: ISearchStrategy + ) => { + this.searchStrategies[name] = strategy; + }; + + private getSearchStrategy = (name: T): ISearchStrategy => { + const strategy = this.searchStrategies[name]; + if (!strategy) { + throw new Error(`Search strategy ${name} not found`); + } + return strategy; + }; + /** * getForceNow uses window.location, so we must have a separate implementation * of calculateBounds on the client and the server. @@ -68,6 +96,11 @@ export class SearchService implements Plugin { ): ISearchSetup { this.esClient = getEsClient(core.injectedMetadata, core.http, packageInfo); + const syncSearchStrategy = syncSearchStrategyProvider(core); + const esSearchStrategy = esSearchStrategyProvider(core, syncSearchStrategy); + this.registerSearchStrategy(SYNC_SEARCH_STRATEGY, syncSearchStrategy); + this.registerSearchStrategy(ES_SEARCH_STRATEGY, esSearchStrategy); + const aggTypesSetup = this.aggTypesRegistry.setup(); // register each agg type @@ -88,6 +121,7 @@ export class SearchService implements Plugin { calculateAutoTimeExpression: getCalculateAutoTimeExpression(core.uiSettings), types: aggTypesSetup, }, + registerSearchStrategy: this.registerSearchStrategy, }; } @@ -99,19 +133,18 @@ export class SearchService implements Plugin { * their own search collector instances */ this.searchInterceptor = new SearchInterceptor( - { - toasts: core.notifications.toasts, - application: core.application, - http: core.http, - uiSettings: core.uiSettings, - }, + core.notifications.toasts, + core.application, core.injectedMetadata.getInjectedVar('esRequestTimeout') as number ); const aggTypesStart = this.aggTypesRegistry.start(); - const search: ISearchGeneric = (request, options) => { - return this.searchInterceptor.search(request, options); + const search: ISearchGeneric = (request, options, strategyName) => { + const { search: defaultSearch } = this.getSearchStrategy( + strategyName || DEFAULT_SEARCH_STRATEGY + ); + return this.searchInterceptor.search(defaultSearch as any, request, options); }; const legacySearch = { @@ -135,6 +168,7 @@ export class SearchService implements Plugin { }, types: aggTypesStart, }, + getSearchStrategy: this.getSearchStrategy, search, searchSource: { create: createSearchSource(dependencies.indexPatterns, searchSourceDependencies), diff --git a/src/plugins/data/server/plugin.ts b/src/plugins/data/server/plugin.ts index c7bcd0c148858..bcf1f4f8ab60b 100644 --- a/src/plugins/data/server/plugin.ts +++ b/src/plugins/data/server/plugin.ts @@ -91,11 +91,11 @@ export class DataServerPlugin implements Plugin new DemoDataPlugin(); +export const plugin: PluginInitializer = ( + initializerContext: PluginInitializerContext +) => { + return new Plugin(initializerContext); +}; From e4a8335ab783bde4994c142165e6b9964f06575c Mon Sep 17 00:00:00 2001 From: Liza K Date: Wed, 8 Jul 2020 01:11:42 +0300 Subject: [PATCH 17/21] fix rebase --- .../public/search/search_interceptor.test.ts | 193 +++++++++++------- .../data/public/search/search_service.ts | 58 +----- 2 files changed, 135 insertions(+), 116 deletions(-) diff --git a/src/plugins/data/public/search/search_interceptor.test.ts b/src/plugins/data/public/search/search_interceptor.test.ts index bd056271688c1..f4c5de2bcaf31 100644 --- a/src/plugins/data/public/search/search_interceptor.test.ts +++ b/src/plugins/data/public/search/search_interceptor.test.ts @@ -17,114 +17,169 @@ * under the License. */ -import { Observable, Subject } from 'rxjs'; import { CoreStart } from '../../../../core/public'; import { coreMock } from '../../../../core/public/mocks'; -import { IKibanaSearchRequest } from '../../common/search'; -import { RequestTimeoutError } from './request_timeout_error'; +import { IEsSearchRequest } from '../../common/search'; import { SearchInterceptor } from './search_interceptor'; +import { AbortError } from '../../common'; -jest.useFakeTimers(); - -const mockSearch = jest.fn(); let searchInterceptor: SearchInterceptor; let mockCoreStart: MockedKeys; +const flushPromises = () => new Promise((resolve) => setImmediate(resolve)); +jest.useFakeTimers(); + describe('SearchInterceptor', () => { beforeEach(() => { mockCoreStart = coreMock.createStart(); - mockSearch.mockClear(); searchInterceptor = new SearchInterceptor( - mockCoreStart.notifications.toasts, - mockCoreStart.application, + { + toasts: mockCoreStart.notifications.toasts, + application: mockCoreStart.application, + uiSettings: mockCoreStart.uiSettings, + http: mockCoreStart.http, + }, 1000 ); }); describe('search', () => { - test('should invoke `search` with the request', () => { - const mockResponse = new Subject(); - mockSearch.mockReturnValue(mockResponse.asObservable()); - const mockRequest: IKibanaSearchRequest = {}; - const response = searchInterceptor.search(mockSearch, mockRequest); - mockResponse.complete(); - - response.subscribe(); - expect(mockSearch.mock.calls[0][0]).toBe(mockRequest); + test('Observable should resolve if fetch is successful', async () => { + const mockResponse: any = { result: 200 }; + mockCoreStart.http.fetch.mockResolvedValueOnce(mockResponse); + const mockRequest: IEsSearchRequest = { + params: {}, + }; + const response = searchInterceptor.search(mockRequest); + + const result = await response.toPromise(); + expect(result).toBe(mockResponse); }); - test('should mirror the observable to completion if the request does not time out', () => { - const mockResponse = new Subject(); - mockSearch.mockReturnValue(mockResponse.asObservable()); - const response = searchInterceptor.search(mockSearch, {}); + test('Observable should fail if fetch has an error', async () => { + const mockResponse: any = { result: 500 }; + mockCoreStart.http.fetch.mockRejectedValueOnce(mockResponse); + const mockRequest: IEsSearchRequest = { + params: {}, + }; + const response = searchInterceptor.search(mockRequest); + + try { + await response.toPromise(); + } catch (e) { + expect(e).toBe(mockResponse); + } + }); - setTimeout(() => mockResponse.next('hi'), 250); - setTimeout(() => mockResponse.complete(), 500); + test('Observable should fail if fetch times out (test merged signal)', async () => { + mockCoreStart.http.fetch.mockImplementationOnce((options: any) => { + return new Promise((resolve, reject) => { + options.signal.addEventListener('abort', () => { + reject(new AbortError()); + }); + + setTimeout(resolve, 5000); + }); + }); + const mockRequest: IEsSearchRequest = { + params: {}, + }; + const response = searchInterceptor.search(mockRequest); const next = jest.fn(); - const complete = jest.fn(); - response.subscribe({ next, complete }); + const error = (e: any) => { + expect(next).not.toBeCalled(); + expect(e).toBeInstanceOf(AbortError); + }; + response.subscribe({ next, error }); - jest.advanceTimersByTime(1000); + jest.advanceTimersByTime(5000); - expect(next).toHaveBeenCalledWith('hi'); - expect(complete).toHaveBeenCalled(); + await flushPromises(); }); - test('should mirror the observable to error if the request does not time out', () => { - const mockResponse = new Subject(); - mockSearch.mockReturnValue(mockResponse.asObservable()); - const response = searchInterceptor.search(mockSearch, {}); - - setTimeout(() => mockResponse.next('hi'), 250); - setTimeout(() => mockResponse.error('error'), 500); + test('Observable should fail if user aborts (test merged signal)', async () => { + const abortController = new AbortController(); + mockCoreStart.http.fetch.mockImplementationOnce((options: any) => { + return new Promise((resolve, reject) => { + options.signal.addEventListener('abort', () => { + reject(new AbortError()); + }); + + setTimeout(resolve, 500); + }); + }); + const mockRequest: IEsSearchRequest = { + params: {}, + }; + const response = searchInterceptor.search(mockRequest, { signal: abortController.signal }); const next = jest.fn(); - const error = jest.fn(); + const error = (e: any) => { + expect(next).not.toBeCalled(); + expect(e).toBeInstanceOf(AbortError); + }; response.subscribe({ next, error }); + setTimeout(() => abortController.abort(), 200); + jest.advanceTimersByTime(5000); - jest.advanceTimersByTime(1000); - - expect(next).toHaveBeenCalledWith('hi'); - expect(error).toHaveBeenCalledWith('error'); + await flushPromises(); }); - test('should return a `RequestTimeoutError` if the request times out', () => { - mockSearch.mockReturnValue(new Observable()); - const response = searchInterceptor.search(mockSearch, {}); - - const error = jest.fn(); + test('Immediatelly aborts if passed an aborted abort signal', async (done) => { + const abort = new AbortController(); + const mockRequest: IEsSearchRequest = { + params: {}, + }; + const response = searchInterceptor.search(mockRequest, { signal: abort.signal }); + abort.abort(); + + const error = (e: any) => { + expect(e).toBeInstanceOf(AbortError); + expect(mockCoreStart.http.fetch).not.toBeCalled(); + done(); + }; response.subscribe({ error }); - - jest.advanceTimersByTime(1000); - - expect(error).toHaveBeenCalled(); - expect(error.mock.calls[0][0] instanceof RequestTimeoutError).toBe(true); }); }); describe('getPendingCount$', () => { test('should observe the number of pending requests', () => { - let i = 0; - const mockResponses = [new Subject(), new Subject()]; - mockSearch.mockImplementation(() => mockResponses[i++]); - const pendingCount$ = searchInterceptor.getPendingCount$(); + const pendingNext = jest.fn(); + pendingCount$.subscribe(pendingNext); + + const mockResponse: any = { result: 200 }; + mockCoreStart.http.fetch.mockResolvedValue(mockResponse); + const mockRequest: IEsSearchRequest = { + params: {}, + }; + const response = searchInterceptor.search(mockRequest); + + response.subscribe({ + complete: () => { + expect(pendingNext.mock.calls).toEqual([[0], [1], [0]]); + }, + }); + }); - const next = jest.fn(); - pendingCount$.subscribe(next); - - const error = jest.fn(); - searchInterceptor.search(mockSearch, {}).subscribe({ error }); - searchInterceptor.search(mockSearch, {}).subscribe({ error }); - - setTimeout(() => mockResponses[0].complete(), 250); - setTimeout(() => mockResponses[1].error('error'), 500); - - jest.advanceTimersByTime(500); - - expect(next).toHaveBeenCalled(); - expect(next.mock.calls).toEqual([[0], [1], [2], [1], [0]]); + test('should observe the number of pending requests on error', () => { + const pendingCount$ = searchInterceptor.getPendingCount$(); + const pendingNext = jest.fn(); + pendingCount$.subscribe(pendingNext); + + const mockResponse: any = { result: 500 }; + mockCoreStart.http.fetch.mockRejectedValue(mockResponse); + const mockRequest: IEsSearchRequest = { + params: {}, + }; + const response = searchInterceptor.search(mockRequest); + + response.subscribe({ + complete: () => { + expect(pendingNext.mock.calls).toEqual([[0], [1], [0]]); + }, + }); }); }); }); diff --git a/src/plugins/data/public/search/search_service.ts b/src/plugins/data/public/search/search_service.ts index 134dc89c2421a..a27eba21714bb 100644 --- a/src/plugins/data/public/search/search_service.ts +++ b/src/plugins/data/public/search/search_service.ts @@ -18,17 +18,14 @@ */ import { Plugin, CoreSetup, CoreStart, PackageInfo } from '../../../../core/public'; -import { SYNC_SEARCH_STRATEGY, syncSearchStrategyProvider } from './sync_search_strategy'; -import { ISearchSetup, ISearchStart, TSearchStrategiesMap, ISearchStrategy } from './types'; +import { ISearchSetup, ISearchStart } from './types'; import { ExpressionsSetup } from '../../../../plugins/expressions/public'; import { createSearchSource, SearchSource, SearchSourceDependencies } from './search_source'; -import { TStrategyTypes } from './strategy_types'; import { getEsClient, LegacyApiCaller } from './legacy'; import { getForceNow } from '../query/timefilter/lib/get_force_now'; import { calculateBounds, TimeRange } from '../../common/query'; -import { ES_SEARCH_STRATEGY, DEFAULT_SEARCH_STRATEGY } from '../../common/search'; -import { esSearchStrategyProvider } from './es_search'; + import { IndexPatternsContract } from '../index_patterns/index_patterns'; import { GetInternalStartServicesFn } from '../types'; import { SearchInterceptor } from './search_interceptor'; @@ -39,7 +36,7 @@ import { AggConfigs, getCalculateAutoTimeExpression, } from './aggs'; -import { ISearchGeneric } from './i_search'; +import { ISearchGeneric } from './types'; interface SearchServiceSetupDependencies { expressions: ExpressionsSetup; @@ -51,38 +48,11 @@ interface SearchServiceStartDependencies { indexPatterns: IndexPatternsContract; } -/** - * The search plugin exposes a method `registerSearchStrategy` for other plugins - * to add their own custom search strategies. - * - * It also comes with two search strategy implementations - SYNC_SEARCH_STRATEGY and ES_SEARCH_STRATEGY. - */ export class SearchService implements Plugin { - /** - * A mapping of search strategies keyed by a unique identifier. Plugins can use this unique identifier - * to override certain strategy implementations. - */ - private searchStrategies: TSearchStrategiesMap = {}; - private esClient?: LegacyApiCaller; private readonly aggTypesRegistry = new AggTypesRegistry(); private searchInterceptor!: SearchInterceptor; - private registerSearchStrategy = ( - name: T, - strategy: ISearchStrategy - ) => { - this.searchStrategies[name] = strategy; - }; - - private getSearchStrategy = (name: T): ISearchStrategy => { - const strategy = this.searchStrategies[name]; - if (!strategy) { - throw new Error(`Search strategy ${name} not found`); - } - return strategy; - }; - /** * getForceNow uses window.location, so we must have a separate implementation * of calculateBounds on the client and the server. @@ -96,11 +66,6 @@ export class SearchService implements Plugin { ): ISearchSetup { this.esClient = getEsClient(core.injectedMetadata, core.http, packageInfo); - const syncSearchStrategy = syncSearchStrategyProvider(core); - const esSearchStrategy = esSearchStrategyProvider(core, syncSearchStrategy); - this.registerSearchStrategy(SYNC_SEARCH_STRATEGY, syncSearchStrategy); - this.registerSearchStrategy(ES_SEARCH_STRATEGY, esSearchStrategy); - const aggTypesSetup = this.aggTypesRegistry.setup(); // register each agg type @@ -121,7 +86,6 @@ export class SearchService implements Plugin { calculateAutoTimeExpression: getCalculateAutoTimeExpression(core.uiSettings), types: aggTypesSetup, }, - registerSearchStrategy: this.registerSearchStrategy, }; } @@ -133,18 +97,19 @@ export class SearchService implements Plugin { * their own search collector instances */ this.searchInterceptor = new SearchInterceptor( - core.notifications.toasts, - core.application, + { + toasts: core.notifications.toasts, + application: core.application, + http: core.http, + uiSettings: core.uiSettings, + }, core.injectedMetadata.getInjectedVar('esRequestTimeout') as number ); const aggTypesStart = this.aggTypesRegistry.start(); - const search: ISearchGeneric = (request, options, strategyName) => { - const { search: defaultSearch } = this.getSearchStrategy( - strategyName || DEFAULT_SEARCH_STRATEGY - ); - return this.searchInterceptor.search(defaultSearch as any, request, options); + const search: ISearchGeneric = (request, options) => { + return this.searchInterceptor.search(request, options); }; const legacySearch = { @@ -168,7 +133,6 @@ export class SearchService implements Plugin { }, types: aggTypesStart, }, - getSearchStrategy: this.getSearchStrategy, search, searchSource: { create: createSearchSource(dependencies.indexPatterns, searchSourceDependencies), From 061f9eed50e117a0107f51a7609e77e5a6fd65b6 Mon Sep 17 00:00:00 2001 From: Liza K Date: Wed, 8 Jul 2020 10:27:01 +0300 Subject: [PATCH 18/21] fix backport --- .../data/server/search/search_service.ts | 3 -- src/plugins/data/server/server.api.md | 48 +++++++++---------- 2 files changed, 24 insertions(+), 27 deletions(-) diff --git a/src/plugins/data/server/search/search_service.ts b/src/plugins/data/server/search/search_service.ts index 950cdf6cefc3e..20f9a7488893f 100644 --- a/src/plugins/data/server/search/search_service.ts +++ b/src/plugins/data/server/search/search_service.ts @@ -26,7 +26,6 @@ import { import { ISearchSetup, ISearchStart, ISearchStrategy } from './types'; import { registerSearchRoute } from './routes'; import { ES_SEARCH_STRATEGY, esSearchStrategyProvider } from './es_search'; -import { searchSavedObjectType } from '../saved_objects'; import { DataPluginStart } from '../plugin'; import { IEsSearchRequest } from '../../common'; @@ -40,8 +39,6 @@ export class SearchService implements Plugin { constructor(private initializerContext: PluginInitializerContext) {} public setup(core: CoreSetup): ISearchSetup { - core.savedObjects.registerType(searchSavedObjectType); - this.registerSearchStrategy( ES_SEARCH_STRATEGY, esSearchStrategyProvider(this.initializerContext.config.legacy.globalConfig$) diff --git a/src/plugins/data/server/server.api.md b/src/plugins/data/server/server.api.md index f0c6c0b8ffc62..dbbfee525c000 100644 --- a/src/plugins/data/server/server.api.md +++ b/src/plugins/data/server/server.api.md @@ -764,30 +764,30 @@ export const UI_SETTINGS: { // src/plugins/data/server/index.ts:40:23 - (ae-forgotten-export) The symbol "buildFilter" needs to be exported by the entry point index.d.ts // src/plugins/data/server/index.ts:71:21 - (ae-forgotten-export) The symbol "getEsQueryConfig" needs to be exported by the entry point index.d.ts // src/plugins/data/server/index.ts:71:21 - (ae-forgotten-export) The symbol "buildEsQuery" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/index.ts:103:26 - (ae-forgotten-export) The symbol "FieldFormatsRegistry" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/index.ts:103:26 - (ae-forgotten-export) The symbol "FieldFormat" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/index.ts:103:26 - (ae-forgotten-export) The symbol "BoolFormat" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/index.ts:103:26 - (ae-forgotten-export) The symbol "BytesFormat" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/index.ts:103:26 - (ae-forgotten-export) The symbol "ColorFormat" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/index.ts:103:26 - (ae-forgotten-export) The symbol "DateNanosFormat" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/index.ts:103:26 - (ae-forgotten-export) The symbol "DurationFormat" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/index.ts:103:26 - (ae-forgotten-export) The symbol "IpFormat" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/index.ts:103:26 - (ae-forgotten-export) The symbol "NumberFormat" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/index.ts:103:26 - (ae-forgotten-export) The symbol "PercentFormat" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/index.ts:103:26 - (ae-forgotten-export) The symbol "RelativeDateFormat" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/index.ts:103:26 - (ae-forgotten-export) The symbol "SourceFormat" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/index.ts:103:26 - (ae-forgotten-export) The symbol "StaticLookupFormat" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/index.ts:103:26 - (ae-forgotten-export) The symbol "UrlFormat" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/index.ts:103:26 - (ae-forgotten-export) The symbol "StringFormat" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/index.ts:103:26 - (ae-forgotten-export) The symbol "TruncateFormat" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/index.ts:131:27 - (ae-forgotten-export) The symbol "isFilterable" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/index.ts:131:27 - (ae-forgotten-export) The symbol "isNestedField" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/index.ts:186:1 - (ae-forgotten-export) The symbol "dateHistogramInterval" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/index.ts:187:1 - (ae-forgotten-export) The symbol "InvalidEsCalendarIntervalError" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/index.ts:188:1 - (ae-forgotten-export) The symbol "InvalidEsIntervalFormatError" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/index.ts:189:1 - (ae-forgotten-export) The symbol "isValidEsInterval" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/index.ts:190:1 - (ae-forgotten-export) The symbol "isValidInterval" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/index.ts:193:1 - (ae-forgotten-export) The symbol "toAbsoluteDates" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index.ts:102:26 - (ae-forgotten-export) The symbol "FieldFormatsRegistry" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index.ts:102:26 - (ae-forgotten-export) The symbol "FieldFormat" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index.ts:102:26 - (ae-forgotten-export) The symbol "BoolFormat" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index.ts:102:26 - (ae-forgotten-export) The symbol "BytesFormat" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index.ts:102:26 - (ae-forgotten-export) The symbol "ColorFormat" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index.ts:102:26 - (ae-forgotten-export) The symbol "DateNanosFormat" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index.ts:102:26 - (ae-forgotten-export) The symbol "DurationFormat" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index.ts:102:26 - (ae-forgotten-export) The symbol "IpFormat" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index.ts:102:26 - (ae-forgotten-export) The symbol "NumberFormat" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index.ts:102:26 - (ae-forgotten-export) The symbol "PercentFormat" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index.ts:102:26 - (ae-forgotten-export) The symbol "RelativeDateFormat" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index.ts:102:26 - (ae-forgotten-export) The symbol "SourceFormat" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index.ts:102:26 - (ae-forgotten-export) The symbol "StaticLookupFormat" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index.ts:102:26 - (ae-forgotten-export) The symbol "UrlFormat" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index.ts:102:26 - (ae-forgotten-export) The symbol "StringFormat" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index.ts:102:26 - (ae-forgotten-export) The symbol "TruncateFormat" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index.ts:129:27 - (ae-forgotten-export) The symbol "isFilterable" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index.ts:129:27 - (ae-forgotten-export) The symbol "isNestedField" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index.ts:179:1 - (ae-forgotten-export) The symbol "dateHistogramInterval" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index.ts:180:1 - (ae-forgotten-export) The symbol "InvalidEsCalendarIntervalError" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index.ts:181:1 - (ae-forgotten-export) The symbol "InvalidEsIntervalFormatError" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index.ts:182:1 - (ae-forgotten-export) The symbol "isValidEsInterval" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index.ts:183:1 - (ae-forgotten-export) The symbol "isValidInterval" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index.ts:186:1 - (ae-forgotten-export) The symbol "toAbsoluteDates" needs to be exported by the entry point index.d.ts // (No @packageDocumentation comment for this package) From 6d86b3863b24df65f2bda398bb316edb3fbf5785 Mon Sep 17 00:00:00 2001 From: Liza K Date: Mon, 13 Jul 2020 09:28:32 +0300 Subject: [PATCH 19/21] types --- src/plugins/data/server/search/types.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/plugins/data/server/search/types.ts b/src/plugins/data/server/search/types.ts index 509b18f6ce014..88dfd9681fdf5 100644 --- a/src/plugins/data/server/search/types.ts +++ b/src/plugins/data/server/search/types.ts @@ -21,6 +21,13 @@ import { RequestHandlerContext } from '../../../../core/server'; import { IKibanaSearchResponse, IKibanaSearchRequest } from '../../common/search'; import { IEsSearchRequest, IEsSearchResponse } from './es_search'; +export interface ISearchOptions { + /** + * An `AbortSignal` that allows the caller of `search` to abort a search request. + */ + signal?: AbortSignal; +} + export interface ISearchSetup { /** * Extension point exposed for other plugins to register their own search @@ -38,17 +45,10 @@ export interface ISearchStart { search: ( context: RequestHandlerContext, request: IKibanaSearchRequest, - options: any + options: ISearchOptions ) => Promise; } -export interface ISearchOptions { - /** - * An `AbortSignal` that allows the caller of `search` to abort a search request. - */ - signal?: AbortSignal; -} - /** * Search strategy interface contains a search method that takes in a request and returns a promise * that resolves to a response. From c3bc240c601c951312051c62b318333b65bbe869 Mon Sep 17 00:00:00 2001 From: Liza K Date: Mon, 13 Jul 2020 19:09:02 +0300 Subject: [PATCH 20/21] TS for strategy --- src/plugins/data/server/search/types.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/plugins/data/server/search/types.ts b/src/plugins/data/server/search/types.ts index 88dfd9681fdf5..12f1a1a508bd2 100644 --- a/src/plugins/data/server/search/types.ts +++ b/src/plugins/data/server/search/types.ts @@ -26,6 +26,7 @@ export interface ISearchOptions { * An `AbortSignal` that allows the caller of `search` to abort a search request. */ signal?: AbortSignal; + strategy?: string; } export interface ISearchSetup { From 7dbe5b4a2da10637e23eaa46b975bee0b5dac6cd Mon Sep 17 00:00:00 2001 From: Liza K Date: Mon, 13 Jul 2020 19:57:18 +0300 Subject: [PATCH 21/21] docs --- ...ibana-plugin-plugins-data-server.isearchoptions.md | 1 + ...gin-plugins-data-server.isearchoptions.strategy.md | 11 +++++++++++ .../kibana-plugin-plugins-data-server.isearchstart.md | 2 +- ...-plugin-plugins-data-server.isearchstart.search.md | 2 +- src/plugins/data/server/server.api.md | 4 +++- 5 files changed, 17 insertions(+), 3 deletions(-) create mode 100644 docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchoptions.strategy.md diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchoptions.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchoptions.md index 49412fc42d3b5..002ce864a1aa4 100644 --- a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchoptions.md +++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchoptions.md @@ -15,4 +15,5 @@ export interface ISearchOptions | Property | Type | Description | | --- | --- | --- | | [signal](./kibana-plugin-plugins-data-server.isearchoptions.signal.md) | AbortSignal | An AbortSignal that allows the caller of search to abort a search request. | +| [strategy](./kibana-plugin-plugins-data-server.isearchoptions.strategy.md) | string | | diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchoptions.strategy.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchoptions.strategy.md new file mode 100644 index 0000000000000..6df72d023e2c0 --- /dev/null +++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchoptions.strategy.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) > [ISearchOptions](./kibana-plugin-plugins-data-server.isearchoptions.md) > [strategy](./kibana-plugin-plugins-data-server.isearchoptions.strategy.md) + +## ISearchOptions.strategy property + +Signature: + +```typescript +strategy?: string; +``` diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchstart.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchstart.md index be64eeb39c117..308ce3cb568bc 100644 --- a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchstart.md +++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchstart.md @@ -15,5 +15,5 @@ export interface ISearchStart | Property | Type | Description | | --- | --- | --- | | [getSearchStrategy](./kibana-plugin-plugins-data-server.isearchstart.getsearchstrategy.md) | (name: string) => ISearchStrategy | Get other registered search strategies. For example, if a new strategy needs to use the already-registered ES search strategy, it can use this function to accomplish that. | -| [search](./kibana-plugin-plugins-data-server.isearchstart.search.md) | (context: RequestHandlerContext, request: IKibanaSearchRequest, options: any) => Promise<IKibanaSearchResponse> | | +| [search](./kibana-plugin-plugins-data-server.isearchstart.search.md) | (context: RequestHandlerContext, request: IKibanaSearchRequest, options: ISearchOptions) => Promise<IKibanaSearchResponse> | | diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchstart.search.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchstart.search.md index b0fa0d6d0b1fe..1c2ae91699559 100644 --- a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchstart.search.md +++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchstart.search.md @@ -7,5 +7,5 @@ Signature: ```typescript -search: (context: RequestHandlerContext, request: IKibanaSearchRequest, options: any) => Promise; +search: (context: RequestHandlerContext, request: IKibanaSearchRequest, options: ISearchOptions) => Promise; ``` diff --git a/src/plugins/data/server/server.api.md b/src/plugins/data/server/server.api.md index 14a6e7bfabfe8..0c32358f36caa 100644 --- a/src/plugins/data/server/server.api.md +++ b/src/plugins/data/server/server.api.md @@ -513,6 +513,8 @@ export class IndexPatternsFetcher { // @public (undocumented) export interface ISearchOptions { signal?: AbortSignal; + // (undocumented) + strategy?: string; } // Warning: (ae-missing-release-tag) "ISearchSetup" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) @@ -532,7 +534,7 @@ export interface ISearchStart { // Warning: (ae-forgotten-export) The symbol "IKibanaSearchResponse" needs to be exported by the entry point index.d.ts // // (undocumented) - search: (context: RequestHandlerContext, request: IKibanaSearchRequest, options: any) => Promise; + search: (context: RequestHandlerContext, request: IKibanaSearchRequest, options: ISearchOptions) => Promise; } // Warning: (ae-missing-release-tag) "ISearchStrategy" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)