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

Kibana property config migrations #55937

Merged
merged 16 commits into from
Feb 4, 2020
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions src/core/server/kibana_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ export const config = {
path: 'kibana',
schema: schema.object({
enabled: schema.boolean({ defaultValue: true }),
defaultAppId: schema.string({ defaultValue: 'home' }),
index: schema.string({ defaultValue: '.kibana' }),
disableWelcomeScreen: schema.boolean({ defaultValue: false }),
autocompleteTerminateAfter: schema.duration({ defaultValue: 100000 }),
autocompleteTimeout: schema.duration({ defaultValue: 1000 }),
}),
Expand Down
2 changes: 1 addition & 1 deletion src/core/server/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import { uuidServiceMock } from './uuid/uuid_service.mock';

export function pluginInitializerContextConfigMock<T>(config: T) {
const globalConfig: SharedGlobalConfig = {
kibana: { defaultAppId: 'home-mocks', index: '.kibana-tests' },
kibana: { index: '.kibana-tests' },
elasticsearch: {
shardTimeout: duration('30s'),
requestTimeout: duration('30s'),
Expand Down
2 changes: 1 addition & 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,7 @@ describe('Plugin Context', () => {
.pipe(first())
.toPromise();
expect(configObject).toStrictEqual({
kibana: { defaultAppId: 'home', index: '.kibana' },
kibana: { index: '.kibana' },
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: ['defaultAppId', 'index'] as const,
kibana: ['index'] as const,
elasticsearch: ['shardTimeout', 'requestTimeout', 'pingTimeout', 'startupTimeout'] as const,
path: ['data'] as const,
};
Expand Down
2 changes: 0 additions & 2 deletions src/legacy/core_plugins/kibana/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ export default function(kibana) {
config: function(Joi) {
return Joi.object({
enabled: Joi.boolean().default(true),
defaultAppId: Joi.string().default('home'),
index: Joi.string().default('.kibana'),
disableWelcomeScreen: Joi.boolean().default(false),
autocompleteTerminateAfter: Joi.number()
.integer()
.min(1)
Expand Down
2 changes: 0 additions & 2 deletions src/legacy/core_plugins/kibana/inject_vars.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ export function injectVars(server) {
);

return {
kbnDefaultAppId: serverConfig.get('kibana.defaultAppId'),
disableWelcomeScreen: serverConfig.get('kibana.disableWelcomeScreen'),
importAndExportableTypes,
autocompleteTerminateAfter: serverConfig.get('kibana.autocompleteTerminateAfter'),
autocompleteTimeout: serverConfig.get('kibana.autocompleteTimeout'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import { IEmbeddableStart } from '../../../../../../plugins/embeddable/public';
import { NavigationPublicPluginStart as NavigationStart } from '../../../../../../plugins/navigation/public';
import { DataPublicPluginStart as NpDataStart } from '../../../../../../plugins/data/public';
import { SharePluginStart } from '../../../../../../plugins/share/public';
import { KibanaLegacyStart } from '../../../../../../plugins/kibana_legacy/public';

export interface RenderDeps {
core: LegacyCoreStart;
Expand All @@ -65,6 +66,7 @@ export interface RenderDeps {
embeddables: IEmbeddableStart;
localStorage: Storage;
share: SharePluginStart;
config: KibanaLegacyStart['config'];
}

let angularModuleInstance: IModule | null = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ export interface DashboardAppScope extends ng.IScope {
export function initDashboardAppDirective(app: any, deps: RenderDeps) {
app.directive('dashboardApp', function($injector: IInjector) {
const confirmModal = $injector.get<ConfirmModalFn>('confirmModal');
const config = deps.uiSettings;

return {
restrict: 'E',
Expand All @@ -106,7 +105,6 @@ export function initDashboardAppDirective(app: any, deps: RenderDeps) {
$route,
$scope,
$routeParams,
config,
confirmModal,
indexPatterns: deps.npDataStart.indexPatterns,
kbnUrlStateStorage,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ export interface DashboardAppControllerDependencies extends RenderDeps {
$routeParams: any;
indexPatterns: IndexPatternsContract;
dashboardConfig: any;
config: any;
confirmModal: ConfirmModalFn;
history: History;
kbnUrlStateStorage: IKbnUrlStateStorage;
Expand All @@ -109,7 +108,6 @@ export class DashboardAppController {
dashboardConfig,
localStorage,
indexPatterns,
config,
confirmModal,
savedQueryService,
embeddables,
Expand Down Expand Up @@ -376,7 +374,7 @@ export class DashboardAppController {
dashboardStateManager.getQuery() || {
query: '',
language:
localStorage.get('kibana.userQueryLanguage') || config.get('search:queryLanguage'),
localStorage.get('kibana.userQueryLanguage') || uiSettings.get('search:queryLanguage'),
},
queryFilter.getFilters()
);
Expand Down Expand Up @@ -493,7 +491,7 @@ export class DashboardAppController {
{
query: '',
language:
localStorage.get('kibana.userQueryLanguage') || config.get('search:queryLanguage'),
localStorage.get('kibana.userQueryLanguage') || uiSettings.get('search:queryLanguage'),
},
queryFilter.getGlobalFilters()
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,10 +251,10 @@ export function initDashboardApp(app, deps) {
},
})
.when(`dashboard/:tail*?`, {
redirectTo: `/${deps.core.injectedMetadata.getInjectedVar('kbnDefaultAppId')}`,
redirectTo: `/${deps.config.defaultAppId}`,
})
.when(`dashboards/:tail*?`, {
redirectTo: `/${deps.core.injectedMetadata.getInjectedVar('kbnDefaultAppId')}`,
redirectTo: `/${deps.config.defaultAppId}`,
});
});
}
1 change: 1 addition & 0 deletions src/legacy/core_plugins/kibana/public/dashboard/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ export class DashboardPlugin implements Plugin {
chrome: contextCore.chrome,
addBasePath: contextCore.http.basePath.prepend,
uiSettings: contextCore.uiSettings,
config: kibana_legacy.config,
savedQueryService: npDataStart.query.savedQueries,
embeddables,
dashboardCapabilities: contextCore.application.capabilities.dashboard,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@ import {
UiSettingsState,
} from 'kibana/public';
import { UiStatsMetricType } from '@kbn/analytics';
import { Environment, FeatureCatalogueEntry } from '../../../../../plugins/home/public';
import {
Environment,
FeatureCatalogueEntry,
HomePublicPluginSetup,
} from '../../../../../plugins/home/public';
import { KibanaLegacySetup } from '../../../../../plugins/kibana_legacy/public';

export interface HomeKibanaServices {
indexPatternService: any;
Expand All @@ -51,6 +56,8 @@ export interface HomeKibanaServices {
chrome: ChromeStart;
telemetryOptInProvider: any;
uiSettings: IUiSettingsClient;
config: KibanaLegacySetup['config'];
homeConfig: HomePublicPluginSetup['config'];
http: HttpStart;
savedObjectsClient: SavedObjectsClientContract;
toastNotifications: NotificationsSetup['toasts'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export class Home extends Component {
super(props);

const isWelcomeEnabled = !(
getServices().getInjected('disableWelcomeScreen') ||
getServices().homeConfig.disableWelcomeScreen ||
props.localStorage.getItem(KEY_ENABLE_WELCOME) === 'false'
);
const currentOptInStatus = this.props.getOptInStatus();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ jest.mock('../../kibana_services', () => ({
getServices: () => ({
getBasePath: () => 'path',
getInjected: () => '',
homeConfig: { disableWelcomeScreen: false },
}),
}));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import { replaceTemplateStrings } from './tutorial/replace_template_strings';
import { getServices } from '../../kibana_services';
export function HomeApp({ directories }) {
const {
getInjected,
config,
savedObjectsClient,
getBasePath,
addBasePath,
Expand All @@ -41,7 +41,7 @@ export function HomeApp({ directories }) {
const mlEnabled = environment.ml;
const apmUiEnabled = environment.apmUi;

const defaultAppId = getInjected('kbnDefaultAppId', 'discover');
const defaultAppId = config.defaultAppId || 'discover';

const renderTutorialDirectory = props => {
return (
Expand Down
5 changes: 5 additions & 0 deletions src/legacy/core_plugins/kibana/public/home/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
Environment,
FeatureCatalogueEntry,
HomePublicPluginStart,
HomePublicPluginSetup,
} from '../../../../../plugins/home/public';

export interface LegacyAngularInjectedDependencies {
Expand Down Expand Up @@ -59,6 +60,7 @@ export interface HomePluginSetupDependencies {
};
usageCollection: UsageCollectionSetup;
kibana_legacy: KibanaLegacySetup;
home: HomePublicPluginSetup;
}

export class HomePlugin implements Plugin {
Expand All @@ -69,6 +71,7 @@ export class HomePlugin implements Plugin {
setup(
core: CoreSetup,
{
home,
kibana_legacy,
usageCollection,
__LEGACY: { getAngularDependencies, ...legacyServices },
Expand All @@ -95,6 +98,8 @@ export class HomePlugin implements Plugin {
getBasePath: core.http.basePath.get,
indexPatternService: this.dataStart!.indexPatterns,
environment: this.environment!,
config: kibana_legacy.config,
homeConfig: home.config,
...angularDependencies,
});
const { renderApp } = await import('./np_ready/application');
Expand Down
4 changes: 2 additions & 2 deletions src/legacy/core_plugins/kibana/public/kibana.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
// autoloading

// preloading (for faster webpack builds)
import chrome from 'ui/chrome';
import routes from 'ui/routes';
import { uiModules } from 'ui/modules';
import { npSetup } from 'ui/new_platform';
Expand Down Expand Up @@ -64,8 +63,9 @@ localApplicationService.attachToAngular(routes);

routes.enable();

const { config } = npSetup.plugins.kibana_legacy;
routes.otherwise({
redirectTo: `/${chrome.getInjected('kbnDefaultAppId', 'discover')}`,
redirectTo: `/${config.defaultAppId || 'discover'}`,
});

uiModules.get('kibana').run(showAppRedirectNotification);
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { VisualizationsStart } from '../../../visualizations/public';
import { SavedVisualizations } from './np_ready/types';
import { UsageCollectionSetup } from '../../../../../plugins/usage_collection/public';
import { Chrome } from './legacy_imports';
import { KibanaLegacyStart } from '../../../../../plugins/kibana_legacy/public';

export interface VisualizeKibanaServices {
addBasePath: (url: string) => string;
Expand All @@ -52,6 +53,7 @@ export interface VisualizeKibanaServices {
savedVisualizations: SavedVisualizations;
share: SharePluginStart;
uiSettings: IUiSettingsClient;
config: KibanaLegacyStart['config'];
visualizeCapabilities: any;
visualizations: VisualizationsStart;
usageCollection?: UsageCollectionSetup;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ export function initVisualizeApp(app, deps) {
},
})
.when(`visualize/:tail*?`, {
redirectTo: `/${deps.core.injectedMetadata.getInjectedVar('kbnDefaultAppId')}`,
redirectTo: `/${deps.config.defaultAppId}`,
});
});
}
1 change: 1 addition & 0 deletions src/legacy/core_plugins/kibana/public/visualize/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ export class VisualizePlugin implements Plugin {
share,
toastNotifications: contextCore.notifications.toasts,
uiSettings: contextCore.uiSettings,
config: kibana_legacy.config,
visualizeCapabilities: contextCore.application.capabilities.visualize,
visualizations,
usageCollection,
Expand Down
3 changes: 3 additions & 0 deletions src/legacy/ui/public/new_platform/__mocks__/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { inspectorPluginMock } from '../../../../../plugins/inspector/public/moc
import { uiActionsPluginMock } from '../../../../../plugins/ui_actions/public/mocks';
import { managementPluginMock } from '../../../../../plugins/management/public/mocks';
import { usageCollectionPluginMock } from '../../../../../plugins/usage_collection/public/mocks';
import { kibanaLegacyPluginMock } from '../../../../../plugins/kibana_legacy/public/mocks';
import { chartPluginMock } from '../../../../../plugins/charts/public/mocks';
/* eslint-enable @kbn/eslint/no-restricted-paths */

Expand All @@ -40,6 +41,7 @@ export const pluginsMock = {
expressions: expressionsPluginMock.createSetupContract(),
uiActions: uiActionsPluginMock.createSetupContract(),
usageCollection: usageCollectionPluginMock.createSetupContract(),
kibana_legacy: kibanaLegacyPluginMock.createSetupContract(),
}),
createStart: () => ({
data: dataPluginMock.createStartContract(),
Expand All @@ -50,6 +52,7 @@ export const pluginsMock = {
expressions: expressionsPluginMock.createStartContract(),
uiActions: uiActionsPluginMock.createStartContract(),
management: managementPluginMock.createStartContract(),
kibana_legacy: kibanaLegacyPluginMock.createStartContract(),
}),
};

Expand Down
12 changes: 12 additions & 0 deletions src/legacy/ui/public/new_platform/new_platform.karma_mock.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ export const npSetup = {
kibana_legacy: {
registerLegacyApp: () => {},
forwardApp: () => {},
config: {
defaultAppId: 'home',
},
},
inspector: {
registerView: () => undefined,
Expand All @@ -140,6 +143,9 @@ export const npSetup = {
environment: {
update: sinon.fake(),
},
config: {
disableWelcomeScreen: false,
},
},
charts: {
theme: {
Expand Down Expand Up @@ -196,6 +202,9 @@ export const npStart = {
kibana_legacy: {
getApps: () => [],
getForwards: () => [],
config: {
defaultAppId: 'home',
},
},
data: {
autocomplete: {
Expand Down Expand Up @@ -297,6 +306,9 @@ export const npStart = {
environment: {
get: sinon.fake(),
},
config: {
disableWelcomeScreen: false,
},
},
navigation: {
ui: {
Expand Down
26 changes: 26 additions & 0 deletions src/plugins/home/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import { schema, TypeOf } from '@kbn/config-schema';

export const configSchema = schema.object({
disableWelcomeScreen: schema.boolean({ defaultValue: false }),
});

export type ConfigSchema = TypeOf<typeof configSchema>;
5 changes: 4 additions & 1 deletion src/plugins/home/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
* under the License.
*/

import { PluginInitializerContext } from 'kibana/public';

export {
FeatureCatalogueSetup,
FeatureCatalogueStart,
Expand All @@ -26,4 +28,5 @@ export {
export { FeatureCatalogueEntry, FeatureCatalogueCategory, Environment } from './services';
import { HomePublicPlugin } from './plugin';

export const plugin = () => new HomePublicPlugin();
export const plugin = (initializerContext: PluginInitializerContext) =>
new HomePublicPlugin(initializerContext);
Loading