Skip to content

Commit

Permalink
Skip feature usage of basic action types
Browse files Browse the repository at this point in the history
  • Loading branch information
mikecote committed Sep 29, 2020
1 parent 718cab3 commit 91287d2
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 7 deletions.
29 changes: 27 additions & 2 deletions x-pack/plugins/actions/server/action_type_registry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ describe('register()', () => {
actionTypeRegistry.register({
id: 'my-action-type',
name: 'My action type',
minimumLicenseRequired: 'basic',
minimumLicenseRequired: 'gold',
executor,
});
expect(actionTypeRegistry.has('my-action-type')).toEqual(true);
Expand All @@ -73,7 +73,7 @@ describe('register()', () => {
`);
expect(actionTypeRegistryParams.licensing.featureUsage.register).toHaveBeenCalledWith(
'Connector: My action type',
'basic'
'gold'
);
});

Expand Down Expand Up @@ -129,6 +129,31 @@ describe('register()', () => {
expect(getRetry(0, new ExecutorError('my message', {}, undefined))).toEqual(false);
expect(getRetry(0, new ExecutorError('my message', {}, retryTime))).toEqual(retryTime);
});

test('registers gold+ action types to the licensing feature usage API', () => {
const actionTypeRegistry = new ActionTypeRegistry(actionTypeRegistryParams);
actionTypeRegistry.register({
id: 'my-action-type',
name: 'My action type',
minimumLicenseRequired: 'gold',
executor,
});
expect(actionTypeRegistryParams.licensing.featureUsage.register).toHaveBeenCalledWith(
'Connector: My action type',
'gold'
);
});

test(`doesn't register basic action types to the licensing feature usage API`, () => {
const actionTypeRegistry = new ActionTypeRegistry(actionTypeRegistryParams);
actionTypeRegistry.register({
id: 'my-action-type',
name: 'My action type',
minimumLicenseRequired: 'basic',
executor,
});
expect(actionTypeRegistryParams.licensing.featureUsage.register).not.toHaveBeenCalled();
});
});

describe('get()', () => {
Expand Down
11 changes: 7 additions & 4 deletions x-pack/plugins/actions/server/action_type_registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,13 @@ export class ActionTypeRegistry {
createTaskRunner: (context: RunContext) => this.taskRunnerFactory.create(context),
},
});
this.licensing.featureUsage.register(
getActionTypeFeatureUsageName(actionType as ActionType),
actionType.minimumLicenseRequired
);
// No need to notify usage on basic action types
if (actionType.minimumLicenseRequired !== 'basic') {
this.licensing.featureUsage.register(
getActionTypeFeatureUsageName(actionType as ActionType),
actionType.minimumLicenseRequired
);
}
}

/**
Expand Down
12 changes: 12 additions & 0 deletions x-pack/plugins/actions/server/lib/license_state.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,18 @@ describe('isLicenseValidForActionType', () => {
expect(mockNotifyUsage).not.toHaveBeenCalled();
});

test('should not call notifyUsage on basic action types', () => {
const basicLicense = licensingMock.createLicense({
license: { status: 'active', type: 'basic' },
});
license.next(basicLicense);
licenseState.isLicenseValidForActionType({
...fooActionType,
minimumLicenseRequired: 'basic',
});
expect(mockNotifyUsage).not.toHaveBeenCalled();
});

test('should call notifyUsage when specified', () => {
const goldLicense = licensingMock.createLicense({
license: { status: 'active', type: 'gold' },
Expand Down
3 changes: 2 additions & 1 deletion x-pack/plugins/actions/server/lib/license_state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ export class LicenseState {
}

private notifyUsage(actionType: ActionType) {
if (this._notifyUsage) {
// No need to notify usage on basic action types
if (this._notifyUsage && actionType.minimumLicenseRequired !== 'basic') {
this._notifyUsage(getActionTypeFeatureUsageName(actionType));
}
}
Expand Down

0 comments on commit 91287d2

Please sign in to comment.