mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
Update autocomplete to use settings from config rather than advanced settings (#58788)
This commit is contained in:
parent
3c92fc8271
commit
8afa902a71
7 changed files with 33 additions and 14 deletions
|
@ -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'),
|
||||
|
|
|
@ -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'),
|
||||
|
|
|
@ -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,
|
||||
};
|
||||
|
|
|
@ -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() {}
|
||||
|
|
|
@ -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$);
|
||||
}
|
||||
|
|
|
@ -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}',
|
||||
|
@ -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(
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue