Skip to content

Commit

Permalink
[Reporting] Ensure uniform plugin enablement
Browse files Browse the repository at this point in the history
  • Loading branch information
tsullivan committed Dec 9, 2021
1 parent 63f58da commit 096d5b2
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
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 @@ -20,6 +20,7 @@ import type {
ReportingStart,
ReportingStartDeps,
} from './types';
import { reportingStatusSavedObjectType, updateLastReported } from './saved_objects';
import { registerReportingUsageCollector } from './usage';

export class ReportingPlugin
Expand All @@ -33,6 +34,8 @@ export class ReportingPlugin
}

public setup(core: CoreSetup, plugins: ReportingSetupDeps) {
core.savedObjects.registerType(reportingStatusSavedObjectType);

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 updateLastReported(core.savedObjects, this.initContext.env.packageInfo);

const store = new ReportingStore(reportingCore, this.logger);

Expand Down
52 changes: 52 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,52 @@
/*
* 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 { PackageInfo, SavedObjectsServiceStart, SavedObjectsType } from 'kibana/server';
import { PLUGIN_ID } from '../../common/constants';

interface ReportingStatusSavedObjectAttributes {
lastReported: string;
lastVersionChecked: string;
}

const SAVED_OBJECT_ID = 'reporting-status';

export const reportingStatusSavedObjectType: SavedObjectsType<ReportingStatusSavedObjectAttributes> =
{
name: PLUGIN_ID,
namespaceType: 'agnostic',
hidden: true,
mappings: {
properties: {
lastReported: {
type: 'date',
},
lastVersionChecked: {
ignore_above: 256,
type: 'keyword',
},
},
},
};

export async function updateLastReported(
savedObjects: SavedObjectsServiceStart,
{ version }: PackageInfo
) {
const reportingStatus: ReportingStatusSavedObjectAttributes = {
lastReported: new Date().toISOString(),
lastVersionChecked: version,
};

const scopedClient = savedObjects.createInternalRepository([PLUGIN_ID]);
await scopedClient.update<ReportingStatusSavedObjectAttributes>(
PLUGIN_ID,
SAVED_OBJECT_ID,
reportingStatus,
{ upsert: reportingStatus }
);
}

0 comments on commit 096d5b2

Please sign in to comment.