Skip to content

Commit

Permalink
Update autocomplete to use settings from config rather than advanced …
Browse files Browse the repository at this point in the history
…settings (elastic#58788)
  • Loading branch information
lukasolson authored Feb 28, 2020
1 parent 3c92fc8 commit 8afa902
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 14 deletions.
7 changes: 6 additions & 1 deletion src/core/server/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,12 @@ import { uuidServiceMock } from './uuid/uuid_service.mock';

export function pluginInitializerContextConfigMock<T>(config: T) {
const globalConfig: SharedGlobalConfig = {
kibana: { defaultAppId: 'home-mocks', index: '.kibana-tests' },
kibana: {
defaultAppId: 'home-mocks',
index: '.kibana-tests',
autocompleteTerminateAfter: duration(100000),
autocompleteTimeout: duration(1000),
},
elasticsearch: {
shardTimeout: duration('30s'),
requestTimeout: duration('30s'),
Expand Down
7 changes: 6 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,12 @@ describe('Plugin Context', () => {
.pipe(first())
.toPromise();
expect(configObject).toStrictEqual({
kibana: { defaultAppId: 'home', index: '.kibana' },
kibana: {
defaultAppId: 'home',
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 @@ -209,7 +209,7 @@ export interface Plugin<

export const SharedGlobalConfigKeys = {
// We can add more if really needed
kibana: ['defaultAppId', 'index'] as const,
kibana: ['defaultAppId', '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,11 +19,16 @@

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, indexPatterns, esFilters } from '../index';

export function registerValueSuggestionsRoute(router: IRouter) {
export function registerValueSuggestionsRoute(
router: IRouter,
config$: Observable<SharedGlobalConfig>
) {
router.post(
{
path: '/api/kibana/suggestions/values/{index}',
Expand All @@ -45,14 +50,14 @@ 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 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 indexPatterns.findIndexPatternById(
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 @@ -37,13 +37,14 @@ export class DataServerPlugin implements Plugin<DataPluginSetup> {
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();

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

0 comments on commit 8afa902

Please sign in to comment.