Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't overwrite sync strategy in xpack #75556

Merged
merged 7 commits into from
Aug 25, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ export interface ISearchSetup
| --- | --- | --- |
| [aggs](./kibana-plugin-plugins-data-server.isearchsetup.aggs.md) | <code>AggsSetup</code> | |
| [registerSearchStrategy](./kibana-plugin-plugins-data-server.isearchsetup.registersearchstrategy.md) | <code>(name: string, strategy: ISearchStrategy) =&gt; void</code> | Extension point exposed for other plugins to register their own search strategies. |
| [setDefaultSearchStrategy](./kibana-plugin-plugins-data-server.isearchsetup.setdefaultsearchstrategy.md) | <code>(name: string) =&gt; void</code> | |
| [usage](./kibana-plugin-plugins-data-server.isearchsetup.usage.md) | <code>SearchUsage</code> | Used internally for telemetry |

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) &gt; [ISearchSetup](./kibana-plugin-plugins-data-server.isearchsetup.md) &gt; [setDefaultSearchStrategy](./kibana-plugin-plugins-data-server.isearchsetup.setdefaultsearchstrategy.md)

## ISearchSetup.setDefaultSearchStrategy property

<b>Signature:</b>

```typescript
setDefaultSearchStrategy: (name: string) => void;
```
3 changes: 0 additions & 3 deletions src/plugins/data/common/search/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ export * from './expressions';
export * from './tabify';
export * from './types';

import { ES_SEARCH_STRATEGY } from './es_search';
export const DEFAULT_SEARCH_STRATEGY = ES_SEARCH_STRATEGY;

