Skip to content

Commit

Permalink
[Unified Search] Move autocomplete logic to unified search plugin (#1…
Browse files Browse the repository at this point in the history
…29977)

* feat: move autocomplete logic from data plugin to unified search

* minor fix after comments

* updated Documentation: data.autocomplete -> unifiedSearch.autocomplete

* changed renameFromRoot order for autocomplete

* removed extra renameFromRoot in config deprecations, updated test

* added configPath for unified search plugin

* Update kibana.json

* updated path to autocomplete

* fix conflict

* fix conflict

* [CI] Auto-commit changed files from 'node scripts/eslint --no-cache --fix'

* fix Linting

* fix functional_with_es_ssl test
  • Loading branch information
nlatipov authored Apr 22, 2022
1 parent fa73237 commit 7c01257
Show file tree
Hide file tree
Showing 163 changed files with 1,253 additions and 392 deletions.
4 changes: 2 additions & 2 deletions config/kibana.yml
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@
# =================== Search Autocomplete ===================
# Time in milliseconds to wait for autocomplete suggestions from Elasticsearch.
# This value must be a whole number greater than zero. Defaults to 1000ms
#data.autocomplete.valueSuggestions.timeout: 1000
#unifiedSearch.autocomplete.valueSuggestions.timeout: 1000

# Maximum number of documents loaded by each shard to generate autocomplete suggestions.
# This value must be a whole number greater than zero. Defaults to 100_000
#data.autocomplete.valueSuggestions.terminateAfter: 100000
#unifiedSearch.autocomplete.valueSuggestions.terminateAfter: 100000
4 changes: 2 additions & 2 deletions docs/setup/settings.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -289,11 +289,11 @@ is an alternative to `elasticsearch.username` and `elasticsearch.password`.
| `interpreter.enableInVisualize`
| Enables use of interpreter in Visualize. *Default: `true`*

| `data.autocomplete.valueSuggestions.timeout:` {ess-icon}
| `unifiedSearch.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"`*

| `data.autocomplete.valueSuggestions.terminateAfter:` {ess-icon}
| `unifiedSearch.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"`*
Expand Down
2 changes: 1 addition & 1 deletion packages/kbn-optimizer/limits.yml
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ pageLoadAssetSize:
sessionView: 77750
cloudSecurityPosture: 19109
visTypeGauge: 24113
unifiedSearch: 49195
unifiedSearch: 104869
data: 454087
expressionXY: 26500
eventAnnotation: 19334
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { uniq } from 'lodash';
import { ListOperatorTypeEnum as OperatorTypeEnum } from '@kbn/securitysolution-io-ts-list-types';

// TODO: I have to use any here for now, but once this is available below, we should use the correct types, https://github.com/elastic/kibana/issues/100715
// import { AutocompleteStart } from '../../../../../../../src/plugins/data/public';
// import { AutocompleteStart } from '../../../../../../../src/plugins/unified_search/public';
type AutocompleteStart = any;

import * as i18n from '../translations';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { ListOperatorTypeEnum as OperatorTypeEnum } from '@kbn/securitysolution-
import { DataViewBase, DataViewFieldBase } from '@kbn/es-query';

// TODO: I have to use any here for now, but once this is available below, we should use the correct types, https://github.com/elastic/kibana/issues/100715
// import { AutocompleteStart } from '../../../../../../../src/plugins/data/public';
// import { AutocompleteStart } from '../../../../../../../src/plugins/unified_search/public';
type AutocompleteStart = any;

import * as i18n from '../translations';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { uniq } from 'lodash';
import { ListOperatorTypeEnum as OperatorTypeEnum } from '@kbn/securitysolution-io-ts-list-types';

// TODO: I have to use any here for now, but once this is available below, we should use the correct types, https://github.com/elastic/kibana/issues/100715
// import { AutocompleteStart } from '../../../../../../../src/plugins/data/public';
// import { AutocompleteStart } from '../../../../../../../src/plugins/unified_search/public';
type AutocompleteStart = any;

