From b343af36bd4e1c050e09b16844c39e507c51bc02 Mon Sep 17 00:00:00 2001 From: James Gowdy Date: Fri, 24 Jul 2020 09:38:09 +0100 Subject: [PATCH 1/7] [ML] Disabling ML if license feature is disabled --- x-pack/plugins/ml/common/license/index.ts | 1 + .../plugins/ml/common/license/ml_license.ts | 4 ++++ x-pack/plugins/ml/public/plugin.ts | 13 +++++++++++- .../lib/capabilities/capabilities_switcher.ts | 20 ++++++++++++++----- 4 files changed, 32 insertions(+), 6 deletions(-) diff --git a/x-pack/plugins/ml/common/license/index.ts b/x-pack/plugins/ml/common/license/index.ts index e87986a26a3b..e09040a9a26f 100644 --- a/x-pack/plugins/ml/common/license/index.ts +++ b/x-pack/plugins/ml/common/license/index.ts @@ -11,4 +11,5 @@ export { MINIMUM_LICENSE, isFullLicense, isMinimumLicense, + isMlEnabled, } from './ml_license'; diff --git a/x-pack/plugins/ml/common/license/ml_license.ts b/x-pack/plugins/ml/common/license/ml_license.ts index e4367c9b921f..44ed892ff0d0 100644 --- a/x-pack/plugins/ml/common/license/ml_license.ts +++ b/x-pack/plugins/ml/common/license/ml_license.ts @@ -82,3 +82,7 @@ export function isFullLicense(license: ILicense) { export function isMinimumLicense(license: ILicense) { return license.check(PLUGIN_ID, MINIMUM_LICENSE).state === 'valid'; } + +export function isMlEnabled(license: ILicense) { + return license.getFeature(PLUGIN_ID).isEnabled; +} diff --git a/x-pack/plugins/ml/public/plugin.ts b/x-pack/plugins/ml/public/plugin.ts index 449d8baa2a18..931af6a7eb6d 100644 --- a/x-pack/plugins/ml/public/plugin.ts +++ b/x-pack/plugins/ml/public/plugin.ts @@ -12,6 +12,7 @@ import { AppMountParameters, PluginInitializerContext, } from 'kibana/public'; +import { take } from 'rxjs/operators'; import { ManagementSetup } from 'src/plugins/management/public'; import { SharePluginSetup, SharePluginStart, UrlGeneratorState } from 'src/plugins/share/public'; import { UsageCollectionSetup } from 'src/plugins/usage_collection/server'; @@ -32,6 +33,7 @@ import { UiActionsSetup, UiActionsStart } from '../../../../src/plugins/ui_actio import { registerMlUiActions } from './ui_actions'; import { KibanaLegacyStart } from '../../../../src/plugins/kibana_legacy/public'; import { MlUrlGenerator, MlUrlGeneratorState, ML_APP_URL_GENERATOR } from './url_generator'; +import { isMlEnabled } from '../common/license'; export interface MlStartDependencies { data: DataPublicPluginStart; @@ -63,7 +65,15 @@ export type MlCoreSetup = CoreSetup; export class MlPlugin implements Plugin { constructor(private initializerContext: PluginInitializerContext) {} - setup(core: MlCoreSetup, pluginsSetup: MlSetupDependencies) { + async setup(core: MlCoreSetup, pluginsSetup: MlSetupDependencies) { + // const license = pluginsSetup.licensing.license$.pipe(take(1)); + const license = await pluginsSetup.licensing.license$.pipe(take(1)).toPromise(); + // licensing.subscribe((license) => { + // console.dir(license.getFeature('ml')); + // console.dir(license.getFeature('graph')); + if (isMlEnabled(license) === false) { + return {}; + } const baseUrl = core.http.basePath.prepend('/app/ml'); pluginsSetup.share.urlGenerators.registerUrlGenerator( @@ -117,6 +127,7 @@ export class MlPlugin implements Plugin { initManagementSection(pluginsSetup, core); registerEmbeddables(pluginsSetup.embeddable, core); registerMlUiActions(pluginsSetup.uiActions, core); + // }); return {}; } diff --git a/x-pack/plugins/ml/server/lib/capabilities/capabilities_switcher.ts b/x-pack/plugins/ml/server/lib/capabilities/capabilities_switcher.ts index 5b8cbc4bdbbe..cf1c5b110f39 100644 --- a/x-pack/plugins/ml/server/lib/capabilities/capabilities_switcher.ts +++ b/x-pack/plugins/ml/server/lib/capabilities/capabilities_switcher.ts @@ -9,7 +9,7 @@ import { Observable } from 'rxjs'; import { take } from 'rxjs/operators'; import { CapabilitiesSwitcher, CoreSetup, Logger } from 'src/core/server'; import { ILicense } from '../../../../licensing/common/types'; -import { isFullLicense, isMinimumLicense } from '../../../common/license'; +import { isFullLicense, isMinimumLicense, isMlEnabled } from '../../../common/license'; import { MlCapabilities, basicLicenseMlCapabilities } from '../../../common/types/capabilities'; export const setupCapabilitiesSwitcher = ( @@ -30,19 +30,23 @@ function getSwitcher(license$: Observable, logger: Logger): Capabiliti try { const license = await license$.pipe(take(1)).toPromise(); + const mlCaps = capabilities.ml as MlCapabilities; + // console.dir(license.getFeature('ml')); + // console.dir(license.getFeature('graph')); + if (isMlEnabled(license) === false) { + disableAllCapabilities(mlCaps); + return capabilities; + } // full license, leave capabilities as they were if (isFullLicense(license)) { return capabilities; } - const mlCaps = capabilities.ml as MlCapabilities; const originalCapabilities = cloneDeep(mlCaps); // not full licence, switch off all capabilities - Object.keys(mlCaps).forEach((k) => { - mlCaps[k as keyof MlCapabilities] = false; - }); + disableAllCapabilities(mlCaps); // for a basic license, reapply the original capabilities for the basic license features if (isMinimumLicense(license)) { @@ -56,3 +60,9 @@ function getSwitcher(license$: Observable, logger: Logger): Capabiliti } }; } + +function disableAllCapabilities(mlCaps: MlCapabilities) { + Object.keys(mlCaps).forEach((k) => { + mlCaps[k as keyof MlCapabilities] = false; + }); +} From 8195b9f5a4e79fad0fbde3b92e8752040f037985 Mon Sep 17 00:00:00 2001 From: James Gowdy Date: Tue, 28 Jul 2020 10:26:18 +0100 Subject: [PATCH 2/7] disabling UI feature --- .../ml/public/application/management/index.ts | 41 +++--- x-pack/plugins/ml/public/plugin.ts | 118 +++++++++--------- .../lib/capabilities/capabilities_switcher.ts | 2 - 3 files changed, 75 insertions(+), 86 deletions(-) diff --git a/x-pack/plugins/ml/public/application/management/index.ts b/x-pack/plugins/ml/public/application/management/index.ts index 897731304ee7..61b497391249 100644 --- a/x-pack/plugins/ml/public/application/management/index.ts +++ b/x-pack/plugins/ml/public/application/management/index.ts @@ -11,37 +11,28 @@ */ import { i18n } from '@kbn/i18n'; -import { take } from 'rxjs/operators'; import { CoreSetup } from 'kibana/public'; -import { MlStartDependencies, MlSetupDependencies } from '../../plugin'; +import { ManagementSetup } from 'src/plugins/management/public'; +import { MlStartDependencies } from '../../plugin'; import { ManagementAppMountParams } from '../../../../../../src/plugins/management/public'; -import { PLUGIN_ID } from '../../../common/constants/app'; -import { MINIMUM_FULL_LICENSE } from '../../../common/license'; export function initManagementSection( - pluginsSetup: MlSetupDependencies, + management: ManagementSetup | undefined, core: CoreSetup ) { - const licensing = pluginsSetup.licensing.license$.pipe(take(1)); - licensing.subscribe((license) => { - const management = pluginsSetup.management; - if ( - management !== undefined && - license.check(PLUGIN_ID, MINIMUM_FULL_LICENSE).state === 'valid' - ) { - management.sections.section.insightsAndAlerting.registerApp({ - id: 'jobsListLink', - title: i18n.translate('xpack.ml.management.jobsListTitle', { - defaultMessage: 'Machine Learning Jobs', - }), - order: 2, - async mount(params: ManagementAppMountParams) { - const { mountApp } = await import('./jobs_list'); - return mountApp(core, params); - }, - }); - } - }); + if (management !== undefined) { + management.sections.section.insightsAndAlerting.registerApp({ + id: 'jobsListLink', + title: i18n.translate('xpack.ml.management.jobsListTitle', { + defaultMessage: 'Machine Learning Jobs', + }), + order: 2, + async mount(params: ManagementAppMountParams) { + const { mountApp } = await import('./jobs_list'); + return mountApp(core, params); + }, + }); + } } diff --git a/x-pack/plugins/ml/public/plugin.ts b/x-pack/plugins/ml/public/plugin.ts index 931af6a7eb6d..1d4102344895 100644 --- a/x-pack/plugins/ml/public/plugin.ts +++ b/x-pack/plugins/ml/public/plugin.ts @@ -33,7 +33,8 @@ import { UiActionsSetup, UiActionsStart } from '../../../../src/plugins/ui_actio import { registerMlUiActions } from './ui_actions'; import { KibanaLegacyStart } from '../../../../src/plugins/kibana_legacy/public'; import { MlUrlGenerator, MlUrlGeneratorState, ML_APP_URL_GENERATOR } from './url_generator'; -import { isMlEnabled } from '../common/license'; +import { isMlEnabled, isFullLicense } from '../common/license'; +import { MINIMUM_FULL_LICENSE } from '../../../common/license'; export interface MlStartDependencies { data: DataPublicPluginStart; @@ -66,69 +67,68 @@ export class MlPlugin implements Plugin { constructor(private initializerContext: PluginInitializerContext) {} async setup(core: MlCoreSetup, pluginsSetup: MlSetupDependencies) { - // const license = pluginsSetup.licensing.license$.pipe(take(1)); - const license = await pluginsSetup.licensing.license$.pipe(take(1)).toPromise(); - // licensing.subscribe((license) => { - // console.dir(license.getFeature('ml')); - // console.dir(license.getFeature('graph')); - if (isMlEnabled(license) === false) { - return {}; - } - const baseUrl = core.http.basePath.prepend('/app/ml'); + const licensing = pluginsSetup.licensing.license$.pipe(take(1)); + licensing.subscribe((license) => { + if (isMlEnabled(license) === false) { + return; + } - pluginsSetup.share.urlGenerators.registerUrlGenerator( - new MlUrlGenerator({ - appBasePath: baseUrl, - useHash: core.uiSettings.get('state:storeInSessionStorage'), - }) - ); + const baseUrl = core.http.basePath.prepend('/app/ml'); - core.application.register({ - id: PLUGIN_ID, - title: i18n.translate('xpack.ml.plugin.title', { - defaultMessage: 'Machine Learning', - }), - order: 5000, - euiIconType: PLUGIN_ICON, - appRoute: '/app/ml', - category: DEFAULT_APP_CATEGORIES.kibana, - mount: async (params: AppMountParameters) => { - const [coreStart, pluginsStart] = await core.getStartServices(); - const kibanaVersion = this.initializerContext.env.packageInfo.version; - const { renderApp } = await import('./application/app'); - return renderApp( - coreStart, - { - data: pluginsStart.data, - share: pluginsStart.share, - kibanaLegacy: pluginsStart.kibanaLegacy, - security: pluginsSetup.security, - licensing: pluginsSetup.licensing, - management: pluginsSetup.management, - usageCollection: pluginsSetup.usageCollection, - licenseManagement: pluginsSetup.licenseManagement, - home: pluginsSetup.home, - embeddable: pluginsSetup.embeddable, - uiActions: pluginsStart.uiActions, - kibanaVersion, - }, - { - element: params.element, - appBasePath: params.appBasePath, - onAppLeave: params.onAppLeave, - history: params.history, - } - ); - }, - }); + pluginsSetup.share.urlGenerators.registerUrlGenerator( + new MlUrlGenerator({ + appBasePath: baseUrl, + useHash: core.uiSettings.get('state:storeInSessionStorage'), + }) + ); - registerFeature(pluginsSetup.home); + core.application.register({ + id: PLUGIN_ID, + title: i18n.translate('xpack.ml.plugin.title', { + defaultMessage: 'Machine Learning', + }), + order: 5000, + euiIconType: PLUGIN_ICON, + appRoute: '/app/ml', + category: DEFAULT_APP_CATEGORIES.kibana, + mount: async (params: AppMountParameters) => { + const [coreStart, pluginsStart] = await core.getStartServices(); + const kibanaVersion = this.initializerContext.env.packageInfo.version; + const { renderApp } = await import('./application/app'); + return renderApp( + coreStart, + { + data: pluginsStart.data, + share: pluginsStart.share, + kibanaLegacy: pluginsStart.kibanaLegacy, + security: pluginsSetup.security, + licensing: pluginsSetup.licensing, + management: pluginsSetup.management, + usageCollection: pluginsSetup.usageCollection, + licenseManagement: pluginsSetup.licenseManagement, + home: pluginsSetup.home, + embeddable: pluginsSetup.embeddable, + uiActions: pluginsStart.uiActions, + kibanaVersion, + }, + { + element: params.element, + appBasePath: params.appBasePath, + onAppLeave: params.onAppLeave, + history: params.history, + } + ); + }, + }); - initManagementSection(pluginsSetup, core); - registerEmbeddables(pluginsSetup.embeddable, core); - registerMlUiActions(pluginsSetup.uiActions, core); - // }); + registerFeature(pluginsSetup.home); + if (isFullLicense(license)) { + initManagementSection(pluginsSetup.management, core); + } + registerEmbeddables(pluginsSetup.embeddable, core); + registerMlUiActions(pluginsSetup.uiActions, core); + }); return {}; } diff --git a/x-pack/plugins/ml/server/lib/capabilities/capabilities_switcher.ts b/x-pack/plugins/ml/server/lib/capabilities/capabilities_switcher.ts index cf1c5b110f39..0eeb7a885134 100644 --- a/x-pack/plugins/ml/server/lib/capabilities/capabilities_switcher.ts +++ b/x-pack/plugins/ml/server/lib/capabilities/capabilities_switcher.ts @@ -31,8 +31,6 @@ function getSwitcher(license$: Observable, logger: Logger): Capabiliti try { const license = await license$.pipe(take(1)).toPromise(); const mlCaps = capabilities.ml as MlCapabilities; - // console.dir(license.getFeature('ml')); - // console.dir(license.getFeature('graph')); if (isMlEnabled(license) === false) { disableAllCapabilities(mlCaps); return capabilities; From aeab5f00128421dc39216dd54f382b12156f0436 Mon Sep 17 00:00:00 2001 From: James Gowdy Date: Tue, 28 Jul 2020 13:03:18 +0100 Subject: [PATCH 3/7] removing unused import --- x-pack/plugins/ml/public/plugin.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/x-pack/plugins/ml/public/plugin.ts b/x-pack/plugins/ml/public/plugin.ts index 1d4102344895..05ef44365eae 100644 --- a/x-pack/plugins/ml/public/plugin.ts +++ b/x-pack/plugins/ml/public/plugin.ts @@ -34,7 +34,6 @@ import { registerMlUiActions } from './ui_actions'; import { KibanaLegacyStart } from '../../../../src/plugins/kibana_legacy/public'; import { MlUrlGenerator, MlUrlGeneratorState, ML_APP_URL_GENERATOR } from './url_generator'; import { isMlEnabled, isFullLicense } from '../common/license'; -import { MINIMUM_FULL_LICENSE } from '../../../common/license'; export interface MlStartDependencies { data: DataPublicPluginStart; From f3ae23b5296725ccf712fe022eedfbf01d413d86 Mon Sep 17 00:00:00 2001 From: James Gowdy Date: Tue, 28 Jul 2020 13:46:53 +0100 Subject: [PATCH 4/7] small refactor --- .../lib/capabilities/capabilities_switcher.ts | 21 +++++++------------ 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/x-pack/plugins/ml/server/lib/capabilities/capabilities_switcher.ts b/x-pack/plugins/ml/server/lib/capabilities/capabilities_switcher.ts index 0eeb7a885134..f2fff4cc64aa 100644 --- a/x-pack/plugins/ml/server/lib/capabilities/capabilities_switcher.ts +++ b/x-pack/plugins/ml/server/lib/capabilities/capabilities_switcher.ts @@ -30,24 +30,23 @@ function getSwitcher(license$: Observable, logger: Logger): Capabiliti try { const license = await license$.pipe(take(1)).toPromise(); - const mlCaps = capabilities.ml as MlCapabilities; - if (isMlEnabled(license) === false) { - disableAllCapabilities(mlCaps); - return capabilities; - } + const mlEnabled = isMlEnabled(license); // full license, leave capabilities as they were - if (isFullLicense(license)) { + if (mlEnabled && isFullLicense(license)) { return capabilities; } + const mlCaps = capabilities.ml as MlCapabilities; const originalCapabilities = cloneDeep(mlCaps); // not full licence, switch off all capabilities - disableAllCapabilities(mlCaps); + Object.keys(mlCaps).forEach((k) => { + mlCaps[k as keyof MlCapabilities] = false; + }); // for a basic license, reapply the original capabilities for the basic license features - if (isMinimumLicense(license)) { + if (mlEnabled && isMinimumLicense(license)) { basicLicenseMlCapabilities.forEach((c) => (mlCaps[c] = originalCapabilities[c])); } @@ -58,9 +57,3 @@ function getSwitcher(license$: Observable, logger: Logger): Capabiliti } }; } - -function disableAllCapabilities(mlCaps: MlCapabilities) { - Object.keys(mlCaps).forEach((k) => { - mlCaps[k as keyof MlCapabilities] = false; - }); -} From eb28cfe9857053c7adf66494b848f40508e96e78 Mon Sep 17 00:00:00 2001 From: James Gowdy Date: Wed, 29 Jul 2020 11:55:03 +0100 Subject: [PATCH 5/7] disabling ml using plugin updater --- x-pack/plugins/ml/public/plugin.ts | 122 +++++++++++----------- x-pack/plugins/ml/public/url_generator.ts | 20 +++- 2 files changed, 82 insertions(+), 60 deletions(-) diff --git a/x-pack/plugins/ml/public/plugin.ts b/x-pack/plugins/ml/public/plugin.ts index 05ef44365eae..14c2725e20f9 100644 --- a/x-pack/plugins/ml/public/plugin.ts +++ b/x-pack/plugins/ml/public/plugin.ts @@ -12,6 +12,7 @@ import { AppMountParameters, PluginInitializerContext, } from 'kibana/public'; +import { BehaviorSubject } from 'rxjs'; import { take } from 'rxjs/operators'; import { ManagementSetup } from 'src/plugins/management/public'; import { SharePluginSetup, SharePluginStart, UrlGeneratorState } from 'src/plugins/share/public'; @@ -20,6 +21,7 @@ import { UsageCollectionSetup } from 'src/plugins/usage_collection/server'; import { DataPublicPluginStart } from 'src/plugins/data/public'; import { HomePublicPluginSetup } from 'src/plugins/home/public'; import { EmbeddableSetup } from 'src/plugins/embeddable/public'; +import { AppStatus, AppUpdater } from '../../../../src/core/public'; import { SecurityPluginSetup } from '../../security/public'; import { LicensingPluginSetup } from '../../licensing/public'; import { initManagementSection } from './application/management'; @@ -32,7 +34,7 @@ import { registerEmbeddables } from './embeddables'; import { UiActionsSetup, UiActionsStart } from '../../../../src/plugins/ui_actions/public'; import { registerMlUiActions } from './ui_actions'; import { KibanaLegacyStart } from '../../../../src/plugins/kibana_legacy/public'; -import { MlUrlGenerator, MlUrlGeneratorState, ML_APP_URL_GENERATOR } from './url_generator'; +import { registerUrlGenerator, MlUrlGeneratorState, ML_APP_URL_GENERATOR } from './url_generator'; import { isMlEnabled, isFullLicense } from '../common/license'; export interface MlStartDependencies { @@ -63,71 +65,73 @@ declare module '../../../../src/plugins/share/public' { export type MlCoreSetup = CoreSetup; export class MlPlugin implements Plugin { + private appUpdater = new BehaviorSubject(() => ({})); + constructor(private initializerContext: PluginInitializerContext) {} - async setup(core: MlCoreSetup, pluginsSetup: MlSetupDependencies) { + setup(core: MlCoreSetup, pluginsSetup: MlSetupDependencies) { + core.application.register({ + id: PLUGIN_ID, + title: i18n.translate('xpack.ml.plugin.title', { + defaultMessage: 'Machine Learning', + }), + order: 5000, + euiIconType: PLUGIN_ICON, + appRoute: '/app/ml', + category: DEFAULT_APP_CATEGORIES.kibana, + updater$: this.appUpdater, + mount: async (params: AppMountParameters) => { + const [coreStart, pluginsStart] = await core.getStartServices(); + const kibanaVersion = this.initializerContext.env.packageInfo.version; + const { renderApp } = await import('./application/app'); + return renderApp( + coreStart, + { + data: pluginsStart.data, + share: pluginsStart.share, + kibanaLegacy: pluginsStart.kibanaLegacy, + security: pluginsSetup.security, + licensing: pluginsSetup.licensing, + management: pluginsSetup.management, + usageCollection: pluginsSetup.usageCollection, + licenseManagement: pluginsSetup.licenseManagement, + home: pluginsSetup.home, + embeddable: pluginsSetup.embeddable, + uiActions: pluginsStart.uiActions, + kibanaVersion, + }, + { + element: params.element, + appBasePath: params.appBasePath, + onAppLeave: params.onAppLeave, + history: params.history, + } + ); + }, + }); + const licensing = pluginsSetup.licensing.license$.pipe(take(1)); licensing.subscribe((license) => { - if (isMlEnabled(license) === false) { - return; - } - - const baseUrl = core.http.basePath.prepend('/app/ml'); + if (isMlEnabled(license)) { + // add ML to home page + registerFeature(pluginsSetup.home); - pluginsSetup.share.urlGenerators.registerUrlGenerator( - new MlUrlGenerator({ - appBasePath: baseUrl, - useHash: core.uiSettings.get('state:storeInSessionStorage'), - }) - ); - - core.application.register({ - id: PLUGIN_ID, - title: i18n.translate('xpack.ml.plugin.title', { - defaultMessage: 'Machine Learning', - }), - order: 5000, - euiIconType: PLUGIN_ICON, - appRoute: '/app/ml', - category: DEFAULT_APP_CATEGORIES.kibana, - mount: async (params: AppMountParameters) => { - const [coreStart, pluginsStart] = await core.getStartServices(); - const kibanaVersion = this.initializerContext.env.packageInfo.version; - const { renderApp } = await import('./application/app'); - return renderApp( - coreStart, - { - data: pluginsStart.data, - share: pluginsStart.share, - kibanaLegacy: pluginsStart.kibanaLegacy, - security: pluginsSetup.security, - licensing: pluginsSetup.licensing, - management: pluginsSetup.management, - usageCollection: pluginsSetup.usageCollection, - licenseManagement: pluginsSetup.licenseManagement, - home: pluginsSetup.home, - embeddable: pluginsSetup.embeddable, - uiActions: pluginsStart.uiActions, - kibanaVersion, - }, - { - element: params.element, - appBasePath: params.appBasePath, - onAppLeave: params.onAppLeave, - history: params.history, - } - ); - }, - }); - - registerFeature(pluginsSetup.home); - - if (isFullLicense(license)) { - initManagementSection(pluginsSetup.management, core); + // register various ML plugin features which require a full license + if (isFullLicense(license)) { + initManagementSection(pluginsSetup.management, core); + registerEmbeddables(pluginsSetup.embeddable, core); + registerMlUiActions(pluginsSetup.uiActions, core); + registerUrlGenerator(pluginsSetup.share, core); + } + } else { + // if ml is disabled in elasticsearch, + // disable ML in kibana + this.appUpdater.next(() => ({ + status: AppStatus.inaccessible, + })); } - registerEmbeddables(pluginsSetup.embeddable, core); - registerMlUiActions(pluginsSetup.uiActions, core); }); + return {}; } diff --git a/x-pack/plugins/ml/public/url_generator.ts b/x-pack/plugins/ml/public/url_generator.ts index 65d5077e081a..c2b57f6349d8 100644 --- a/x-pack/plugins/ml/public/url_generator.ts +++ b/x-pack/plugins/ml/public/url_generator.ts @@ -4,11 +4,13 @@ * you may not use this file except in compliance with the Elastic License. */ -import { UrlGeneratorsDefinition } from '../../../../src/plugins/share/public'; +import { CoreSetup } from 'kibana/public'; +import { SharePluginSetup, UrlGeneratorsDefinition } from '../../../../src/plugins/share/public'; import { TimeRange } from '../../../../src/plugins/data/public'; import { setStateToKbnUrl } from '../../../../src/plugins/kibana_utils/public'; import { JobId } from '../../reporting/common/types'; import { ExplorerAppState } from './application/explorer/explorer_dashboard_service'; +import { MlStartDependencies } from './plugin'; export const ML_APP_URL_GENERATOR = 'ML_APP_URL_GENERATOR'; @@ -88,3 +90,19 @@ export class MlUrlGenerator implements UrlGeneratorsDefinition +) { + const baseUrl = core.http.basePath.prepend('/app/ml'); + share.urlGenerators.registerUrlGenerator( + new MlUrlGenerator({ + appBasePath: baseUrl, + useHash: core.uiSettings.get('state:storeInSessionStorage'), + }) + ); +} From 8347c5b11ac22f48200040dcda48b261a31e8a08 Mon Sep 17 00:00:00 2001 From: James Gowdy Date: Wed, 29 Jul 2020 12:06:16 +0100 Subject: [PATCH 6/7] function rename --- x-pack/plugins/ml/public/application/management/index.ts | 2 +- x-pack/plugins/ml/public/plugin.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/x-pack/plugins/ml/public/application/management/index.ts b/x-pack/plugins/ml/public/application/management/index.ts index 61b497391249..a1b8484f200e 100644 --- a/x-pack/plugins/ml/public/application/management/index.ts +++ b/x-pack/plugins/ml/public/application/management/index.ts @@ -18,7 +18,7 @@ import { MlStartDependencies } from '../../plugin'; import { ManagementAppMountParams } from '../../../../../../src/plugins/management/public'; -export function initManagementSection( +export function registerManagementSection( management: ManagementSetup | undefined, core: CoreSetup ) { diff --git a/x-pack/plugins/ml/public/plugin.ts b/x-pack/plugins/ml/public/plugin.ts index 14c2725e20f9..6fed092aacdb 100644 --- a/x-pack/plugins/ml/public/plugin.ts +++ b/x-pack/plugins/ml/public/plugin.ts @@ -24,7 +24,7 @@ import { EmbeddableSetup } from 'src/plugins/embeddable/public'; import { AppStatus, AppUpdater } from '../../../../src/core/public'; import { SecurityPluginSetup } from '../../security/public'; import { LicensingPluginSetup } from '../../licensing/public'; -import { initManagementSection } from './application/management'; +import { registerManagementSection } from './application/management'; import { LicenseManagementUIPluginSetup } from '../../license_management/public'; import { setDependencyCache } from './application/util/dependency_cache'; import { PLUGIN_ID, PLUGIN_ICON } from '../common/constants/app'; @@ -118,7 +118,7 @@ export class MlPlugin implements Plugin { // register various ML plugin features which require a full license if (isFullLicense(license)) { - initManagementSection(pluginsSetup.management, core); + registerManagementSection(pluginsSetup.management, core); registerEmbeddables(pluginsSetup.embeddable, core); registerMlUiActions(pluginsSetup.uiActions, core); registerUrlGenerator(pluginsSetup.share, core); From 13258932e9ee9bb9186b358bc0745fb93b57e419 Mon Sep 17 00:00:00 2001 From: James Gowdy Date: Wed, 29 Jul 2020 12:07:36 +0100 Subject: [PATCH 7/7] update comment --- x-pack/plugins/ml/public/plugin.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/x-pack/plugins/ml/public/plugin.ts b/x-pack/plugins/ml/public/plugin.ts index 6fed092aacdb..a8e1e804c2fe 100644 --- a/x-pack/plugins/ml/public/plugin.ts +++ b/x-pack/plugins/ml/public/plugin.ts @@ -124,8 +124,7 @@ export class MlPlugin implements Plugin { registerUrlGenerator(pluginsSetup.share, core); } } else { - // if ml is disabled in elasticsearch, - // disable ML in kibana + // if ml is disabled in elasticsearch, disable ML in kibana this.appUpdater.next(() => ({ status: AppStatus.inaccessible, }));