[ML] Fix registering home screen panel (#79080)

* [ML] Import tweak.

* [ML] Attempt at fixing flaky registering.

* [ML] Re-enable tests.

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
Walter Rafelsberger 2020-10-07 11:22:07 +02:00 committed by GitHub
parent edce4ebcd9
commit f1905ecaf5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 30 deletions

View file

@ -30,16 +30,20 @@ import type { EmbeddableSetup } from 'src/plugins/embeddable/public';
import { AppStatus, AppUpdater, DEFAULT_APP_CATEGORIES } from '../../../../src/core/public';
import type { UiActionsSetup, UiActionsStart } from '../../../../src/plugins/ui_actions/public';
import type { KibanaLegacyStart } from '../../../../src/plugins/kibana_legacy/public';
import { MlCardState } from '../../../../src/plugins/index_pattern_management/public';
import type { LicenseManagementUIPluginSetup } from '../../license_management/public';
import type { LicensingPluginSetup } from '../../licensing/public';
import type { SecurityPluginSetup } from '../../security/public';
import { PLUGIN_ICON_SOLUTION, PLUGIN_ID } from '../common/constants/app';
import { ML_APP_URL_GENERATOR } from '../common/constants/ml_url_generator';
import { isFullLicense, isMlEnabled } from '../common/license';
import { setDependencyCache } from './application/util/dependency_cache';
import { ML_APP_URL_GENERATOR } from '../common/constants/ml_url_generator';
import { registerUrlGenerator } from './ml_url_generator';
import { registerFeature } from './register_feature';
// Not importing from `ml_url_generator/index` here to avoid importing unnecessary code
import { registerUrlGenerator } from './ml_url_generator/ml_url_generator';
export interface MlStartDependencies {
data: DataPublicPluginStart;
@ -112,46 +116,39 @@ export class MlPlugin implements Plugin<MlPluginSetup, MlPluginStart> {
const licensing = pluginsSetup.licensing.license$.pipe(take(1));
licensing.subscribe(async (license) => {
const [coreStart] = await core.getStartServices();
const {
isFullLicense,
isMlEnabled,
registerEmbeddables,
registerFeature,
registerManagementSection,
registerMlUiActions,
MlCardState,
} = await import('./register_helper');
const { capabilities } = coreStart.application;
if (isMlEnabled(license)) {
// add ML to home page
if (pluginsSetup.home) {
registerFeature(pluginsSetup.home);
}
const { capabilities } = coreStart.application;
// register ML for the index pattern management no data screen.
pluginsSetup.indexPatternManagement.environment.update({
ml: () =>
capabilities.ml.canFindFileStructure ? MlCardState.ENABLED : MlCardState.HIDDEN,
});
const canManageMLJobs = capabilities.management?.insightsAndAlerting?.jobsListLink ?? false;
// register various ML plugin features which require a full license
if (isFullLicense(license)) {
if (canManageMLJobs && pluginsSetup.management !== undefined) {
registerManagementSection(pluginsSetup.management, core).enable();
}
registerEmbeddables(pluginsSetup.embeddable, core);
registerMlUiActions(pluginsSetup.uiActions, core);
}
} else {
// if ml is disabled in elasticsearch, disable ML in kibana
this.appUpdater.next(() => ({
status: AppStatus.inaccessible,
}));
}
// register various ML plugin features which require a full license
const { registerEmbeddables, registerManagementSection, registerMlUiActions } = await import(
'./register_helper'
);
if (isMlEnabled(license) && isFullLicense(license)) {
const canManageMLJobs = capabilities.management?.insightsAndAlerting?.jobsListLink ?? false;
if (canManageMLJobs && pluginsSetup.management !== undefined) {
registerManagementSection(pluginsSetup.management, core).enable();
}
registerEmbeddables(pluginsSetup.embeddable, core);
registerMlUiActions(pluginsSetup.uiActions, core);
}
});
return {

View file

@ -4,10 +4,6 @@
* you may not use this file except in compliance with the Elastic License.
*/
export { MlCardState } from '../../../../src/plugins/index_pattern_management/public';
export { isFullLicense, isMlEnabled } from '../common/license';
export { registerEmbeddables } from './embeddables';
export { registerFeature } from './register_feature';
export { registerManagementSection } from './application/management';

View file

@ -16,8 +16,7 @@ export default function ({ getService }: FtrProviderContext) {
const testUsers = [USER.ML_POWERUSER, USER.ML_POWERUSER_SPACES];
// flaky UI behavior makes this test fail, see https://github.com/elastic/kibana/issues/78965
describe.skip('for user with full ML access', function () {
describe('for user with full ML access', function () {
this.tags(['skipFirefox', 'mlqa']);
describe('with no data loaded', function () {