From be3359348e8742bd1957941e8f5ee62f4a7ebca8 Mon Sep 17 00:00:00 2001 From: Alexey Antonov Date: Mon, 24 Aug 2020 20:33:52 +0300 Subject: [PATCH] Add Timelion deprecation warning to server log (#75541) (#75765) * Add Timelion deprecation warning to the migration assistant Closes: #63014 * fix PR comments * update message * fix integration tests Co-authored-by: Elastic Machine Co-authored-by: Elastic Machine --- .../integration_tests/static_assets.test.ts | 2 +- .../http_resources_service.test.ts | 1 + .../integration_tests/legacy_service.test.ts | 5 +- .../legacy/integration_tests/logging.test.ts | 1 + .../routes/integration_tests/migrate.test.ts | 2 +- .../integration_tests/routes.test.ts | 2 +- .../max_payload_size.test.js | 6 +- src/plugins/timelion/server/plugin.ts | 62 +++++++++++-------- .../timelion/server/saved_objects/index.ts | 20 ++++++ .../server/saved_objects/timelion_sheet.ts | 45 ++++++++++++++ 10 files changed, 114 insertions(+), 32 deletions(-) create mode 100644 src/plugins/timelion/server/saved_objects/index.ts create mode 100644 src/plugins/timelion/server/saved_objects/timelion_sheet.ts diff --git a/src/core/server/core_app/integration_tests/static_assets.test.ts b/src/core/server/core_app/integration_tests/static_assets.test.ts index 23125cb3a6704..160ef064a14d9 100644 --- a/src/core/server/core_app/integration_tests/static_assets.test.ts +++ b/src/core/server/core_app/integration_tests/static_assets.test.ts @@ -23,7 +23,7 @@ describe('Platform assets', function () { let root: Root; beforeAll(async function () { - root = kbnTestServer.createRoot(); + root = kbnTestServer.createRoot({ plugins: { initialize: false } }); await root.setup(); await root.start(); diff --git a/src/core/server/http_resources/integration_tests/http_resources_service.test.ts b/src/core/server/http_resources/integration_tests/http_resources_service.test.ts index 0a5daa02e17e9..eee7dc2786076 100644 --- a/src/core/server/http_resources/integration_tests/http_resources_service.test.ts +++ b/src/core/server/http_resources/integration_tests/http_resources_service.test.ts @@ -28,6 +28,7 @@ describe('http resources service', () => { csp: { rules: [defaultCspRules], }, + plugins: { initialize: false }, }); }, 30000); diff --git a/src/core/server/legacy/integration_tests/legacy_service.test.ts b/src/core/server/legacy/integration_tests/legacy_service.test.ts index e8bcf7a42d192..1dc8d53e7c3d6 100644 --- a/src/core/server/legacy/integration_tests/legacy_service.test.ts +++ b/src/core/server/legacy/integration_tests/legacy_service.test.ts @@ -22,7 +22,10 @@ describe('legacy service', () => { describe('http server', () => { let root: ReturnType; beforeEach(() => { - root = kbnTestServer.createRoot({ migrations: { skip: true } }); + root = kbnTestServer.createRoot({ + migrations: { skip: true }, + plugins: { initialize: false }, + }); }, 30000); afterEach(async () => await root.shutdown()); diff --git a/src/core/server/legacy/integration_tests/logging.test.ts b/src/core/server/legacy/integration_tests/logging.test.ts index 66234f677903f..2581c85debf26 100644 --- a/src/core/server/legacy/integration_tests/logging.test.ts +++ b/src/core/server/legacy/integration_tests/logging.test.ts @@ -28,6 +28,7 @@ import { LegacyLoggingConfig } from '../config/legacy_object_to_config_adapter'; function createRoot(legacyLoggingConfig: LegacyLoggingConfig = {}) { return kbnTestServer.createRoot({ migrations: { skip: true }, // otherwise stuck in polling ES + plugins: { initialize: false }, logging: { // legacy platform config silent: false, diff --git a/src/core/server/saved_objects/routes/integration_tests/migrate.test.ts b/src/core/server/saved_objects/routes/integration_tests/migrate.test.ts index 5bc7d126ace03..7a0e39b71afb8 100644 --- a/src/core/server/saved_objects/routes/integration_tests/migrate.test.ts +++ b/src/core/server/saved_objects/routes/integration_tests/migrate.test.ts @@ -24,7 +24,7 @@ describe('SavedObjects /_migrate endpoint', () => { let root: ReturnType; beforeEach(async () => { - root = kbnTestServer.createRoot({ migrations: { skip: true } }); + root = kbnTestServer.createRoot({ migrations: { skip: true }, plugins: { initialize: false } }); await root.setup(); await root.start(); migratorInstanceMock.runMigrations.mockClear(); diff --git a/src/core/server/ui_settings/integration_tests/routes.test.ts b/src/core/server/ui_settings/integration_tests/routes.test.ts index c1261bc7c1350..b18cc370fac3c 100644 --- a/src/core/server/ui_settings/integration_tests/routes.test.ts +++ b/src/core/server/ui_settings/integration_tests/routes.test.ts @@ -24,7 +24,7 @@ describe('ui settings service', () => { describe('routes', () => { let root: ReturnType; beforeAll(async () => { - root = kbnTestServer.createRoot(); + root = kbnTestServer.createRoot({ plugins: { initialize: false } }); const { uiSettings } = await root.setup(); uiSettings.register({ diff --git a/src/legacy/server/http/integration_tests/max_payload_size.test.js b/src/legacy/server/http/integration_tests/max_payload_size.test.js index a019220ca7a2a..789a54f681ba6 100644 --- a/src/legacy/server/http/integration_tests/max_payload_size.test.js +++ b/src/legacy/server/http/integration_tests/max_payload_size.test.js @@ -21,7 +21,11 @@ import * as kbnTestServer from '../../../../test_utils/kbn_server'; let root; beforeAll(async () => { - root = kbnTestServer.createRoot({ server: { maxPayloadBytes: 100 }, migrations: { skip: true } }); + root = kbnTestServer.createRoot({ + server: { maxPayloadBytes: 100 }, + migrations: { skip: true }, + plugins: { initialize: false }, + }); await root.setup(); await root.start(); diff --git a/src/plugins/timelion/server/plugin.ts b/src/plugins/timelion/server/plugin.ts index 3e4cd5467dd44..fe77ebeb0866d 100644 --- a/src/plugins/timelion/server/plugin.ts +++ b/src/plugins/timelion/server/plugin.ts @@ -17,13 +17,42 @@ * under the License. */ -import { CoreSetup, Plugin, PluginInitializerContext } from 'src/core/server'; +import { CoreSetup, CoreStart, Plugin, PluginInitializerContext, Logger } from 'src/core/server'; import { i18n } from '@kbn/i18n'; import { schema } from '@kbn/config-schema'; import { TimelionConfigType } from './config'; +import { timelionSheetSavedObjectType } from './saved_objects'; + +/** + * Deprecated since 7.0, the Timelion app will be removed in 8.0. + * To continue using your Timelion worksheets, migrate them to a dashboard. + * + * @link https://www.elastic.co/guide/en/kibana/master/timelion.html#timelion-deprecation + **/ +const showWarningMessageIfTimelionSheetWasFound = (core: CoreStart, logger: Logger) => { + const { savedObjects } = core; + const savedObjectsClient = savedObjects.createInternalRepository(); + + savedObjectsClient + .find({ + type: 'timelion-sheet', + perPage: 1, + }) + .then( + ({ total }) => + total && + logger.warn( + 'Deprecated since 7.0, the Timelion app will be removed in 8.0. To continue using your Timelion worksheets, migrate them to a dashboard. See https://www.elastic.co/guide/en/kibana/master/timelion.html#timelion-deprecation.' + ) + ); +}; export class TimelionPlugin implements Plugin { - constructor(context: PluginInitializerContext) {} + private logger: Logger; + + constructor(context: PluginInitializerContext) { + this.logger = context.logger.get(); + } public setup(core: CoreSetup) { core.capabilities.registerProvider(() => ({ @@ -31,30 +60,7 @@ export class TimelionPlugin implements Plugin { save: true, }, })); - core.savedObjects.registerType({ - name: 'timelion-sheet', - hidden: false, - namespaceType: 'single', - mappings: { - properties: { - description: { type: 'text' }, - hits: { type: 'integer' }, - kibanaSavedObjectMeta: { - properties: { - searchSourceJSON: { type: 'text' }, - }, - }, - timelion_chart_height: { type: 'integer' }, - timelion_columns: { type: 'integer' }, - timelion_interval: { type: 'keyword' }, - timelion_other_interval: { type: 'keyword' }, - timelion_rows: { type: 'integer' }, - timelion_sheet: { type: 'text' }, - title: { type: 'text' }, - version: { type: 'integer' }, - }, - }, - }); + core.savedObjects.registerType(timelionSheetSavedObjectType); core.uiSettings.register({ 'timelion:showTutorial': { @@ -92,6 +98,8 @@ export class TimelionPlugin implements Plugin { }, }); } - start() {} + start(core: CoreStart) { + showWarningMessageIfTimelionSheetWasFound(core, this.logger); + } stop() {} } diff --git a/src/plugins/timelion/server/saved_objects/index.ts b/src/plugins/timelion/server/saved_objects/index.ts new file mode 100644 index 0000000000000..102dc25811019 --- /dev/null +++ b/src/plugins/timelion/server/saved_objects/index.ts @@ -0,0 +1,20 @@ +/* + * 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 { timelionSheetSavedObjectType } from './timelion_sheet'; diff --git a/src/plugins/timelion/server/saved_objects/timelion_sheet.ts b/src/plugins/timelion/server/saved_objects/timelion_sheet.ts new file mode 100644 index 0000000000000..6a46217c3e61b --- /dev/null +++ b/src/plugins/timelion/server/saved_objects/timelion_sheet.ts @@ -0,0 +1,45 @@ +/* + * 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 { SavedObjectsType } from 'kibana/server'; + +export const timelionSheetSavedObjectType: SavedObjectsType = { + name: 'timelion-sheet', + hidden: false, + namespaceType: 'single', + mappings: { + properties: { + description: { type: 'text' }, + hits: { type: 'integer' }, + kibanaSavedObjectMeta: { + properties: { + searchSourceJSON: { type: 'text' }, + }, + }, + timelion_chart_height: { type: 'integer' }, + timelion_columns: { type: 'integer' }, + timelion_interval: { type: 'keyword' }, + timelion_other_interval: { type: 'keyword' }, + timelion_rows: { type: 'integer' }, + timelion_sheet: { type: 'text' }, + title: { type: 'text' }, + version: { type: 'integer' }, + }, + }, +};