Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Reporting] Ensure uniform enablement of the plugin #121020

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions x-pack/plugins/reporting/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;

Expand Down Expand Up @@ -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);

Expand Down
60 changes: 60 additions & 0 deletions x-pack/plugins/reporting/server/saved_objects/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* 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';

/*
* 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 {
enabled: true;
}

export const reportingStatusSavedObject = {
get type() {
const reportingStatusSavedObjectType: SavedObjectsType<Attributes> = {
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 };

// Reporting creates the object to raise a flag in instances that have
// disabled Reporting.
await scopedClient.update<Attributes>(PLUGIN_ID, SAVED_OBJECT_ID, reportingStatus, {
upsert: reportingStatus,
});
},
};