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

[Autocomplete] Use settings from config rather than UI settings #58784

Merged
merged 7 commits into from
Feb 28, 2020
6 changes: 5 additions & 1 deletion src/core/server/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ import { uuidServiceMock } from './uuid/uuid_service.mock';

export function pluginInitializerContextConfigMock<T>(config: T) {
const globalConfig: SharedGlobalConfig = {
kibana: { index: '.kibana-tests' },
kibana: {
index: '.kibana-tests',
autocompleteTerminateAfter: duration(100000),
autocompleteTimeout: duration(1000),
},
elasticsearch: {
shardTimeout: duration('30s'),
requestTimeout: duration('30s'),
Expand Down
6 changes: 5 additions & 1 deletion src/core/server/plugins/plugin_context.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,11 @@ describe('Plugin Context', () => {
.pipe(first())
.toPromise();
expect(configObject).toStrictEqual({
kibana: { index: '.kibana' },
kibana: {
index: '.kibana',
autocompleteTerminateAfter: duration(100000),
autocompleteTimeout: duration(1000),
},
elasticsearch: {
shardTimeout: duration(30, 's'),
requestTimeout: duration(30, 's'),
Expand Down
2 changes: 1 addition & 1 deletion src/core/server/plugins/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ export interface Plugin<

export const SharedGlobalConfigKeys = {
// We can add more if really needed
kibana: ['index'] as const,
kibana: ['index', 'autocompleteTerminateAfter', 'autocompleteTimeout'] as const,
elasticsearch: ['shardTimeout', 'requestTimeout', 'pingTimeout', 'startupTimeout'] as const,
path: ['data'] as const,
};
Expand Down
6 changes: 4 additions & 2 deletions src/plugins/data/server/autocomplete/autocomplete_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@
* under the License.
*/

import { CoreSetup, Plugin } from 'kibana/server';
import { CoreSetup, Plugin, PluginInitializerContext } from 'kibana/server';
import { registerRoutes } from './routes';

export class AutocompleteService implements Plugin<void> {
constructor(private initializerContext: PluginInitializerContext) {}

public setup(core: CoreSetup) {
registerRoutes(core);
registerRoutes(core, this.initializerContext.config.legacy.globalConfig$);
}

public start() {}
Expand Down
7 changes: 4 additions & 3 deletions src/plugins/data/server/autocomplete/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@
* under the License.
*/

import { CoreSetup } from 'kibana/server';
import { Observable } from 'rxjs';
import { CoreSetup, SharedGlobalConfig } from 'kibana/server';
import { registerValueSuggestionsRoute } from './value_suggestions_route';

export function registerRoutes({ http }: CoreSetup): void {
export function registerRoutes({ http }: CoreSetup, config$: Observable<SharedGlobalConfig>): void {
const router = http.createRouter();

registerValueSuggestionsRoute(router);
registerValueSuggestionsRoute(router, config$);
}
15 changes: 10 additions & 5 deletions src/plugins/data/server/autocomplete/value_suggestions_route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,18 @@

import { get, map } from 'lodash';
import { schema } from '@kbn/config-schema';
import { IRouter } from 'kibana/server';
import { IRouter, SharedGlobalConfig } from 'kibana/server';

import { Observable } from 'rxjs';
import { first } from 'rxjs/operators';
import { IFieldType, Filter } from '../index';
import { findIndexPatternById, getFieldByName } from '../index_patterns';
import { getRequestAbortedSignal } from '../lib';

export function registerValueSuggestionsRoute(router: IRouter) {
export function registerValueSuggestionsRoute(
router: IRouter,
config$: Observable<SharedGlobalConfig>
) {
router.post(
{
path: '/api/kibana/suggestions/values/{index}',
Expand All @@ -47,15 +52,15 @@ export function registerValueSuggestionsRoute(router: IRouter) {
},
},
async (context, request, response) => {
const { client: uiSettings } = context.core.uiSettings;
const config = await config$.pipe(first()).toPromise();
const { field: fieldName, query, boolFilter } = request.body;
const { index } = request.params;
const { dataClient } = context.core.elasticsearch;
const signal = getRequestAbortedSignal(request.events.aborted$);

const autocompleteSearchOptions = {
timeout: await uiSettings.get<number>('kibana.autocompleteTimeout'),
terminate_after: await uiSettings.get<number>('kibana.autocompleteTerminateAfter'),
timeout: `${config.kibana.autocompleteTimeout.asMilliseconds()}ms`,
terminate_after: config.kibana.autocompleteTerminateAfter.asMilliseconds(),
};

const indexPattern = await findIndexPatternById(context.core.savedObjects.client, index);
Expand Down
3 changes: 2 additions & 1 deletion src/plugins/data/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,15 @@ export class DataServerPlugin implements Plugin<DataPluginSetup, DataPluginStart
private readonly searchService: SearchService;
private readonly scriptsService: ScriptsService;
private readonly kqlTelemetryService: KqlTelemetryService;
private readonly autocompleteService = new AutocompleteService();
private readonly autocompleteService: AutocompleteService;
private readonly indexPatterns = new IndexPatternsService();
private readonly fieldFormats = new FieldFormatsService();

constructor(initializerContext: PluginInitializerContext) {
this.searchService = new SearchService(initializerContext);
this.scriptsService = new ScriptsService();
this.kqlTelemetryService = new KqlTelemetryService(initializerContext);
this.autocompleteService = new AutocompleteService(initializerContext);
}

public setup(core: CoreSetup, { usageCollection }: DataPluginSetupDependencies) {
Expand Down