import * as i18n from '../translations';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { ListOperatorTypeEnum as OperatorTypeEnum } from '@kbn/securitysolution-
import { DataViewBase, DataViewFieldBase, getDataViewFieldSubtypeNested } from '@kbn/es-query';

// TODO: I have to use any here for now, but once this is available below, we should use the correct types, https://github.com/elastic/kibana/issues/100715
// import { AutocompleteStart } from '../../../../../../../../src/plugins/data/public';
// import { AutocompleteStart } from '../../../../../../../../src/plugins/unified_search/public';
type AutocompleteStart = any;

interface FuncArgs {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ kibana_vars=(
csp.report_to
data.autocomplete.valueSuggestions.terminateAfter
data.autocomplete.valueSuggestions.timeout
unifiedSearch.autocomplete.valueSuggestions.terminateAfter
unifiedSearch.autocomplete.valueSuggestions.timeout
unifiedSearch.autocomplete.querySuggestions.enabled
unifiedSearch.autocomplete.valueSuggestions.enabled
unifiedSearch.autocomplete.valueSuggestions.tiers
elasticsearch.customHeaders
elasticsearch.hosts
elasticsearch.logQueries
Expand Down
3 changes: 2 additions & 1 deletion src/plugins/controls/kibana.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"expressions",
"embeddable",
"dataViews",
"data"
"data",
"unifiedSearch"
],
"optionalPlugins": []
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import { decorators } from './decorators';
import { ControlsPanels } from '../control_group/types';
import { ControlGroupContainer } from '../control_group';
import { pluginServices, registry } from '../services/storybook';
import { replaceValueSuggestionMethod } from '../services/storybook/data';
import { replaceValueSuggestionMethod } from '../services/storybook/unified_search';
import { injectStorybookDataView } from '../services/storybook/data_views';
import { populateStorybookControlFactories } from './storybook_control_factories';
import { OptionsListRequest } from '../services/options_list';
Expand Down
1 change: 0 additions & 1 deletion src/plugins/controls/public/services/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ export interface ControlsDataService {
) => Observable<{ min?: number; max?: number }>;
getDataView: DataPublicPluginStart['dataViews']['get'];
getDataView$: (id: string) => Observable<DataView>;
autocomplete: DataPublicPluginStart['autocomplete'];
query: DataPublicPluginStart['query'];
searchSource: DataPublicPluginStart['search']['searchSource'];
timefilter: DataPublicPluginStart['query']['timefilter']['timefilter'];
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/controls/public/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { ControlsOverlaysService } from './overlays';
import { registry as stubRegistry } from './stub';
import { ControlsPluginStart } from '../types';
import { ControlsDataService } from './data';
import { ControlsUnifiedSearchService } from './unified_search';
import { ControlsService } from './controls';
import { ControlsHTTPService } from './http';
import { ControlsOptionsListService } from './options_list';
Expand All @@ -22,6 +23,7 @@ export interface ControlsServices {
dataViews: ControlsDataViewsService;
overlays: ControlsOverlaysService;
data: ControlsDataService;
unifiedSearch: ControlsUnifiedSearchService;
http: ControlsHTTPService;
settings: ControlsSettingsService;

Expand Down
3 changes: 1 addition & 2 deletions src/plugins/controls/public/services/kibana/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const minMaxAgg = (field?: DataViewField) => {

export const dataServiceFactory: DataServiceFactory = ({ startPlugins }) => {
const {
data: { query: queryPlugin, search, autocomplete },
data: { query: queryPlugin, search },
} = startPlugins;
const { data } = startPlugins;

Expand Down Expand Up @@ -95,7 +95,6 @@ export const dataServiceFactory: DataServiceFactory = ({ startPlugins }) => {
from(fetchFieldRange(dataView, fieldName, input)),
getDataView: data.dataViews.get,
getDataView$: (id: string) => from(data.dataViews.get(id)),
autocomplete,
query: queryPlugin,
searchSource: search.searchSource,
timefilter: queryPlugin.timefilter.timefilter,
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/controls/public/services/kibana/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@ import { dataServiceFactory } from './data';
import { httpServiceFactory } from './http';
import { optionsListServiceFactory } from './options_list';
import { settingsServiceFactory } from './settings';
import { unifiedSearchServiceFactory } from './unified_search';

export const providers: PluginServiceProviders<
ControlsServices,
KibanaPluginServiceParams<ControlsPluginStartDeps>
> = {
http: new PluginServiceProvider(httpServiceFactory),
data: new PluginServiceProvider(dataServiceFactory),
unifiedSearch: new PluginServiceProvider(unifiedSearchServiceFactory),
overlays: new PluginServiceProvider(overlaysServiceFactory),
dataViews: new PluginServiceProvider(dataViewsServiceFactory),
settings: new PluginServiceProvider(settingsServiceFactory),
Expand Down
26 changes: 26 additions & 0 deletions src/plugins/controls/public/services/kibana/unified_search.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* 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 { KibanaPluginServiceFactory } from '@kbn/presentation-util-plugin/public';
import { ControlsUnifiedSearchService } from '../unified_search';
import { ControlsPluginStartDeps } from '../../types';

export type UnifiedSearchServiceFactory = KibanaPluginServiceFactory<
ControlsUnifiedSearchService,
ControlsPluginStartDeps
>;

export const unifiedSearchServiceFactory: UnifiedSearchServiceFactory = ({ startPlugins }) => {
const {
unifiedSearch: { autocomplete },
} = startPlugins;

return {
autocomplete,
};
};
11 changes: 1 addition & 10 deletions src/plugins/controls/public/services/storybook/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,11 @@
import { of, Observable } from 'rxjs';
import { PluginServiceFactory } from '@kbn/presentation-util-plugin/public';
import { DataPublicPluginStart } from '@kbn/data-plugin/public';
import { DataViewField, DataView } from '@kbn/data-views-plugin/common';
import { DataView } from '@kbn/data-views-plugin/common';
import { ControlsDataService } from '../data';

let valueSuggestionMethod = ({ field, query }: { field: DataViewField; query: string }) =>
Promise.resolve(['storybook', 'default', 'values']);
export const replaceValueSuggestionMethod = (
newMethod: ({ field, query }: { field: DataViewField; query: string }) => Promise<string[]>
) => (valueSuggestionMethod = newMethod);

export type DataServiceFactory = PluginServiceFactory<ControlsDataService>;
export const dataServiceFactory: DataServiceFactory = () => ({
autocomplete: {
getValueSuggestions: valueSuggestionMethod,
} as unknown as DataPublicPluginStart['autocomplete'],
query: {} as unknown as DataPublicPluginStart['query'],
searchSource: {
create: () => ({
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/controls/public/services/storybook/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
} from '@kbn/presentation-util-plugin/public';
import { ControlsServices } from '..';
import { dataServiceFactory } from './data';
import { unifiedSearchServiceFactory } from './unified_search';
import { overlaysServiceFactory } from './overlays';
import { dataViewsServiceFactory } from './data_views';
import { httpServiceFactory } from '../stub/http';
Expand All @@ -28,6 +29,7 @@ export const providers: PluginServiceProviders<ControlsServices> = {
dataViews: new PluginServiceProvider(dataViewsServiceFactory),
http: new PluginServiceProvider(httpServiceFactory),
data: new PluginServiceProvider(dataServiceFactory),
unifiedSearch: new PluginServiceProvider(unifiedSearchServiceFactory),
overlays: new PluginServiceProvider(overlaysServiceFactory),
settings: new PluginServiceProvider(settingsServiceFactory),

Expand Down
25 changes: 25 additions & 0 deletions src/plugins/controls/public/services/storybook/unified_search.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* 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 { PluginServiceFactory } from '@kbn/presentation-util-plugin/public';
import { DataViewField } from '@kbn/data-views-plugin/common';
import { UnifiedSearchPublicPluginStart } from '@kbn/unified-search-plugin/public';
import { ControlsUnifiedSearchService } from '../unified_search';

let valueSuggestionMethod = ({ field, query }: { field: DataViewField; query: string }) =>
Promise.resolve(['storybook', 'default', 'values']);
export const replaceValueSuggestionMethod = (
newMethod: ({ field, query }: { field: DataViewField; query: string }) => Promise<string[]>
) => (valueSuggestionMethod = newMethod);

export type UnifiedSearchServiceFactory = PluginServiceFactory<ControlsUnifiedSearchService>;
export const unifiedSearchServiceFactory: UnifiedSearchServiceFactory = () => ({
autocomplete: {
getValueSuggestions: valueSuggestionMethod,
} as unknown as UnifiedSearchPublicPluginStart['autocomplete'],
});
3 changes: 2 additions & 1 deletion src/plugins/controls/public/services/stub/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@ import { dataServiceFactory } from '../storybook/data';
import { dataViewsServiceFactory } from '../storybook/data_views';
import { optionsListServiceFactory } from '../storybook/options_list';
import { settingsServiceFactory } from '../storybook/settings';
import { unifiedSearchServiceFactory } from '../storybook/unified_search';

export const providers: PluginServiceProviders<ControlsServices> = {
http: new PluginServiceProvider(httpServiceFactory),
data: new PluginServiceProvider(dataServiceFactory),
overlays: new PluginServiceProvider(overlaysServiceFactory),
dataViews: new PluginServiceProvider(dataViewsServiceFactory),
settings: new PluginServiceProvider(settingsServiceFactory),

unifiedSearch: new PluginServiceProvider(unifiedSearchServiceFactory),
controls: new PluginServiceProvider(controlsServiceFactory),
optionsList: new PluginServiceProvider(optionsListServiceFactory),
};
Expand Down
13 changes: 13 additions & 0 deletions src/plugins/controls/public/services/unified_search.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* 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 { UnifiedSearchPublicPluginStart } from '@kbn/unified-search-plugin/public';

export interface ControlsUnifiedSearchService {
autocomplete: UnifiedSearchPublicPluginStart['autocomplete'];
}
2 changes: 2 additions & 0 deletions src/plugins/controls/public/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
} from '@kbn/embeddable-plugin/public';
import { DataPublicPluginStart } from '@kbn/data-plugin/public';
import { DataView, DataViewsPublicPluginStart } from '@kbn/data-views-plugin/public';
import { UnifiedSearchPublicPluginStart } from '@kbn/unified-search-plugin/public';
import { ControlInput } from '../common/types';
import { ControlsService } from './services/controls';

Expand Down Expand Up @@ -70,6 +71,7 @@ export interface ControlsPluginSetupDeps {
}
export interface ControlsPluginStartDeps {
data: DataPublicPluginStart;
unifiedSearch: UnifiedSearchPublicPluginStart;
embeddable: EmbeddableStart;
dataViews: DataViewsPublicPluginStart;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ import { Observable } from 'rxjs';

import { CoreSetup, ElasticsearchClient } from '@kbn/core/server';
import { getKbnServerError, reportServerError } from '@kbn/kibana-utils-plugin/server';
import { PluginSetup as DataPluginSetup } from '@kbn/data-plugin/server';
import { FieldSpec, getFieldSubtypeNested } from '@kbn/data-views-plugin/common';
import { PluginSetup as UnifiedSearchPluginSetup } from '@kbn/unified-search-plugin/server';
import {
OptionsListRequestBody,
OptionsListResponse,
} from '../../../common/control_types/options_list/types';

export const setupOptionsListSuggestionsRoute = (
{ http }: CoreSetup,
getAutocompleteSettings: DataPluginSetup['autocomplete']['getAutocompleteSettings']
getAutocompleteSettings: UnifiedSearchPluginSetup['autocomplete']['getAutocompleteSettings']
) => {
const router = http.createRouter();

Expand Down
6 changes: 4 additions & 2 deletions src/plugins/controls/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { CoreSetup, Plugin } from '@kbn/core/server';

import { EmbeddableSetup } from '@kbn/embeddable-plugin/server';
import { PluginSetup as DataSetup } from '@kbn/data-plugin/server';
import { PluginSetup as UnifiedSearchSetup } from '@kbn/unified-search-plugin/server';
import { setupOptionsListSuggestionsRoute } from './control_types/options_list/options_list_suggestions_route';
import { controlGroupContainerPersistableStateServiceFactory } from './control_group/control_group_container_factory';
import { optionsListPersistableStateServiceFactory } from './control_types/options_list/options_list_embeddable_factory';
Expand All @@ -18,18 +19,19 @@ import { timeSliderPersistableStateServiceFactory } from './control_types/time_s
interface SetupDeps {
embeddable: EmbeddableSetup;
data: DataSetup;
unifiedSearch: UnifiedSearchSetup;
}

export class ControlsPlugin implements Plugin<object, object, SetupDeps> {
public setup(core: CoreSetup, { embeddable, data }: SetupDeps) {
public setup(core: CoreSetup, { embeddable, unifiedSearch }: SetupDeps) {
embeddable.registerEmbeddableFactory(optionsListPersistableStateServiceFactory());
embeddable.registerEmbeddableFactory(timeSliderPersistableStateServiceFactory());

embeddable.registerEmbeddableFactory(
controlGroupContainerPersistableStateServiceFactory(embeddable)
);

setupOptionsListSuggestionsRoute(core, data.autocomplete.getAutocompleteSettings);
setupOptionsListSuggestionsRoute(core, unifiedSearch.autocomplete.getAutocompleteSettings);
return {};
}

Expand Down
3 changes: 2 additions & 1 deletion src/plugins/controls/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
{ "path": "../embeddable/tsconfig.json" },
{ "path": "../presentation_util/tsconfig.json" },
{ "path": "../kibana_react/tsconfig.json" },
{ "path": "../data/tsconfig.json" }
{ "path": "../data/tsconfig.json" },
{ "path": "../unified_search/tsconfig.json" }
]
}
22 changes: 0 additions & 22 deletions src/plugins/data/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,6 @@
import { schema, TypeOf } from '@kbn/config-schema';

export const configSchema = schema.object({
autocomplete: schema.object({
querySuggestions: schema.object({
enabled: schema.boolean({ defaultValue: true }),
}),
valueSuggestions: schema.object({
enabled: schema.boolean({ defaultValue: true }),
tiers: schema.arrayOf(
schema.oneOf([
schema.literal('data_content'),
schema.literal('data_hot'),
schema.literal('data_warm'),
schema.literal('data_cold'),
schema.literal('data_frozen'),
]),
{
defaultValue: ['data_hot', 'data_warm', 'data_content', 'data_cold'],
}
),
terminateAfter: schema.duration({ defaultValue: 100000 }),
timeout: schema.duration({ defaultValue: 1000 }),
}),
}),
search: schema.object({
aggs: schema.object({
shardDelay: schema.object({
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/data/kibana.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"server": true,
"ui": true,
"requiredPlugins": ["bfetch", "expressions", "uiActions", "share", "inspector", "fieldFormats", "dataViews"],
"serviceFolders": ["search", "query", "autocomplete", "ui"],
"serviceFolders": ["search", "query", "ui"],
"optionalPlugins": ["usageCollection", "taskManager", "security"],
"extraPublicDirs": ["common"],
"requiredBundles": ["kibanaUtils", "kibanaReact", "inspector"],
Expand Down
Loading

0 comments on commit 7c01257

Please sign in to comment.