Skip to content

Commit

Permalink
[ML] Register ML for the kibana home page
Browse files Browse the repository at this point in the history
  • Loading branch information
jgowdyelastic committed Apr 3, 2020
1 parent c3aa421 commit 773ba85
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
11 changes: 10 additions & 1 deletion x-pack/plugins/ml/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ import { SharePluginStart } from 'src/plugins/share/public';
import { UsageCollectionSetup } from 'src/plugins/usage_collection/server';

import { DataPublicPluginStart } from 'src/plugins/data/public';
import { HomePublicPluginSetup } from 'src/plugins/home/public';
import { SecurityPluginSetup } from '../../security/public';
import { LicensingPluginSetup } from '../../licensing/public';
import { initManagementSection } 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';
import { registerFeature } from './register_feature';

export interface MlStartDependencies {
data: DataPublicPluginStart;
Expand All @@ -28,10 +30,14 @@ export interface MlSetupDependencies {
management: ManagementSetup;
usageCollection: UsageCollectionSetup;
licenseManagement?: LicenseManagementUIPluginSetup;
home: HomePublicPluginSetup;
}

export class MlPlugin implements Plugin<MlPluginSetup, MlPluginStart> {
setup(core: CoreSetup<MlStartDependencies, MlPluginStart>, pluginsSetup: MlSetupDependencies) {
const home = pluginsSetup.home;
const licensing = pluginsSetup.licensing;

core.application.register({
id: PLUGIN_ID,
title: i18n.translate('xpack.ml.plugin.title', {
Expand All @@ -49,10 +55,11 @@ export class MlPlugin implements Plugin<MlPluginSetup, MlPluginStart> {
data: pluginsStart.data,
share: pluginsStart.share,
security: pluginsSetup.security,
licensing: pluginsSetup.licensing,
management: pluginsSetup.management,
usageCollection: pluginsSetup.usageCollection,
licenseManagement: pluginsSetup.licenseManagement,
licensing,
home,
},
{
element: params.element,
Expand All @@ -64,6 +71,8 @@ export class MlPlugin implements Plugin<MlPluginSetup, MlPluginStart> {
},
});

registerFeature(licensing, home);

initManagementSection(pluginsSetup, core);
return {};
}
Expand Down
41 changes: 41 additions & 0 deletions x-pack/plugins/ml/public/register_feature.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import { i18n } from '@kbn/i18n';
import {
HomePublicPluginSetup,
FeatureCatalogueCategory,
} from '../../../../src/plugins/home/public';
import { LicensingPluginSetup } from '../../licensing/public';
import { PLUGIN_ID } from '../common/constants/app';
import { MINIMUM_LICENSE } from '../common/license';
import { LICENSE_CHECK_STATE } from '../../licensing/common/types';

export const registerFeature = (license: LicensingPluginSetup, home: HomePublicPluginSetup) => {
license.license$.subscribe(async lic => {
if (lic.check(PLUGIN_ID, MINIMUM_LICENSE).state === LICENSE_CHECK_STATE.Valid) {
// register ML for the kibana home screen.
// so the file data visualizer appears to allow people to import data
home.environment.update({ ml: true });

// register ML to appear on the app list
home.featureCatalogue.register({
id: PLUGIN_ID,
title: i18n.translate('xpack.ml.machineLearningTitle', {
defaultMessage: 'Machine Learning',
}),
description: i18n.translate('xpack.ml.machineLearningDescription', {
defaultMessage:
'Automatically model the normal behavior of your time series data to detect anomalies.',
}),
icon: 'machineLearningApp',
path: '/app/ml',
showOnHomePage: true,
category: FeatureCatalogueCategory.DATA,
});
}
});
};

0 comments on commit 773ba85

Please sign in to comment.