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

[Graph] Register graph usage #72041

Merged
merged 1 commit into from
Jul 17, 2020
Merged
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
13 changes: 13 additions & 0 deletions x-pack/plugins/graph/server/lib/license_state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
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';

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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just an thought when viewing this, why not call it licenseNotifyUsage to omit the _


private updateInformation(licenseInformation: GraphLicenseInformation) {
this.licenseInformation = licenseInformation;
Expand All @@ -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();
Expand Down
10 changes: 7 additions & 3 deletions x-pack/plugins/graph/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/graph/server/routes/explore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export function registerExploreRoute({
response
) => {
verifyApiAccess(licenseState);
licenseState.notifyUsage('Graph');
try {
return response.ok({
body: {
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/graph/server/routes/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down