From 04b348d8a9522089d2860980f9b4811dc8ab942b Mon Sep 17 00:00:00 2001 From: Timothy Sullivan Date: Thu, 9 Dec 2021 15:26:46 -0700 Subject: [PATCH 1/2] [Reporting] Add Reporting Saved Obj type to ensure uniform plugin enablement --- x-pack/plugins/reporting/server/plugin.ts | 4 ++ .../reporting/server/saved_objects/index.ts | 39 +++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 x-pack/plugins/reporting/server/saved_objects/index.ts diff --git a/x-pack/plugins/reporting/server/plugin.ts b/x-pack/plugins/reporting/server/plugin.ts index 0a2318daded029..0e227d74a982e3 100644 --- a/x-pack/plugins/reporting/server/plugin.ts +++ b/x-pack/plugins/reporting/server/plugin.ts @@ -20,6 +20,7 @@ import type { ReportingStart, ReportingStartDeps, } from './types'; +import { reportingStatusSavedObject } from './saved_objects'; import { registerReportingUsageCollector } from './usage'; export class ReportingPlugin @@ -33,6 +34,8 @@ export class ReportingPlugin } public setup(core: CoreSetup, plugins: ReportingSetupDeps) { + core.savedObjects.registerType(reportingStatusSavedObject.type); + const { http } = core; const { features, licensing, security, spaces, taskManager } = plugins; @@ -95,6 +98,7 @@ export class ReportingPlugin // async background start (async () => { await reportingCore.pluginSetsUp(); + await reportingStatusSavedObject.setStatus(core.savedObjects); const store = new ReportingStore(reportingCore, this.logger); diff --git a/x-pack/plugins/reporting/server/saved_objects/index.ts b/x-pack/plugins/reporting/server/saved_objects/index.ts new file mode 100644 index 00000000000000..398042a79f1834 --- /dev/null +++ b/x-pack/plugins/reporting/server/saved_objects/index.ts @@ -0,0 +1,39 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import { SavedObjectsServiceStart, SavedObjectsType } from 'kibana/server'; +import { PLUGIN_ID } from '../../common/constants'; + +const SAVED_OBJECT_ID = 'reporting-status'; + +interface Attributes { + enabled: true; +} + +export const reportingStatusSavedObject = { + get type() { + const reportingStatusSavedObjectType: SavedObjectsType = { + name: PLUGIN_ID, + namespaceType: 'agnostic', + hidden: true, + mappings: { + properties: { + enabled: { type: 'boolean' }, + }, + }, + }; + return reportingStatusSavedObjectType; + }, + + async setStatus(savedObjects: SavedObjectsServiceStart) { + const scopedClient = savedObjects.createInternalRepository([PLUGIN_ID]); + const reportingStatus: Attributes = { enabled: true }; + await scopedClient.update(PLUGIN_ID, SAVED_OBJECT_ID, reportingStatus, { + upsert: reportingStatus, + }); + }, +}; From 0f1b55201dda7695eb6f955a1fba5465ebafd600 Mon Sep 17 00:00:00 2001 From: Timothy Sullivan Date: Thu, 9 Dec 2021 17:23:27 -0700 Subject: [PATCH 2/2] add comments --- x-pack/plugins/reporting/server/plugin.ts | 2 +- .../reporting/server/saved_objects/index.ts | 21 +++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/x-pack/plugins/reporting/server/plugin.ts b/x-pack/plugins/reporting/server/plugin.ts index 0e227d74a982e3..e22d37221541e2 100644 --- a/x-pack/plugins/reporting/server/plugin.ts +++ b/x-pack/plugins/reporting/server/plugin.ts @@ -12,6 +12,7 @@ import { buildConfig, registerUiSettings, ReportingConfigType } from './config'; import { registerDeprecations } from './deprecations'; import { LevelLogger, ReportingStore } from './lib'; import { registerRoutes } from './routes'; +import { reportingStatusSavedObject } from './saved_objects'; import { setFieldFormats } from './services'; import type { ReportingRequestHandlerContext, @@ -20,7 +21,6 @@ import type { ReportingStart, ReportingStartDeps, } from './types'; -import { reportingStatusSavedObject } from './saved_objects'; import { registerReportingUsageCollector } from './usage'; export class ReportingPlugin diff --git a/x-pack/plugins/reporting/server/saved_objects/index.ts b/x-pack/plugins/reporting/server/saved_objects/index.ts index 398042a79f1834..87b51d7b3c0fdc 100644 --- a/x-pack/plugins/reporting/server/saved_objects/index.ts +++ b/x-pack/plugins/reporting/server/saved_objects/index.ts @@ -8,6 +8,24 @@ import { SavedObjectsServiceStart, SavedObjectsType } from 'kibana/server'; import { PLUGIN_ID } from '../../common/constants'; +/* + * The purpose of this saved object is to ensure that if Reporting is disabled in + * a Kibana, it is disabled in every Kibana instance. + * + * Reporting creates this saved object as a safety check from instances that + * have the Reporting plugin disabled. Those instances should fail to start up + * since this saved object type isn't registered. The unknown type of object is + * meant to cause Kibana to fail to start. + * + * If an administrator wishes to disable Reporting, they should use + * `xpack.reporting.queue.pollEnabled: false` from simply stopping the + * Reporting plugin from doing any processing work. + * + * If they wish to completely disable Reporting, but Reporting has been run on + * a previous instance, they will have to manually remove this saved object + * from the Kibana instance to clear the "unknown" object. + */ + const SAVED_OBJECT_ID = 'reporting-status'; interface Attributes { @@ -32,6 +50,9 @@ export const reportingStatusSavedObject = { async setStatus(savedObjects: SavedObjectsServiceStart) { const scopedClient = savedObjects.createInternalRepository([PLUGIN_ID]); const reportingStatus: Attributes = { enabled: true }; + + // Reporting creates the object to raise a flag in instances that have + // disabled Reporting. await scopedClient.update(PLUGIN_ID, SAVED_OBJECT_ID, reportingStatus, { upsert: reportingStatus, });