2020-02-28 03:15:08 +01:00
|
|
|
/*
|
|
|
|
* 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';
|
2020-03-12 11:04:40 +01:00
|
|
|
import {
|
|
|
|
CoreSetup,
|
|
|
|
Plugin,
|
|
|
|
IScopedClusterClient,
|
|
|
|
Logger,
|
|
|
|
PluginInitializerContext,
|
|
|
|
} from 'kibana/server';
|
2020-03-04 11:14:11 +01:00
|
|
|
import { PluginsSetup, RouteInitialization } from './types';
|
2020-03-13 20:16:41 +01:00
|
|
|
import { PLUGIN_ID, PLUGIN_ICON } from '../common/constants/app';
|
2020-02-28 03:15:08 +01:00
|
|
|
|
|
|
|
import { elasticsearchJsPlugin } from './client/elasticsearch_ml';
|
2020-03-18 09:33:53 +01:00
|
|
|
import { initMlTelemetry } from './lib/telemetry';
|
2020-02-28 03:15:08 +01:00
|
|
|
import { initMlServerLog } from './client/log';
|
2020-03-04 11:14:11 +01:00
|
|
|
import { initSampleDataSets } from './lib/sample_data_sets';
|
2020-02-28 03:15:08 +01:00
|
|
|
|
|
|
|
import { annotationRoutes } from './routes/annotations';
|
|
|
|
import { calendars } from './routes/calendars';
|
|
|
|
import { dataFeedRoutes } from './routes/datafeeds';
|
|
|
|
import { dataFrameAnalyticsRoutes } from './routes/data_frame_analytics';
|
|
|
|
import { dataRecognizer } from './routes/modules';
|
|
|
|
import { dataVisualizerRoutes } from './routes/data_visualizer';
|
|
|
|
import { fieldsService } from './routes/fields_service';
|
|
|
|
import { fileDataVisualizerRoutes } from './routes/file_data_visualizer';
|
|
|
|
import { filtersRoutes } from './routes/filters';
|
|
|
|
import { indicesRoutes } from './routes/indices';
|
|
|
|
import { jobAuditMessagesRoutes } from './routes/job_audit_messages';
|
|
|
|
import { jobRoutes } from './routes/anomaly_detectors';
|
|
|
|
import { jobServiceRoutes } from './routes/job_service';
|
|
|
|
import { jobValidationRoutes } from './routes/job_validation';
|
|
|
|
import { notificationRoutes } from './routes/notification_settings';
|
|
|
|
import { resultsServiceRoutes } from './routes/results_service';
|
|
|
|
import { systemRoutes } from './routes/system';
|
2020-03-13 20:16:41 +01:00
|
|
|
import { MlLicense } from '../common/license';
|
2020-03-04 11:14:11 +01:00
|
|
|
import { MlServerLicense } from './lib/license';
|
2020-03-12 11:04:40 +01:00
|
|
|
import { createSharedServices, SharedServices } from './shared_services';
|
2020-02-28 03:15:08 +01:00
|
|
|
|
|
|
|
declare module 'kibana/server' {
|
|
|
|
interface RequestHandlerContext {
|
|
|
|
ml?: {
|
|
|
|
mlClient: IScopedClusterClient;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-24 15:25:59 +01:00
|
|
|
export type MlPluginSetup = SharedServices;
|
|
|
|
export type MlPluginStart = void;
|
2020-03-12 11:04:40 +01:00
|
|
|
|
2020-03-24 15:25:59 +01:00
|
|
|
export class MlServerPlugin implements Plugin<MlPluginSetup, MlPluginStart, PluginsSetup> {
|
2020-02-28 03:15:08 +01:00
|
|
|
private log: Logger;
|
|
|
|
private version: string;
|
2020-03-04 11:14:11 +01:00
|
|
|
private mlLicense: MlServerLicense;
|
2020-02-28 03:15:08 +01:00
|
|
|
|
|
|
|
constructor(ctx: PluginInitializerContext) {
|
|
|
|
this.log = ctx.logger.get();
|
|
|
|
this.version = ctx.env.packageInfo.branch;
|
2020-03-04 11:14:11 +01:00
|
|
|
this.mlLicense = new MlServerLicense();
|
2020-02-28 03:15:08 +01:00
|
|
|
}
|
|
|
|
|
2020-03-24 15:25:59 +01:00
|
|
|
public setup(coreSetup: CoreSetup, plugins: PluginsSetup): MlPluginSetup {
|
2020-02-28 03:15:08 +01:00
|
|
|
plugins.features.registerFeature({
|
|
|
|
id: PLUGIN_ID,
|
|
|
|
name: i18n.translate('xpack.ml.featureRegistry.mlFeatureName', {
|
|
|
|
defaultMessage: 'Machine Learning',
|
|
|
|
}),
|
2020-03-13 20:16:41 +01:00
|
|
|
icon: PLUGIN_ICON,
|
2020-03-24 16:12:49 +01:00
|
|
|
order: 500,
|
2020-02-28 03:15:08 +01:00
|
|
|
navLinkId: PLUGIN_ID,
|
|
|
|
app: [PLUGIN_ID, 'kibana'],
|
|
|
|
catalogue: [PLUGIN_ID],
|
2020-03-24 16:12:49 +01:00
|
|
|
privileges: null,
|
2020-02-28 03:15:08 +01:00
|
|
|
reserved: {
|
|
|
|
privilege: {
|
2020-03-24 16:12:49 +01:00
|
|
|
app: [PLUGIN_ID, 'kibana'],
|
|
|
|
catalogue: [PLUGIN_ID],
|
2020-02-28 03:15:08 +01:00
|
|
|
savedObject: {
|
|
|
|
all: [],
|
|
|
|
read: [],
|
|
|
|
},
|
|
|
|
ui: [],
|
|
|
|
},
|
|
|
|
description: i18n.translate('xpack.ml.feature.reserved.description', {
|
|
|
|
defaultMessage:
|
|
|
|
'To grant users access, you should also assign either the machine_learning_user or machine_learning_admin role.',
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2020-03-04 11:14:11 +01:00
|
|
|
this.mlLicense.setup(plugins.licensing.license$, [
|
|
|
|
(mlLicense: MlLicense) => initSampleDataSets(mlLicense, plugins),
|
|
|
|
]);
|
|
|
|
|
2020-02-28 03:15:08 +01:00
|
|
|
// Can access via router's handler function 'context' parameter - context.ml.mlClient
|
|
|
|
const mlClient = coreSetup.elasticsearch.createClient(PLUGIN_ID, {
|
|
|
|
plugins: [elasticsearchJsPlugin],
|
|
|
|
});
|
|
|
|
|
|
|
|
coreSetup.http.registerRouteHandlerContext(PLUGIN_ID, (context, request) => {
|
|
|
|
return {
|
|
|
|
mlClient: mlClient.asScoped(request),
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
const routeInit: RouteInitialization = {
|
|
|
|
router: coreSetup.http.createRouter(),
|
2020-03-04 11:14:11 +01:00
|
|
|
mlLicense: this.mlLicense,
|
2020-02-28 03:15:08 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
annotationRoutes(routeInit, plugins.security);
|
|
|
|
calendars(routeInit);
|
|
|
|
dataFeedRoutes(routeInit);
|
|
|
|
dataFrameAnalyticsRoutes(routeInit);
|
|
|
|
dataRecognizer(routeInit);
|
|
|
|
dataVisualizerRoutes(routeInit);
|
|
|
|
fieldsService(routeInit);
|
|
|
|
fileDataVisualizerRoutes(routeInit);
|
|
|
|
filtersRoutes(routeInit);
|
|
|
|
indicesRoutes(routeInit);
|
|
|
|
jobAuditMessagesRoutes(routeInit);
|
|
|
|
jobRoutes(routeInit);
|
|
|
|
jobServiceRoutes(routeInit);
|
|
|
|
notificationRoutes(routeInit);
|
|
|
|
resultsServiceRoutes(routeInit);
|
|
|
|
jobValidationRoutes(routeInit, this.version);
|
|
|
|
systemRoutes(routeInit, {
|
2020-03-05 16:06:36 +01:00
|
|
|
spaces: plugins.spaces,
|
2020-02-28 03:15:08 +01:00
|
|
|
cloud: plugins.cloud,
|
|
|
|
});
|
|
|
|
initMlServerLog({ log: this.log });
|
2020-03-18 09:33:53 +01:00
|
|
|
initMlTelemetry(coreSetup, plugins.usageCollection);
|
2020-03-12 11:04:40 +01:00
|
|
|
|
|
|
|
return createSharedServices(this.mlLicense, plugins.spaces, plugins.cloud);
|
2020-02-28 03:15:08 +01:00
|
|
|
}
|
|
|
|
|
2020-03-24 15:25:59 +01:00
|
|
|
public start(): MlPluginStart {}
|
2020-02-28 03:15:08 +01:00
|
|
|
|
2020-03-04 11:14:11 +01:00
|
|
|
public stop() {
|
|
|
|
this.mlLicense.unsubscribe();
|
|
|
|
}
|
2020-02-28 03:15:08 +01:00
|
|
|
}
|