From 8edb316e6933406f9619748d25482cfff1ca8d23 Mon Sep 17 00:00:00 2001 From: Lukas Olson Date: Tue, 1 Jun 2021 12:36:07 -0700 Subject: [PATCH] Migrate kibana.autocomplete config to data plugin (#100586) * Migrate kibana.autocomplete config to data plugin * Fix CI * Fix tests Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> --- docs/setup/settings.asciidoc | 4 +- src/core/server/kibana_config.test.ts | 2 - src/core/server/kibana_config.ts | 6 -- src/core/server/mocks.ts | 2 - src/core/server/plugins/legacy_config.test.ts | 4 -- .../server/plugins/plugin_context.test.ts | 2 - src/core/server/plugins/types.ts | 2 +- src/plugins/data/config.ts | 2 + .../autocomplete/autocomplete_service.ts | 9 ++- src/plugins/data/public/mocks.ts | 5 +- .../autocomplete/autocomplete_service.ts | 8 +-- .../data/server/autocomplete/routes.ts | 5 +- .../autocomplete/value_suggestions_route.ts | 12 ++-- .../data/server/config_deprecations.test.ts | 71 +++++++++++++++++++ .../data/server/config_deprecations.ts | 19 +++++ src/plugins/data/server/index.ts | 2 + src/plugins/data/server/server.api.md | 24 +++---- src/plugins/input_control_vis/kibana.json | 2 +- .../input_control_vis/public/plugin.ts | 11 +-- src/plugins/input_control_vis/server/index.ts | 42 ----------- 20 files changed, 134 insertions(+), 100 deletions(-) create mode 100644 src/plugins/data/server/config_deprecations.test.ts create mode 100644 src/plugins/data/server/config_deprecations.ts delete mode 100644 src/plugins/input_control_vis/server/index.ts diff --git a/docs/setup/settings.asciidoc b/docs/setup/settings.asciidoc index bac2b0ebdf15fa..6e8026c4a747df 100644 --- a/docs/setup/settings.asciidoc +++ b/docs/setup/settings.asciidoc @@ -262,11 +262,11 @@ on the {kib} index at startup. {kib} users still need to authenticate with {es} {ref}/indices-create-index.html[index name limitations]. *Default: `".kibana"`* -| `kibana.autocompleteTimeout:` {ess-icon} +| `data.autocomplete.valueSuggestions.timeout:` {ess-icon} | Time in milliseconds to wait for autocomplete suggestions from {es}. This value must be a whole number greater than zero. *Default: `"1000"`* -| `kibana.autocompleteTerminateAfter:` {ess-icon} +| `data.autocomplete.valueSuggestions.terminateAfter:` {ess-icon} | Maximum number of documents loaded by each shard to generate autocomplete suggestions. This value must be a whole number greater than zero. *Default: `"100000"`* diff --git a/src/core/server/kibana_config.test.ts b/src/core/server/kibana_config.test.ts index 47bb6cf2a064c8..72ddb3b65081b5 100644 --- a/src/core/server/kibana_config.test.ts +++ b/src/core/server/kibana_config.test.ts @@ -22,8 +22,6 @@ it('set correct defaults ', () => { const configValue = config.schema.validate({}); expect(configValue).toMatchInlineSnapshot(` Object { - "autocompleteTerminateAfter": "PT1M40S", - "autocompleteTimeout": "PT1S", "enabled": true, "index": ".kibana", } diff --git a/src/core/server/kibana_config.ts b/src/core/server/kibana_config.ts index 848c51dcb69f36..623ffa86c0e8d9 100644 --- a/src/core/server/kibana_config.ts +++ b/src/core/server/kibana_config.ts @@ -29,12 +29,6 @@ export const config = { schema: schema.object({ enabled: schema.boolean({ defaultValue: true }), index: schema.string({ defaultValue: '.kibana' }), - autocompleteTerminateAfter: schema.duration({ defaultValue: 100000 }), - autocompleteTimeout: schema.duration({ defaultValue: 1000 }), }), deprecations, - exposeToUsage: { - autocompleteTerminateAfter: true, - autocompleteTimeout: true, - }, }; diff --git a/src/core/server/mocks.ts b/src/core/server/mocks.ts index 6f1b9dc5bf8203..0d52ff64499c1c 100644 --- a/src/core/server/mocks.ts +++ b/src/core/server/mocks.ts @@ -58,8 +58,6 @@ export function pluginInitializerContextConfigMock(config: T) { const globalConfig: SharedGlobalConfig = { kibana: { index: '.kibana-tests', - autocompleteTerminateAfter: duration(100000), - autocompleteTimeout: duration(1000), }, elasticsearch: { shardTimeout: duration('30s'), diff --git a/src/core/server/plugins/legacy_config.test.ts b/src/core/server/plugins/legacy_config.test.ts index 0ea26f2e0333e0..2a980e38a4e191 100644 --- a/src/core/server/plugins/legacy_config.test.ts +++ b/src/core/server/plugins/legacy_config.test.ts @@ -43,8 +43,6 @@ describe('Legacy config', () => { expect(legacyConfig).toStrictEqual({ kibana: { index: '.kibana', - autocompleteTerminateAfter: duration(100000), - autocompleteTimeout: duration(1000), }, elasticsearch: { shardTimeout: duration(30, 's'), @@ -66,8 +64,6 @@ describe('Legacy config', () => { expect(legacyConfig).toStrictEqual({ kibana: { index: '.kibana', - autocompleteTerminateAfter: duration(100000), - autocompleteTimeout: duration(1000), }, elasticsearch: { shardTimeout: duration(30, 's'), diff --git a/src/core/server/plugins/plugin_context.test.ts b/src/core/server/plugins/plugin_context.test.ts index e37d985d423212..4ba34ccb2149f0 100644 --- a/src/core/server/plugins/plugin_context.test.ts +++ b/src/core/server/plugins/plugin_context.test.ts @@ -115,8 +115,6 @@ describe('createPluginInitializerContext', () => { expect(configObject).toStrictEqual({ kibana: { index: '.kibana', - autocompleteTerminateAfter: duration(100000), - autocompleteTimeout: duration(1000), }, elasticsearch: { shardTimeout: duration(30, 's'), diff --git a/src/core/server/plugins/types.ts b/src/core/server/plugins/types.ts index 2b5acd8ed5e940..6b50b5e820665e 100644 --- a/src/core/server/plugins/types.ts +++ b/src/core/server/plugins/types.ts @@ -313,7 +313,7 @@ export interface AsyncPlugin< export const SharedGlobalConfigKeys = { // We can add more if really needed - kibana: ['index', 'autocompleteTerminateAfter', 'autocompleteTimeout'] as const, + kibana: ['index'] as const, elasticsearch: ['shardTimeout', 'requestTimeout', 'pingTimeout'] as const, path: ['data'] as const, savedObjects: ['maxImportPayloadBytes'] as const, diff --git a/src/plugins/data/config.ts b/src/plugins/data/config.ts index 72fa547f44a77b..9306b64019bbc7 100644 --- a/src/plugins/data/config.ts +++ b/src/plugins/data/config.ts @@ -15,6 +15,8 @@ export const configSchema = schema.object({ }), valueSuggestions: schema.object({ enabled: schema.boolean({ defaultValue: true }), + terminateAfter: schema.duration({ defaultValue: 100000 }), + timeout: schema.duration({ defaultValue: 1000 }), }), }), search: schema.object({ diff --git a/src/plugins/data/public/autocomplete/autocomplete_service.ts b/src/plugins/data/public/autocomplete/autocomplete_service.ts index eb9d859664c4d4..67efbe2af29ce8 100644 --- a/src/plugins/data/public/autocomplete/autocomplete_service.ts +++ b/src/plugins/data/public/autocomplete/autocomplete_service.ts @@ -7,6 +7,7 @@ */ import { CoreSetup, PluginInitializerContext } from 'src/core/public'; +import moment from 'moment'; import { TimefilterSetup } from '../query'; import { QuerySuggestionGetFn } from './providers/query_suggestion_provider'; import { @@ -27,7 +28,7 @@ import { DataPublicPluginStart, DataStartDependencies } from '../types'; export class AutocompleteService { autocompleteConfig: ConfigSchema['autocomplete']; - constructor(initializerContext: PluginInitializerContext) { + constructor(private initializerContext: PluginInitializerContext) { const { autocomplete } = initializerContext.config.get(); this.autocompleteConfig = autocomplete; @@ -55,6 +56,8 @@ export class AutocompleteService { usageCollection, }: { timefilter: TimefilterSetup; usageCollection?: UsageCollectionSetup } ) { + const { autocomplete } = this.initializerContext.config.get(); + const { terminateAfter, timeout } = autocomplete.valueSuggestions; const usageCollector = createUsageCollector(core.getStartServices, usageCollection); this.getValueSuggestions = this.autocompleteConfig.valueSuggestions.enabled @@ -71,6 +74,10 @@ export class AutocompleteService { * please use "getQuerySuggestions" from the start contract */ getQuerySuggestions: this.getQuerySuggestions, + getAutocompleteSettings: () => ({ + terminateAfter: moment.duration(terminateAfter).asMilliseconds(), + timeout: moment.duration(timeout).asMilliseconds(), + }), }; } diff --git a/src/plugins/data/public/mocks.ts b/src/plugins/data/public/mocks.ts index f5def327b5473b..1277e31be2103c 100644 --- a/src/plugins/data/public/mocks.ts +++ b/src/plugins/data/public/mocks.ts @@ -16,8 +16,9 @@ import { createNowProviderMock } from './now_provider/mocks'; export type Setup = jest.Mocked>; export type Start = jest.Mocked>; -const automcompleteSetupMock: jest.Mocked = { +const autocompleteSetupMock: jest.Mocked = { getQuerySuggestions: jest.fn(), + getAutocompleteSettings: jest.fn(), }; const autocompleteStartMock: jest.Mocked = { @@ -29,7 +30,7 @@ const autocompleteStartMock: jest.Mocked = { const createSetupContract = (): Setup => { const querySetupMock = queryServiceMock.createSetupContract(); return { - autocomplete: automcompleteSetupMock, + autocomplete: autocompleteSetupMock, search: searchServiceMock.createSetupContract(), fieldFormats: fieldFormatsServiceMock.createSetupContract(), query: querySetupMock, diff --git a/src/plugins/data/server/autocomplete/autocomplete_service.ts b/src/plugins/data/server/autocomplete/autocomplete_service.ts index 5633a78ab53fab..ef718af2ab3975 100644 --- a/src/plugins/data/server/autocomplete/autocomplete_service.ts +++ b/src/plugins/data/server/autocomplete/autocomplete_service.ts @@ -6,23 +6,21 @@ * Side Public License, v 1. */ -import { TypeOf } from '@kbn/config-schema'; import { CoreSetup, Plugin, PluginInitializerContext } from 'kibana/server'; import { registerRoutes } from './routes'; -import { ConfigSchema, configSchema } from '../../config'; +import { ConfigSchema } from '../../config'; export class AutocompleteService implements Plugin { private valueSuggestionsEnabled: boolean = true; constructor(private initializerContext: PluginInitializerContext) { - initializerContext.config.create>().subscribe((configUpdate) => { + initializerContext.config.create().subscribe((configUpdate) => { this.valueSuggestionsEnabled = configUpdate.autocomplete.valueSuggestions.enabled; }); } public setup(core: CoreSetup) { - if (this.valueSuggestionsEnabled) - registerRoutes(core, this.initializerContext.config.legacy.globalConfig$); + if (this.valueSuggestionsEnabled) registerRoutes(core, this.initializerContext.config.create()); } public start() {} diff --git a/src/plugins/data/server/autocomplete/routes.ts b/src/plugins/data/server/autocomplete/routes.ts index c453094ff68749..bdefd4df87b592 100644 --- a/src/plugins/data/server/autocomplete/routes.ts +++ b/src/plugins/data/server/autocomplete/routes.ts @@ -7,10 +7,11 @@ */ import { Observable } from 'rxjs'; -import { CoreSetup, SharedGlobalConfig } from 'kibana/server'; +import { CoreSetup } from 'kibana/server'; import { registerValueSuggestionsRoute } from './value_suggestions_route'; +import { ConfigSchema } from '../../config'; -export function registerRoutes({ http }: CoreSetup, config$: Observable): void { +export function registerRoutes({ http }: CoreSetup, config$: Observable): void { const router = http.createRouter(); registerValueSuggestionsRoute(router, config$); diff --git a/src/plugins/data/server/autocomplete/value_suggestions_route.ts b/src/plugins/data/server/autocomplete/value_suggestions_route.ts index f0487b93b8ee53..b2568a5a43611b 100644 --- a/src/plugins/data/server/autocomplete/value_suggestions_route.ts +++ b/src/plugins/data/server/autocomplete/value_suggestions_route.ts @@ -8,7 +8,7 @@ import { get, map } from 'lodash'; import { schema } from '@kbn/config-schema'; -import { IRouter, SharedGlobalConfig } from 'kibana/server'; +import { IRouter } from 'kibana/server'; import { Observable } from 'rxjs'; import { first } from 'rxjs/operators'; @@ -16,11 +16,9 @@ import type { estypes } from '@elastic/elasticsearch'; import type { IFieldType } from '../index'; import { findIndexPatternById, getFieldByName } from '../index_patterns'; import { getRequestAbortedSignal } from '../lib'; +import { ConfigSchema } from '../../config'; -export function registerValueSuggestionsRoute( - router: IRouter, - config$: Observable -) { +export function registerValueSuggestionsRoute(router: IRouter, config$: Observable) { router.post( { path: '/api/kibana/suggestions/values/{index}', @@ -50,8 +48,8 @@ export function registerValueSuggestionsRoute( const signal = getRequestAbortedSignal(request.events.aborted$); const autocompleteSearchOptions = { - timeout: `${config.kibana.autocompleteTimeout.asMilliseconds()}ms`, - terminate_after: config.kibana.autocompleteTerminateAfter.asMilliseconds(), + timeout: `${config.autocomplete.valueSuggestions.timeout.asMilliseconds()}ms`, + terminate_after: config.autocomplete.valueSuggestions.terminateAfter.asMilliseconds(), }; let field: IFieldType | undefined = fieldMeta; diff --git a/src/plugins/data/server/config_deprecations.test.ts b/src/plugins/data/server/config_deprecations.test.ts new file mode 100644 index 00000000000000..28298c654f2734 --- /dev/null +++ b/src/plugins/data/server/config_deprecations.test.ts @@ -0,0 +1,71 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +import { cloneDeep } from 'lodash'; + +import { applyDeprecations, configDeprecationFactory } from '@kbn/config'; + +import { autocompleteConfigDeprecationProvider } from './config_deprecations'; + +const applyConfigDeprecations = (settings: Record = {}) => { + const deprecations = autocompleteConfigDeprecationProvider(configDeprecationFactory); + const deprecationMessages: string[] = []; + const migrated = applyDeprecations( + settings, + deprecations.map((deprecation) => ({ + deprecation, + path: '', + })), + () => ({ message }) => deprecationMessages.push(message) + ); + return { + messages: deprecationMessages, + migrated: migrated.config, + }; +}; + +describe('Config Deprecations', () => { + it('does not report deprecations for default configuration', () => { + const defaultConfig = { data: { autocomplete: { valueSuggestions: {} } } }; + const { messages, migrated } = applyConfigDeprecations(cloneDeep(defaultConfig)); + expect(migrated).toEqual(defaultConfig); + expect(messages).toHaveLength(0); + }); + + it('renames kibana.autocompleteTerminateAfter to data.autocomplete.valueSuggestions.terminateAfter', () => { + const config = { + kibana: { + autocompleteTerminateAfter: 123, + }, + }; + const { messages, migrated } = applyConfigDeprecations(cloneDeep(config)); + expect(migrated.kibana.autocompleteTerminateAfter).not.toBeDefined(); + expect(migrated.data.autocomplete.valueSuggestions.terminateAfter).toEqual(123); + expect(messages).toMatchInlineSnapshot(` + Array [ + "\\"kibana.autocompleteTerminateAfter\\" is deprecated and has been replaced by \\"data.autocomplete.valueSuggestions.terminateAfter\\"", + ] + `); + }); + + it('renames kibana.autocompleteTimeout to data.autocomplete.valueSuggestions.timeout', () => { + const config = { + kibana: { + autocompleteTimeout: 123, + }, + }; + const { messages, migrated } = applyConfigDeprecations(cloneDeep(config)); + expect(migrated.kibana.autocompleteTimeout).not.toBeDefined(); + expect(migrated.data.autocomplete.valueSuggestions.timeout).toEqual(123); + expect(messages).toMatchInlineSnapshot(` + Array [ + "\\"kibana.autocompleteTimeout\\" is deprecated and has been replaced by \\"data.autocomplete.valueSuggestions.timeout\\"", + ] + `); + }); +}); diff --git a/src/plugins/data/server/config_deprecations.ts b/src/plugins/data/server/config_deprecations.ts new file mode 100644 index 00000000000000..47a88217611a31 --- /dev/null +++ b/src/plugins/data/server/config_deprecations.ts @@ -0,0 +1,19 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +import type { ConfigDeprecationProvider } from 'src/core/server'; + +export const autocompleteConfigDeprecationProvider: ConfigDeprecationProvider = ({ + renameFromRoot, +}) => [ + renameFromRoot( + 'kibana.autocompleteTerminateAfter', + 'data.autocomplete.valueSuggestions.terminateAfter' + ), + renameFromRoot('kibana.autocompleteTimeout', 'data.autocomplete.valueSuggestions.timeout'), +]; diff --git a/src/plugins/data/server/index.ts b/src/plugins/data/server/index.ts index e782fc0d4ffeaa..0764f4f441e425 100644 --- a/src/plugins/data/server/index.ts +++ b/src/plugins/data/server/index.ts @@ -181,6 +181,7 @@ import { tabifyGetColumns, calcAutoIntervalLessThan, } from '../common'; +import { autocompleteConfigDeprecationProvider } from './config_deprecations'; export { // aggs @@ -301,6 +302,7 @@ export { }; export const config: PluginConfigDescriptor = { + deprecations: autocompleteConfigDeprecationProvider, exposeToBrowser: { autocomplete: true, search: true, diff --git a/src/plugins/data/server/server.api.md b/src/plugins/data/server/server.api.md index 4f3802cda7a3a4..8821db0d65f282 100644 --- a/src/plugins/data/server/server.api.md +++ b/src/plugins/data/server/server.api.md @@ -1543,18 +1543,18 @@ export function usageProvider(core: CoreSetup_2): SearchUsage; // src/plugins/data/server/index.ts:101:26 - (ae-forgotten-export) The symbol "HistogramFormat" needs to be exported by the entry point index.d.ts // src/plugins/data/server/index.ts:128:27 - (ae-forgotten-export) The symbol "isFilterable" needs to be exported by the entry point index.d.ts // src/plugins/data/server/index.ts:128:27 - (ae-forgotten-export) The symbol "isNestedField" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/index.ts:243:20 - (ae-forgotten-export) The symbol "tabifyAggResponse" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/index.ts:243:20 - (ae-forgotten-export) The symbol "tabifyGetColumns" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/index.ts:245:1 - (ae-forgotten-export) The symbol "CidrMask" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/index.ts:246:1 - (ae-forgotten-export) The symbol "dateHistogramInterval" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/index.ts:255:1 - (ae-forgotten-export) The symbol "InvalidEsCalendarIntervalError" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/index.ts:256:1 - (ae-forgotten-export) The symbol "InvalidEsIntervalFormatError" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/index.ts:257:1 - (ae-forgotten-export) The symbol "IpAddress" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/index.ts:261:1 - (ae-forgotten-export) The symbol "isValidEsInterval" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/index.ts:262:1 - (ae-forgotten-export) The symbol "isValidInterval" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/index.ts:266:1 - (ae-forgotten-export) The symbol "propFilter" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/index.ts:269:1 - (ae-forgotten-export) The symbol "toAbsoluteDates" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/index.ts:270:1 - (ae-forgotten-export) The symbol "calcAutoIntervalLessThan" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index.ts:244:20 - (ae-forgotten-export) The symbol "tabifyAggResponse" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index.ts:244:20 - (ae-forgotten-export) The symbol "tabifyGetColumns" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index.ts:246:1 - (ae-forgotten-export) The symbol "CidrMask" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index.ts:247:1 - (ae-forgotten-export) The symbol "dateHistogramInterval" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index.ts:256:1 - (ae-forgotten-export) The symbol "InvalidEsCalendarIntervalError" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index.ts:257:1 - (ae-forgotten-export) The symbol "InvalidEsIntervalFormatError" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index.ts:258:1 - (ae-forgotten-export) The symbol "IpAddress" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index.ts:262:1 - (ae-forgotten-export) The symbol "isValidEsInterval" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index.ts:263:1 - (ae-forgotten-export) The symbol "isValidInterval" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index.ts:267:1 - (ae-forgotten-export) The symbol "propFilter" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index.ts:270:1 - (ae-forgotten-export) The symbol "toAbsoluteDates" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index.ts:271:1 - (ae-forgotten-export) The symbol "calcAutoIntervalLessThan" needs to be exported by the entry point index.d.ts // src/plugins/data/server/plugin.ts:81:74 - (ae-forgotten-export) The symbol "DataEnhancements" needs to be exported by the entry point index.d.ts // src/plugins/data/server/search/types.ts:115:5 - (ae-forgotten-export) The symbol "ISearchStartSearchSource" needs to be exported by the entry point index.d.ts diff --git a/src/plugins/input_control_vis/kibana.json b/src/plugins/input_control_vis/kibana.json index 5acb79a8ab0386..d05c5072c22e3b 100644 --- a/src/plugins/input_control_vis/kibana.json +++ b/src/plugins/input_control_vis/kibana.json @@ -2,7 +2,7 @@ "id": "inputControlVis", "version": "8.0.0", "kibanaVersion": "kibana", - "server": true, + "server": false, "ui": true, "requiredPlugins": [ "data", diff --git a/src/plugins/input_control_vis/public/plugin.ts b/src/plugins/input_control_vis/public/plugin.ts index f4b6706bf8d2a3..c086bc7f74d61d 100644 --- a/src/plugins/input_control_vis/public/plugin.ts +++ b/src/plugins/input_control_vis/public/plugin.ts @@ -44,8 +44,6 @@ export interface InputControlVisPluginStartDependencies { /** @internal */ export class InputControlVisPlugin implements Plugin { - private cachedSettings: InputControlSettings | undefined = undefined; - constructor(public initializerContext: PluginInitializerContext) {} public setup( @@ -56,13 +54,8 @@ export class InputControlVisPlugin implements Plugin { core, data, getSettings: async () => { - if (!this.cachedSettings) { - this.cachedSettings = await core.http.get( - '/api/input_control_vis/settings' - ); - } - - return this.cachedSettings; + const { timeout, terminateAfter } = data.autocomplete.getAutocompleteSettings(); + return { autocompleteTimeout: timeout, autocompleteTerminateAfter: terminateAfter }; }, }; diff --git a/src/plugins/input_control_vis/server/index.ts b/src/plugins/input_control_vis/server/index.ts deleted file mode 100644 index 05145720b88c8e..00000000000000 --- a/src/plugins/input_control_vis/server/index.ts +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -import { CoreSetup, PluginConfigDescriptor, PluginInitializerContext } from 'kibana/server'; -import { schema } from '@kbn/config-schema'; -import { first } from 'rxjs/operators'; - -export const config: PluginConfigDescriptor = { - schema: schema.object({ enabled: schema.boolean({ defaultValue: true }) }), -}; - -export const plugin = (initializerContext: PluginInitializerContext) => ({ - setup(core: CoreSetup) { - // TODO this is a workaround to pass global config settings to the client - // once kibana.autocompleteTerminateAfter and kibana.autocompleteTimeout - // are migrated completely and owned by a plugin, this can be done completely - // client side and the additional endpoint is not required anymore - core.http.createRouter().get( - { - path: '/api/input_control_vis/settings', - validate: false, - }, - async (context, request, response) => { - const legacyConfig = await initializerContext.config.legacy.globalConfig$ - .pipe(first()) - .toPromise(); - return response.ok({ - body: { - autocompleteTimeout: legacyConfig.kibana.autocompleteTimeout.asMilliseconds(), - autocompleteTerminateAfter: legacyConfig.kibana.autocompleteTerminateAfter.asMilliseconds(), - }, - }); - } - ); - }, - start() {}, -});