Skip to content

Commit 825c168

Browse files
authored
register graph usage (#72041)
1 parent 39381ca commit 825c168

File tree

4 files changed

+22
-3
lines changed

4 files changed

+22
-3
lines changed

x-pack/plugins/graph/server/lib/license_state.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@
77
import Boom from 'boom';
88
import { map } from 'rxjs/operators';
99
import { Observable, Subscription } from 'rxjs';
10+
import { LicensingPluginStart } from '../../../licensing/server';
1011
import { ILicense } from '../../../licensing/common/types';
1112
import { checkLicense, GraphLicenseInformation } from '../../common/check_license';
1213

1314
export class LicenseState {
1415
private licenseInformation: GraphLicenseInformation = checkLicense(undefined);
1516
private subscription: Subscription | null = null;
1617
private observable: Observable<GraphLicenseInformation> | null = null;
18+
private _notifyUsage: LicensingPluginStart['featureUsage']['notifyUsage'] | null = null;
1719

1820
private updateInformation(licenseInformation: GraphLicenseInformation) {
1921
this.licenseInformation = licenseInformation;
@@ -24,6 +26,17 @@ export class LicenseState {
2426
this.subscription = this.observable.subscribe(this.updateInformation.bind(this));
2527
}
2628

29+
public setNotifyUsage(notifyUsage: LicensingPluginStart['featureUsage']['notifyUsage']) {
30+
this._notifyUsage = notifyUsage;
31+
}
32+
33+
// 'Graph' is the only allowed feature here at the moment, if this gets extended in the future, add to the union type
34+
public notifyUsage(featureName: 'Graph') {
35+
if (this._notifyUsage) {
36+
this._notifyUsage(featureName);
37+
}
38+
}
39+
2740
public stop() {
2841
if (this.subscription) {
2942
this.subscription.unsubscribe();

x-pack/plugins/graph/server/plugin.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
*/
66

77
import { i18n } from '@kbn/i18n';
8-
import { Plugin, CoreSetup } from 'src/core/server';
9-
import { LicensingPluginSetup } from '../../licensing/server';
8+
import { Plugin, CoreSetup, CoreStart } from 'src/core/server';
9+
import { LicensingPluginSetup, LicensingPluginStart } from '../../licensing/server';
1010
import { LicenseState } from './lib/license_state';
1111
import { registerSearchRoute } from './routes/search';
1212
import { registerExploreRoute } from './routes/explore';
@@ -34,6 +34,7 @@ export class GraphPlugin implements Plugin {
3434
licenseState.start(licensing.license$);
3535
this.licenseState = licenseState;
3636
core.savedObjects.registerType(graphWorkspace);
37+
licensing.featureUsage.register('Graph', 'platinum');
3738

3839
if (home) {
3940
registerSampleData(home.sampleData, licenseState);
@@ -79,7 +80,10 @@ export class GraphPlugin implements Plugin {
7980
registerExploreRoute({ licenseState, router });
8081
}
8182

82-
public start() {}
83+
public start(core: CoreStart, { licensing }: { licensing: LicensingPluginStart }) {
84+
this.licenseState!.setNotifyUsage(licensing.featureUsage.notifyUsage);
85+
}
86+
8387
public stop() {
8488
if (this.licenseState) {
8589
this.licenseState.stop();

x-pack/plugins/graph/server/routes/explore.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export function registerExploreRoute({
4242
response
4343
) => {
4444
verifyApiAccess(licenseState);
45+
licenseState.notifyUsage('Graph');
4546
try {
4647
return response.ok({
4748
body: {

x-pack/plugins/graph/server/routes/search.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export function registerSearchRoute({
4242
response
4343
) => {
4444
verifyApiAccess(licenseState);
45+
licenseState.notifyUsage('Graph');
4546
const includeFrozen = await uiSettings.get<boolean>(UI_SETTINGS.SEARCH_INCLUDE_FROZEN);
4647
try {
4748
return response.ok({

0 commit comments

Comments
 (0)