From 8d49809635cf4c133c997fd3bd4f1a08a4319f25 Mon Sep 17 00:00:00 2001 From: Christiane Heiligers Date: Sat, 16 Nov 2019 13:28:38 -0700 Subject: [PATCH] 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) ); }