register graph usage (#72041)

This commit is contained in:
Joe Reuter 2020-07-17 17:16:28 +02:00 committed by GitHub
parent 39381ca3c8
commit 825c16875e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 22 additions and 3 deletions

View file

@ -7,6 +7,7 @@
import Boom from 'boom';
import { map } from 'rxjs/operators';
import { Observable, Subscription } from 'rxjs';
import { LicensingPluginStart } from '../../../licensing/server';
import { ILicense } from '../../../licensing/common/types';
import { checkLicense, GraphLicenseInformation } from '../../common/check_license';
@ -14,6 +15,7 @@ export class LicenseState {
private licenseInformation: GraphLicenseInformation = checkLicense(undefined);
private subscription: Subscription | null = null;
private observable: Observable<GraphLicenseInformation> | null = null;
private _notifyUsage: LicensingPluginStart['featureUsage']['notifyUsage'] | null = null;
private updateInformation(licenseInformation: GraphLicenseInformation) {
this.licenseInformation = licenseInformation;
@ -24,6 +26,17 @@ export class LicenseState {
this.subscription = this.observable.subscribe(this.updateInformation.bind(this));
}
public setNotifyUsage(notifyUsage: LicensingPluginStart['featureUsage']['notifyUsage']) {
this._notifyUsage = notifyUsage;
}
// 'Graph' is the only allowed feature here at the moment, if this gets extended in the future, add to the union type
public notifyUsage(featureName: 'Graph') {
if (this._notifyUsage) {
this._notifyUsage(featureName);
}
}
public stop() {
if (this.subscription) {
this.subscription.unsubscribe();

View file

@ -5,8 +5,8 @@
*/
import { i18n } from '@kbn/i18n';
import { Plugin, CoreSetup } from 'src/core/server';
import { LicensingPluginSetup } from '../../licensing/server';
import { Plugin, CoreSetup, CoreStart } from 'src/core/server';
import { LicensingPluginSetup, LicensingPluginStart } from '../../licensing/server';
import { LicenseState } from './lib/license_state';
import { registerSearchRoute } from './routes/search';
import { registerExploreRoute } from './routes/explore';
@ -34,6 +34,7 @@ export class GraphPlugin implements Plugin {
licenseState.start(licensing.license$);
this.licenseState = licenseState;
core.savedObjects.registerType(graphWorkspace);
licensing.featureUsage.register('Graph', 'platinum');
if (home) {
registerSampleData(home.sampleData, licenseState);
@ -79,7 +80,10 @@ export class GraphPlugin implements Plugin {
registerExploreRoute({ licenseState, router });
}
public start() {}
public start(core: CoreStart, { licensing }: { licensing: LicensingPluginStart }) {
this.licenseState!.setNotifyUsage(licensing.featureUsage.notifyUsage);
}
public stop() {
if (this.licenseState) {
this.licenseState.stop();

View file

@ -42,6 +42,7 @@ export function registerExploreRoute({
response
) => {
verifyApiAccess(licenseState);
licenseState.notifyUsage('Graph');
try {
return response.ok({
body: {

View file

@ -42,6 +42,7 @@ export function registerSearchRoute({
response
) => {
verifyApiAccess(licenseState);
licenseState.notifyUsage('Graph');
const includeFrozen = await uiSettings.get<boolean>(UI_SETTINGS.SEARCH_INCLUDE_FROZEN);
try {
return response.ok({