Skip to content

Commit

Permalink
[ML] Fix registering home screen panel (#79080)
Browse files Browse the repository at this point in the history
* [ML] Import tweak.

* [ML] Attempt at fixing flaky registering.

* [ML] Re-enable tests.

Co-authored-by: Kibana Machine <[email protected]>
  • Loading branch information
walterra and kibanamachine authored Oct 7, 2020
1 parent edce4eb commit f1905ec
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 30 deletions.
45 changes: 21 additions & 24 deletions x-pack/plugins/ml/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 0 additions & 4 deletions x-pack/plugins/ml/public/register_helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
3 changes: 1 addition & 2 deletions x-pack/test/functional/apps/ml/permissions/full_ml_access.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down

0 comments on commit f1905ec

Please sign in to comment.