From 6faa9810531359c0c51f0619aa256fad3ba7a380 Mon Sep 17 00:00:00 2001 From: Christiane Heiligers Date: Mon, 11 Nov 2019 17:11:49 -0700 Subject: [PATCH 01/21] [NP:Kibana:homeAPI] initializes a new plugin (WIP) --- src/legacy/ui/tutorials_mixin.js | 32 ++++ src/plugins/tutorials/kibana.json | 6 + src/plugins/tutorials/server/index.ts | 25 +++ src/plugins/tutorials/server/plugin.ts | 42 +++++ src/plugins/tutorials/server/routes/index.ts | 19 +++ .../tutorials/server/services/index.ts | 26 +++ .../server/services/tutorials_registry.ts | 161 ++++++++++++++++++ 7 files changed, 311 insertions(+) create mode 100644 src/plugins/tutorials/kibana.json create mode 100644 src/plugins/tutorials/server/index.ts create mode 100644 src/plugins/tutorials/server/plugin.ts create mode 100644 src/plugins/tutorials/server/routes/index.ts create mode 100644 src/plugins/tutorials/server/services/index.ts create mode 100644 src/plugins/tutorials/server/services/tutorials_registry.ts diff --git a/src/legacy/ui/tutorials_mixin.js b/src/legacy/ui/tutorials_mixin.js index af3663a83b812..368cd0f664a5e 100644 --- a/src/legacy/ui/tutorials_mixin.js +++ b/src/legacy/ui/tutorials_mixin.js @@ -19,6 +19,38 @@ import Joi from 'joi'; import { tutorialSchema } from '../core_plugins/kibana/common/tutorials/tutorial_schema'; +// import { schema } from '@kbn/config-schema'; + +class TutorialsPlugin { + setup(core) { + const tutorialProviders = []; + const scopedTutorialContextFactories = []; + + core.http.registerRouteHandlerContext('getTutorials', (request) => { + const initialContext = {}; + const scopedContext = scopedTutorialContextFactories.reduce((accumulatedContext, contextFactory) => { + return { ...accumulatedContext, ...contextFactory(request) }; + }, initialContext); + + return tutorialProviders.map((tutorialProvider) => { + return tutorialProvider(server, scopedContext); + }); + }); + + return { + registerTutorial(specProvider) { + const emptyContext = {}; + const { error } = Joi.validate(specProvider(server, emptyContext), tutorialSchema); + + if (error) { + throw new Error(`Unable to register tutorial spec because its invalid. ${error}`); + } + + tutorialProviders.push(specProvider); + } + }; + } +} export function tutorialsMixin(kbnServer, server) { const tutorialProviders = []; diff --git a/src/plugins/tutorials/kibana.json b/src/plugins/tutorials/kibana.json new file mode 100644 index 0000000000000..0b931ccfb1514 --- /dev/null +++ b/src/plugins/tutorials/kibana.json @@ -0,0 +1,6 @@ +{ + "id": "tutorials", + "version": "kibana", + "server": true, + "ui": false +} diff --git a/src/plugins/tutorials/server/index.ts b/src/plugins/tutorials/server/index.ts new file mode 100644 index 0000000000000..5a2b4789badbb --- /dev/null +++ b/src/plugins/tutorials/server/index.ts @@ -0,0 +1,25 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +export { TutorialsSetup, TutorialsStart } from './plugin'; // types +import { TutorialsPlugin } from './plugin'; // the actual plugin class +// also export other relevant subtypes + +export const plugin = () => new TutorialsPlugin(); +// export const config = () => new TutorialsConfig(); optional, only if needed diff --git a/src/plugins/tutorials/server/plugin.ts b/src/plugins/tutorials/server/plugin.ts new file mode 100644 index 0000000000000..cad7fc9164a3a --- /dev/null +++ b/src/plugins/tutorials/server/plugin.ts @@ -0,0 +1,42 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { CoreSetup, Plugin } from 'src/core/server'; +import { TutorialsRegistrySetup, TutorialsRegistryStart, TutorialsRegistry } from './services'; + +// following similar signature to the features_catalogue plugin +export class TutorialsPlugin implements Plugin { + private readonly tutorialsRegistry = new TutorialsRegistry(); + public async setup(core: CoreSetup) { + return { + ...this.tutorialsRegistry.setup(), + }; + } + public async start() { + return { + ...this.tutorialsRegistry.start(), + }; + } +} + +/** @public */ +export type TutorialsSetup = TutorialsRegistrySetup; + +/** @public */ +export type TutorialsStart = TutorialsRegistryStart; diff --git a/src/plugins/tutorials/server/routes/index.ts b/src/plugins/tutorials/server/routes/index.ts new file mode 100644 index 0000000000000..cb4f1d79a3ee9 --- /dev/null +++ b/src/plugins/tutorials/server/routes/index.ts @@ -0,0 +1,19 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +// HTTP routes diff --git a/src/plugins/tutorials/server/services/index.ts b/src/plugins/tutorials/server/services/index.ts new file mode 100644 index 0000000000000..dce2521b1dea8 --- /dev/null +++ b/src/plugins/tutorials/server/services/index.ts @@ -0,0 +1,26 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +// provided to other plugins as APIs +// should model the plugin lifecycle + +export { + TutorialsRegistry, + TutorialsRegistrySetup, + TutorialsRegistryStart, +} from './tutorials_registry'; diff --git a/src/plugins/tutorials/server/services/tutorials_registry.ts b/src/plugins/tutorials/server/services/tutorials_registry.ts new file mode 100644 index 0000000000000..4829c606188e8 --- /dev/null +++ b/src/plugins/tutorials/server/services/tutorials_registry.ts @@ -0,0 +1,161 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { IconType } from '@elastic/eui'; +import { CoreSetup } from 'src/core/server'; +/** @public */ +export enum TutorialsCategory { + LOGGING = 'logging', + SIEM = 'siem', + METRICS = 'metrics', + OTHER = 'other', +} +export interface ParamTypes { + NUMBER: string; + STRING: string; +} +export interface InstructionSetSchema { + readonly title: string; + readonly callOut: { + title: string; + message: string; + iconType: IconType; + }; +} +export interface ParamsSchema { + defaultValue: any; + id: string; + label: string; + type: ParamTypes; +} +export interface InstructionsSchema { + readonly instructionSets: InstructionSetSchema[]; + readonly params: ParamsSchema[]; +} +export interface DashboardSchema { + id: string; + linkLabel?: { + is: boolean; + then: any; + }; + isOverview: boolean; +} +export interface ArtifactsSchema { + readonly exportedFields: { + documentationUrl: string; + }; + readonly dashboards: DashboardSchema[]; + readonly application: { + path: string; + label: string; + }; +} +export interface TutorialSchema { + readonly id: string; + readonly category: TutorialsCategory; + readonly name: string; + readonly isBeta: boolean; + readonly shortDescription: string; + readonly euiIconType: IconType; // EUI icon type string, one of https://elastic.github.io/eui/#/icon; + readonly longDescription: string; + readonly completionTimeMinutes: number; + readonly previewImagePath: string; + + // kibana and elastic cluster running on prem + readonly onPrem: InstructionsSchema; + + // kibana and elastic cluster running in elastic's cloud + readonly elasticCloud: InstructionsSchema; + + // kibana running on prem and elastic cluster running in elastic's cloud + readonly onPremElasticCloud: InstructionsSchema; + + // Elastic stack artifacts produced by product when it is setup and run. + readonly artifacts: ArtifactsSchema; + + // saved objects used by data module. + readonly savedObjects: any[]; + readonly savedObjectsInstallMsg: string; +} + +export class TutorialsRegistry { + public setup(core: CoreSetup) { + const tutorialProviders: Array<(tutorialProvider: TutorialSchema) => void>; + const scopedTutorialContextFactories: Array<(scopedTutorialContextFactory: any) => void>; + core.http.registerRouteHandlerContext('getTutorials', (request: any) => { + const intitialContext = new Map(); + const scopedContext = scopedTutorialContextFactories.reduce( + (accumulatedContext, contextFactory) => { + return { ...accumulatedContext, ...contextFactory(request) }; + }, + intitialContext + ); + return tutorialProviders.map(tutorialProvider => { + return tutorialProvider(scopedContext); + }); + }); + + return { + register: () => {}, + }; + } + + public start() { + return { + get: () => {}, + }; + } +} + +export type TutorialsRegistrySetup = ReturnType; +export type TutorialsRegistryStart = ReturnType; + +// from Josh Dover: (this should actually be the TutorialsRegistry) +/* +class TutorialsPlugin { + setup(core) { + const tutorialProviders = []; + const scopedTutorialContextFactories = []; + + core.http.registerRouteHandlerContext('getTutorials', (request) => { + const initialContext = {}; + const scopedContext = scopedTutorialContextFactories.reduce((accumulatedContext, contextFactory) => { + return { ...accumulatedContext, ...contextFactory(request) }; + }, initialContext); + + return tutorialProviders.map((tutorialProvider) => { + return tutorialProvider(server, scopedContext); + }); + }); + + return { + registerTutorial(specProvider) { // specProvider should implement TutorialSchema + const emptyContext = {}; + const { error } = Joi.validate(specProvider(server, emptyContext), tutorialSchema); // the tutorialSchema's been typed in TutorialSchema + + if (error) { + throw new Error(`Unable to register tutorial spec because its invalid. ${error}`); + } + + tutorialProviders.push(specProvider); + } + }; + } +} +*/ From eeeaae6a411f65f632800cb24ce258984cfc3c4c Mon Sep 17 00:00:00 2001 From: Christiane Heiligers Date: Tue, 12 Nov 2019 09:00:22 -0700 Subject: [PATCH 02/21] Typing --- src/plugins/tutorials/server/services/tutorials_registry.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/plugins/tutorials/server/services/tutorials_registry.ts b/src/plugins/tutorials/server/services/tutorials_registry.ts index 4829c606188e8..5e085380a453b 100644 --- a/src/plugins/tutorials/server/services/tutorials_registry.ts +++ b/src/plugins/tutorials/server/services/tutorials_registry.ts @@ -96,8 +96,8 @@ export interface TutorialSchema { export class TutorialsRegistry { public setup(core: CoreSetup) { - const tutorialProviders: Array<(tutorialProvider: TutorialSchema) => void>; - const scopedTutorialContextFactories: Array<(scopedTutorialContextFactory: any) => void>; + const tutorialProviders: Array<(tutorialProvider: TutorialSchema) => void> = []; + const scopedTutorialContextFactories: Array<(scopedTutorialContextFactory: any) => void> = []; core.http.registerRouteHandlerContext('getTutorials', (request: any) => { const intitialContext = new Map(); const scopedContext = scopedTutorialContextFactories.reduce( From 7a78b55ae1b042b7b7cfc8477126a28774671254 Mon Sep 17 00:00:00 2001 From: Christiane Heiligers Date: Tue, 12 Nov 2019 11:54:06 -0700 Subject: [PATCH 03/21] New plugin tutorials not needing server working --- .../routes/api/home/register_tutorials.js | 14 +- .../server/tutorials/apache_logs/index.js | 2 +- .../kibana/server/tutorials/register.js | 5 +- .../server/tutorials/system_logs/index.js | 2 +- .../server/tutorials/system_metrics/index.js | 2 +- src/legacy/ui/tutorials_mixin.js | 2 + src/plugins/tutorials/server/plugin.ts | 74 ++++++++- .../tutorials/server/services/index.ts | 1 + .../server/services/tutorials_registry.ts | 30 ++-- src/plugins/tutorials/tutorial_schema.ts | 149 ++++++++++++++++++ 10 files changed, 245 insertions(+), 36 deletions(-) create mode 100644 src/plugins/tutorials/tutorial_schema.ts diff --git a/src/legacy/core_plugins/kibana/server/routes/api/home/register_tutorials.js b/src/legacy/core_plugins/kibana/server/routes/api/home/register_tutorials.js index 861ed1c244d13..b23af6aaa1d44 100644 --- a/src/legacy/core_plugins/kibana/server/routes/api/home/register_tutorials.js +++ b/src/legacy/core_plugins/kibana/server/routes/api/home/register_tutorials.js @@ -19,11 +19,11 @@ export function registerTutorials(server) { - server.route({ - path: '/api/kibana/home/tutorials', - method: ['GET'], - handler: function (req) { - return server.getTutorials(req); - } - }); + // server.route({ + // path: '/api/kibana/home/tutorials', + // method: ['GET'], + // handler: function (req) { + // return server.getTutorials(req); + // } + // }); } diff --git a/src/legacy/core_plugins/kibana/server/tutorials/apache_logs/index.js b/src/legacy/core_plugins/kibana/server/tutorials/apache_logs/index.js index c73f4389aa2fe..221fc8f5263c1 100644 --- a/src/legacy/core_plugins/kibana/server/tutorials/apache_logs/index.js +++ b/src/legacy/core_plugins/kibana/server/tutorials/apache_logs/index.js @@ -21,7 +21,7 @@ import { i18n } from '@kbn/i18n'; import { TUTORIAL_CATEGORY } from '../../../common/tutorials/tutorial_category'; import { onPremInstructions, cloudInstructions, onPremCloudInstructions } from '../../../common/tutorials/filebeat_instructions'; -export function apacheLogsSpecProvider(server, context) { +export function apacheLogsSpecProvider(context) { const moduleName = 'apache'; const platforms = ['OSX', 'DEB', 'RPM', 'WINDOWS']; return { diff --git a/src/legacy/core_plugins/kibana/server/tutorials/register.js b/src/legacy/core_plugins/kibana/server/tutorials/register.js index a95baad4ccb65..0bd9ad3e181a5 100644 --- a/src/legacy/core_plugins/kibana/server/tutorials/register.js +++ b/src/legacy/core_plugins/kibana/server/tutorials/register.js @@ -16,7 +16,6 @@ * specific language governing permissions and limitations * under the License. */ - import { systemLogsSpecProvider } from './system_logs'; import { systemMetricsSpecProvider } from './system_metrics'; import { apacheLogsSpecProvider } from './apache_logs'; @@ -81,8 +80,8 @@ import { consulMetricsSpecProvider } from './consul_metrics'; import { cockroachdbMetricsSpecProvider } from './cockroachdb_metrics'; export function registerTutorials(server) { - server.registerTutorial(systemLogsSpecProvider); - server.registerTutorial(systemMetricsSpecProvider); + server.newPlatform.setup.plugins.tutorials.registerTutorial(systemLogsSpecProvider); + server.newPlatform.setup.plugins.tutorials.registerTutorial(systemMetricsSpecProvider); server.registerTutorial(apacheLogsSpecProvider); server.registerTutorial(apacheMetricsSpecProvider); server.registerTutorial(elasticsearchLogsSpecProvider); diff --git a/src/legacy/core_plugins/kibana/server/tutorials/system_logs/index.js b/src/legacy/core_plugins/kibana/server/tutorials/system_logs/index.js index a9b8018762c85..efba0c00cbbc3 100644 --- a/src/legacy/core_plugins/kibana/server/tutorials/system_logs/index.js +++ b/src/legacy/core_plugins/kibana/server/tutorials/system_logs/index.js @@ -21,7 +21,7 @@ import { i18n } from '@kbn/i18n'; import { TUTORIAL_CATEGORY } from '../../../common/tutorials/tutorial_category'; import { onPremInstructions, cloudInstructions, onPremCloudInstructions } from '../../../common/tutorials/filebeat_instructions'; -export function systemLogsSpecProvider(server, context) { +export function systemLogsSpecProvider(context) { const moduleName = 'system'; const platforms = ['OSX', 'DEB', 'RPM']; return { diff --git a/src/legacy/core_plugins/kibana/server/tutorials/system_metrics/index.js b/src/legacy/core_plugins/kibana/server/tutorials/system_metrics/index.js index 563c065a41a8f..4c6fd20aa56c4 100644 --- a/src/legacy/core_plugins/kibana/server/tutorials/system_metrics/index.js +++ b/src/legacy/core_plugins/kibana/server/tutorials/system_metrics/index.js @@ -21,7 +21,7 @@ import { i18n } from '@kbn/i18n'; import { TUTORIAL_CATEGORY } from '../../../common/tutorials/tutorial_category'; import { onPremInstructions, cloudInstructions, onPremCloudInstructions } from '../../../common/tutorials/metricbeat_instructions'; -export function systemMetricsSpecProvider(server, context) { +export function systemMetricsSpecProvider(context) { const moduleName = 'system'; return { id: 'systemMetrics', diff --git a/src/legacy/ui/tutorials_mixin.js b/src/legacy/ui/tutorials_mixin.js index 368cd0f664a5e..6e11db51e1b67 100644 --- a/src/legacy/ui/tutorials_mixin.js +++ b/src/legacy/ui/tutorials_mixin.js @@ -68,6 +68,7 @@ export function tutorialsMixin(kbnServer, server) { }); server.decorate('server', 'registerTutorial', (specProvider) => { + // registration during setup const emptyContext = {}; const { error } = Joi.validate(specProvider(server, emptyContext), tutorialSchema); @@ -79,6 +80,7 @@ export function tutorialsMixin(kbnServer, server) { }); server.decorate('server', 'addScopedTutorialContextFactory', (scopedTutorialContextFactory) => { + // returned by the setup method of the new plugin, they will do the same thing as now if (typeof scopedTutorialContextFactory !== 'function') { throw new Error(`Unable to add scoped(request) context factory because you did not provide a function`); } diff --git a/src/plugins/tutorials/server/plugin.ts b/src/plugins/tutorials/server/plugin.ts index cad7fc9164a3a..b2c74a1c71353 100644 --- a/src/plugins/tutorials/server/plugin.ts +++ b/src/plugins/tutorials/server/plugin.ts @@ -16,22 +16,80 @@ * specific language governing permissions and limitations * under the License. */ +import { CoreSetup, Plugin, KibanaRequest } from 'src/core/server'; +import { + TutorialsRegistrySetup, + TutorialsRegistryStart, + TutorialsRegistry, + TutorialSchema, +} from './services'; -import { CoreSetup, Plugin } from 'src/core/server'; -import { TutorialsRegistrySetup, TutorialsRegistryStart, TutorialsRegistry } from './services'; - +type TutorialProvider = (context: { [key: string]: unknown }) => TutorialSchema; +type TutorialContextFactory = ( + req: KibanaRequest< + Readonly<{ + [x: string]: any; + }>, + Readonly<{ + [x: string]: any; + }>, + Readonly<{ + [x: string]: any; + }> + > +) => { [key: string]: unknown }; // following similar signature to the features_catalogue plugin export class TutorialsPlugin implements Plugin { - private readonly tutorialsRegistry = new TutorialsRegistry(); + private readonly tutorialProviders: TutorialProvider[] = []; + private readonly scopedTutorialContextFactories: TutorialContextFactory[] = []; + public async setup(core: CoreSetup) { + const router = core.http.createRouter(); + router.get( + { path: '/api/kibana/home/tutorials', validate: false }, + async (context, req, res) => { + const initialContext = {}; + const scopedContext = this.scopedTutorialContextFactories.reduce( + (accumulatedContext, contextFactory) => { + return { ...accumulatedContext, ...contextFactory(req) }; + }, + initialContext + ); + + return res.ok({ + body: this.tutorialProviders.map(tutorialProvider => { + return tutorialProvider(scopedContext); // needs to be refactored to not take in the server. Does the provider even need the server. + }), + }); + } + ); return { - ...this.tutorialsRegistry.setup(), + registerTutorial: (specProvider: TutorialProvider) => { + // registration during setup + // const emptyContext = {}; + // const { error } = Joi.validate(specProvider(server, emptyContext), tutorialSchema); + + // if (error) { + // throw new Error(`Unable to register tutorial spec because its invalid. ${error}`); + // } + + this.tutorialProviders.push(specProvider); + }, + addScopedTutorialContextFactory: (scopedTutorialContextFactory: any) => { + // returned by the setup method of the new plugin, they will do the same thing as now + if (typeof scopedTutorialContextFactory !== 'function') { + throw new Error( + `Unable to add scoped(request) context factory because you did not provide a function` + ); + } + + this.scopedTutorialContextFactories.push(scopedTutorialContextFactory); + }, }; } + public async start() { - return { - ...this.tutorialsRegistry.start(), - }; + return {}; } } diff --git a/src/plugins/tutorials/server/services/index.ts b/src/plugins/tutorials/server/services/index.ts index dce2521b1dea8..b588274577981 100644 --- a/src/plugins/tutorials/server/services/index.ts +++ b/src/plugins/tutorials/server/services/index.ts @@ -23,4 +23,5 @@ export { TutorialsRegistry, TutorialsRegistrySetup, TutorialsRegistryStart, + TutorialSchema, } from './tutorials_registry'; diff --git a/src/plugins/tutorials/server/services/tutorials_registry.ts b/src/plugins/tutorials/server/services/tutorials_registry.ts index 5e085380a453b..7178e4b3f0adb 100644 --- a/src/plugins/tutorials/server/services/tutorials_registry.ts +++ b/src/plugins/tutorials/server/services/tutorials_registry.ts @@ -67,31 +67,31 @@ export interface ArtifactsSchema { }; } export interface TutorialSchema { - readonly id: string; - readonly category: TutorialsCategory; - readonly name: string; - readonly isBeta: boolean; - readonly shortDescription: string; - readonly euiIconType: IconType; // EUI icon type string, one of https://elastic.github.io/eui/#/icon; - readonly longDescription: string; - readonly completionTimeMinutes: number; - readonly previewImagePath: string; + id: string; + category: TutorialsCategory; + name: string; + isBeta: boolean; + shortDescription: string; + euiIconType: IconType; // EUI icon type string, one of https://elastic.github.io/eui/#/icon; + longDescription: string; + completionTimeMinutes: number; + previewImagePath: string; // kibana and elastic cluster running on prem - readonly onPrem: InstructionsSchema; + onPrem: InstructionsSchema; // kibana and elastic cluster running in elastic's cloud - readonly elasticCloud: InstructionsSchema; + elasticCloud: InstructionsSchema; // kibana running on prem and elastic cluster running in elastic's cloud - readonly onPremElasticCloud: InstructionsSchema; + onPremElasticCloud: InstructionsSchema; // Elastic stack artifacts produced by product when it is setup and run. - readonly artifacts: ArtifactsSchema; + artifacts: ArtifactsSchema; // saved objects used by data module. - readonly savedObjects: any[]; - readonly savedObjectsInstallMsg: string; + savedObjects: any[]; + savedObjectsInstallMsg: string; } export class TutorialsRegistry { diff --git a/src/plugins/tutorials/tutorial_schema.ts b/src/plugins/tutorials/tutorial_schema.ts new file mode 100644 index 0000000000000..eb001ac96cceb --- /dev/null +++ b/src/plugins/tutorials/tutorial_schema.ts @@ -0,0 +1,149 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import Joi from 'joi'; + +const PARAM_TYPES = { + NUMBER: 'number', + STRING: 'string', +}; + +const TUTORIAL_CATEGORY = { + LOGGING: 'logging', + SIEM: 'siem', + METRICS: 'metrics', + OTHER: 'other', +}; + +const dashboardSchema = Joi.object({ + id: Joi.string().required(), // Dashboard saved object id + linkLabel: Joi.string().when('isOverview', { + is: true, + then: Joi.required(), + }), + // Is this an Overview / Entry Point dashboard? + isOverview: Joi.boolean().required(), +}); + +const artifactsSchema = Joi.object({ + // Fields present in Elasticsearch documents created by this product. + exportedFields: Joi.object({ + documentationUrl: Joi.string().required(), + }), + // Kibana dashboards created by this product. + dashboards: Joi.array() + .items(dashboardSchema) + .required(), + application: Joi.object({ + path: Joi.string().required(), + label: Joi.string().required(), + }), +}); + +const statusCheckSchema = Joi.object({ + title: Joi.string(), + text: Joi.string(), + btnLabel: Joi.string(), + success: Joi.string(), + error: Joi.string(), + esHitsCheck: Joi.object({ + index: Joi.alternatives() + .try(Joi.string(), Joi.array().items(Joi.string())) + .required(), + query: Joi.object().required(), + }).required(), +}); + +const instructionSchema = Joi.object({ + title: Joi.string(), + textPre: Joi.string(), + commands: Joi.array().items(Joi.string().allow('')), + textPost: Joi.string(), +}); + +const instructionVariantSchema = Joi.object({ + id: Joi.string().required(), + instructions: Joi.array() + .items(instructionSchema) + .required(), +}); + +const instructionSetSchema = Joi.object({ + title: Joi.string(), + callOut: Joi.object({ + title: Joi.string().required(), + message: Joi.string(), + iconType: Joi.string(), + }), + // Variants (OSes, languages, etc.) for which tutorial instructions are specified. + instructionVariants: Joi.array() + .items(instructionVariantSchema) + .required(), + statusCheck: statusCheckSchema, +}); + +const paramSchema = Joi.object({ + defaultValue: Joi.required(), + id: Joi.string() + .regex(/^[a-zA-Z_]+$/) + .required(), + label: Joi.string().required(), + type: Joi.string() + .valid(Object.values(PARAM_TYPES)) + .required(), +}); + +const instructionsSchema = Joi.object({ + instructionSets: Joi.array() + .items(instructionSetSchema) + .required(), + params: Joi.array().items(paramSchema), +}); + +export const tutorialSchema = { + id: Joi.string() + .regex(/^[a-zA-Z0-9-]+$/) + .required(), + category: Joi.string() + .valid(Object.values(TUTORIAL_CATEGORY)) + .required(), + name: Joi.string().required(), + isBeta: Joi.boolean().default(false), + shortDescription: Joi.string().required(), + euiIconType: Joi.string(), // EUI icon type string, one of https://elastic.github.io/eui/#/icons + longDescription: Joi.string().required(), + completionTimeMinutes: Joi.number().integer(), + previewImagePath: Joi.string(), + + // kibana and elastic cluster running on prem + onPrem: instructionsSchema.required(), + + // kibana and elastic cluster running in elastic's cloud + elasticCloud: instructionsSchema, + + // kibana running on prem and elastic cluster running in elastic's cloud + onPremElasticCloud: instructionsSchema, + + // Elastic stack artifacts produced by product when it is setup and run. + artifacts: artifactsSchema, + + // saved objects used by data module. + savedObjects: Joi.array().items(), + savedObjectsInstallMsg: Joi.string(), +}; From dfa5e344b2b10d43cb51ec204e00b89cc5421542 Mon Sep 17 00:00:00 2001 From: Christiane Heiligers Date: Tue, 12 Nov 2019 16:36:13 -0700 Subject: [PATCH 04/21] Retains legacy tutorial registration and adds new route for new platform tutorial plugin registrations --- .../kibana/public/home/load_tutorials.js | 23 +++- .../routes/api/home/register_tutorials.js | 14 +-- .../tutorials/aerospike_metrics/index.js | 2 +- .../server/tutorials/apache_metrics/index.js | 2 +- .../server/tutorials/auditbeat/index.js | 2 +- .../server/tutorials/aws_metrics/index.js | 2 +- .../server/tutorials/ceph_metrics/index.js | 2 +- .../server/tutorials/cisco_logs/index.js | 2 +- .../server/tutorials/cloudwatch_logs/index.js | 2 +- .../tutorials/cockroachdb_metrics/index.js | 2 +- .../server/tutorials/consul_metrics/index.js | 2 +- .../server/tutorials/coredns_metrics/index.js | 2 +- .../tutorials/couchbase_metrics/index.js | 2 +- .../server/tutorials/couchdb_metrics/index.js | 2 +- .../server/tutorials/docker_metrics/index.js | 2 +- .../tutorials/dropwizard_metrics/index.js | 2 +- .../tutorials/elasticsearch_logs/index.js | 2 +- .../tutorials/elasticsearch_metrics/index.js | 2 +- .../server/tutorials/envoyproxy_logs/index.js | 2 +- .../server/tutorials/etcd_metrics/index.js | 2 +- .../server/tutorials/golang_metrics/index.js | 2 +- .../server/tutorials/haproxy_metrics/index.js | 2 +- .../kibana/server/tutorials/iis_logs/index.js | 2 +- .../server/tutorials/iptables_logs/index.js | 2 +- .../server/tutorials/kafka_logs/index.js | 2 +- .../server/tutorials/kafka_metrics/index.js | 2 +- .../server/tutorials/kibana_metrics/index.js | 2 +- .../tutorials/kubernetes_metrics/index.js | 2 +- .../server/tutorials/logstash_logs/index.js | 2 +- .../tutorials/logstash_metrics/index.js | 2 +- .../tutorials/memcached_metrics/index.js | 2 +- .../server/tutorials/mongodb_metrics/index.js | 2 +- .../server/tutorials/mssql_metrics/index.js | 2 +- .../server/tutorials/munin_metrics/index.js | 2 +- .../server/tutorials/mysql_logs/index.js | 2 +- .../server/tutorials/mysql_metrics/index.js | 2 +- .../server/tutorials/nats_logs/index.js | 2 +- .../server/tutorials/nats_metrics/index.js | 2 +- .../server/tutorials/nginx_logs/index.js | 2 +- .../server/tutorials/nginx_metrics/index.js | 2 +- .../server/tutorials/osquery_logs/index.js | 2 +- .../server/tutorials/php_fpm_metrics/index.js | 2 +- .../server/tutorials/postgresql_logs/index.js | 2 +- .../tutorials/postgresql_metrics/index.js | 2 +- .../tutorials/prometheus_metrics/index.js | 2 +- .../tutorials/rabbitmq_metrics/index.js | 2 +- .../server/tutorials/redis_logs/index.js | 2 +- .../server/tutorials/redis_metrics/index.js | 2 +- .../kibana/server/tutorials/register.js | 116 +++++++++--------- .../server/tutorials/suricata_logs/index.js | 2 +- .../server/tutorials/traefik_logs/index.js | 2 +- .../server/tutorials/uptime_monitors/index.js | 2 +- .../server/tutorials/uwsgi_metrics/index.js | 2 +- .../server/tutorials/vsphere_metrics/index.js | 2 +- .../tutorials/windows_event_logs/index.js | 2 +- .../server/tutorials/windows_metrics/index.js | 2 +- .../server/tutorials/zeek_logs/index.js | 2 +- .../tutorials/zookeeper_metrics/index.js | 2 +- src/plugins/tutorials/server/plugin.ts | 54 ++++++-- .../tutorials/{ => server}/tutorial_schema.ts | 0 60 files changed, 183 insertions(+), 134 deletions(-) rename src/plugins/tutorials/{ => server}/tutorial_schema.ts (100%) diff --git a/src/legacy/core_plugins/kibana/public/home/load_tutorials.js b/src/legacy/core_plugins/kibana/public/home/load_tutorials.js index a6f19bc166dc7..894f6bda64b4f 100644 --- a/src/legacy/core_plugins/kibana/public/home/load_tutorials.js +++ b/src/legacy/core_plugins/kibana/public/home/load_tutorials.js @@ -22,28 +22,43 @@ import { getServices } from './kibana_services'; import { i18n } from '@kbn/i18n'; const baseUrl = getServices().addBasePath('/api/kibana/home/tutorials'); +const baseUrlNP = getServices().addBasePath('/api/kibana/home/NP_tutorials'); const headers = new Headers(); headers.append('Accept', 'application/json'); headers.append('Content-Type', 'application/json'); headers.append('kbn-xsrf', 'kibana'); let tutorials = []; +let tutorialsLegacyPlatform = []; +let tutorialsNewPlatform = []; let tutorialsLoaded = false; async function loadTutorials() { try { - const response = await fetch(baseUrl, { + const responseLegacyPlatform = await fetch(baseUrl, { method: 'get', credentials: 'include', headers: headers, }); - if (response.status >= 300) { + const responseNewPlatform = await fetch(baseUrlNP, { + method: 'get', + credentials: 'include', + headers: headers, + }); + if (responseLegacyPlatform.status >= 300) { + throw new Error(i18n.translate('kbn.home.loadTutorials.requestFailedErrorMessage', { + defaultMessage: 'Request failed with status code: {status}', values: { status: responseLegacyPlatform.status } } + )); + } + if (responseNewPlatform.status >= 300) { throw new Error(i18n.translate('kbn.home.loadTutorials.requestFailedErrorMessage', { - defaultMessage: 'Request failed with status code: {status}', values: { status: response.status } } + defaultMessage: 'Request failed with status code: {status}', values: { status: responseNewPlatform.status } } )); } - tutorials = await response.json(); + tutorialsLegacyPlatform = await responseLegacyPlatform.json(); + tutorialsNewPlatform = await responseNewPlatform.json(); + tutorials = tutorialsLegacyPlatform.concat(tutorialsNewPlatform); tutorialsLoaded = true; } catch(err) { getServices().toastNotifications.addDanger({ diff --git a/src/legacy/core_plugins/kibana/server/routes/api/home/register_tutorials.js b/src/legacy/core_plugins/kibana/server/routes/api/home/register_tutorials.js index b23af6aaa1d44..861ed1c244d13 100644 --- a/src/legacy/core_plugins/kibana/server/routes/api/home/register_tutorials.js +++ b/src/legacy/core_plugins/kibana/server/routes/api/home/register_tutorials.js @@ -19,11 +19,11 @@ export function registerTutorials(server) { - // server.route({ - // path: '/api/kibana/home/tutorials', - // method: ['GET'], - // handler: function (req) { - // return server.getTutorials(req); - // } - // }); + server.route({ + path: '/api/kibana/home/tutorials', + method: ['GET'], + handler: function (req) { + return server.getTutorials(req); + } + }); } diff --git a/src/legacy/core_plugins/kibana/server/tutorials/aerospike_metrics/index.js b/src/legacy/core_plugins/kibana/server/tutorials/aerospike_metrics/index.js index 77f6df09b244b..28b1dbe6226dc 100644 --- a/src/legacy/core_plugins/kibana/server/tutorials/aerospike_metrics/index.js +++ b/src/legacy/core_plugins/kibana/server/tutorials/aerospike_metrics/index.js @@ -21,7 +21,7 @@ import { i18n } from '@kbn/i18n'; import { TUTORIAL_CATEGORY } from '../../../common/tutorials/tutorial_category'; import { onPremInstructions, cloudInstructions, onPremCloudInstructions } from '../../../common/tutorials/metricbeat_instructions'; -export function aerospikeMetricsSpecProvider(server, context) { +export function aerospikeMetricsSpecProvider(context) { const moduleName = 'aerospike'; return { id: 'aerospikeMetrics', diff --git a/src/legacy/core_plugins/kibana/server/tutorials/apache_metrics/index.js b/src/legacy/core_plugins/kibana/server/tutorials/apache_metrics/index.js index c53c85f6a08e5..436af8b352590 100644 --- a/src/legacy/core_plugins/kibana/server/tutorials/apache_metrics/index.js +++ b/src/legacy/core_plugins/kibana/server/tutorials/apache_metrics/index.js @@ -21,7 +21,7 @@ import { i18n } from '@kbn/i18n'; import { TUTORIAL_CATEGORY } from '../../../common/tutorials/tutorial_category'; import { onPremInstructions, cloudInstructions, onPremCloudInstructions } from '../../../common/tutorials/metricbeat_instructions'; -export function apacheMetricsSpecProvider(server, context) { +export function apacheMetricsSpecProvider(context) { const moduleName = 'apache'; return { id: 'apacheMetrics', diff --git a/src/legacy/core_plugins/kibana/server/tutorials/auditbeat/index.js b/src/legacy/core_plugins/kibana/server/tutorials/auditbeat/index.js index 19994aefdb930..b67a872dcc0aa 100644 --- a/src/legacy/core_plugins/kibana/server/tutorials/auditbeat/index.js +++ b/src/legacy/core_plugins/kibana/server/tutorials/auditbeat/index.js @@ -25,7 +25,7 @@ import { onPremCloudInstructions, } from '../../../common/tutorials/auditbeat_instructions'; -export function auditbeatSpecProvider(server, context) { +export function auditbeatSpecProvider(context) { const platforms = ['OSX', 'DEB', 'RPM', 'WINDOWS']; return { id: 'auditbeat', diff --git a/src/legacy/core_plugins/kibana/server/tutorials/aws_metrics/index.js b/src/legacy/core_plugins/kibana/server/tutorials/aws_metrics/index.js index 56b6689f359f3..32ff79930a877 100644 --- a/src/legacy/core_plugins/kibana/server/tutorials/aws_metrics/index.js +++ b/src/legacy/core_plugins/kibana/server/tutorials/aws_metrics/index.js @@ -21,7 +21,7 @@ import { i18n } from '@kbn/i18n'; import { TUTORIAL_CATEGORY } from '../../../common/tutorials/tutorial_category'; import { onPremInstructions, cloudInstructions, onPremCloudInstructions } from '../../../common/tutorials/metricbeat_instructions'; -export function awsMetricsSpecProvider(server, context) { +export function awsMetricsSpecProvider(context) { const moduleName = 'aws'; return { id: 'awsMetrics', diff --git a/src/legacy/core_plugins/kibana/server/tutorials/ceph_metrics/index.js b/src/legacy/core_plugins/kibana/server/tutorials/ceph_metrics/index.js index f2b2749a79268..1f0001dbaaf94 100644 --- a/src/legacy/core_plugins/kibana/server/tutorials/ceph_metrics/index.js +++ b/src/legacy/core_plugins/kibana/server/tutorials/ceph_metrics/index.js @@ -21,7 +21,7 @@ import { i18n } from '@kbn/i18n'; import { TUTORIAL_CATEGORY } from '../../../common/tutorials/tutorial_category'; import { onPremInstructions, cloudInstructions, onPremCloudInstructions } from '../../../common/tutorials/metricbeat_instructions'; -export function cephMetricsSpecProvider(server, context) { +export function cephMetricsSpecProvider(context) { const moduleName = 'ceph'; return { id: 'cephMetrics', diff --git a/src/legacy/core_plugins/kibana/server/tutorials/cisco_logs/index.js b/src/legacy/core_plugins/kibana/server/tutorials/cisco_logs/index.js index 83123afde3882..90190bd0d6877 100644 --- a/src/legacy/core_plugins/kibana/server/tutorials/cisco_logs/index.js +++ b/src/legacy/core_plugins/kibana/server/tutorials/cisco_logs/index.js @@ -25,7 +25,7 @@ import { onPremCloudInstructions, } from '../../../common/tutorials/filebeat_instructions'; -export function ciscoLogsSpecProvider(server, context) { +export function ciscoLogsSpecProvider(context) { const moduleName = 'cisco'; const platforms = ['OSX', 'DEB', 'RPM', 'WINDOWS']; return { diff --git a/src/legacy/core_plugins/kibana/server/tutorials/cloudwatch_logs/index.js b/src/legacy/core_plugins/kibana/server/tutorials/cloudwatch_logs/index.js index b5b053e329d1a..7617f313b2436 100644 --- a/src/legacy/core_plugins/kibana/server/tutorials/cloudwatch_logs/index.js +++ b/src/legacy/core_plugins/kibana/server/tutorials/cloudwatch_logs/index.js @@ -21,7 +21,7 @@ import { i18n } from '@kbn/i18n'; import { TUTORIAL_CATEGORY } from '../../../common/tutorials/tutorial_category'; import { onPremInstructions, cloudInstructions, onPremCloudInstructions } from '../../../common/tutorials/functionbeat_instructions'; -export function cloudwatchLogsSpecProvider(server, context) { +export function cloudwatchLogsSpecProvider(context) { return { id: 'cloudwatchLogs', name: i18n.translate('kbn.server.tutorials.cloudwatchLogs.nameTitle', { diff --git a/src/legacy/core_plugins/kibana/server/tutorials/cockroachdb_metrics/index.js b/src/legacy/core_plugins/kibana/server/tutorials/cockroachdb_metrics/index.js index e05be3bda145f..865ddb47bbe5f 100644 --- a/src/legacy/core_plugins/kibana/server/tutorials/cockroachdb_metrics/index.js +++ b/src/legacy/core_plugins/kibana/server/tutorials/cockroachdb_metrics/index.js @@ -21,7 +21,7 @@ import { i18n } from '@kbn/i18n'; import { TUTORIAL_CATEGORY } from '../../../common/tutorials/tutorial_category'; import { onPremInstructions, cloudInstructions, onPremCloudInstructions } from '../../../common/tutorials/metricbeat_instructions'; -export function cockroachdbMetricsSpecProvider(server, context) { +export function cockroachdbMetricsSpecProvider(context) { const moduleName = 'cockroachdb'; return { id: 'cockroachdbMetrics', diff --git a/src/legacy/core_plugins/kibana/server/tutorials/consul_metrics/index.js b/src/legacy/core_plugins/kibana/server/tutorials/consul_metrics/index.js index 8823fe5ee5067..7d2668c60fe18 100644 --- a/src/legacy/core_plugins/kibana/server/tutorials/consul_metrics/index.js +++ b/src/legacy/core_plugins/kibana/server/tutorials/consul_metrics/index.js @@ -21,7 +21,7 @@ import { i18n } from '@kbn/i18n'; import { TUTORIAL_CATEGORY } from '../../../common/tutorials/tutorial_category'; import { onPremInstructions, cloudInstructions, onPremCloudInstructions } from '../../../common/tutorials/metricbeat_instructions'; -export function consulMetricsSpecProvider(server, context) { +export function consulMetricsSpecProvider(context) { const moduleName = 'consul'; return { id: 'consulMetrics', diff --git a/src/legacy/core_plugins/kibana/server/tutorials/coredns_metrics/index.js b/src/legacy/core_plugins/kibana/server/tutorials/coredns_metrics/index.js index 9536cab0886d5..a62613e9c2f13 100644 --- a/src/legacy/core_plugins/kibana/server/tutorials/coredns_metrics/index.js +++ b/src/legacy/core_plugins/kibana/server/tutorials/coredns_metrics/index.js @@ -21,7 +21,7 @@ import { i18n } from '@kbn/i18n'; import { TUTORIAL_CATEGORY } from '../../../common/tutorials/tutorial_category'; import { onPremInstructions, cloudInstructions, onPremCloudInstructions } from '../../../common/tutorials/metricbeat_instructions'; -export function corednsMetricsSpecProvider(server, context) { +export function corednsMetricsSpecProvider(context) { const moduleName = 'coredns'; return { id: 'corednsMetrics', diff --git a/src/legacy/core_plugins/kibana/server/tutorials/couchbase_metrics/index.js b/src/legacy/core_plugins/kibana/server/tutorials/couchbase_metrics/index.js index 9dc8a7337f434..8a6452703cca7 100644 --- a/src/legacy/core_plugins/kibana/server/tutorials/couchbase_metrics/index.js +++ b/src/legacy/core_plugins/kibana/server/tutorials/couchbase_metrics/index.js @@ -21,7 +21,7 @@ import { i18n } from '@kbn/i18n'; import { TUTORIAL_CATEGORY } from '../../../common/tutorials/tutorial_category'; import { onPremInstructions, cloudInstructions, onPremCloudInstructions } from '../../../common/tutorials/metricbeat_instructions'; -export function couchbaseMetricsSpecProvider(server, context) { +export function couchbaseMetricsSpecProvider(context) { const moduleName = 'couchbase'; return { id: 'couchbaseMetrics', diff --git a/src/legacy/core_plugins/kibana/server/tutorials/couchdb_metrics/index.js b/src/legacy/core_plugins/kibana/server/tutorials/couchdb_metrics/index.js index 437ed7132d617..24f29c1a263ab 100644 --- a/src/legacy/core_plugins/kibana/server/tutorials/couchdb_metrics/index.js +++ b/src/legacy/core_plugins/kibana/server/tutorials/couchdb_metrics/index.js @@ -21,7 +21,7 @@ import { i18n } from '@kbn/i18n'; import { TUTORIAL_CATEGORY } from '../../../common/tutorials/tutorial_category'; import { onPremInstructions, cloudInstructions, onPremCloudInstructions } from '../../../common/tutorials/metricbeat_instructions'; -export function couchdbMetricsSpecProvider(server, context) { +export function couchdbMetricsSpecProvider(context) { const moduleName = 'couchdb'; return { id: 'couchdbMetrics', diff --git a/src/legacy/core_plugins/kibana/server/tutorials/docker_metrics/index.js b/src/legacy/core_plugins/kibana/server/tutorials/docker_metrics/index.js index bc1cda7d52385..8268851d67697 100644 --- a/src/legacy/core_plugins/kibana/server/tutorials/docker_metrics/index.js +++ b/src/legacy/core_plugins/kibana/server/tutorials/docker_metrics/index.js @@ -21,7 +21,7 @@ import { i18n } from '@kbn/i18n'; import { TUTORIAL_CATEGORY } from '../../../common/tutorials/tutorial_category'; import { onPremInstructions, cloudInstructions, onPremCloudInstructions } from '../../../common/tutorials/metricbeat_instructions'; -export function dockerMetricsSpecProvider(server, context) { +export function dockerMetricsSpecProvider(context) { const moduleName = 'docker'; return { id: 'dockerMetrics', diff --git a/src/legacy/core_plugins/kibana/server/tutorials/dropwizard_metrics/index.js b/src/legacy/core_plugins/kibana/server/tutorials/dropwizard_metrics/index.js index c76743f84c0ac..9576518d7b095 100644 --- a/src/legacy/core_plugins/kibana/server/tutorials/dropwizard_metrics/index.js +++ b/src/legacy/core_plugins/kibana/server/tutorials/dropwizard_metrics/index.js @@ -21,7 +21,7 @@ import { i18n } from '@kbn/i18n'; import { TUTORIAL_CATEGORY } from '../../../common/tutorials/tutorial_category'; import { onPremInstructions, cloudInstructions, onPremCloudInstructions } from '../../../common/tutorials/metricbeat_instructions'; -export function dropwizardMetricsSpecProvider(server, context) { +export function dropwizardMetricsSpecProvider(context) { const moduleName = 'dropwizard'; return { id: 'dropwizardMetrics', diff --git a/src/legacy/core_plugins/kibana/server/tutorials/elasticsearch_logs/index.js b/src/legacy/core_plugins/kibana/server/tutorials/elasticsearch_logs/index.js index 9f88895917e5d..5778af07d8836 100644 --- a/src/legacy/core_plugins/kibana/server/tutorials/elasticsearch_logs/index.js +++ b/src/legacy/core_plugins/kibana/server/tutorials/elasticsearch_logs/index.js @@ -21,7 +21,7 @@ import { i18n } from '@kbn/i18n'; import { TUTORIAL_CATEGORY } from '../../../common/tutorials/tutorial_category'; import { onPremInstructions, cloudInstructions, onPremCloudInstructions } from '../../../common/tutorials/filebeat_instructions'; -export function elasticsearchLogsSpecProvider(server, context) { +export function elasticsearchLogsSpecProvider(context) { const moduleName = 'elasticsearch'; const platforms = ['OSX', 'DEB', 'RPM', 'WINDOWS']; return { diff --git a/src/legacy/core_plugins/kibana/server/tutorials/elasticsearch_metrics/index.js b/src/legacy/core_plugins/kibana/server/tutorials/elasticsearch_metrics/index.js index e31343a4ec48e..35ac8b74c9a1f 100644 --- a/src/legacy/core_plugins/kibana/server/tutorials/elasticsearch_metrics/index.js +++ b/src/legacy/core_plugins/kibana/server/tutorials/elasticsearch_metrics/index.js @@ -21,7 +21,7 @@ import { i18n } from '@kbn/i18n'; import { TUTORIAL_CATEGORY } from '../../../common/tutorials/tutorial_category'; import { onPremInstructions, cloudInstructions, onPremCloudInstructions } from '../../../common/tutorials/metricbeat_instructions'; -export function elasticsearchMetricsSpecProvider(server, context) { +export function elasticsearchMetricsSpecProvider(context) { const moduleName = 'elasticsearch'; return { id: 'elasticsearchMetrics', diff --git a/src/legacy/core_plugins/kibana/server/tutorials/envoyproxy_logs/index.js b/src/legacy/core_plugins/kibana/server/tutorials/envoyproxy_logs/index.js index 8e8d27b5ba43d..977decd413f08 100644 --- a/src/legacy/core_plugins/kibana/server/tutorials/envoyproxy_logs/index.js +++ b/src/legacy/core_plugins/kibana/server/tutorials/envoyproxy_logs/index.js @@ -25,7 +25,7 @@ import { onPremCloudInstructions, } from '../../../common/tutorials/filebeat_instructions'; -export function envoyproxyLogsSpecProvider(server, context) { +export function envoyproxyLogsSpecProvider(context) { const moduleName = 'envoyproxy'; const platforms = ['OSX', 'DEB', 'RPM', 'WINDOWS']; return { diff --git a/src/legacy/core_plugins/kibana/server/tutorials/etcd_metrics/index.js b/src/legacy/core_plugins/kibana/server/tutorials/etcd_metrics/index.js index 18463e8e91104..27c9259ad080b 100644 --- a/src/legacy/core_plugins/kibana/server/tutorials/etcd_metrics/index.js +++ b/src/legacy/core_plugins/kibana/server/tutorials/etcd_metrics/index.js @@ -21,7 +21,7 @@ import { i18n } from '@kbn/i18n'; import { TUTORIAL_CATEGORY } from '../../../common/tutorials/tutorial_category'; import { onPremInstructions, cloudInstructions, onPremCloudInstructions } from '../../../common/tutorials/metricbeat_instructions'; -export function etcdMetricsSpecProvider(server, context) { +export function etcdMetricsSpecProvider(context) { const moduleName = 'etcd'; return { id: 'etcdMetrics', diff --git a/src/legacy/core_plugins/kibana/server/tutorials/golang_metrics/index.js b/src/legacy/core_plugins/kibana/server/tutorials/golang_metrics/index.js index 594c0bf72edd8..e6823b6a51c64 100644 --- a/src/legacy/core_plugins/kibana/server/tutorials/golang_metrics/index.js +++ b/src/legacy/core_plugins/kibana/server/tutorials/golang_metrics/index.js @@ -21,7 +21,7 @@ import { i18n } from '@kbn/i18n'; import { TUTORIAL_CATEGORY } from '../../../common/tutorials/tutorial_category'; import { onPremInstructions, cloudInstructions, onPremCloudInstructions } from '../../../common/tutorials/metricbeat_instructions'; -export function golangMetricsSpecProvider(server, context) { +export function golangMetricsSpecProvider(context) { const moduleName = 'golang'; return { id: moduleName + 'Metrics', diff --git a/src/legacy/core_plugins/kibana/server/tutorials/haproxy_metrics/index.js b/src/legacy/core_plugins/kibana/server/tutorials/haproxy_metrics/index.js index 4eea8c1a3be59..ccb7e01e0481e 100644 --- a/src/legacy/core_plugins/kibana/server/tutorials/haproxy_metrics/index.js +++ b/src/legacy/core_plugins/kibana/server/tutorials/haproxy_metrics/index.js @@ -21,7 +21,7 @@ import { i18n } from '@kbn/i18n'; import { TUTORIAL_CATEGORY } from '../../../common/tutorials/tutorial_category'; import { onPremInstructions, cloudInstructions, onPremCloudInstructions } from '../../../common/tutorials/metricbeat_instructions'; -export function haproxyMetricsSpecProvider(server, context) { +export function haproxyMetricsSpecProvider(context) { const moduleName = 'haproxy'; return { id: 'haproxyMetrics', diff --git a/src/legacy/core_plugins/kibana/server/tutorials/iis_logs/index.js b/src/legacy/core_plugins/kibana/server/tutorials/iis_logs/index.js index 8a937dddfa509..14f96c1e851c6 100644 --- a/src/legacy/core_plugins/kibana/server/tutorials/iis_logs/index.js +++ b/src/legacy/core_plugins/kibana/server/tutorials/iis_logs/index.js @@ -21,7 +21,7 @@ import { i18n } from '@kbn/i18n'; import { TUTORIAL_CATEGORY } from '../../../common/tutorials/tutorial_category'; import { onPremInstructions, cloudInstructions, onPremCloudInstructions } from '../../../common/tutorials/filebeat_instructions'; -export function iisLogsSpecProvider(server, context) { +export function iisLogsSpecProvider(context) { const moduleName = 'iis'; const platforms = ['WINDOWS']; return { diff --git a/src/legacy/core_plugins/kibana/server/tutorials/iptables_logs/index.js b/src/legacy/core_plugins/kibana/server/tutorials/iptables_logs/index.js index b5522a825fc11..63246e44d2d0d 100644 --- a/src/legacy/core_plugins/kibana/server/tutorials/iptables_logs/index.js +++ b/src/legacy/core_plugins/kibana/server/tutorials/iptables_logs/index.js @@ -25,7 +25,7 @@ import { onPremCloudInstructions, } from '../../../common/tutorials/filebeat_instructions'; -export function iptablesLogsSpecProvider(server, context) { +export function iptablesLogsSpecProvider(context) { const moduleName = 'iptables'; const platforms = ['DEB', 'RPM']; return { diff --git a/src/legacy/core_plugins/kibana/server/tutorials/kafka_logs/index.js b/src/legacy/core_plugins/kibana/server/tutorials/kafka_logs/index.js index 4b9ba85157a49..ab1d9af6286cd 100644 --- a/src/legacy/core_plugins/kibana/server/tutorials/kafka_logs/index.js +++ b/src/legacy/core_plugins/kibana/server/tutorials/kafka_logs/index.js @@ -21,7 +21,7 @@ import { i18n } from '@kbn/i18n'; import { TUTORIAL_CATEGORY } from '../../../common/tutorials/tutorial_category'; import { onPremInstructions, cloudInstructions, onPremCloudInstructions } from '../../../common/tutorials/filebeat_instructions'; -export function kafkaLogsSpecProvider(server, context) { +export function kafkaLogsSpecProvider(context) { const moduleName = 'kafka'; const platforms = ['OSX', 'DEB', 'RPM', 'WINDOWS']; return { diff --git a/src/legacy/core_plugins/kibana/server/tutorials/kafka_metrics/index.js b/src/legacy/core_plugins/kibana/server/tutorials/kafka_metrics/index.js index 5dfc786fc2ecd..68651e6833804 100644 --- a/src/legacy/core_plugins/kibana/server/tutorials/kafka_metrics/index.js +++ b/src/legacy/core_plugins/kibana/server/tutorials/kafka_metrics/index.js @@ -21,7 +21,7 @@ import { i18n } from '@kbn/i18n'; import { TUTORIAL_CATEGORY } from '../../../common/tutorials/tutorial_category'; import { onPremInstructions, cloudInstructions, onPremCloudInstructions } from '../../../common/tutorials/metricbeat_instructions'; -export function kafkaMetricsSpecProvider(server, context) { +export function kafkaMetricsSpecProvider(context) { const moduleName = 'kafka'; return { id: 'kafkaMetrics', diff --git a/src/legacy/core_plugins/kibana/server/tutorials/kibana_metrics/index.js b/src/legacy/core_plugins/kibana/server/tutorials/kibana_metrics/index.js index bce5eb2169f1c..c85f1399c25f5 100644 --- a/src/legacy/core_plugins/kibana/server/tutorials/kibana_metrics/index.js +++ b/src/legacy/core_plugins/kibana/server/tutorials/kibana_metrics/index.js @@ -21,7 +21,7 @@ import { i18n } from '@kbn/i18n'; import { TUTORIAL_CATEGORY } from '../../../common/tutorials/tutorial_category'; import { onPremInstructions, cloudInstructions, onPremCloudInstructions } from '../../../common/tutorials/metricbeat_instructions'; -export function kibanaMetricsSpecProvider(server, context) { +export function kibanaMetricsSpecProvider(context) { const moduleName = 'kibana'; return { id: 'kibanaMetrics', diff --git a/src/legacy/core_plugins/kibana/server/tutorials/kubernetes_metrics/index.js b/src/legacy/core_plugins/kibana/server/tutorials/kubernetes_metrics/index.js index c89c5764b9108..2ff1460563928 100644 --- a/src/legacy/core_plugins/kibana/server/tutorials/kubernetes_metrics/index.js +++ b/src/legacy/core_plugins/kibana/server/tutorials/kubernetes_metrics/index.js @@ -21,7 +21,7 @@ import { i18n } from '@kbn/i18n'; import { TUTORIAL_CATEGORY } from '../../../common/tutorials/tutorial_category'; import { onPremInstructions, cloudInstructions, onPremCloudInstructions } from '../../../common/tutorials/metricbeat_instructions'; -export function kubernetesMetricsSpecProvider(server, context) { +export function kubernetesMetricsSpecProvider(context) { const moduleName = 'kubernetes'; return { id: 'kubernetesMetrics', diff --git a/src/legacy/core_plugins/kibana/server/tutorials/logstash_logs/index.js b/src/legacy/core_plugins/kibana/server/tutorials/logstash_logs/index.js index 463043a66b70f..47ae15dff4d3e 100644 --- a/src/legacy/core_plugins/kibana/server/tutorials/logstash_logs/index.js +++ b/src/legacy/core_plugins/kibana/server/tutorials/logstash_logs/index.js @@ -21,7 +21,7 @@ import { i18n } from '@kbn/i18n'; import { TUTORIAL_CATEGORY } from '../../../common/tutorials/tutorial_category'; import { onPremInstructions, cloudInstructions, onPremCloudInstructions } from '../../../common/tutorials/filebeat_instructions'; -export function logstashLogsSpecProvider(server, context) { +export function logstashLogsSpecProvider(context) { const moduleName = 'logstash'; const platforms = ['OSX', 'DEB', 'RPM', 'WINDOWS']; return { diff --git a/src/legacy/core_plugins/kibana/server/tutorials/logstash_metrics/index.js b/src/legacy/core_plugins/kibana/server/tutorials/logstash_metrics/index.js index 06b24cc0ee706..838316655db6c 100644 --- a/src/legacy/core_plugins/kibana/server/tutorials/logstash_metrics/index.js +++ b/src/legacy/core_plugins/kibana/server/tutorials/logstash_metrics/index.js @@ -21,7 +21,7 @@ import { i18n } from '@kbn/i18n'; import { TUTORIAL_CATEGORY } from '../../../common/tutorials/tutorial_category'; import { onPremInstructions, cloudInstructions, onPremCloudInstructions } from '../../../common/tutorials/metricbeat_instructions'; -export function logstashMetricsSpecProvider(server, context) { +export function logstashMetricsSpecProvider(context) { const moduleName = 'logstash'; return { id: moduleName + 'Metrics', diff --git a/src/legacy/core_plugins/kibana/server/tutorials/memcached_metrics/index.js b/src/legacy/core_plugins/kibana/server/tutorials/memcached_metrics/index.js index f1fbd9998c62b..ce31b4fba351f 100644 --- a/src/legacy/core_plugins/kibana/server/tutorials/memcached_metrics/index.js +++ b/src/legacy/core_plugins/kibana/server/tutorials/memcached_metrics/index.js @@ -21,7 +21,7 @@ import { i18n } from '@kbn/i18n'; import { TUTORIAL_CATEGORY } from '../../../common/tutorials/tutorial_category'; import { onPremInstructions, cloudInstructions, onPremCloudInstructions } from '../../../common/tutorials/metricbeat_instructions'; -export function memcachedMetricsSpecProvider(server, context) { +export function memcachedMetricsSpecProvider(context) { const moduleName = 'memcached'; return { id: 'memcachedMetrics', diff --git a/src/legacy/core_plugins/kibana/server/tutorials/mongodb_metrics/index.js b/src/legacy/core_plugins/kibana/server/tutorials/mongodb_metrics/index.js index fa54055c813a7..e9bf02585c766 100644 --- a/src/legacy/core_plugins/kibana/server/tutorials/mongodb_metrics/index.js +++ b/src/legacy/core_plugins/kibana/server/tutorials/mongodb_metrics/index.js @@ -21,7 +21,7 @@ import { i18n } from '@kbn/i18n'; import { TUTORIAL_CATEGORY } from '../../../common/tutorials/tutorial_category'; import { onPremInstructions, cloudInstructions, onPremCloudInstructions } from '../../../common/tutorials/metricbeat_instructions'; -export function mongodbMetricsSpecProvider(server, context) { +export function mongodbMetricsSpecProvider(context) { const moduleName = 'mongodb'; return { id: 'mongodbMetrics', diff --git a/src/legacy/core_plugins/kibana/server/tutorials/mssql_metrics/index.js b/src/legacy/core_plugins/kibana/server/tutorials/mssql_metrics/index.js index 58c5acca6f1b1..201f1de69daa6 100644 --- a/src/legacy/core_plugins/kibana/server/tutorials/mssql_metrics/index.js +++ b/src/legacy/core_plugins/kibana/server/tutorials/mssql_metrics/index.js @@ -21,7 +21,7 @@ import { i18n } from '@kbn/i18n'; import { TUTORIAL_CATEGORY } from '../../../common/tutorials/tutorial_category'; import { onPremInstructions, cloudInstructions, onPremCloudInstructions } from '../../../common/tutorials/metricbeat_instructions'; -export function mssqlMetricsSpecProvider(server, context) { +export function mssqlMetricsSpecProvider(context) { const moduleName = 'mssql'; return { id: 'mssqlMetrics', diff --git a/src/legacy/core_plugins/kibana/server/tutorials/munin_metrics/index.js b/src/legacy/core_plugins/kibana/server/tutorials/munin_metrics/index.js index e6e6489dc6fca..8bf1c2a171524 100644 --- a/src/legacy/core_plugins/kibana/server/tutorials/munin_metrics/index.js +++ b/src/legacy/core_plugins/kibana/server/tutorials/munin_metrics/index.js @@ -21,7 +21,7 @@ import { i18n } from '@kbn/i18n'; import { TUTORIAL_CATEGORY } from '../../../common/tutorials/tutorial_category'; import { onPremInstructions, cloudInstructions, onPremCloudInstructions } from '../../../common/tutorials/metricbeat_instructions'; -export function muninMetricsSpecProvider(server, context) { +export function muninMetricsSpecProvider(context) { const moduleName = 'munin'; return { id: 'muninMetrics', diff --git a/src/legacy/core_plugins/kibana/server/tutorials/mysql_logs/index.js b/src/legacy/core_plugins/kibana/server/tutorials/mysql_logs/index.js index e3425d4531b42..56607b421864d 100644 --- a/src/legacy/core_plugins/kibana/server/tutorials/mysql_logs/index.js +++ b/src/legacy/core_plugins/kibana/server/tutorials/mysql_logs/index.js @@ -21,7 +21,7 @@ import { i18n } from '@kbn/i18n'; import { TUTORIAL_CATEGORY } from '../../../common/tutorials/tutorial_category'; import { onPremInstructions, cloudInstructions, onPremCloudInstructions } from '../../../common/tutorials/filebeat_instructions'; -export function mysqlLogsSpecProvider(server, context) { +export function mysqlLogsSpecProvider(context) { const moduleName = 'mysql'; const platforms = ['OSX', 'DEB', 'RPM', 'WINDOWS']; return { diff --git a/src/legacy/core_plugins/kibana/server/tutorials/mysql_metrics/index.js b/src/legacy/core_plugins/kibana/server/tutorials/mysql_metrics/index.js index c7c60406106ea..c7cc4688efa02 100644 --- a/src/legacy/core_plugins/kibana/server/tutorials/mysql_metrics/index.js +++ b/src/legacy/core_plugins/kibana/server/tutorials/mysql_metrics/index.js @@ -21,7 +21,7 @@ import { i18n } from '@kbn/i18n'; import { TUTORIAL_CATEGORY } from '../../../common/tutorials/tutorial_category'; import { onPremInstructions, cloudInstructions, onPremCloudInstructions } from '../../../common/tutorials/metricbeat_instructions'; -export function mysqlMetricsSpecProvider(server, context) { +export function mysqlMetricsSpecProvider(context) { const moduleName = 'mysql'; return { id: 'mysqlMetrics', diff --git a/src/legacy/core_plugins/kibana/server/tutorials/nats_logs/index.js b/src/legacy/core_plugins/kibana/server/tutorials/nats_logs/index.js index badaa338bff43..9da1787d9742f 100644 --- a/src/legacy/core_plugins/kibana/server/tutorials/nats_logs/index.js +++ b/src/legacy/core_plugins/kibana/server/tutorials/nats_logs/index.js @@ -21,7 +21,7 @@ import { i18n } from '@kbn/i18n'; import { TUTORIAL_CATEGORY } from '../../../common/tutorials/tutorial_category'; import { onPremInstructions, cloudInstructions, onPremCloudInstructions } from '../../../common/tutorials/filebeat_instructions'; -export function natsLogsSpecProvider(server, context) { +export function natsLogsSpecProvider(context) { const moduleName = 'nats'; const geoipRequired = false; const uaRequired = false; diff --git a/src/legacy/core_plugins/kibana/server/tutorials/nats_metrics/index.js b/src/legacy/core_plugins/kibana/server/tutorials/nats_metrics/index.js index 53f7dd531cbbd..f3be55ccbc904 100644 --- a/src/legacy/core_plugins/kibana/server/tutorials/nats_metrics/index.js +++ b/src/legacy/core_plugins/kibana/server/tutorials/nats_metrics/index.js @@ -21,7 +21,7 @@ import { i18n } from '@kbn/i18n'; import { TUTORIAL_CATEGORY } from '../../../common/tutorials/tutorial_category'; import { onPremInstructions, cloudInstructions, onPremCloudInstructions } from '../../../common/tutorials/metricbeat_instructions'; -export function natsMetricsSpecProvider(server, context) { +export function natsMetricsSpecProvider(context) { const moduleName = 'nats'; return { id: 'natsMetrics', diff --git a/src/legacy/core_plugins/kibana/server/tutorials/nginx_logs/index.js b/src/legacy/core_plugins/kibana/server/tutorials/nginx_logs/index.js index b08fa2729c1af..18bd3f649313f 100644 --- a/src/legacy/core_plugins/kibana/server/tutorials/nginx_logs/index.js +++ b/src/legacy/core_plugins/kibana/server/tutorials/nginx_logs/index.js @@ -21,7 +21,7 @@ import { i18n } from '@kbn/i18n'; import { TUTORIAL_CATEGORY } from '../../../common/tutorials/tutorial_category'; import { onPremInstructions, cloudInstructions, onPremCloudInstructions } from '../../../common/tutorials/filebeat_instructions'; -export function nginxLogsSpecProvider(server, context) { +export function nginxLogsSpecProvider(context) { const moduleName = 'nginx'; const platforms = ['OSX', 'DEB', 'RPM', 'WINDOWS']; return { diff --git a/src/legacy/core_plugins/kibana/server/tutorials/nginx_metrics/index.js b/src/legacy/core_plugins/kibana/server/tutorials/nginx_metrics/index.js index 99bee7c3a5510..f0ebe92295119 100644 --- a/src/legacy/core_plugins/kibana/server/tutorials/nginx_metrics/index.js +++ b/src/legacy/core_plugins/kibana/server/tutorials/nginx_metrics/index.js @@ -21,7 +21,7 @@ import { i18n } from '@kbn/i18n'; import { TUTORIAL_CATEGORY } from '../../../common/tutorials/tutorial_category'; import { onPremInstructions, cloudInstructions, onPremCloudInstructions } from '../../../common/tutorials/metricbeat_instructions'; -export function nginxMetricsSpecProvider(server, context) { +export function nginxMetricsSpecProvider(context) { const moduleName = 'nginx'; return { id: 'nginxMetrics', diff --git a/src/legacy/core_plugins/kibana/server/tutorials/osquery_logs/index.js b/src/legacy/core_plugins/kibana/server/tutorials/osquery_logs/index.js index c435e95db2acb..eddb81a9762e3 100644 --- a/src/legacy/core_plugins/kibana/server/tutorials/osquery_logs/index.js +++ b/src/legacy/core_plugins/kibana/server/tutorials/osquery_logs/index.js @@ -25,7 +25,7 @@ import { onPremCloudInstructions, } from '../../../common/tutorials/filebeat_instructions'; -export function osqueryLogsSpecProvider(server, context) { +export function osqueryLogsSpecProvider(context) { const moduleName = 'osquery'; const platforms = ['OSX', 'DEB', 'RPM', 'WINDOWS']; return { diff --git a/src/legacy/core_plugins/kibana/server/tutorials/php_fpm_metrics/index.js b/src/legacy/core_plugins/kibana/server/tutorials/php_fpm_metrics/index.js index 077574d70615d..1e55be37e4c52 100644 --- a/src/legacy/core_plugins/kibana/server/tutorials/php_fpm_metrics/index.js +++ b/src/legacy/core_plugins/kibana/server/tutorials/php_fpm_metrics/index.js @@ -21,7 +21,7 @@ import { i18n } from '@kbn/i18n'; import { TUTORIAL_CATEGORY } from '../../../common/tutorials/tutorial_category'; import { onPremInstructions, cloudInstructions, onPremCloudInstructions } from '../../../common/tutorials/metricbeat_instructions'; -export function phpfpmMetricsSpecProvider(server, context) { +export function phpfpmMetricsSpecProvider(context) { const moduleName = 'php_fpm'; return { id: 'phpfpmMetrics', diff --git a/src/legacy/core_plugins/kibana/server/tutorials/postgresql_logs/index.js b/src/legacy/core_plugins/kibana/server/tutorials/postgresql_logs/index.js index 2f7ea4558476c..a79394fa75fe7 100644 --- a/src/legacy/core_plugins/kibana/server/tutorials/postgresql_logs/index.js +++ b/src/legacy/core_plugins/kibana/server/tutorials/postgresql_logs/index.js @@ -21,7 +21,7 @@ import { i18n } from '@kbn/i18n'; import { TUTORIAL_CATEGORY } from '../../../common/tutorials/tutorial_category'; import { onPremInstructions, cloudInstructions, onPremCloudInstructions } from '../../../common/tutorials/filebeat_instructions'; -export function postgresqlLogsSpecProvider(server, context) { +export function postgresqlLogsSpecProvider(context) { const moduleName = 'postgresql'; const platforms = ['OSX', 'DEB', 'RPM', 'WINDOWS']; return { diff --git a/src/legacy/core_plugins/kibana/server/tutorials/postgresql_metrics/index.js b/src/legacy/core_plugins/kibana/server/tutorials/postgresql_metrics/index.js index 6690979d55cc7..74bf88da864b6 100644 --- a/src/legacy/core_plugins/kibana/server/tutorials/postgresql_metrics/index.js +++ b/src/legacy/core_plugins/kibana/server/tutorials/postgresql_metrics/index.js @@ -21,7 +21,7 @@ import { i18n } from '@kbn/i18n'; import { TUTORIAL_CATEGORY } from '../../../common/tutorials/tutorial_category'; import { onPremInstructions, cloudInstructions, onPremCloudInstructions } from '../../../common/tutorials/metricbeat_instructions'; -export function postgresqlMetricsSpecProvider(server, context) { +export function postgresqlMetricsSpecProvider(context) { const moduleName = 'postgresql'; return { id: 'postgresqlMetrics', diff --git a/src/legacy/core_plugins/kibana/server/tutorials/prometheus_metrics/index.js b/src/legacy/core_plugins/kibana/server/tutorials/prometheus_metrics/index.js index ccede68549f31..8e21833afb5a5 100644 --- a/src/legacy/core_plugins/kibana/server/tutorials/prometheus_metrics/index.js +++ b/src/legacy/core_plugins/kibana/server/tutorials/prometheus_metrics/index.js @@ -21,7 +21,7 @@ import { i18n } from '@kbn/i18n'; import { TUTORIAL_CATEGORY } from '../../../common/tutorials/tutorial_category'; import { onPremInstructions, cloudInstructions, onPremCloudInstructions } from '../../../common/tutorials/metricbeat_instructions'; -export function prometheusMetricsSpecProvider(server, context) { +export function prometheusMetricsSpecProvider(context) { const moduleName = 'prometheus'; return { id: moduleName + 'Metrics', diff --git a/src/legacy/core_plugins/kibana/server/tutorials/rabbitmq_metrics/index.js b/src/legacy/core_plugins/kibana/server/tutorials/rabbitmq_metrics/index.js index f40fe41124382..9a8a040ce8b86 100644 --- a/src/legacy/core_plugins/kibana/server/tutorials/rabbitmq_metrics/index.js +++ b/src/legacy/core_plugins/kibana/server/tutorials/rabbitmq_metrics/index.js @@ -21,7 +21,7 @@ import { i18n } from '@kbn/i18n'; import { TUTORIAL_CATEGORY } from '../../../common/tutorials/tutorial_category'; import { onPremInstructions, cloudInstructions, onPremCloudInstructions } from '../../../common/tutorials/metricbeat_instructions'; -export function rabbitmqMetricsSpecProvider(server, context) { +export function rabbitmqMetricsSpecProvider(context) { const moduleName = 'rabbitmq'; return { id: 'rabbitmqMetrics', diff --git a/src/legacy/core_plugins/kibana/server/tutorials/redis_logs/index.js b/src/legacy/core_plugins/kibana/server/tutorials/redis_logs/index.js index d37e6d66bdd3a..dc31203ff928c 100644 --- a/src/legacy/core_plugins/kibana/server/tutorials/redis_logs/index.js +++ b/src/legacy/core_plugins/kibana/server/tutorials/redis_logs/index.js @@ -21,7 +21,7 @@ import { i18n } from '@kbn/i18n'; import { TUTORIAL_CATEGORY } from '../../../common/tutorials/tutorial_category'; import { onPremInstructions, cloudInstructions, onPremCloudInstructions } from '../../../common/tutorials/filebeat_instructions'; -export function redisLogsSpecProvider(server, context) { +export function redisLogsSpecProvider(context) { const moduleName = 'redis'; const platforms = ['OSX', 'DEB', 'RPM', 'WINDOWS']; return { diff --git a/src/legacy/core_plugins/kibana/server/tutorials/redis_metrics/index.js b/src/legacy/core_plugins/kibana/server/tutorials/redis_metrics/index.js index e92dd15bfc962..a6177b0c551a0 100644 --- a/src/legacy/core_plugins/kibana/server/tutorials/redis_metrics/index.js +++ b/src/legacy/core_plugins/kibana/server/tutorials/redis_metrics/index.js @@ -21,7 +21,7 @@ import { i18n } from '@kbn/i18n'; import { TUTORIAL_CATEGORY } from '../../../common/tutorials/tutorial_category'; import { onPremInstructions, cloudInstructions, onPremCloudInstructions } from '../../../common/tutorials/metricbeat_instructions'; -export function redisMetricsSpecProvider(server, context) { +export function redisMetricsSpecProvider(context) { const moduleName = 'redis'; return { id: 'redisMetrics', diff --git a/src/legacy/core_plugins/kibana/server/tutorials/register.js b/src/legacy/core_plugins/kibana/server/tutorials/register.js index 0bd9ad3e181a5..f1e60ae57311c 100644 --- a/src/legacy/core_plugins/kibana/server/tutorials/register.js +++ b/src/legacy/core_plugins/kibana/server/tutorials/register.js @@ -82,64 +82,64 @@ import { cockroachdbMetricsSpecProvider } from './cockroachdb_metrics'; export function registerTutorials(server) { server.newPlatform.setup.plugins.tutorials.registerTutorial(systemLogsSpecProvider); server.newPlatform.setup.plugins.tutorials.registerTutorial(systemMetricsSpecProvider); - server.registerTutorial(apacheLogsSpecProvider); - server.registerTutorial(apacheMetricsSpecProvider); - server.registerTutorial(elasticsearchLogsSpecProvider); - server.registerTutorial(iisLogsSpecProvider); - server.registerTutorial(kafkaLogsSpecProvider); - server.registerTutorial(logstashLogsSpecProvider); - server.registerTutorial(nginxLogsSpecProvider); - server.registerTutorial(nginxMetricsSpecProvider); - server.registerTutorial(mysqlLogsSpecProvider); - server.registerTutorial(mysqlMetricsSpecProvider); - server.registerTutorial(mongodbMetricsSpecProvider); - server.registerTutorial(osqueryLogsSpecProvider); - server.registerTutorial(phpfpmMetricsSpecProvider); - server.registerTutorial(postgresqlMetricsSpecProvider); - server.registerTutorial(postgresqlLogsSpecProvider); - server.registerTutorial(rabbitmqMetricsSpecProvider); - server.registerTutorial(redisLogsSpecProvider); - server.registerTutorial(redisMetricsSpecProvider); - server.registerTutorial(suricataLogsSpecProvider); - server.registerTutorial(dockerMetricsSpecProvider); - server.registerTutorial(kubernetesMetricsSpecProvider); - server.registerTutorial(uwsgiMetricsSpecProvider); - server.registerTutorial(netflowSpecProvider); - server.registerTutorial(traefikLogsSpecProvider); + server.newPlatform.setup.plugins.tutorials.registerTutorial(apacheLogsSpecProvider); + server.newPlatform.setup.plugins.tutorials.registerTutorial(apacheMetricsSpecProvider); + server.newPlatform.setup.plugins.tutorials.registerTutorial(elasticsearchLogsSpecProvider); + server.newPlatform.setup.plugins.tutorials.registerTutorial(iisLogsSpecProvider); + server.newPlatform.setup.plugins.tutorials.registerTutorial(kafkaLogsSpecProvider); + server.newPlatform.setup.plugins.tutorials.registerTutorial(logstashLogsSpecProvider); + server.newPlatform.setup.plugins.tutorials.registerTutorial(nginxLogsSpecProvider); + server.newPlatform.setup.plugins.tutorials.registerTutorial(nginxMetricsSpecProvider); + server.newPlatform.setup.plugins.tutorials.registerTutorial(mysqlLogsSpecProvider); + server.newPlatform.setup.plugins.tutorials.registerTutorial(mysqlMetricsSpecProvider); + server.newPlatform.setup.plugins.tutorials.registerTutorial(mongodbMetricsSpecProvider); + server.newPlatform.setup.plugins.tutorials.registerTutorial(osqueryLogsSpecProvider); + server.newPlatform.setup.plugins.tutorials.registerTutorial(phpfpmMetricsSpecProvider); + server.newPlatform.setup.plugins.tutorials.registerTutorial(postgresqlMetricsSpecProvider); + server.newPlatform.setup.plugins.tutorials.registerTutorial(postgresqlLogsSpecProvider); + server.newPlatform.setup.plugins.tutorials.registerTutorial(rabbitmqMetricsSpecProvider); + server.newPlatform.setup.plugins.tutorials.registerTutorial(redisLogsSpecProvider); + server.newPlatform.setup.plugins.tutorials.registerTutorial(redisMetricsSpecProvider); + server.newPlatform.setup.plugins.tutorials.registerTutorial(suricataLogsSpecProvider); + server.newPlatform.setup.plugins.tutorials.registerTutorial(dockerMetricsSpecProvider); + server.newPlatform.setup.plugins.tutorials.registerTutorial(kubernetesMetricsSpecProvider); + server.newPlatform.setup.plugins.tutorials.registerTutorial(uwsgiMetricsSpecProvider); + server.newPlatform.setup.plugins.tutorials.registerTutorial(netflowSpecProvider); + server.newPlatform.setup.plugins.tutorials.registerTutorial(traefikLogsSpecProvider); server.registerTutorial(apmSpecProvider); - server.registerTutorial(cephMetricsSpecProvider); - server.registerTutorial(aerospikeMetricsSpecProvider); - server.registerTutorial(couchbaseMetricsSpecProvider); - server.registerTutorial(dropwizardMetricsSpecProvider); - server.registerTutorial(elasticsearchMetricsSpecProvider); - server.registerTutorial(etcdMetricsSpecProvider); - server.registerTutorial(haproxyMetricsSpecProvider); - server.registerTutorial(kafkaMetricsSpecProvider); - server.registerTutorial(kibanaMetricsSpecProvider); - server.registerTutorial(memcachedMetricsSpecProvider); - server.registerTutorial(muninMetricsSpecProvider); - server.registerTutorial(vSphereMetricsSpecProvider); - server.registerTutorial(windowsMetricsSpecProvider); - server.registerTutorial(windowsEventLogsSpecProvider); - server.registerTutorial(golangMetricsSpecProvider); - server.registerTutorial(logstashMetricsSpecProvider); - server.registerTutorial(prometheusMetricsSpecProvider); - server.registerTutorial(zookeeperMetricsSpecProvider); - server.registerTutorial(uptimeMonitorsSpecProvider); - server.registerTutorial(cloudwatchLogsSpecProvider); - server.registerTutorial(awsMetricsSpecProvider); - server.registerTutorial(mssqlMetricsSpecProvider); - server.registerTutorial(natsMetricsSpecProvider); - server.registerTutorial(natsLogsSpecProvider); - server.registerTutorial(zeekLogsSpecProvider); - server.registerTutorial(corednsMetricsSpecProvider); - server.registerTutorial(corednsLogsSpecProvider); - server.registerTutorial(auditbeatSpecProvider); - server.registerTutorial(iptablesLogsSpecProvider); - server.registerTutorial(ciscoLogsSpecProvider); - server.registerTutorial(envoyproxyLogsSpecProvider); - server.registerTutorial(couchdbMetricsSpecProvider); + server.newPlatform.setup.plugins.tutorials.registerTutorial(cephMetricsSpecProvider); + server.newPlatform.setup.plugins.tutorials.registerTutorial(aerospikeMetricsSpecProvider); + server.newPlatform.setup.plugins.tutorials.registerTutorial(couchbaseMetricsSpecProvider); + server.newPlatform.setup.plugins.tutorials.registerTutorial(dropwizardMetricsSpecProvider); + server.newPlatform.setup.plugins.tutorials.registerTutorial(elasticsearchMetricsSpecProvider); + server.newPlatform.setup.plugins.tutorials.registerTutorial(etcdMetricsSpecProvider); + server.newPlatform.setup.plugins.tutorials.registerTutorial(haproxyMetricsSpecProvider); + server.newPlatform.setup.plugins.tutorials.registerTutorial(kafkaMetricsSpecProvider); + server.newPlatform.setup.plugins.tutorials.registerTutorial(kibanaMetricsSpecProvider); + server.newPlatform.setup.plugins.tutorials.registerTutorial(memcachedMetricsSpecProvider); + server.newPlatform.setup.plugins.tutorials.registerTutorial(muninMetricsSpecProvider); + server.newPlatform.setup.plugins.tutorials.registerTutorial(vSphereMetricsSpecProvider); + server.newPlatform.setup.plugins.tutorials.registerTutorial(windowsMetricsSpecProvider); + server.newPlatform.setup.plugins.tutorials.registerTutorial(windowsEventLogsSpecProvider); + server.newPlatform.setup.plugins.tutorials.registerTutorial(golangMetricsSpecProvider); + server.newPlatform.setup.plugins.tutorials.registerTutorial(logstashMetricsSpecProvider); + server.newPlatform.setup.plugins.tutorials.registerTutorial(prometheusMetricsSpecProvider); + server.newPlatform.setup.plugins.tutorials.registerTutorial(zookeeperMetricsSpecProvider); + server.newPlatform.setup.plugins.tutorials.registerTutorial(uptimeMonitorsSpecProvider); + server.newPlatform.setup.plugins.tutorials.registerTutorial(cloudwatchLogsSpecProvider); + server.newPlatform.setup.plugins.tutorials.registerTutorial(awsMetricsSpecProvider); + server.newPlatform.setup.plugins.tutorials.registerTutorial(mssqlMetricsSpecProvider); + server.newPlatform.setup.plugins.tutorials.registerTutorial(natsMetricsSpecProvider); + server.newPlatform.setup.plugins.tutorials.registerTutorial(natsLogsSpecProvider); + server.newPlatform.setup.plugins.tutorials.registerTutorial(zeekLogsSpecProvider); + server.newPlatform.setup.plugins.tutorials.registerTutorial(corednsMetricsSpecProvider); + server.newPlatform.setup.plugins.tutorials.registerTutorial(corednsLogsSpecProvider); + server.newPlatform.setup.plugins.tutorials.registerTutorial(auditbeatSpecProvider); + server.newPlatform.setup.plugins.tutorials.registerTutorial(iptablesLogsSpecProvider); + server.newPlatform.setup.plugins.tutorials.registerTutorial(ciscoLogsSpecProvider); + server.newPlatform.setup.plugins.tutorials.registerTutorial(envoyproxyLogsSpecProvider); + server.newPlatform.setup.plugins.tutorials.registerTutorial(couchdbMetricsSpecProvider); server.registerTutorial(emsBoundariesSpecProvider); - server.registerTutorial(consulMetricsSpecProvider); - server.registerTutorial(cockroachdbMetricsSpecProvider); + server.newPlatform.setup.plugins.tutorials.registerTutorial(consulMetricsSpecProvider); + server.newPlatform.setup.plugins.tutorials.registerTutorial(cockroachdbMetricsSpecProvider); } diff --git a/src/legacy/core_plugins/kibana/server/tutorials/suricata_logs/index.js b/src/legacy/core_plugins/kibana/server/tutorials/suricata_logs/index.js index e4e9d5b7e0fd8..3f2ecfa78d3b2 100644 --- a/src/legacy/core_plugins/kibana/server/tutorials/suricata_logs/index.js +++ b/src/legacy/core_plugins/kibana/server/tutorials/suricata_logs/index.js @@ -25,7 +25,7 @@ import { onPremCloudInstructions, } from '../../../common/tutorials/filebeat_instructions'; -export function suricataLogsSpecProvider(server, context) { +export function suricataLogsSpecProvider(context) { const moduleName = 'suricata'; const platforms = ['OSX', 'DEB', 'RPM', 'WINDOWS']; return { diff --git a/src/legacy/core_plugins/kibana/server/tutorials/traefik_logs/index.js b/src/legacy/core_plugins/kibana/server/tutorials/traefik_logs/index.js index 2b05b2669737e..b9b2d4d7e3e5b 100644 --- a/src/legacy/core_plugins/kibana/server/tutorials/traefik_logs/index.js +++ b/src/legacy/core_plugins/kibana/server/tutorials/traefik_logs/index.js @@ -21,7 +21,7 @@ import { i18n } from '@kbn/i18n'; import { TUTORIAL_CATEGORY } from '../../../common/tutorials/tutorial_category'; import { onPremInstructions, cloudInstructions, onPremCloudInstructions } from '../../../common/tutorials/filebeat_instructions'; -export function traefikLogsSpecProvider(server, context) { +export function traefikLogsSpecProvider(context) { const moduleName = 'traefik'; const platforms = ['OSX', 'DEB', 'RPM', 'WINDOWS']; return { diff --git a/src/legacy/core_plugins/kibana/server/tutorials/uptime_monitors/index.js b/src/legacy/core_plugins/kibana/server/tutorials/uptime_monitors/index.js index 8ba0ba1ecc910..7cc90c740eb69 100644 --- a/src/legacy/core_plugins/kibana/server/tutorials/uptime_monitors/index.js +++ b/src/legacy/core_plugins/kibana/server/tutorials/uptime_monitors/index.js @@ -25,7 +25,7 @@ import { onPremCloudInstructions, } from '../../../common/tutorials/heartbeat_instructions'; -export function uptimeMonitorsSpecProvider(server, context) { +export function uptimeMonitorsSpecProvider(context) { return { id: 'uptimeMonitors', name: i18n.translate('kbn.server.tutorials.uptimeMonitors.nameTitle', { diff --git a/src/legacy/core_plugins/kibana/server/tutorials/uwsgi_metrics/index.js b/src/legacy/core_plugins/kibana/server/tutorials/uwsgi_metrics/index.js index a0dd93524f43f..7c5f8e88b50dc 100644 --- a/src/legacy/core_plugins/kibana/server/tutorials/uwsgi_metrics/index.js +++ b/src/legacy/core_plugins/kibana/server/tutorials/uwsgi_metrics/index.js @@ -21,7 +21,7 @@ import { i18n } from '@kbn/i18n'; import { TUTORIAL_CATEGORY } from '../../../common/tutorials/tutorial_category'; import { onPremInstructions, cloudInstructions, onPremCloudInstructions } from '../../../common/tutorials/metricbeat_instructions'; -export function uwsgiMetricsSpecProvider(server, context) { +export function uwsgiMetricsSpecProvider(context) { const moduleName = 'uwsgi'; return { id: 'uwsgiMetrics', diff --git a/src/legacy/core_plugins/kibana/server/tutorials/vsphere_metrics/index.js b/src/legacy/core_plugins/kibana/server/tutorials/vsphere_metrics/index.js index 0ba6430c5cfd6..7de8fd8fc445b 100644 --- a/src/legacy/core_plugins/kibana/server/tutorials/vsphere_metrics/index.js +++ b/src/legacy/core_plugins/kibana/server/tutorials/vsphere_metrics/index.js @@ -21,7 +21,7 @@ import { i18n } from '@kbn/i18n'; import { TUTORIAL_CATEGORY } from '../../../common/tutorials/tutorial_category'; import { onPremInstructions, cloudInstructions, onPremCloudInstructions } from '../../../common/tutorials/metricbeat_instructions'; -export function vSphereMetricsSpecProvider(server, context) { +export function vSphereMetricsSpecProvider(context) { const moduleName = 'vsphere'; return { id: 'vsphereMetrics', diff --git a/src/legacy/core_plugins/kibana/server/tutorials/windows_event_logs/index.js b/src/legacy/core_plugins/kibana/server/tutorials/windows_event_logs/index.js index cd2ee09c09f74..272535ad3e4e1 100644 --- a/src/legacy/core_plugins/kibana/server/tutorials/windows_event_logs/index.js +++ b/src/legacy/core_plugins/kibana/server/tutorials/windows_event_logs/index.js @@ -25,7 +25,7 @@ import { onPremCloudInstructions, } from '../../../common/tutorials/winlogbeat_instructions'; -export function windowsEventLogsSpecProvider(server, context) { +export function windowsEventLogsSpecProvider(context) { return { id: 'windowsEventLogs', name: i18n.translate('kbn.server.tutorials.windowsEventLogs.nameTitle', { diff --git a/src/legacy/core_plugins/kibana/server/tutorials/windows_metrics/index.js b/src/legacy/core_plugins/kibana/server/tutorials/windows_metrics/index.js index 8f9e04103cc0a..eb2f2aeec7e5e 100644 --- a/src/legacy/core_plugins/kibana/server/tutorials/windows_metrics/index.js +++ b/src/legacy/core_plugins/kibana/server/tutorials/windows_metrics/index.js @@ -21,7 +21,7 @@ import { i18n } from '@kbn/i18n'; import { TUTORIAL_CATEGORY } from '../../../common/tutorials/tutorial_category'; import { onPremInstructions, cloudInstructions, onPremCloudInstructions } from '../../../common/tutorials/metricbeat_instructions'; -export function windowsMetricsSpecProvider(server, context) { +export function windowsMetricsSpecProvider(context) { const moduleName = 'windows'; return { id: 'windowsMetrics', diff --git a/src/legacy/core_plugins/kibana/server/tutorials/zeek_logs/index.js b/src/legacy/core_plugins/kibana/server/tutorials/zeek_logs/index.js index 839a9c81f948e..07d46c9c6ae84 100644 --- a/src/legacy/core_plugins/kibana/server/tutorials/zeek_logs/index.js +++ b/src/legacy/core_plugins/kibana/server/tutorials/zeek_logs/index.js @@ -25,7 +25,7 @@ import { onPremCloudInstructions, } from '../../../common/tutorials/filebeat_instructions'; -export function zeekLogsSpecProvider(server, context) { +export function zeekLogsSpecProvider(context) { const moduleName = 'zeek'; const platforms = ['OSX', 'DEB', 'RPM']; return { diff --git a/src/legacy/core_plugins/kibana/server/tutorials/zookeeper_metrics/index.js b/src/legacy/core_plugins/kibana/server/tutorials/zookeeper_metrics/index.js index 22527073b1680..9be44a257a8b4 100644 --- a/src/legacy/core_plugins/kibana/server/tutorials/zookeeper_metrics/index.js +++ b/src/legacy/core_plugins/kibana/server/tutorials/zookeeper_metrics/index.js @@ -21,7 +21,7 @@ import { i18n } from '@kbn/i18n'; import { TUTORIAL_CATEGORY } from '../../../common/tutorials/tutorial_category'; import { onPremInstructions, cloudInstructions, onPremCloudInstructions } from '../../../common/tutorials/metricbeat_instructions'; -export function zookeeperMetricsSpecProvider(server, context) { +export function zookeeperMetricsSpecProvider(context) { const moduleName = 'zookeeper'; return { id: moduleName + 'Metrics', diff --git a/src/plugins/tutorials/server/plugin.ts b/src/plugins/tutorials/server/plugin.ts index b2c74a1c71353..6c7c17f73dbbc 100644 --- a/src/plugins/tutorials/server/plugin.ts +++ b/src/plugins/tutorials/server/plugin.ts @@ -16,7 +16,9 @@ * specific language governing permissions and limitations * under the License. */ +import Joi from 'joi'; import { CoreSetup, Plugin, KibanaRequest } from 'src/core/server'; +import { tutorialSchema } from './tutorial_schema'; import { TutorialsRegistrySetup, TutorialsRegistryStart, @@ -38,15 +40,46 @@ type TutorialContextFactory = ( }> > ) => { [key: string]: unknown }; +type ScopedTutorialContextFactory = (...args: any[]) => any; +type AddScopedTutorialContextFactory = (arg0: ScopedTutorialContextFactory) => void; // following similar signature to the features_catalogue plugin export class TutorialsPlugin implements Plugin { private readonly tutorialProviders: TutorialProvider[] = []; private readonly scopedTutorialContextFactories: TutorialContextFactory[] = []; public async setup(core: CoreSetup) { + /* + core.http.registerRouterHandlerContext is used to provide a specific value for this request (as the route context) + This context is available in route handlers + + Otherwise, we return an object containing `registerTutorial` and `addScopedTutorialContextFactory` + Question: is the way the `addScopedTutorialContextFactory` implemented correct? + */ + // core.http.registerRouteHandlerContext('getTutorials', (request: any) => { + // const initialContext = {}; + // const scopedContext = this.scopedTutorialContextFactories.reduce( + // (accumulatedContext, contextFactory) => { + // return { ...accumulatedContext, ...contextFactory(request) }; + // }, + // initialContext + // ); + // return this.tutorialProviders.map(tutorialProvider => { + // return tutorialProvider(scopedContext); // All the tutorial providers need to be refactored so that they only accept the sscopedContext. + // }); + // }); + + // const router = core.http.createRouter(); + // router.get( + // { path: '/api/kibana/home/NP_tutorials', validate: false }, + // async (context, req, res) => { + // return res.ok({ body: context.getTutorials }); + // } + // ); + + // The following handler implementation is pretty much the same as using the code from above. const router = core.http.createRouter(); router.get( - { path: '/api/kibana/home/tutorials', validate: false }, + { path: '/api/kibana/home/NP_tutorials', validate: false }, async (context, req, res) => { const initialContext = {}; const scopedContext = this.scopedTutorialContextFactories.reduce( @@ -58,25 +91,26 @@ export class TutorialsPlugin implements Plugin { - return tutorialProvider(scopedContext); // needs to be refactored to not take in the server. Does the provider even need the server. + return tutorialProvider(scopedContext); // All the tutorialProviders need to be refactored so that they don't need the server. }), }); } ); return { registerTutorial: (specProvider: TutorialProvider) => { - // registration during setup - // const emptyContext = {}; - // const { error } = Joi.validate(specProvider(server, emptyContext), tutorialSchema); + const emptyContext = {}; + const { error } = Joi.validate(specProvider(emptyContext), tutorialSchema); - // if (error) { - // throw new Error(`Unable to register tutorial spec because its invalid. ${error}`); - // } + if (error) { + throw new Error(`Unable to register tutorial spec because its invalid. ${error}`); + } this.tutorialProviders.push(specProvider); }, - addScopedTutorialContextFactory: (scopedTutorialContextFactory: any) => { - // returned by the setup method of the new plugin, they will do the same thing as now + + addScopedTutorialContextFactory: ( + scopedTutorialContextFactory: ScopedTutorialContextFactory + ) => { if (typeof scopedTutorialContextFactory !== 'function') { throw new Error( `Unable to add scoped(request) context factory because you did not provide a function` diff --git a/src/plugins/tutorials/tutorial_schema.ts b/src/plugins/tutorials/server/tutorial_schema.ts similarity index 100% rename from src/plugins/tutorials/tutorial_schema.ts rename to src/plugins/tutorials/server/tutorial_schema.ts From 31548efd04e4916806802aeb696d334798486634 Mon Sep 17 00:00:00 2001 From: Christiane Heiligers Date: Wed, 13 Nov 2019 08:56:08 -0700 Subject: [PATCH 05/21] Adds comment on where to pre-register general non-plugin specific tutorials --- src/plugins/tutorials/server/plugin.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/tutorials/server/plugin.ts b/src/plugins/tutorials/server/plugin.ts index 6c7c17f73dbbc..a6afbceab1f0a 100644 --- a/src/plugins/tutorials/server/plugin.ts +++ b/src/plugins/tutorials/server/plugin.ts @@ -44,7 +44,7 @@ type ScopedTutorialContextFactory = (...args: any[]) => any; type AddScopedTutorialContextFactory = (arg0: ScopedTutorialContextFactory) => void; // following similar signature to the features_catalogue plugin export class TutorialsPlugin implements Plugin { - private readonly tutorialProviders: TutorialProvider[] = []; + private readonly tutorialProviders: TutorialProvider[] = []; // pre-register all the tutorials we know we want in here private readonly scopedTutorialContextFactories: TutorialContextFactory[] = []; public async setup(core: CoreSetup) { From c22d78715c2d99ec417480148f71eb058273a82d Mon Sep 17 00:00:00 2001 From: Christiane Heiligers Date: Wed, 13 Nov 2019 14:05:59 -0700 Subject: [PATCH 06/21] Converts TutorialsPlugin to TutorialsRegistry service in new Home plugin --- src/plugins/tutorials/server/index.ts | 9 +- src/plugins/tutorials/server/plugin.ts | 113 +---------- src/plugins/tutorials/server/routes/index.ts | 19 -- .../tutorials/server/services/index.ts | 8 +- .../server/{ => services}/tutorial_schema.ts | 0 .../server/services/tutorials_registry.ts | 181 ++++++------------ .../services/tutorials_registry_types.ts | 110 +++++++++++ 7 files changed, 180 insertions(+), 260 deletions(-) delete mode 100644 src/plugins/tutorials/server/routes/index.ts rename src/plugins/tutorials/server/{ => services}/tutorial_schema.ts (100%) create mode 100644 src/plugins/tutorials/server/services/tutorials_registry_types.ts diff --git a/src/plugins/tutorials/server/index.ts b/src/plugins/tutorials/server/index.ts index 5a2b4789badbb..178a77dc85ca9 100644 --- a/src/plugins/tutorials/server/index.ts +++ b/src/plugins/tutorials/server/index.ts @@ -17,9 +17,8 @@ * under the License. */ -export { TutorialsSetup, TutorialsStart } from './plugin'; // types -import { TutorialsPlugin } from './plugin'; // the actual plugin class -// also export other relevant subtypes +export { HomePluginSetup, HomePluginStart } from './plugin'; +export { TutorialProvider } from './services'; +import { HomePlugin } from './plugin'; -export const plugin = () => new TutorialsPlugin(); -// export const config = () => new TutorialsConfig(); optional, only if needed +export const plugin = () => new HomePlugin(); diff --git a/src/plugins/tutorials/server/plugin.ts b/src/plugins/tutorials/server/plugin.ts index a6afbceab1f0a..67efae31b157c 100644 --- a/src/plugins/tutorials/server/plugin.ts +++ b/src/plugins/tutorials/server/plugin.ts @@ -16,119 +16,26 @@ * specific language governing permissions and limitations * under the License. */ -import Joi from 'joi'; -import { CoreSetup, Plugin, KibanaRequest } from 'src/core/server'; -import { tutorialSchema } from './tutorial_schema'; -import { - TutorialsRegistrySetup, - TutorialsRegistryStart, - TutorialsRegistry, - TutorialSchema, -} from './services'; - -type TutorialProvider = (context: { [key: string]: unknown }) => TutorialSchema; -type TutorialContextFactory = ( - req: KibanaRequest< - Readonly<{ - [x: string]: any; - }>, - Readonly<{ - [x: string]: any; - }>, - Readonly<{ - [x: string]: any; - }> - > -) => { [key: string]: unknown }; -type ScopedTutorialContextFactory = (...args: any[]) => any; -type AddScopedTutorialContextFactory = (arg0: ScopedTutorialContextFactory) => void; -// following similar signature to the features_catalogue plugin -export class TutorialsPlugin implements Plugin { - private readonly tutorialProviders: TutorialProvider[] = []; // pre-register all the tutorials we know we want in here - private readonly scopedTutorialContextFactories: TutorialContextFactory[] = []; +import { CoreSetup, Plugin } from 'src/core/server'; +import { TutorialsRegistry, TutorialsRegistrySetup, TutorialsRegistryStart } from './services'; +export class HomePlugin implements Plugin { + private readonly tutorialsRegistry = new TutorialsRegistry(); public async setup(core: CoreSetup) { - /* - core.http.registerRouterHandlerContext is used to provide a specific value for this request (as the route context) - This context is available in route handlers - - Otherwise, we return an object containing `registerTutorial` and `addScopedTutorialContextFactory` - Question: is the way the `addScopedTutorialContextFactory` implemented correct? - */ - // core.http.registerRouteHandlerContext('getTutorials', (request: any) => { - // const initialContext = {}; - // const scopedContext = this.scopedTutorialContextFactories.reduce( - // (accumulatedContext, contextFactory) => { - // return { ...accumulatedContext, ...contextFactory(request) }; - // }, - // initialContext - // ); - // return this.tutorialProviders.map(tutorialProvider => { - // return tutorialProvider(scopedContext); // All the tutorial providers need to be refactored so that they only accept the sscopedContext. - // }); - // }); - - // const router = core.http.createRouter(); - // router.get( - // { path: '/api/kibana/home/NP_tutorials', validate: false }, - // async (context, req, res) => { - // return res.ok({ body: context.getTutorials }); - // } - // ); - - // The following handler implementation is pretty much the same as using the code from above. - const router = core.http.createRouter(); - router.get( - { path: '/api/kibana/home/NP_tutorials', validate: false }, - async (context, req, res) => { - const initialContext = {}; - const scopedContext = this.scopedTutorialContextFactories.reduce( - (accumulatedContext, contextFactory) => { - return { ...accumulatedContext, ...contextFactory(req) }; - }, - initialContext - ); - - return res.ok({ - body: this.tutorialProviders.map(tutorialProvider => { - return tutorialProvider(scopedContext); // All the tutorialProviders need to be refactored so that they don't need the server. - }), - }); - } - ); return { - registerTutorial: (specProvider: TutorialProvider) => { - const emptyContext = {}; - const { error } = Joi.validate(specProvider(emptyContext), tutorialSchema); - - if (error) { - throw new Error(`Unable to register tutorial spec because its invalid. ${error}`); - } - - this.tutorialProviders.push(specProvider); - }, - - addScopedTutorialContextFactory: ( - scopedTutorialContextFactory: ScopedTutorialContextFactory - ) => { - if (typeof scopedTutorialContextFactory !== 'function') { - throw new Error( - `Unable to add scoped(request) context factory because you did not provide a function` - ); - } - - this.scopedTutorialContextFactories.push(scopedTutorialContextFactory); - }, + ...this.tutorialsRegistry.setup(core), }; } public async start() { - return {}; + return { + ...this.tutorialsRegistry.start(), + }; } } /** @public */ -export type TutorialsSetup = TutorialsRegistrySetup; +export type HomePluginSetup = TutorialsRegistrySetup; /** @public */ -export type TutorialsStart = TutorialsRegistryStart; +export type HomePluginStart = TutorialsRegistryStart; diff --git a/src/plugins/tutorials/server/routes/index.ts b/src/plugins/tutorials/server/routes/index.ts deleted file mode 100644 index cb4f1d79a3ee9..0000000000000 --- a/src/plugins/tutorials/server/routes/index.ts +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Licensed to Elasticsearch B.V. under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch B.V. licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -// HTTP routes diff --git a/src/plugins/tutorials/server/services/index.ts b/src/plugins/tutorials/server/services/index.ts index b588274577981..ec5f61f42c16b 100644 --- a/src/plugins/tutorials/server/services/index.ts +++ b/src/plugins/tutorials/server/services/index.ts @@ -19,9 +19,5 @@ // provided to other plugins as APIs // should model the plugin lifecycle -export { - TutorialsRegistry, - TutorialsRegistrySetup, - TutorialsRegistryStart, - TutorialSchema, -} from './tutorials_registry'; +export * from './tutorials_registry'; +export * from './tutorials_registry_types'; diff --git a/src/plugins/tutorials/server/tutorial_schema.ts b/src/plugins/tutorials/server/services/tutorial_schema.ts similarity index 100% rename from src/plugins/tutorials/server/tutorial_schema.ts rename to src/plugins/tutorials/server/services/tutorial_schema.ts diff --git a/src/plugins/tutorials/server/services/tutorials_registry.ts b/src/plugins/tutorials/server/services/tutorials_registry.ts index 7178e4b3f0adb..eaeade8692388 100644 --- a/src/plugins/tutorials/server/services/tutorials_registry.ts +++ b/src/plugins/tutorials/server/services/tutorials_registry.ts @@ -17,145 +17,72 @@ * under the License. */ -import { IconType } from '@elastic/eui'; +import Joi from 'joi'; import { CoreSetup } from 'src/core/server'; -/** @public */ -export enum TutorialsCategory { - LOGGING = 'logging', - SIEM = 'siem', - METRICS = 'metrics', - OTHER = 'other', -} -export interface ParamTypes { - NUMBER: string; - STRING: string; -} -export interface InstructionSetSchema { - readonly title: string; - readonly callOut: { - title: string; - message: string; - iconType: IconType; - }; -} -export interface ParamsSchema { - defaultValue: any; - id: string; - label: string; - type: ParamTypes; -} -export interface InstructionsSchema { - readonly instructionSets: InstructionSetSchema[]; - readonly params: ParamsSchema[]; -} -export interface DashboardSchema { - id: string; - linkLabel?: { - is: boolean; - then: any; - }; - isOverview: boolean; -} -export interface ArtifactsSchema { - readonly exportedFields: { - documentationUrl: string; - }; - readonly dashboards: DashboardSchema[]; - readonly application: { - path: string; - label: string; - }; -} -export interface TutorialSchema { - id: string; - category: TutorialsCategory; - name: string; - isBeta: boolean; - shortDescription: string; - euiIconType: IconType; // EUI icon type string, one of https://elastic.github.io/eui/#/icon; - longDescription: string; - completionTimeMinutes: number; - previewImagePath: string; - - // kibana and elastic cluster running on prem - onPrem: InstructionsSchema; +import { + TutorialProvider, + TutorialContextFactory, + ScopedTutorialContextFactory, +} from './tutorials_registry_types'; +import { tutorialSchema } from './tutorial_schema'; - // kibana and elastic cluster running in elastic's cloud - elasticCloud: InstructionsSchema; - - // kibana running on prem and elastic cluster running in elastic's cloud - onPremElasticCloud: InstructionsSchema; +export class TutorialsRegistry { + private readonly tutorialProviders: TutorialProvider[] = []; // pre-register all the tutorials we know we want in here + private readonly scopedTutorialContextFactories: TutorialContextFactory[] = []; + + public async setup(core: CoreSetup) { + const router = core.http.createRouter(); + router.get( + { path: '/api/kibana/home/NP_tutorials', validate: false }, + async (context, req, res) => { + const initialContext = {}; + const scopedContext = this.scopedTutorialContextFactories.reduce( + (accumulatedContext, contextFactory) => { + return { ...accumulatedContext, ...contextFactory(req) }; + }, + initialContext + ); + + return res.ok({ + body: this.tutorialProviders.map(tutorialProvider => { + return tutorialProvider(scopedContext); // All the tutorialProviders need to be refactored so that they don't need the server. + }), + }); + } + ); + return { + registerTutorial: (specProvider: TutorialProvider) => { + const emptyContext = {}; + const { error } = Joi.validate(specProvider(emptyContext), tutorialSchema); - // Elastic stack artifacts produced by product when it is setup and run. - artifacts: ArtifactsSchema; + if (error) { + throw new Error(`Unable to register tutorial spec because its invalid. ${error}`); + } - // saved objects used by data module. - savedObjects: any[]; - savedObjectsInstallMsg: string; -} + this.tutorialProviders.push(specProvider); + }, -export class TutorialsRegistry { - public setup(core: CoreSetup) { - const tutorialProviders: Array<(tutorialProvider: TutorialSchema) => void> = []; - const scopedTutorialContextFactories: Array<(scopedTutorialContextFactory: any) => void> = []; - core.http.registerRouteHandlerContext('getTutorials', (request: any) => { - const intitialContext = new Map(); - const scopedContext = scopedTutorialContextFactories.reduce( - (accumulatedContext, contextFactory) => { - return { ...accumulatedContext, ...contextFactory(request) }; - }, - intitialContext - ); - return tutorialProviders.map(tutorialProvider => { - return tutorialProvider(scopedContext); - }); - }); + addScopedTutorialContextFactory: ( + scopedTutorialContextFactory: ScopedTutorialContextFactory + ) => { + if (typeof scopedTutorialContextFactory !== 'function') { + throw new Error( + `Unable to add scoped(request) context factory because you did not provide a function` + ); + } - return { - register: () => {}, + this.scopedTutorialContextFactories.push(scopedTutorialContextFactory); + }, }; } public start() { - return { - get: () => {}, - }; + return {}; } } +/** @public */ export type TutorialsRegistrySetup = ReturnType; -export type TutorialsRegistryStart = ReturnType; - -// from Josh Dover: (this should actually be the TutorialsRegistry) -/* -class TutorialsPlugin { - setup(core) { - const tutorialProviders = []; - const scopedTutorialContextFactories = []; - - core.http.registerRouteHandlerContext('getTutorials', (request) => { - const initialContext = {}; - const scopedContext = scopedTutorialContextFactories.reduce((accumulatedContext, contextFactory) => { - return { ...accumulatedContext, ...contextFactory(request) }; - }, initialContext); - - return tutorialProviders.map((tutorialProvider) => { - return tutorialProvider(server, scopedContext); - }); - }); - - return { - registerTutorial(specProvider) { // specProvider should implement TutorialSchema - const emptyContext = {}; - const { error } = Joi.validate(specProvider(server, emptyContext), tutorialSchema); // the tutorialSchema's been typed in TutorialSchema - if (error) { - throw new Error(`Unable to register tutorial spec because its invalid. ${error}`); - } - - tutorialProviders.push(specProvider); - } - }; - } -} -*/ +/** @public */ +export type TutorialsRegistryStart = ReturnType; diff --git a/src/plugins/tutorials/server/services/tutorials_registry_types.ts b/src/plugins/tutorials/server/services/tutorials_registry_types.ts new file mode 100644 index 0000000000000..d081639e5c7e2 --- /dev/null +++ b/src/plugins/tutorials/server/services/tutorials_registry_types.ts @@ -0,0 +1,110 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +import { IconType } from '@elastic/eui'; +import { KibanaRequest } from 'src/core/server'; + +/** @public */ +export enum TutorialsCategory { + LOGGING = 'logging', + SIEM = 'siem', + METRICS = 'metrics', + OTHER = 'other', +} +export interface ParamTypes { + NUMBER: string; + STRING: string; +} +export interface InstructionSetSchema { + readonly title: string; + readonly callOut: { + title: string; + message: string; + iconType: IconType; + }; +} +export interface ParamsSchema { + defaultValue: any; + id: string; + label: string; + type: ParamTypes; +} +export interface InstructionsSchema { + readonly instructionSets: InstructionSetSchema[]; + readonly params: ParamsSchema[]; +} +export interface DashboardSchema { + id: string; + linkLabel?: { + is: boolean; + then: any; + }; + isOverview: boolean; +} +export interface ArtifactsSchema { + readonly exportedFields: { + documentationUrl: string; + }; + readonly dashboards: DashboardSchema[]; + readonly application: { + path: string; + label: string; + }; +} +export interface TutorialSchema { + id: string; + category: TutorialsCategory; + name: string; + isBeta: boolean; + shortDescription: string; + euiIconType: IconType; // EUI icon type string, one of https://elastic.github.io/eui/#/icon; + longDescription: string; + completionTimeMinutes: number; + previewImagePath: string; + + // kibana and elastic cluster running on prem + onPrem: InstructionsSchema; + + // kibana and elastic cluster running in elastic's cloud + elasticCloud: InstructionsSchema; + + // kibana running on prem and elastic cluster running in elastic's cloud + onPremElasticCloud: InstructionsSchema; + + // Elastic stack artifacts produced by product when it is setup and run. + artifacts: ArtifactsSchema; + + // saved objects used by data module. + savedObjects: any[]; + savedObjectsInstallMsg: string; +} +export type TutorialProvider = (context: { [key: string]: unknown }) => TutorialSchema; +export type TutorialContextFactory = ( + req: KibanaRequest< + Readonly<{ + [x: string]: any; + }>, + Readonly<{ + [x: string]: any; + }>, + Readonly<{ + [x: string]: any; + }> + > +) => { [key: string]: unknown }; +export type ScopedTutorialContextFactory = (...args: any[]) => any; From 1741e3c50dfcb83592b2af02168fa359df35cd3d Mon Sep 17 00:00:00 2001 From: Christiane Heiligers Date: Wed, 13 Nov 2019 15:21:53 -0700 Subject: [PATCH 07/21] Changes call to location of registerTutorial in registerTutorials --- .../kibana/server/tutorials/register.js | 120 +++++++++--------- src/plugins/{tutorials => home}/kibana.json | 2 +- .../{tutorials => home}/server/index.ts | 0 .../{tutorials => home}/server/plugin.ts | 1 + .../server/services/index.ts | 6 +- .../server/services/tutorial_schema.ts | 0 .../server/services/tutorials_registry.ts | 0 .../services/tutorials_registry_types.ts | 0 8 files changed, 67 insertions(+), 62 deletions(-) rename src/plugins/{tutorials => home}/kibana.json (73%) rename src/plugins/{tutorials => home}/server/index.ts (100%) rename src/plugins/{tutorials => home}/server/plugin.ts (99%) rename src/plugins/{tutorials => home}/server/services/index.ts (89%) rename src/plugins/{tutorials => home}/server/services/tutorial_schema.ts (100%) rename src/plugins/{tutorials => home}/server/services/tutorials_registry.ts (100%) rename src/plugins/{tutorials => home}/server/services/tutorials_registry_types.ts (100%) diff --git a/src/legacy/core_plugins/kibana/server/tutorials/register.js b/src/legacy/core_plugins/kibana/server/tutorials/register.js index f1e60ae57311c..7ede17a2d0886 100644 --- a/src/legacy/core_plugins/kibana/server/tutorials/register.js +++ b/src/legacy/core_plugins/kibana/server/tutorials/register.js @@ -80,66 +80,66 @@ import { consulMetricsSpecProvider } from './consul_metrics'; import { cockroachdbMetricsSpecProvider } from './cockroachdb_metrics'; export function registerTutorials(server) { - server.newPlatform.setup.plugins.tutorials.registerTutorial(systemLogsSpecProvider); - server.newPlatform.setup.plugins.tutorials.registerTutorial(systemMetricsSpecProvider); - server.newPlatform.setup.plugins.tutorials.registerTutorial(apacheLogsSpecProvider); - server.newPlatform.setup.plugins.tutorials.registerTutorial(apacheMetricsSpecProvider); - server.newPlatform.setup.plugins.tutorials.registerTutorial(elasticsearchLogsSpecProvider); - server.newPlatform.setup.plugins.tutorials.registerTutorial(iisLogsSpecProvider); - server.newPlatform.setup.plugins.tutorials.registerTutorial(kafkaLogsSpecProvider); - server.newPlatform.setup.plugins.tutorials.registerTutorial(logstashLogsSpecProvider); - server.newPlatform.setup.plugins.tutorials.registerTutorial(nginxLogsSpecProvider); - server.newPlatform.setup.plugins.tutorials.registerTutorial(nginxMetricsSpecProvider); - server.newPlatform.setup.plugins.tutorials.registerTutorial(mysqlLogsSpecProvider); - server.newPlatform.setup.plugins.tutorials.registerTutorial(mysqlMetricsSpecProvider); - server.newPlatform.setup.plugins.tutorials.registerTutorial(mongodbMetricsSpecProvider); - server.newPlatform.setup.plugins.tutorials.registerTutorial(osqueryLogsSpecProvider); - server.newPlatform.setup.plugins.tutorials.registerTutorial(phpfpmMetricsSpecProvider); - server.newPlatform.setup.plugins.tutorials.registerTutorial(postgresqlMetricsSpecProvider); - server.newPlatform.setup.plugins.tutorials.registerTutorial(postgresqlLogsSpecProvider); - server.newPlatform.setup.plugins.tutorials.registerTutorial(rabbitmqMetricsSpecProvider); - server.newPlatform.setup.plugins.tutorials.registerTutorial(redisLogsSpecProvider); - server.newPlatform.setup.plugins.tutorials.registerTutorial(redisMetricsSpecProvider); - server.newPlatform.setup.plugins.tutorials.registerTutorial(suricataLogsSpecProvider); - server.newPlatform.setup.plugins.tutorials.registerTutorial(dockerMetricsSpecProvider); - server.newPlatform.setup.plugins.tutorials.registerTutorial(kubernetesMetricsSpecProvider); - server.newPlatform.setup.plugins.tutorials.registerTutorial(uwsgiMetricsSpecProvider); - server.newPlatform.setup.plugins.tutorials.registerTutorial(netflowSpecProvider); - server.newPlatform.setup.plugins.tutorials.registerTutorial(traefikLogsSpecProvider); + server.newPlatform.setup.plugins.home.registerTutorial(systemLogsSpecProvider); + server.newPlatform.setup.plugins.home.registerTutorial(systemMetricsSpecProvider); + server.newPlatform.setup.plugins.home.registerTutorial(apacheLogsSpecProvider); + server.newPlatform.setup.plugins.home.registerTutorial(apacheMetricsSpecProvider); + server.newPlatform.setup.plugins.home.registerTutorial(elasticsearchLogsSpecProvider); + server.newPlatform.setup.plugins.home.registerTutorial(iisLogsSpecProvider); + server.newPlatform.setup.plugins.home.registerTutorial(kafkaLogsSpecProvider); + server.newPlatform.setup.plugins.home.registerTutorial(logstashLogsSpecProvider); + server.newPlatform.setup.plugins.home.registerTutorial(nginxLogsSpecProvider); + server.newPlatform.setup.plugins.home.registerTutorial(nginxMetricsSpecProvider); + server.newPlatform.setup.plugins.home.registerTutorial(mysqlLogsSpecProvider); + server.newPlatform.setup.plugins.home.registerTutorial(mysqlMetricsSpecProvider); + server.newPlatform.setup.plugins.home.registerTutorial(mongodbMetricsSpecProvider); + server.newPlatform.setup.plugins.home.registerTutorial(osqueryLogsSpecProvider); + server.newPlatform.setup.plugins.home.registerTutorial(phpfpmMetricsSpecProvider); + server.newPlatform.setup.plugins.home.registerTutorial(postgresqlMetricsSpecProvider); + server.newPlatform.setup.plugins.home.registerTutorial(postgresqlLogsSpecProvider); + server.newPlatform.setup.plugins.home.registerTutorial(rabbitmqMetricsSpecProvider); + server.newPlatform.setup.plugins.home.registerTutorial(redisLogsSpecProvider); + server.newPlatform.setup.plugins.home.registerTutorial(redisMetricsSpecProvider); + server.newPlatform.setup.plugins.home.registerTutorial(suricataLogsSpecProvider); + server.newPlatform.setup.plugins.home.registerTutorial(dockerMetricsSpecProvider); + server.newPlatform.setup.plugins.home.registerTutorial(kubernetesMetricsSpecProvider); + server.newPlatform.setup.plugins.home.registerTutorial(uwsgiMetricsSpecProvider); + server.newPlatform.setup.plugins.home.registerTutorial(netflowSpecProvider); + server.newPlatform.setup.plugins.home.registerTutorial(traefikLogsSpecProvider); server.registerTutorial(apmSpecProvider); - server.newPlatform.setup.plugins.tutorials.registerTutorial(cephMetricsSpecProvider); - server.newPlatform.setup.plugins.tutorials.registerTutorial(aerospikeMetricsSpecProvider); - server.newPlatform.setup.plugins.tutorials.registerTutorial(couchbaseMetricsSpecProvider); - server.newPlatform.setup.plugins.tutorials.registerTutorial(dropwizardMetricsSpecProvider); - server.newPlatform.setup.plugins.tutorials.registerTutorial(elasticsearchMetricsSpecProvider); - server.newPlatform.setup.plugins.tutorials.registerTutorial(etcdMetricsSpecProvider); - server.newPlatform.setup.plugins.tutorials.registerTutorial(haproxyMetricsSpecProvider); - server.newPlatform.setup.plugins.tutorials.registerTutorial(kafkaMetricsSpecProvider); - server.newPlatform.setup.plugins.tutorials.registerTutorial(kibanaMetricsSpecProvider); - server.newPlatform.setup.plugins.tutorials.registerTutorial(memcachedMetricsSpecProvider); - server.newPlatform.setup.plugins.tutorials.registerTutorial(muninMetricsSpecProvider); - server.newPlatform.setup.plugins.tutorials.registerTutorial(vSphereMetricsSpecProvider); - server.newPlatform.setup.plugins.tutorials.registerTutorial(windowsMetricsSpecProvider); - server.newPlatform.setup.plugins.tutorials.registerTutorial(windowsEventLogsSpecProvider); - server.newPlatform.setup.plugins.tutorials.registerTutorial(golangMetricsSpecProvider); - server.newPlatform.setup.plugins.tutorials.registerTutorial(logstashMetricsSpecProvider); - server.newPlatform.setup.plugins.tutorials.registerTutorial(prometheusMetricsSpecProvider); - server.newPlatform.setup.plugins.tutorials.registerTutorial(zookeeperMetricsSpecProvider); - server.newPlatform.setup.plugins.tutorials.registerTutorial(uptimeMonitorsSpecProvider); - server.newPlatform.setup.plugins.tutorials.registerTutorial(cloudwatchLogsSpecProvider); - server.newPlatform.setup.plugins.tutorials.registerTutorial(awsMetricsSpecProvider); - server.newPlatform.setup.plugins.tutorials.registerTutorial(mssqlMetricsSpecProvider); - server.newPlatform.setup.plugins.tutorials.registerTutorial(natsMetricsSpecProvider); - server.newPlatform.setup.plugins.tutorials.registerTutorial(natsLogsSpecProvider); - server.newPlatform.setup.plugins.tutorials.registerTutorial(zeekLogsSpecProvider); - server.newPlatform.setup.plugins.tutorials.registerTutorial(corednsMetricsSpecProvider); - server.newPlatform.setup.plugins.tutorials.registerTutorial(corednsLogsSpecProvider); - server.newPlatform.setup.plugins.tutorials.registerTutorial(auditbeatSpecProvider); - server.newPlatform.setup.plugins.tutorials.registerTutorial(iptablesLogsSpecProvider); - server.newPlatform.setup.plugins.tutorials.registerTutorial(ciscoLogsSpecProvider); - server.newPlatform.setup.plugins.tutorials.registerTutorial(envoyproxyLogsSpecProvider); - server.newPlatform.setup.plugins.tutorials.registerTutorial(couchdbMetricsSpecProvider); + server.newPlatform.setup.plugins.home.registerTutorial(cephMetricsSpecProvider); + server.newPlatform.setup.plugins.home.registerTutorial(aerospikeMetricsSpecProvider); + server.newPlatform.setup.plugins.home.registerTutorial(couchbaseMetricsSpecProvider); + server.newPlatform.setup.plugins.home.registerTutorial(dropwizardMetricsSpecProvider); + server.newPlatform.setup.plugins.home.registerTutorial(elasticsearchMetricsSpecProvider); + server.newPlatform.setup.plugins.home.registerTutorial(etcdMetricsSpecProvider); + server.newPlatform.setup.plugins.home.registerTutorial(haproxyMetricsSpecProvider); + server.newPlatform.setup.plugins.home.registerTutorial(kafkaMetricsSpecProvider); + server.newPlatform.setup.plugins.home.registerTutorial(kibanaMetricsSpecProvider); + server.newPlatform.setup.plugins.home.registerTutorial(memcachedMetricsSpecProvider); + server.newPlatform.setup.plugins.home.registerTutorial(muninMetricsSpecProvider); + server.newPlatform.setup.plugins.home.registerTutorial(vSphereMetricsSpecProvider); + server.newPlatform.setup.plugins.home.registerTutorial(windowsMetricsSpecProvider); + server.newPlatform.setup.plugins.home.registerTutorial(windowsEventLogsSpecProvider); + server.newPlatform.setup.plugins.home.registerTutorial(golangMetricsSpecProvider); + server.newPlatform.setup.plugins.home.registerTutorial(logstashMetricsSpecProvider); + server.newPlatform.setup.plugins.home.registerTutorial(prometheusMetricsSpecProvider); + server.newPlatform.setup.plugins.home.registerTutorial(zookeeperMetricsSpecProvider); + server.newPlatform.setup.plugins.home.registerTutorial(uptimeMonitorsSpecProvider); + server.newPlatform.setup.plugins.home.registerTutorial(cloudwatchLogsSpecProvider); + server.newPlatform.setup.plugins.home.registerTutorial(awsMetricsSpecProvider); + server.newPlatform.setup.plugins.home.registerTutorial(mssqlMetricsSpecProvider); + server.newPlatform.setup.plugins.home.registerTutorial(natsMetricsSpecProvider); + server.newPlatform.setup.plugins.home.registerTutorial(natsLogsSpecProvider); + server.newPlatform.setup.plugins.home.registerTutorial(zeekLogsSpecProvider); + server.newPlatform.setup.plugins.home.registerTutorial(corednsMetricsSpecProvider); + server.newPlatform.setup.plugins.home.registerTutorial(corednsLogsSpecProvider); + server.newPlatform.setup.plugins.home.registerTutorial(auditbeatSpecProvider); + server.newPlatform.setup.plugins.home.registerTutorial(iptablesLogsSpecProvider); + server.newPlatform.setup.plugins.home.registerTutorial(ciscoLogsSpecProvider); + server.newPlatform.setup.plugins.home.registerTutorial(envoyproxyLogsSpecProvider); + server.newPlatform.setup.plugins.home.registerTutorial(couchdbMetricsSpecProvider); server.registerTutorial(emsBoundariesSpecProvider); - server.newPlatform.setup.plugins.tutorials.registerTutorial(consulMetricsSpecProvider); - server.newPlatform.setup.plugins.tutorials.registerTutorial(cockroachdbMetricsSpecProvider); + server.newPlatform.setup.plugins.home.registerTutorial(consulMetricsSpecProvider); + server.newPlatform.setup.plugins.home.registerTutorial(cockroachdbMetricsSpecProvider); } diff --git a/src/plugins/tutorials/kibana.json b/src/plugins/home/kibana.json similarity index 73% rename from src/plugins/tutorials/kibana.json rename to src/plugins/home/kibana.json index 0b931ccfb1514..8d2d79560f854 100644 --- a/src/plugins/tutorials/kibana.json +++ b/src/plugins/home/kibana.json @@ -1,5 +1,5 @@ { - "id": "tutorials", + "id": "home", "version": "kibana", "server": true, "ui": false diff --git a/src/plugins/tutorials/server/index.ts b/src/plugins/home/server/index.ts similarity index 100% rename from src/plugins/tutorials/server/index.ts rename to src/plugins/home/server/index.ts diff --git a/src/plugins/tutorials/server/plugin.ts b/src/plugins/home/server/plugin.ts similarity index 99% rename from src/plugins/tutorials/server/plugin.ts rename to src/plugins/home/server/plugin.ts index 67efae31b157c..54ce68aa1c239 100644 --- a/src/plugins/tutorials/server/plugin.ts +++ b/src/plugins/home/server/plugin.ts @@ -18,6 +18,7 @@ */ import { CoreSetup, Plugin } from 'src/core/server'; import { TutorialsRegistry, TutorialsRegistrySetup, TutorialsRegistryStart } from './services'; + export class HomePlugin implements Plugin { private readonly tutorialsRegistry = new TutorialsRegistry(); diff --git a/src/plugins/tutorials/server/services/index.ts b/src/plugins/home/server/services/index.ts similarity index 89% rename from src/plugins/tutorials/server/services/index.ts rename to src/plugins/home/server/services/index.ts index ec5f61f42c16b..958ea25622815 100644 --- a/src/plugins/tutorials/server/services/index.ts +++ b/src/plugins/home/server/services/index.ts @@ -19,5 +19,9 @@ // provided to other plugins as APIs // should model the plugin lifecycle -export * from './tutorials_registry'; +export { + TutorialsRegistry, + TutorialsRegistrySetup, + TutorialsRegistryStart, +} from './tutorials_registry'; export * from './tutorials_registry_types'; diff --git a/src/plugins/tutorials/server/services/tutorial_schema.ts b/src/plugins/home/server/services/tutorial_schema.ts similarity index 100% rename from src/plugins/tutorials/server/services/tutorial_schema.ts rename to src/plugins/home/server/services/tutorial_schema.ts diff --git a/src/plugins/tutorials/server/services/tutorials_registry.ts b/src/plugins/home/server/services/tutorials_registry.ts similarity index 100% rename from src/plugins/tutorials/server/services/tutorials_registry.ts rename to src/plugins/home/server/services/tutorials_registry.ts diff --git a/src/plugins/tutorials/server/services/tutorials_registry_types.ts b/src/plugins/home/server/services/tutorials_registry_types.ts similarity index 100% rename from src/plugins/tutorials/server/services/tutorials_registry_types.ts rename to src/plugins/home/server/services/tutorials_registry_types.ts From aca40b9ddd30883a616082ef8f8fa03c9e8a349f Mon Sep 17 00:00:00 2001 From: Christiane Heiligers Date: Wed, 13 Nov 2019 15:44:40 -0700 Subject: [PATCH 08/21] Adds console log for the home plugin that's returning an empty object --- src/legacy/core_plugins/kibana/server/tutorials/register.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/legacy/core_plugins/kibana/server/tutorials/register.js b/src/legacy/core_plugins/kibana/server/tutorials/register.js index 7ede17a2d0886..b7d76aebd4170 100644 --- a/src/legacy/core_plugins/kibana/server/tutorials/register.js +++ b/src/legacy/core_plugins/kibana/server/tutorials/register.js @@ -80,6 +80,7 @@ import { consulMetricsSpecProvider } from './consul_metrics'; import { cockroachdbMetricsSpecProvider } from './cockroachdb_metrics'; export function registerTutorials(server) { + console.log('--> server.newPlatform.setup.plugins.home', server.newPlatform.setup.plugins.home); server.newPlatform.setup.plugins.home.registerTutorial(systemLogsSpecProvider); server.newPlatform.setup.plugins.home.registerTutorial(systemMetricsSpecProvider); server.newPlatform.setup.plugins.home.registerTutorial(apacheLogsSpecProvider); From 10d477aa8f5a21ac39aedc3e2a3ed1f903f6d6b9 Mon Sep 17 00:00:00 2001 From: Christiane Heiligers Date: Wed, 13 Nov 2019 16:32:09 -0700 Subject: [PATCH 09/21] Removes async from setup and start methods in the home plugin and the tutorials service --- src/legacy/core_plugins/kibana/server/tutorials/register.js | 1 - src/plugins/home/server/plugin.ts | 4 ++-- src/plugins/home/server/services/tutorials_registry.ts | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/legacy/core_plugins/kibana/server/tutorials/register.js b/src/legacy/core_plugins/kibana/server/tutorials/register.js index b7d76aebd4170..7ede17a2d0886 100644 --- a/src/legacy/core_plugins/kibana/server/tutorials/register.js +++ b/src/legacy/core_plugins/kibana/server/tutorials/register.js @@ -80,7 +80,6 @@ import { consulMetricsSpecProvider } from './consul_metrics'; import { cockroachdbMetricsSpecProvider } from './cockroachdb_metrics'; export function registerTutorials(server) { - console.log('--> server.newPlatform.setup.plugins.home', server.newPlatform.setup.plugins.home); server.newPlatform.setup.plugins.home.registerTutorial(systemLogsSpecProvider); server.newPlatform.setup.plugins.home.registerTutorial(systemMetricsSpecProvider); server.newPlatform.setup.plugins.home.registerTutorial(apacheLogsSpecProvider); diff --git a/src/plugins/home/server/plugin.ts b/src/plugins/home/server/plugin.ts index 54ce68aa1c239..302641404e8ad 100644 --- a/src/plugins/home/server/plugin.ts +++ b/src/plugins/home/server/plugin.ts @@ -22,13 +22,13 @@ import { TutorialsRegistry, TutorialsRegistrySetup, TutorialsRegistryStart } fro export class HomePlugin implements Plugin { private readonly tutorialsRegistry = new TutorialsRegistry(); - public async setup(core: CoreSetup) { + public setup(core: CoreSetup) { return { ...this.tutorialsRegistry.setup(core), }; } - public async start() { + public start() { return { ...this.tutorialsRegistry.start(), }; diff --git a/src/plugins/home/server/services/tutorials_registry.ts b/src/plugins/home/server/services/tutorials_registry.ts index eaeade8692388..53454090f8091 100644 --- a/src/plugins/home/server/services/tutorials_registry.ts +++ b/src/plugins/home/server/services/tutorials_registry.ts @@ -30,7 +30,7 @@ export class TutorialsRegistry { private readonly tutorialProviders: TutorialProvider[] = []; // pre-register all the tutorials we know we want in here private readonly scopedTutorialContextFactories: TutorialContextFactory[] = []; - public async setup(core: CoreSetup) { + public setup(core: CoreSetup) { const router = core.http.createRouter(); router.get( { path: '/api/kibana/home/NP_tutorials', validate: false }, From de06bc03c9d5771948aaf2983629e4b22f8f49f3 Mon Sep 17 00:00:00 2001 From: Christiane Heiligers Date: Wed, 13 Nov 2019 17:10:17 -0700 Subject: [PATCH 10/21] Starts writing tests and creating mocks --- src/core/server/index.ts | 1 + .../kibana/server/tutorials/register.js | 1 + src/plugins/home/server/plugin.test.ts | 18 ++++++ .../services/tutorials_registry.mock.ts | 56 +++++++++++++++++++ .../services/tutorials_registry.test.ts | 18 ++++++ 5 files changed, 94 insertions(+) create mode 100644 src/plugins/home/server/plugin.test.ts create mode 100644 src/plugins/home/server/services/tutorials_registry.mock.ts create mode 100644 src/plugins/home/server/services/tutorials_registry.test.ts diff --git a/src/core/server/index.ts b/src/core/server/index.ts index 2a5631ad1c380..72f0af26c9a69 100644 --- a/src/core/server/index.ts +++ b/src/core/server/index.ts @@ -223,6 +223,7 @@ export interface RequestHandlerContext { * @public */ export interface CoreSetup { + application: any; /** {@link ContextSetup} */ context: ContextSetup; /** {@link ElasticsearchServiceSetup} */ diff --git a/src/legacy/core_plugins/kibana/server/tutorials/register.js b/src/legacy/core_plugins/kibana/server/tutorials/register.js index 7ede17a2d0886..eb622fdd7a86f 100644 --- a/src/legacy/core_plugins/kibana/server/tutorials/register.js +++ b/src/legacy/core_plugins/kibana/server/tutorials/register.js @@ -122,6 +122,7 @@ export function registerTutorials(server) { server.newPlatform.setup.plugins.home.registerTutorial(windowsMetricsSpecProvider); server.newPlatform.setup.plugins.home.registerTutorial(windowsEventLogsSpecProvider); server.newPlatform.setup.plugins.home.registerTutorial(golangMetricsSpecProvider); + server.newPlatform.setup.plugins.home.registerTutorial(golangMetricsSpecProvider); server.newPlatform.setup.plugins.home.registerTutorial(logstashMetricsSpecProvider); server.newPlatform.setup.plugins.home.registerTutorial(prometheusMetricsSpecProvider); server.newPlatform.setup.plugins.home.registerTutorial(zookeeperMetricsSpecProvider); diff --git a/src/plugins/home/server/plugin.test.ts b/src/plugins/home/server/plugin.test.ts new file mode 100644 index 0000000000000..9880b336e76e5 --- /dev/null +++ b/src/plugins/home/server/plugin.test.ts @@ -0,0 +1,18 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ diff --git a/src/plugins/home/server/services/tutorials_registry.mock.ts b/src/plugins/home/server/services/tutorials_registry.mock.ts new file mode 100644 index 0000000000000..fb999529f3177 --- /dev/null +++ b/src/plugins/home/server/services/tutorials_registry.mock.ts @@ -0,0 +1,56 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { + TutorialsRegistrySetup, + TutorialsRegistryStart, + TutorialsRegistry, +} from './tutorials_registry'; + +type PublicMethodsOf = { + [P in { [K in keyof T]: T[K] extends (...args: any[]) => any ? K : never }[keyof T]]: T[P]; +}; +const createSetupMock = (): jest.Mocked => { + const setup = { + registerTutorial: jest.fn(), + addScopedTutorialContextFactory: jest.fn(), + }; + return setup; +}; + +const createStartMock = (): jest.Mocked => { + const start = {}; + return start; +}; + +const createMock = (): jest.Mocked> => { + const service = { + setup: jest.fn(), + start: jest.fn(), + }; + service.setup.mockImplementation(createSetupMock); + service.start.mockImplementation(createStartMock); + return service; +}; + +export const tutorialsRegistryMock = { + createSetup: createSetupMock, + createStart: createStartMock, + create: createMock, +}; diff --git a/src/plugins/home/server/services/tutorials_registry.test.ts b/src/plugins/home/server/services/tutorials_registry.test.ts new file mode 100644 index 0000000000000..7bed8f7910e26 --- /dev/null +++ b/src/plugins/home/server/services/tutorials_registry.test.ts @@ -0,0 +1,18 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ import { TutorialsRegistry } from './tutorials_registry'; From 7a7ce9aa83193aab8f17760b088a8e19fd85da9d Mon Sep 17 00:00:00 2001 From: Christiane Heiligers Date: Thu, 14 Nov 2019 12:47:37 -0700 Subject: [PATCH 11/21] Adds basic tests for TutorialRegistry service --- src/plugins/home/server/plugin.test.ts | 6 + .../services/tutorials_registry.test.ts | 107 +++++++++++++++++- 2 files changed, 112 insertions(+), 1 deletion(-) diff --git a/src/plugins/home/server/plugin.test.ts b/src/plugins/home/server/plugin.test.ts index 9880b336e76e5..df63b467d8656 100644 --- a/src/plugins/home/server/plugin.test.ts +++ b/src/plugins/home/server/plugin.test.ts @@ -16,3 +16,9 @@ * specific language governing permissions and limitations * under the License. */ +import { tutorialsRegistryMock } from './services/tutorials_registry.mock'; + +export const registryMock = tutorialsRegistryMock.create(); +jest.doMock('./services', () => ({ + TutorialsRegistry: jest.fn(() => registryMock), +})); diff --git a/src/plugins/home/server/services/tutorials_registry.test.ts b/src/plugins/home/server/services/tutorials_registry.test.ts index 7bed8f7910e26..2f9b37596c7ba 100644 --- a/src/plugins/home/server/services/tutorials_registry.test.ts +++ b/src/plugins/home/server/services/tutorials_registry.test.ts @@ -15,4 +15,109 @@ * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. - */ import { TutorialsRegistry } from './tutorials_registry'; + */ + +import { TutorialsRegistry } from './tutorials_registry'; +import { coreMock } from '../../../../core/server/mocks'; +import { CoreSetup } from '../../../../core/server'; +import { + TutorialProvider, + TutorialSchema, + TutorialsCategory, + ScopedTutorialContextFactory, +} from './tutorials_registry_types'; + +const TEST_TUTORIAL: TutorialSchema = { + id: 'test', + category: 'logging' as TutorialsCategory, + name: '', + isBeta: false, + shortDescription: 'short description', + euiIconType: 'alert', + longDescription: 'long description with lots of text', + completionTimeMinutes: 10, + previewImagePath: 'path', + onPrem: { instructionSets: [], params: [] }, + elasticCloud: { instructionSets: [], params: [] }, + onPremElasticCloud: { instructionSets: [], params: [] }, + artifacts: { + exportedFields: { documentationUrl: 'url' }, + dashboards: [], + application: { path: 'path', label: 'path' }, + }, + savedObjects: [], + savedObjectsInstallMsg: 'testMsg', +}; +const VALID_TUTORIAL: TutorialSchema = { + id: 'test', + category: 'logging' as TutorialsCategory, + name: 'new tutorial provider', + isBeta: false, + shortDescription: 'short description', + euiIconType: 'alert', + longDescription: 'long description with lots of text', + completionTimeMinutes: 10, + previewImagePath: 'path', + onPrem: { instructionSets: [], params: [] }, + elasticCloud: { instructionSets: [], params: [] }, + onPremElasticCloud: { instructionSets: [], params: [] }, + artifacts: { + exportedFields: { documentationUrl: 'url' }, + dashboards: [], + application: { path: 'path', label: 'path' }, + }, + savedObjects: [], + savedObjectsInstallMsg: 'testMsg', +}; +const testTutorialProvider = TEST_TUTORIAL; +const testTutorialProvider2 = VALID_TUTORIAL; + +describe('TutorialsRegistry', () => { + let mockCoreSetup: MockedKeys; + let testProvider: TutorialProvider; + let testScopedTutorialContextFactory: ScopedTutorialContextFactory; + + beforeEach(() => { + mockCoreSetup = coreMock.createSetup(); + }); + + describe('setup', () => { + test('exposes proper contract', () => { + const setup = new TutorialsRegistry().setup(mockCoreSetup); + expect(setup).toHaveProperty('registerTutorial'); + expect(setup).toHaveProperty('addScopedTutorialContextFactory'); + }); + test('registerTutorial throws when registering a tutorial with an invalid schema', () => { + const setup = new TutorialsRegistry().setup(mockCoreSetup); + testProvider = ({}) => testTutorialProvider; + expect(() => setup.registerTutorial(testProvider)).toThrowErrorMatchingInlineSnapshot( + `"Unable to register tutorial spec because its invalid. ValidationError: child \\"name\\" fails because [\\"name\\" is not allowed to be empty]"` + ); + }); + test('registerTutorial registers a tutorial with a valid schema', () => { + const setup = new TutorialsRegistry().setup(mockCoreSetup); + testProvider = ({}) => testTutorialProvider2; + expect(() => setup.registerTutorial(testProvider)).not.toThrowError(); + }); + test('addScopedTutorialContextFactory throws when given a scopedTutorialContextFactory that is not a function', () => { + const setup = new TutorialsRegistry().setup(mockCoreSetup); + const testItem = {}; + expect(() => + setup.addScopedTutorialContextFactory(testItem) + ).toThrowErrorMatchingInlineSnapshot( + `"Unable to add scoped(request) context factory because you did not provide a function"` + ); + }); + test('addScopedTutorialContextFactory adds a scopedTutorialContextFactory when given a function', () => { + const setup = new TutorialsRegistry().setup(mockCoreSetup); + const testItem = ({}) => 'string'; + expect(() => setup.addScopedTutorialContextFactory(testItem)).not.toThrowError(); + }); + }); + describe('start', () => { + test('exposes proper contract', () => { + const start = new TutorialsRegistry().start(); + expect(start).toBeDefined(); + }); + }); +}); From fcedb410ec0bfbc1b2699c0d6dcaa775d81e3758 Mon Sep 17 00:00:00 2001 From: Christiane Heiligers Date: Thu, 14 Nov 2019 12:48:59 -0700 Subject: [PATCH 12/21] Adds basic tests for TutorialRegistry service --- src/plugins/home/server/services/tutorials_registry.test.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/plugins/home/server/services/tutorials_registry.test.ts b/src/plugins/home/server/services/tutorials_registry.test.ts index 2f9b37596c7ba..d4564c18d1896 100644 --- a/src/plugins/home/server/services/tutorials_registry.test.ts +++ b/src/plugins/home/server/services/tutorials_registry.test.ts @@ -110,8 +110,10 @@ describe('TutorialsRegistry', () => { }); test('addScopedTutorialContextFactory adds a scopedTutorialContextFactory when given a function', () => { const setup = new TutorialsRegistry().setup(mockCoreSetup); - const testItem = ({}) => 'string'; - expect(() => setup.addScopedTutorialContextFactory(testItem)).not.toThrowError(); + testScopedTutorialContextFactory = ({}) => 'string'; + expect(() => + setup.addScopedTutorialContextFactory(testScopedTutorialContextFactory) + ).not.toThrowError(); }); }); describe('start', () => { From 628e410a5d430fddf03bbdddb31ca13986231c1e Mon Sep 17 00:00:00 2001 From: Christiane Heiligers Date: Thu, 14 Nov 2019 16:06:37 -0700 Subject: [PATCH 13/21] Adds test for route --- .../services/tutorials_registry.test.ts | 34 ++++++++++++++----- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/src/plugins/home/server/services/tutorials_registry.test.ts b/src/plugins/home/server/services/tutorials_registry.test.ts index d4564c18d1896..6d3ada7c95a41 100644 --- a/src/plugins/home/server/services/tutorials_registry.test.ts +++ b/src/plugins/home/server/services/tutorials_registry.test.ts @@ -20,6 +20,9 @@ import { TutorialsRegistry } from './tutorials_registry'; import { coreMock } from '../../../../core/server/mocks'; import { CoreSetup } from '../../../../core/server'; +import { httpServiceMock, httpServerMock } from '../../../../../src/core/server/mocks'; +import { IRouter } from 'kibana/server'; + import { TutorialProvider, TutorialSchema, @@ -27,7 +30,7 @@ import { ScopedTutorialContextFactory, } from './tutorials_registry_types'; -const TEST_TUTORIAL: TutorialSchema = { +const INVALID_TUTORIAL: TutorialSchema = { id: 'test', category: 'logging' as TutorialsCategory, name: '', @@ -69,16 +72,26 @@ const VALID_TUTORIAL: TutorialSchema = { savedObjects: [], savedObjectsInstallMsg: 'testMsg', }; -const testTutorialProvider = TEST_TUTORIAL; -const testTutorialProvider2 = VALID_TUTORIAL; +const invalidTutorialProvider = INVALID_TUTORIAL; +const validTutorialProvider = VALID_TUTORIAL; describe('TutorialsRegistry', () => { let mockCoreSetup: MockedKeys; let testProvider: TutorialProvider; let testScopedTutorialContextFactory: ScopedTutorialContextFactory; - beforeEach(() => { - mockCoreSetup = coreMock.createSetup(); + describe('GET /api/kibana/home/NP_tutorials', () => { + let routerMock: jest.Mocked; + + beforeEach(() => { + mockCoreSetup = coreMock.createSetup(); + routerMock = httpServiceMock.createRouter(); + }); + + test('has a router that retrieves registered tutorials', () => { + const mockResponse = httpServerMock.createResponseFactory(); + expect(mockResponse.ok.mock.calls).toMatchInlineSnapshot(`Array []`); + }); }); describe('setup', () => { @@ -87,27 +100,31 @@ describe('TutorialsRegistry', () => { expect(setup).toHaveProperty('registerTutorial'); expect(setup).toHaveProperty('addScopedTutorialContextFactory'); }); + test('registerTutorial throws when registering a tutorial with an invalid schema', () => { const setup = new TutorialsRegistry().setup(mockCoreSetup); - testProvider = ({}) => testTutorialProvider; + testProvider = ({}) => invalidTutorialProvider; expect(() => setup.registerTutorial(testProvider)).toThrowErrorMatchingInlineSnapshot( `"Unable to register tutorial spec because its invalid. ValidationError: child \\"name\\" fails because [\\"name\\" is not allowed to be empty]"` ); }); + test('registerTutorial registers a tutorial with a valid schema', () => { const setup = new TutorialsRegistry().setup(mockCoreSetup); - testProvider = ({}) => testTutorialProvider2; + testProvider = ({}) => validTutorialProvider; expect(() => setup.registerTutorial(testProvider)).not.toThrowError(); }); + test('addScopedTutorialContextFactory throws when given a scopedTutorialContextFactory that is not a function', () => { const setup = new TutorialsRegistry().setup(mockCoreSetup); - const testItem = {}; + const testItem = {} as TutorialProvider; expect(() => setup.addScopedTutorialContextFactory(testItem) ).toThrowErrorMatchingInlineSnapshot( `"Unable to add scoped(request) context factory because you did not provide a function"` ); }); + test('addScopedTutorialContextFactory adds a scopedTutorialContextFactory when given a function', () => { const setup = new TutorialsRegistry().setup(mockCoreSetup); testScopedTutorialContextFactory = ({}) => 'string'; @@ -116,6 +133,7 @@ describe('TutorialsRegistry', () => { ).not.toThrowError(); }); }); + describe('start', () => { test('exposes proper contract', () => { const start = new TutorialsRegistry().start(); From cc978bd8c458740d472305230401d0c018dbaa14 Mon Sep 17 00:00:00 2001 From: Christiane Heiligers Date: Thu, 14 Nov 2019 16:28:12 -0700 Subject: [PATCH 14/21] Adds mocks and tests for the home plugin --- src/plugins/home/server/plugin.test.mocks.ts | 24 +++++++++++++ src/plugins/home/server/plugin.test.ts | 36 +++++++++++++++++--- 2 files changed, 55 insertions(+), 5 deletions(-) create mode 100644 src/plugins/home/server/plugin.test.mocks.ts diff --git a/src/plugins/home/server/plugin.test.mocks.ts b/src/plugins/home/server/plugin.test.mocks.ts new file mode 100644 index 0000000000000..df63b467d8656 --- /dev/null +++ b/src/plugins/home/server/plugin.test.mocks.ts @@ -0,0 +1,24 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +import { tutorialsRegistryMock } from './services/tutorials_registry.mock'; + +export const registryMock = tutorialsRegistryMock.create(); +jest.doMock('./services', () => ({ + TutorialsRegistry: jest.fn(() => registryMock), +})); diff --git a/src/plugins/home/server/plugin.test.ts b/src/plugins/home/server/plugin.test.ts index df63b467d8656..5a76de03f9fd6 100644 --- a/src/plugins/home/server/plugin.test.ts +++ b/src/plugins/home/server/plugin.test.ts @@ -16,9 +16,35 @@ * specific language governing permissions and limitations * under the License. */ -import { tutorialsRegistryMock } from './services/tutorials_registry.mock'; -export const registryMock = tutorialsRegistryMock.create(); -jest.doMock('./services', () => ({ - TutorialsRegistry: jest.fn(() => registryMock), -})); +import { registryMock } from './plugin.test.mocks'; +import { HomePlugin } from './plugin'; +import { coreMock } from '../../../core/server/mocks'; +import { CoreSetup } from '../../../core/server'; + +type MockedKeys = { [P in keyof T]: jest.Mocked }; + +describe('HomePlugin', () => { + beforeEach(() => { + registryMock.setup.mockClear(); + registryMock.start.mockClear(); + }); + + describe('setup', () => { + // let mockCoreSetup: MockedKeys; + const mockCoreSetup: MockedKeys = coreMock.createSetup(); + + test('wires up and returns registerTutorial and addScopedTutorialContextFactory', () => { + const setup = new HomePlugin().setup(mockCoreSetup); + expect(setup).toHaveProperty('registerTutorial'); + expect(setup).toHaveProperty('addScopedTutorialContextFactory'); + }); + }); + + describe('start', () => { + test('is defined', () => { + const start = new HomePlugin().start(); + expect(start).toBeDefined(); + }); + }); +}); From 6607a404f1b56df23024495b49b52be7e5b8c0a8 Mon Sep 17 00:00:00 2001 From: Christiane Heiligers Date: Fri, 15 Nov 2019 08:20:22 -0700 Subject: [PATCH 15/21] Adds home plugin to security plugin and registers scoped tutorials service --- x-pack/plugins/spaces/kibana.json | 2 +- x-pack/plugins/spaces/server/plugin.ts | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/x-pack/plugins/spaces/kibana.json b/x-pack/plugins/spaces/kibana.json index ae121e299cc55..313e4415a8e7c 100644 --- a/x-pack/plugins/spaces/kibana.json +++ b/x-pack/plugins/spaces/kibana.json @@ -4,7 +4,7 @@ "kibanaVersion": "kibana", "configPath": ["xpack", "spaces"], "requiredPlugins": ["features", "licensing"], - "optionalPlugins": ["security"], + "optionalPlugins": ["security", "home"], "server": true, "ui": false } diff --git a/x-pack/plugins/spaces/server/plugin.ts b/x-pack/plugins/spaces/server/plugin.ts index aabdc5bcb97e8..755fe6339f35f 100644 --- a/x-pack/plugins/spaces/server/plugin.ts +++ b/x-pack/plugins/spaces/server/plugin.ts @@ -7,6 +7,7 @@ import { Observable } from 'rxjs'; import { take } from 'rxjs/operators'; import { CapabilitiesModifier } from 'src/legacy/server/capabilities'; +import { HomePluginSetup } from 'src/plugins/home'; import { SavedObjectsLegacyService, CoreSetup, @@ -62,6 +63,7 @@ export interface PluginsSetup { features: FeaturesPluginSetup; licensing: LicensingPluginSetup; security?: SecurityPluginSetup; + home?: HomePluginSetup; } export interface SpacesPluginSetup { @@ -138,6 +140,12 @@ export class Plugin { plugins.security.registerSpacesService(spacesService); } + if (plugins.home) { + plugins.home.addScopedTutorialContextFactory( + createSpacesTutorialContextFactory(spacesService) + ); + } + return { spacesService, __legacyCompat: { From 8e6177ff984f20d3d818f068f9a927fdd9c1540d Mon Sep 17 00:00:00 2001 From: Christiane Heiligers Date: Fri, 15 Nov 2019 08:26:06 -0700 Subject: [PATCH 16/21] Removes incorrect addition to src core server --- src/core/server/index.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/core/server/index.ts b/src/core/server/index.ts index 72f0af26c9a69..2a5631ad1c380 100644 --- a/src/core/server/index.ts +++ b/src/core/server/index.ts @@ -223,7 +223,6 @@ export interface RequestHandlerContext { * @public */ export interface CoreSetup { - application: any; /** {@link ContextSetup} */ context: ContextSetup; /** {@link ElasticsearchServiceSetup} */ From 14d3068643f80ce682dabfab1f1e68c3af2a65e9 Mon Sep 17 00:00:00 2001 From: Christiane Heiligers Date: Fri, 15 Nov 2019 09:24:58 -0700 Subject: [PATCH 17/21] Fixes type errors --- src/plugins/home/server/services/tutorials_registry.test.ts | 6 +----- x-pack/plugins/spaces/server/plugin.ts | 3 +-- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/src/plugins/home/server/services/tutorials_registry.test.ts b/src/plugins/home/server/services/tutorials_registry.test.ts index 6d3ada7c95a41..76837640d46d5 100644 --- a/src/plugins/home/server/services/tutorials_registry.test.ts +++ b/src/plugins/home/server/services/tutorials_registry.test.ts @@ -20,8 +20,7 @@ import { TutorialsRegistry } from './tutorials_registry'; import { coreMock } from '../../../../core/server/mocks'; import { CoreSetup } from '../../../../core/server'; -import { httpServiceMock, httpServerMock } from '../../../../../src/core/server/mocks'; -import { IRouter } from 'kibana/server'; +import { httpServerMock } from '../../../../../src/core/server/mocks'; import { TutorialProvider, @@ -81,11 +80,8 @@ describe('TutorialsRegistry', () => { let testScopedTutorialContextFactory: ScopedTutorialContextFactory; describe('GET /api/kibana/home/NP_tutorials', () => { - let routerMock: jest.Mocked; - beforeEach(() => { mockCoreSetup = coreMock.createSetup(); - routerMock = httpServiceMock.createRouter(); }); test('has a router that retrieves registered tutorials', () => { diff --git a/x-pack/plugins/spaces/server/plugin.ts b/x-pack/plugins/spaces/server/plugin.ts index 755fe6339f35f..2bf184f981831 100644 --- a/x-pack/plugins/spaces/server/plugin.ts +++ b/x-pack/plugins/spaces/server/plugin.ts @@ -7,7 +7,6 @@ import { Observable } from 'rxjs'; import { take } from 'rxjs/operators'; import { CapabilitiesModifier } from 'src/legacy/server/capabilities'; -import { HomePluginSetup } from 'src/plugins/home'; import { SavedObjectsLegacyService, CoreSetup, @@ -32,7 +31,7 @@ import { ConfigType } from './config'; import { toggleUICapabilities } from './lib/toggle_ui_capabilities'; import { initSpacesRequestInterceptors } from './lib/request_interceptors'; import { initExternalSpacesApi } from './routes/api/external'; - +import { HomePluginSetup } from '../../../../src/plugins/home/server'; /** * Describes a set of APIs that is available in the legacy platform only and required by this plugin * to function properly. From 16a0a38516493e368d318faaf2e11472f08ec25a Mon Sep 17 00:00:00 2001 From: Christiane Heiligers Date: Fri, 15 Nov 2019 09:41:50 -0700 Subject: [PATCH 18/21] Deletes unused code --- src/legacy/ui/tutorials_mixin.js | 32 ------------------- .../{services => lib}/tutorial_schema.ts | 0 .../tutorials_registry_types.ts | 0 src/plugins/home/server/plugin.test.ts | 1 - src/plugins/home/server/services/index.ts | 2 +- .../services/tutorials_registry.mock.ts | 3 -- .../services/tutorials_registry.test.ts | 2 +- .../server/services/tutorials_registry.ts | 4 +-- 8 files changed, 4 insertions(+), 40 deletions(-) rename src/plugins/home/server/{services => lib}/tutorial_schema.ts (100%) rename src/plugins/home/server/{services => lib}/tutorials_registry_types.ts (100%) diff --git a/src/legacy/ui/tutorials_mixin.js b/src/legacy/ui/tutorials_mixin.js index 6e11db51e1b67..5238e82e8f14f 100644 --- a/src/legacy/ui/tutorials_mixin.js +++ b/src/legacy/ui/tutorials_mixin.js @@ -19,38 +19,6 @@ import Joi from 'joi'; import { tutorialSchema } from '../core_plugins/kibana/common/tutorials/tutorial_schema'; -// import { schema } from '@kbn/config-schema'; - -class TutorialsPlugin { - setup(core) { - const tutorialProviders = []; - const scopedTutorialContextFactories = []; - - core.http.registerRouteHandlerContext('getTutorials', (request) => { - const initialContext = {}; - const scopedContext = scopedTutorialContextFactories.reduce((accumulatedContext, contextFactory) => { - return { ...accumulatedContext, ...contextFactory(request) }; - }, initialContext); - - return tutorialProviders.map((tutorialProvider) => { - return tutorialProvider(server, scopedContext); - }); - }); - - return { - registerTutorial(specProvider) { - const emptyContext = {}; - const { error } = Joi.validate(specProvider(server, emptyContext), tutorialSchema); - - if (error) { - throw new Error(`Unable to register tutorial spec because its invalid. ${error}`); - } - - tutorialProviders.push(specProvider); - } - }; - } -} export function tutorialsMixin(kbnServer, server) { const tutorialProviders = []; diff --git a/src/plugins/home/server/services/tutorial_schema.ts b/src/plugins/home/server/lib/tutorial_schema.ts similarity index 100% rename from src/plugins/home/server/services/tutorial_schema.ts rename to src/plugins/home/server/lib/tutorial_schema.ts diff --git a/src/plugins/home/server/services/tutorials_registry_types.ts b/src/plugins/home/server/lib/tutorials_registry_types.ts similarity index 100% rename from src/plugins/home/server/services/tutorials_registry_types.ts rename to src/plugins/home/server/lib/tutorials_registry_types.ts diff --git a/src/plugins/home/server/plugin.test.ts b/src/plugins/home/server/plugin.test.ts index 5a76de03f9fd6..d971d8aec3cf7 100644 --- a/src/plugins/home/server/plugin.test.ts +++ b/src/plugins/home/server/plugin.test.ts @@ -31,7 +31,6 @@ describe('HomePlugin', () => { }); describe('setup', () => { - // let mockCoreSetup: MockedKeys; const mockCoreSetup: MockedKeys = coreMock.createSetup(); test('wires up and returns registerTutorial and addScopedTutorialContextFactory', () => { diff --git a/src/plugins/home/server/services/index.ts b/src/plugins/home/server/services/index.ts index 958ea25622815..5fe5cb0ba4760 100644 --- a/src/plugins/home/server/services/index.ts +++ b/src/plugins/home/server/services/index.ts @@ -24,4 +24,4 @@ export { TutorialsRegistrySetup, TutorialsRegistryStart, } from './tutorials_registry'; -export * from './tutorials_registry_types'; +export * from '../lib/tutorials_registry_types'; diff --git a/src/plugins/home/server/services/tutorials_registry.mock.ts b/src/plugins/home/server/services/tutorials_registry.mock.ts index fb999529f3177..b54b0be4ea2b7 100644 --- a/src/plugins/home/server/services/tutorials_registry.mock.ts +++ b/src/plugins/home/server/services/tutorials_registry.mock.ts @@ -23,9 +23,6 @@ import { TutorialsRegistry, } from './tutorials_registry'; -type PublicMethodsOf = { - [P in { [K in keyof T]: T[K] extends (...args: any[]) => any ? K : never }[keyof T]]: T[P]; -}; const createSetupMock = (): jest.Mocked => { const setup = { registerTutorial: jest.fn(), diff --git a/src/plugins/home/server/services/tutorials_registry.test.ts b/src/plugins/home/server/services/tutorials_registry.test.ts index 76837640d46d5..f6e004d4cc737 100644 --- a/src/plugins/home/server/services/tutorials_registry.test.ts +++ b/src/plugins/home/server/services/tutorials_registry.test.ts @@ -27,7 +27,7 @@ import { TutorialSchema, TutorialsCategory, ScopedTutorialContextFactory, -} from './tutorials_registry_types'; +} from '../lib/tutorials_registry_types'; const INVALID_TUTORIAL: TutorialSchema = { id: 'test', diff --git a/src/plugins/home/server/services/tutorials_registry.ts b/src/plugins/home/server/services/tutorials_registry.ts index 53454090f8091..bd64c8b9f1a8c 100644 --- a/src/plugins/home/server/services/tutorials_registry.ts +++ b/src/plugins/home/server/services/tutorials_registry.ts @@ -23,8 +23,8 @@ import { TutorialProvider, TutorialContextFactory, ScopedTutorialContextFactory, -} from './tutorials_registry_types'; -import { tutorialSchema } from './tutorial_schema'; +} from '../lib/tutorials_registry_types'; +import { tutorialSchema } from '../lib/tutorial_schema'; export class TutorialsRegistry { private readonly tutorialProviders: TutorialProvider[] = []; // pre-register all the tutorials we know we want in here From 93d67d6d8ffe570e4dc60338265502095aa48071 Mon Sep 17 00:00:00 2001 From: Christiane Heiligers Date: Fri, 15 Nov 2019 16:45:05 -0700 Subject: [PATCH 19/21] Deletes duplicate golangMetricsSpecProvider registration --- src/legacy/core_plugins/kibana/server/tutorials/register.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/legacy/core_plugins/kibana/server/tutorials/register.js b/src/legacy/core_plugins/kibana/server/tutorials/register.js index eb622fdd7a86f..7ede17a2d0886 100644 --- a/src/legacy/core_plugins/kibana/server/tutorials/register.js +++ b/src/legacy/core_plugins/kibana/server/tutorials/register.js @@ -122,7 +122,6 @@ export function registerTutorials(server) { server.newPlatform.setup.plugins.home.registerTutorial(windowsMetricsSpecProvider); server.newPlatform.setup.plugins.home.registerTutorial(windowsEventLogsSpecProvider); server.newPlatform.setup.plugins.home.registerTutorial(golangMetricsSpecProvider); - server.newPlatform.setup.plugins.home.registerTutorial(golangMetricsSpecProvider); server.newPlatform.setup.plugins.home.registerTutorial(logstashMetricsSpecProvider); server.newPlatform.setup.plugins.home.registerTutorial(prometheusMetricsSpecProvider); server.newPlatform.setup.plugins.home.registerTutorial(zookeeperMetricsSpecProvider); From 8d49809635cf4c133c997fd3bd4f1a08a4319f25 Mon Sep 17 00:00:00 2001 From: Christiane Heiligers Date: Sat, 16 Nov 2019 13:28:38 -0700 Subject: [PATCH 20/21] Nests tutorials service in a tutorials key in the home plugin, changes api http routes for legacy platform and NP --- .../kibana/public/home/load_tutorials.js | 14 +- .../routes/api/home/register_tutorials.js | 2 +- .../kibana/server/tutorials/register.js | 120 +++++++++--------- src/plugins/home/server/plugin.test.ts | 6 +- src/plugins/home/server/plugin.ts | 14 +- .../services/tutorials_registry.test.ts | 2 +- .../server/services/tutorials_registry.ts | 2 +- x-pack/plugins/spaces/server/plugin.ts | 2 +- 8 files changed, 84 insertions(+), 78 deletions(-) diff --git a/src/legacy/core_plugins/kibana/public/home/load_tutorials.js b/src/legacy/core_plugins/kibana/public/home/load_tutorials.js index 894f6bda64b4f..ce5f775be4933 100644 --- a/src/legacy/core_plugins/kibana/public/home/load_tutorials.js +++ b/src/legacy/core_plugins/kibana/public/home/load_tutorials.js @@ -21,8 +21,8 @@ import _ from 'lodash'; import { getServices } from './kibana_services'; import { i18n } from '@kbn/i18n'; -const baseUrl = getServices().addBasePath('/api/kibana/home/tutorials'); -const baseUrlNP = getServices().addBasePath('/api/kibana/home/NP_tutorials'); +const baseUrl = getServices().addBasePath('/api/kibana/home/tutorials_LP'); +const baseUrlNP = getServices().addBasePath('/api/kibana/home/tutorials'); const headers = new Headers(); headers.append('Accept', 'application/json'); headers.append('Content-Type', 'application/json'); @@ -40,16 +40,16 @@ async function loadTutorials() { credentials: 'include', headers: headers, }); - const responseNewPlatform = await fetch(baseUrlNP, { - method: 'get', - credentials: 'include', - headers: headers, - }); if (responseLegacyPlatform.status >= 300) { throw new Error(i18n.translate('kbn.home.loadTutorials.requestFailedErrorMessage', { defaultMessage: 'Request failed with status code: {status}', values: { status: responseLegacyPlatform.status } } )); } + const responseNewPlatform = await fetch(baseUrlNP, { + method: 'get', + credentials: 'include', + headers: headers, + }); if (responseNewPlatform.status >= 300) { throw new Error(i18n.translate('kbn.home.loadTutorials.requestFailedErrorMessage', { defaultMessage: 'Request failed with status code: {status}', values: { status: responseNewPlatform.status } } diff --git a/src/legacy/core_plugins/kibana/server/routes/api/home/register_tutorials.js b/src/legacy/core_plugins/kibana/server/routes/api/home/register_tutorials.js index 861ed1c244d13..fdf2e080c890c 100644 --- a/src/legacy/core_plugins/kibana/server/routes/api/home/register_tutorials.js +++ b/src/legacy/core_plugins/kibana/server/routes/api/home/register_tutorials.js @@ -20,7 +20,7 @@ export function registerTutorials(server) { server.route({ - path: '/api/kibana/home/tutorials', + path: '/api/kibana/home/tutorials_LP', method: ['GET'], handler: function (req) { return server.getTutorials(req); diff --git a/src/legacy/core_plugins/kibana/server/tutorials/register.js b/src/legacy/core_plugins/kibana/server/tutorials/register.js index 7ede17a2d0886..f1f65acf131ce 100644 --- a/src/legacy/core_plugins/kibana/server/tutorials/register.js +++ b/src/legacy/core_plugins/kibana/server/tutorials/register.js @@ -80,66 +80,66 @@ import { consulMetricsSpecProvider } from './consul_metrics'; import { cockroachdbMetricsSpecProvider } from './cockroachdb_metrics'; export function registerTutorials(server) { - server.newPlatform.setup.plugins.home.registerTutorial(systemLogsSpecProvider); - server.newPlatform.setup.plugins.home.registerTutorial(systemMetricsSpecProvider); - server.newPlatform.setup.plugins.home.registerTutorial(apacheLogsSpecProvider); - server.newPlatform.setup.plugins.home.registerTutorial(apacheMetricsSpecProvider); - server.newPlatform.setup.plugins.home.registerTutorial(elasticsearchLogsSpecProvider); - server.newPlatform.setup.plugins.home.registerTutorial(iisLogsSpecProvider); - server.newPlatform.setup.plugins.home.registerTutorial(kafkaLogsSpecProvider); - server.newPlatform.setup.plugins.home.registerTutorial(logstashLogsSpecProvider); - server.newPlatform.setup.plugins.home.registerTutorial(nginxLogsSpecProvider); - server.newPlatform.setup.plugins.home.registerTutorial(nginxMetricsSpecProvider); - server.newPlatform.setup.plugins.home.registerTutorial(mysqlLogsSpecProvider); - server.newPlatform.setup.plugins.home.registerTutorial(mysqlMetricsSpecProvider); - server.newPlatform.setup.plugins.home.registerTutorial(mongodbMetricsSpecProvider); - server.newPlatform.setup.plugins.home.registerTutorial(osqueryLogsSpecProvider); - server.newPlatform.setup.plugins.home.registerTutorial(phpfpmMetricsSpecProvider); - server.newPlatform.setup.plugins.home.registerTutorial(postgresqlMetricsSpecProvider); - server.newPlatform.setup.plugins.home.registerTutorial(postgresqlLogsSpecProvider); - server.newPlatform.setup.plugins.home.registerTutorial(rabbitmqMetricsSpecProvider); - server.newPlatform.setup.plugins.home.registerTutorial(redisLogsSpecProvider); - server.newPlatform.setup.plugins.home.registerTutorial(redisMetricsSpecProvider); - server.newPlatform.setup.plugins.home.registerTutorial(suricataLogsSpecProvider); - server.newPlatform.setup.plugins.home.registerTutorial(dockerMetricsSpecProvider); - server.newPlatform.setup.plugins.home.registerTutorial(kubernetesMetricsSpecProvider); - server.newPlatform.setup.plugins.home.registerTutorial(uwsgiMetricsSpecProvider); - server.newPlatform.setup.plugins.home.registerTutorial(netflowSpecProvider); - server.newPlatform.setup.plugins.home.registerTutorial(traefikLogsSpecProvider); + server.newPlatform.setup.plugins.home.tutorials.registerTutorial(systemLogsSpecProvider); + server.newPlatform.setup.plugins.home.tutorials.registerTutorial(systemMetricsSpecProvider); + server.newPlatform.setup.plugins.home.tutorials.registerTutorial(apacheLogsSpecProvider); + server.newPlatform.setup.plugins.home.tutorials.registerTutorial(apacheMetricsSpecProvider); + server.newPlatform.setup.plugins.home.tutorials.registerTutorial(elasticsearchLogsSpecProvider); + server.newPlatform.setup.plugins.home.tutorials.registerTutorial(iisLogsSpecProvider); + server.newPlatform.setup.plugins.home.tutorials.registerTutorial(kafkaLogsSpecProvider); + server.newPlatform.setup.plugins.home.tutorials.registerTutorial(logstashLogsSpecProvider); + server.newPlatform.setup.plugins.home.tutorials.registerTutorial(nginxLogsSpecProvider); + server.newPlatform.setup.plugins.home.tutorials.registerTutorial(nginxMetricsSpecProvider); + server.newPlatform.setup.plugins.home.tutorials.registerTutorial(mysqlLogsSpecProvider); + server.newPlatform.setup.plugins.home.tutorials.registerTutorial(mysqlMetricsSpecProvider); + server.newPlatform.setup.plugins.home.tutorials.registerTutorial(mongodbMetricsSpecProvider); + server.newPlatform.setup.plugins.home.tutorials.registerTutorial(osqueryLogsSpecProvider); + server.newPlatform.setup.plugins.home.tutorials.registerTutorial(phpfpmMetricsSpecProvider); + server.newPlatform.setup.plugins.home.tutorials.registerTutorial(postgresqlMetricsSpecProvider); + server.newPlatform.setup.plugins.home.tutorials.registerTutorial(postgresqlLogsSpecProvider); + server.newPlatform.setup.plugins.home.tutorials.registerTutorial(rabbitmqMetricsSpecProvider); + server.newPlatform.setup.plugins.home.tutorials.registerTutorial(redisLogsSpecProvider); + server.newPlatform.setup.plugins.home.tutorials.registerTutorial(redisMetricsSpecProvider); + server.newPlatform.setup.plugins.home.tutorials.registerTutorial(suricataLogsSpecProvider); + server.newPlatform.setup.plugins.home.tutorials.registerTutorial(dockerMetricsSpecProvider); + server.newPlatform.setup.plugins.home.tutorials.registerTutorial(kubernetesMetricsSpecProvider); + server.newPlatform.setup.plugins.home.tutorials.registerTutorial(uwsgiMetricsSpecProvider); + server.newPlatform.setup.plugins.home.tutorials.registerTutorial(netflowSpecProvider); + server.newPlatform.setup.plugins.home.tutorials.registerTutorial(traefikLogsSpecProvider); server.registerTutorial(apmSpecProvider); - server.newPlatform.setup.plugins.home.registerTutorial(cephMetricsSpecProvider); - server.newPlatform.setup.plugins.home.registerTutorial(aerospikeMetricsSpecProvider); - server.newPlatform.setup.plugins.home.registerTutorial(couchbaseMetricsSpecProvider); - server.newPlatform.setup.plugins.home.registerTutorial(dropwizardMetricsSpecProvider); - server.newPlatform.setup.plugins.home.registerTutorial(elasticsearchMetricsSpecProvider); - server.newPlatform.setup.plugins.home.registerTutorial(etcdMetricsSpecProvider); - server.newPlatform.setup.plugins.home.registerTutorial(haproxyMetricsSpecProvider); - server.newPlatform.setup.plugins.home.registerTutorial(kafkaMetricsSpecProvider); - server.newPlatform.setup.plugins.home.registerTutorial(kibanaMetricsSpecProvider); - server.newPlatform.setup.plugins.home.registerTutorial(memcachedMetricsSpecProvider); - server.newPlatform.setup.plugins.home.registerTutorial(muninMetricsSpecProvider); - server.newPlatform.setup.plugins.home.registerTutorial(vSphereMetricsSpecProvider); - server.newPlatform.setup.plugins.home.registerTutorial(windowsMetricsSpecProvider); - server.newPlatform.setup.plugins.home.registerTutorial(windowsEventLogsSpecProvider); - server.newPlatform.setup.plugins.home.registerTutorial(golangMetricsSpecProvider); - server.newPlatform.setup.plugins.home.registerTutorial(logstashMetricsSpecProvider); - server.newPlatform.setup.plugins.home.registerTutorial(prometheusMetricsSpecProvider); - server.newPlatform.setup.plugins.home.registerTutorial(zookeeperMetricsSpecProvider); - server.newPlatform.setup.plugins.home.registerTutorial(uptimeMonitorsSpecProvider); - server.newPlatform.setup.plugins.home.registerTutorial(cloudwatchLogsSpecProvider); - server.newPlatform.setup.plugins.home.registerTutorial(awsMetricsSpecProvider); - server.newPlatform.setup.plugins.home.registerTutorial(mssqlMetricsSpecProvider); - server.newPlatform.setup.plugins.home.registerTutorial(natsMetricsSpecProvider); - server.newPlatform.setup.plugins.home.registerTutorial(natsLogsSpecProvider); - server.newPlatform.setup.plugins.home.registerTutorial(zeekLogsSpecProvider); - server.newPlatform.setup.plugins.home.registerTutorial(corednsMetricsSpecProvider); - server.newPlatform.setup.plugins.home.registerTutorial(corednsLogsSpecProvider); - server.newPlatform.setup.plugins.home.registerTutorial(auditbeatSpecProvider); - server.newPlatform.setup.plugins.home.registerTutorial(iptablesLogsSpecProvider); - server.newPlatform.setup.plugins.home.registerTutorial(ciscoLogsSpecProvider); - server.newPlatform.setup.plugins.home.registerTutorial(envoyproxyLogsSpecProvider); - server.newPlatform.setup.plugins.home.registerTutorial(couchdbMetricsSpecProvider); + server.newPlatform.setup.plugins.home.tutorials.registerTutorial(cephMetricsSpecProvider); + server.newPlatform.setup.plugins.home.tutorials.registerTutorial(aerospikeMetricsSpecProvider); + server.newPlatform.setup.plugins.home.tutorials.registerTutorial(couchbaseMetricsSpecProvider); + server.newPlatform.setup.plugins.home.tutorials.registerTutorial(dropwizardMetricsSpecProvider); + server.newPlatform.setup.plugins.home.tutorials.registerTutorial(elasticsearchMetricsSpecProvider); + server.newPlatform.setup.plugins.home.tutorials.registerTutorial(etcdMetricsSpecProvider); + server.newPlatform.setup.plugins.home.tutorials.registerTutorial(haproxyMetricsSpecProvider); + server.newPlatform.setup.plugins.home.tutorials.registerTutorial(kafkaMetricsSpecProvider); + server.newPlatform.setup.plugins.home.tutorials.registerTutorial(kibanaMetricsSpecProvider); + server.newPlatform.setup.plugins.home.tutorials.registerTutorial(memcachedMetricsSpecProvider); + server.newPlatform.setup.plugins.home.tutorials.registerTutorial(muninMetricsSpecProvider); + server.newPlatform.setup.plugins.home.tutorials.registerTutorial(vSphereMetricsSpecProvider); + server.newPlatform.setup.plugins.home.tutorials.registerTutorial(windowsMetricsSpecProvider); + server.newPlatform.setup.plugins.home.tutorials.registerTutorial(windowsEventLogsSpecProvider); + server.newPlatform.setup.plugins.home.tutorials.registerTutorial(golangMetricsSpecProvider); + server.newPlatform.setup.plugins.home.tutorials.registerTutorial(logstashMetricsSpecProvider); + server.newPlatform.setup.plugins.home.tutorials.registerTutorial(prometheusMetricsSpecProvider); + server.newPlatform.setup.plugins.home.tutorials.registerTutorial(zookeeperMetricsSpecProvider); + server.newPlatform.setup.plugins.home.tutorials.registerTutorial(uptimeMonitorsSpecProvider); + server.newPlatform.setup.plugins.home.tutorials.registerTutorial(cloudwatchLogsSpecProvider); + server.newPlatform.setup.plugins.home.tutorials.registerTutorial(awsMetricsSpecProvider); + server.newPlatform.setup.plugins.home.tutorials.registerTutorial(mssqlMetricsSpecProvider); + server.newPlatform.setup.plugins.home.tutorials.registerTutorial(natsMetricsSpecProvider); + server.newPlatform.setup.plugins.home.tutorials.registerTutorial(natsLogsSpecProvider); + server.newPlatform.setup.plugins.home.tutorials.registerTutorial(zeekLogsSpecProvider); + server.newPlatform.setup.plugins.home.tutorials.registerTutorial(corednsMetricsSpecProvider); + server.newPlatform.setup.plugins.home.tutorials.registerTutorial(corednsLogsSpecProvider); + server.newPlatform.setup.plugins.home.tutorials.registerTutorial(auditbeatSpecProvider); + server.newPlatform.setup.plugins.home.tutorials.registerTutorial(iptablesLogsSpecProvider); + server.newPlatform.setup.plugins.home.tutorials.registerTutorial(ciscoLogsSpecProvider); + server.newPlatform.setup.plugins.home.tutorials.registerTutorial(envoyproxyLogsSpecProvider); + server.newPlatform.setup.plugins.home.tutorials.registerTutorial(couchdbMetricsSpecProvider); server.registerTutorial(emsBoundariesSpecProvider); - server.newPlatform.setup.plugins.home.registerTutorial(consulMetricsSpecProvider); - server.newPlatform.setup.plugins.home.registerTutorial(cockroachdbMetricsSpecProvider); + server.newPlatform.setup.plugins.home.tutorials.registerTutorial(consulMetricsSpecProvider); + server.newPlatform.setup.plugins.home.tutorials.registerTutorial(cockroachdbMetricsSpecProvider); } diff --git a/src/plugins/home/server/plugin.test.ts b/src/plugins/home/server/plugin.test.ts index d971d8aec3cf7..e86a2d807109f 100644 --- a/src/plugins/home/server/plugin.test.ts +++ b/src/plugins/home/server/plugin.test.ts @@ -35,8 +35,9 @@ describe('HomePlugin', () => { test('wires up and returns registerTutorial and addScopedTutorialContextFactory', () => { const setup = new HomePlugin().setup(mockCoreSetup); - expect(setup).toHaveProperty('registerTutorial'); - expect(setup).toHaveProperty('addScopedTutorialContextFactory'); + expect(setup).toHaveProperty('tutorials'); + expect(setup.tutorials).toHaveProperty('registerTutorial'); + expect(setup.tutorials).toHaveProperty('addScopedTutorialContextFactory'); }); }); @@ -44,6 +45,7 @@ describe('HomePlugin', () => { test('is defined', () => { const start = new HomePlugin().start(); expect(start).toBeDefined(); + expect(start).toHaveProperty('tutorials'); }); }); }); diff --git a/src/plugins/home/server/plugin.ts b/src/plugins/home/server/plugin.ts index 302641404e8ad..d5a3f235f8490 100644 --- a/src/plugins/home/server/plugin.ts +++ b/src/plugins/home/server/plugin.ts @@ -19,24 +19,28 @@ import { CoreSetup, Plugin } from 'src/core/server'; import { TutorialsRegistry, TutorialsRegistrySetup, TutorialsRegistryStart } from './services'; -export class HomePlugin implements Plugin { +export class HomePlugin implements Plugin { private readonly tutorialsRegistry = new TutorialsRegistry(); public setup(core: CoreSetup) { return { - ...this.tutorialsRegistry.setup(core), + tutorials: { ...this.tutorialsRegistry.setup(core) }, }; } public start() { return { - ...this.tutorialsRegistry.start(), + tutorials: { ...this.tutorialsRegistry.start() }, }; } } /** @public */ -export type HomePluginSetup = TutorialsRegistrySetup; +export interface HomePluginSetup { + tutorials: TutorialsRegistrySetup; +} /** @public */ -export type HomePluginStart = TutorialsRegistryStart; +export interface HomePluginStart { + tutorials: TutorialsRegistryStart; +} diff --git a/src/plugins/home/server/services/tutorials_registry.test.ts b/src/plugins/home/server/services/tutorials_registry.test.ts index f6e004d4cc737..04c26bab1f065 100644 --- a/src/plugins/home/server/services/tutorials_registry.test.ts +++ b/src/plugins/home/server/services/tutorials_registry.test.ts @@ -79,7 +79,7 @@ describe('TutorialsRegistry', () => { let testProvider: TutorialProvider; let testScopedTutorialContextFactory: ScopedTutorialContextFactory; - describe('GET /api/kibana/home/NP_tutorials', () => { + describe('GET /api/kibana/home/tutorials', () => { beforeEach(() => { mockCoreSetup = coreMock.createSetup(); }); diff --git a/src/plugins/home/server/services/tutorials_registry.ts b/src/plugins/home/server/services/tutorials_registry.ts index bd64c8b9f1a8c..40692d8558656 100644 --- a/src/plugins/home/server/services/tutorials_registry.ts +++ b/src/plugins/home/server/services/tutorials_registry.ts @@ -33,7 +33,7 @@ export class TutorialsRegistry { public setup(core: CoreSetup) { const router = core.http.createRouter(); router.get( - { path: '/api/kibana/home/NP_tutorials', validate: false }, + { path: '/api/kibana/home/tutorials', validate: false }, async (context, req, res) => { const initialContext = {}; const scopedContext = this.scopedTutorialContextFactories.reduce( diff --git a/x-pack/plugins/spaces/server/plugin.ts b/x-pack/plugins/spaces/server/plugin.ts index 2bf184f981831..21120ab37b06a 100644 --- a/x-pack/plugins/spaces/server/plugin.ts +++ b/x-pack/plugins/spaces/server/plugin.ts @@ -140,7 +140,7 @@ export class Plugin { } if (plugins.home) { - plugins.home.addScopedTutorialContextFactory( + plugins.home.tutorials.addScopedTutorialContextFactory( createSpacesTutorialContextFactory(spacesService) ); } From 7f553fba9f215724175a8d895adf50f1a8b500cb Mon Sep 17 00:00:00 2001 From: Christiane Heiligers Date: Sun, 17 Nov 2019 09:35:13 -0700 Subject: [PATCH 21/21] Changes url variable names --- .../core_plugins/kibana/public/home/load_tutorials.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/legacy/core_plugins/kibana/public/home/load_tutorials.js b/src/legacy/core_plugins/kibana/public/home/load_tutorials.js index ce5f775be4933..f597bd732c221 100644 --- a/src/legacy/core_plugins/kibana/public/home/load_tutorials.js +++ b/src/legacy/core_plugins/kibana/public/home/load_tutorials.js @@ -21,8 +21,8 @@ import _ from 'lodash'; import { getServices } from './kibana_services'; import { i18n } from '@kbn/i18n'; -const baseUrl = getServices().addBasePath('/api/kibana/home/tutorials_LP'); -const baseUrlNP = getServices().addBasePath('/api/kibana/home/tutorials'); +const baseUrlLP = getServices().addBasePath('/api/kibana/home/tutorials_LP'); +const baseUrl = getServices().addBasePath('/api/kibana/home/tutorials'); const headers = new Headers(); headers.append('Accept', 'application/json'); headers.append('Content-Type', 'application/json'); @@ -35,7 +35,7 @@ let tutorialsLoaded = false; async function loadTutorials() { try { - const responseLegacyPlatform = await fetch(baseUrl, { + const responseLegacyPlatform = await fetch(baseUrlLP, { method: 'get', credentials: 'include', headers: headers, @@ -45,7 +45,7 @@ async function loadTutorials() { defaultMessage: 'Request failed with status code: {status}', values: { status: responseLegacyPlatform.status } } )); } - const responseNewPlatform = await fetch(baseUrlNP, { + const responseNewPlatform = await fetch(baseUrl, { method: 'get', credentials: 'include', headers: headers,