export {
IEsSearchRequest,
IEsSearchResponse,
Expand Down
1 change: 1 addition & 0 deletions src/plugins/data/server/search/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export function createSearchSetupMock(): jest.Mocked<ISearchSetup> {
return {
aggs: searchAggsSetupMock(),
registerSearchStrategy: jest.fn(),
setDefaultSearchStrategy: jest.fn(),
};
}

Expand Down
14 changes: 9 additions & 5 deletions src/plugins/data/server/search/search_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export interface SearchServiceStartDependencies {
export class SearchService implements Plugin<ISearchSetup, ISearchStart> {
private readonly aggsService = new AggsService();
private searchStrategies: StrategyMap = {};
private defaultSearchStrategyName: string = ES_SEARCH_STRATEGY;

constructor(
private initializerContext: PluginInitializerContext,
Expand Down Expand Up @@ -88,6 +89,11 @@ export class SearchService implements Plugin<ISearchSetup, ISearchStart> {
return {
aggs: this.aggsService.setup({ registerFunction }),
registerSearchStrategy: this.registerSearchStrategy,
setDefaultSearchStrategy: (name: string) => {
if (this.searchStrategies.hasOwnProperty(name)) {
this.defaultSearchStrategyName = name;
}
},
usage,
};
}
Expand All @@ -97,11 +103,9 @@ export class SearchService implements Plugin<ISearchSetup, ISearchStart> {
searchRequest: IEsSearchRequest,
options: Record<string, any>
) {
return this.getSearchStrategy(options.strategy || ES_SEARCH_STRATEGY).search(
context,
searchRequest,
{ signal: options.signal }
);
return this.getSearchStrategy(
options.strategy || this.defaultSearchStrategyName
).search(context, searchRequest, { signal: options.signal });
}

public start(
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/data/server/search/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ export interface ISearchSetup {
*/
registerSearchStrategy: (name: string, strategy: ISearchStrategy) => void;

setDefaultSearchStrategy: (name: string) => void;

/**
* Used internally for telemetry
*/
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/data/server/server.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -690,6 +690,8 @@ export interface ISearchSetup {
// (undocumented)
aggs: AggsSetup;
registerSearchStrategy: (name: string, strategy: ISearchStrategy) => void;
// (undocumented)
setDefaultSearchStrategy: (name: string) => void;
usage?: SearchUsage;
}

Expand Down
7 changes: 6 additions & 1 deletion x-pack/plugins/data_enhanced/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,9 @@
* you may not use this file except in compliance with the Elastic License.
*/

export { EnhancedSearchParams, IEnhancedEsSearchRequest, IAsyncSearchRequest } from './search';
export {
EnhancedSearchParams,
IEnhancedEsSearchRequest,
IAsyncSearchRequest,
ENHANCED_ES_SEARCH_STRATEGY,
} from './search';
7 changes: 6 additions & 1 deletion x-pack/plugins/data_enhanced/common/search/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,9 @@
* you may not use this file except in compliance with the Elastic License.
*/

export { EnhancedSearchParams, IEnhancedEsSearchRequest, IAsyncSearchRequest } from './types';
export {
EnhancedSearchParams,
IEnhancedEsSearchRequest,
IAsyncSearchRequest,
ENHANCED_ES_SEARCH_STRATEGY,
} from './types';
2 changes: 2 additions & 0 deletions x-pack/plugins/data_enhanced/common/search/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

import { IEsSearchRequest, ISearchRequestParams } from '../../../../../src/plugins/data/common';

export const ENHANCED_ES_SEARCH_STRATEGY = 'ese';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we give this a more meaningful name like enhanced_es or something?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to keep it shorter, as this is what gets sent in the URL.
I think keeping it short is clearer, and we use the constant name elsewhere anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And I did change it to use the enhance pattern. I agree it makes more sense this way.


export interface EnhancedSearchParams extends ISearchRequestParams {
ignoreThrottled: boolean;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
} from '../../../../../src/plugins/data/public';
import { AbortError, toPromise } from '../../../../../src/plugins/data/common';
import { IAsyncSearchOptions } from '.';
import { IAsyncSearchRequest } from '../../common';
import { IAsyncSearchRequest, ENHANCED_ES_SEARCH_STRATEGY } from '../../common';

export class EnhancedSearchInterceptor extends SearchInterceptor {
/**
Expand Down Expand Up @@ -76,10 +76,11 @@ export class EnhancedSearchInterceptor extends SearchInterceptor {

const { combinedSignal, cleanup } = this.setupTimers(options);
const aborted$ = from(toPromise(combinedSignal));
const strategy = options?.strategy || ENHANCED_ES_SEARCH_STRATEGY;

this.pendingCount$.next(this.pendingCount$.getValue() + 1);

return this.runSearch(request, combinedSignal, options?.strategy).pipe(
return this.runSearch(request, combinedSignal, strategy).pipe(
expand((response) => {
// If the response indicates of an error, stop polling and complete the observable
if (!response || (!response.isRunning && response.isPartial)) {
Expand All @@ -96,7 +97,7 @@ export class EnhancedSearchInterceptor extends SearchInterceptor {
return timer(pollInterval).pipe(
// Send future requests using just the ID from the response
mergeMap(() => {
return this.runSearch({ id }, combinedSignal, options?.strategy);
return this.runSearch({ id }, combinedSignal, strategy);
})
);
}),
Expand Down
6 changes: 4 additions & 2 deletions x-pack/plugins/data_enhanced/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ import {
Plugin,
Logger,
} from '../../../../src/core/server';
import { ES_SEARCH_STRATEGY } from '../../../../src/plugins/data/common';
import {
PluginSetup as DataPluginSetup,
PluginStart as DataPluginStart,
usageProvider,
} from '../../../../src/plugins/data/server';
import { enhancedEsSearchStrategyProvider } from './search';
import { UsageCollectionSetup } from '../../../../src/plugins/usage_collection/server';
import { ENHANCED_ES_SEARCH_STRATEGY } from '../common';

interface SetupDependencies {
data: DataPluginSetup;
Expand All @@ -36,13 +36,15 @@ export class EnhancedDataServerPlugin implements Plugin<void, void, SetupDepende
const usage = deps.usageCollection ? usageProvider(core) : undefined;

deps.data.search.registerSearchStrategy(
ES_SEARCH_STRATEGY,
ENHANCED_ES_SEARCH_STRATEGY,
enhancedEsSearchStrategyProvider(
this.initializerContext.config.legacy.globalConfig$,
this.logger,
usage
)
);

deps.data.search.setDefaultSearchStrategy(ENHANCED_ES_SEARCH_STRATEGY);
}

public start(core: CoreStart) {}
Expand Down