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

[Alerts][License] Define minimum license required for each alert type #84997

Merged
Show file tree
Hide file tree
Changes from 8 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
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export const alertType: AlertType<AlwaysFiringParams> = {
name: 'Always firing',
actionGroups: ACTION_GROUPS,
defaultActionGroupId: DEFAULT_ACTION_GROUP,
minimumLicenseRequired: 'basic',
async executor({
services,
params: { instances = DEFAULT_INSTANCES_TO_GENERATE, thresholds },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export const alertType: AlertType = {
id: 'example.people-in-space',
name: 'People In Space Right Now',
actionGroups: [{ id: 'default', name: 'default' }],
minimumLicenseRequired: 'basic',
defaultActionGroupId: 'default',
recoveryActionGroup: {
id: 'hasLandedBackOnEarth',
Expand Down
2 changes: 2 additions & 0 deletions x-pack/plugins/alerts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ server.newPlatform.setup.plugins.alerts.registerType({
{ name: 'cpuUsage', description: 'CPU usage' },
],
},
minimumLicenseRequired: 'basic',
async executor({
alertId,
startedAt,
Expand Down Expand Up @@ -239,6 +240,7 @@ server.newPlatform.setup.plugins.alerts.registerType({
},
],
defaultActionGroupId: 'default',
minimumLicenseRequired: 'basic',
actionVariables: {
context: [
{ name: 'server', description: 'the server' },
Expand Down
3 changes: 3 additions & 0 deletions x-pack/plugins/alerts/common/alert_type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { LicenseType } from '../../licensing/common/types';

export interface AlertType {
id: string;
name: string;
Expand All @@ -12,6 +14,7 @@ export interface AlertType {
actionVariables: string[];
defaultActionGroupId: ActionGroup['id'];
producer: string;
minimumLicenseRequired: LicenseType;
}

export interface ActionGroup {
Expand Down
4 changes: 4 additions & 0 deletions x-pack/plugins/alerts/public/alert_api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ describe('loadAlertTypes', () => {
actionVariables: ['var1'],
actionGroups: [{ id: 'default', name: 'Default' }],
defaultActionGroupId: 'default',
minimumLicenseRequired: 'basic',
recoveryActionGroup: RecoveredActionGroup,
producer: 'alerts',
},
Expand All @@ -46,6 +47,7 @@ describe('loadAlertType', () => {
actionVariables: ['var1'],
actionGroups: [{ id: 'default', name: 'Default' }],
defaultActionGroupId: 'default',
minimumLicenseRequired: 'basic',
recoveryActionGroup: RecoveredActionGroup,
producer: 'alerts',
};
Expand All @@ -67,6 +69,7 @@ describe('loadAlertType', () => {
actionVariables: [],
actionGroups: [{ id: 'default', name: 'Default' }],
defaultActionGroupId: 'default',
minimumLicenseRequired: 'basic',
recoveryActionGroup: RecoveredActionGroup,
producer: 'alerts',
};
Expand All @@ -83,6 +86,7 @@ describe('loadAlertType', () => {
actionVariables: [],
actionGroups: [{ id: 'default', name: 'Default' }],
defaultActionGroupId: 'default',
minimumLicenseRequired: 'basic',
recoveryActionGroup: RecoveredActionGroup,
producer: 'alerts',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const mockAlertType = (id: string): AlertType => ({
actionVariables: [],
defaultActionGroupId: 'default',
producer: 'alerts',
minimumLicenseRequired: 'basic',
});

describe('AlertNavigationRegistry', () => {
Expand Down
29 changes: 22 additions & 7 deletions x-pack/plugins/alerts/server/alert_type_registry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ describe('has()', () => {
},
],
defaultActionGroupId: 'default',
minimumLicenseRequired: 'basic',
executor: jest.fn(),
producer: 'alerts',
});
Expand All @@ -44,7 +45,7 @@ describe('has()', () => {

describe('register()', () => {
test('throws if AlertType Id contains invalid characters', () => {
const alertType = {
const alertType: AlertType = {
id: 'test',
name: 'Test',
actionGroups: [
Expand All @@ -54,6 +55,7 @@ describe('register()', () => {
},
],
defaultActionGroupId: 'default',
minimumLicenseRequired: 'basic',
executor: jest.fn(),
producer: 'alerts',
};
Expand All @@ -75,7 +77,7 @@ describe('register()', () => {
});

test('throws if AlertType Id isnt a string', () => {
const alertType = {
const alertType: AlertType = {
id: (123 as unknown) as string,
name: 'Test',
actionGroups: [
Expand All @@ -85,6 +87,7 @@ describe('register()', () => {
},
],
defaultActionGroupId: 'default',
minimumLicenseRequired: 'basic',
executor: jest.fn(),
producer: 'alerts',
};
Expand All @@ -96,7 +99,7 @@ describe('register()', () => {
});

test('throws if AlertType action groups contains reserved group id', () => {
const alertType = {
const alertType: AlertType = {
id: 'test',
name: 'Test',
actionGroups: [
Expand All @@ -110,6 +113,7 @@ describe('register()', () => {
},
],
defaultActionGroupId: 'default',
minimumLicenseRequired: 'basic',
executor: jest.fn(),
producer: 'alerts',
};
Expand All @@ -123,7 +127,7 @@ describe('register()', () => {
});

test('allows an AlertType to specify a custom recovery group', () => {
const alertType = {
const alertType: AlertType = {
id: 'test',
name: 'Test',
actionGroups: [
Expand All @@ -139,6 +143,7 @@ describe('register()', () => {
},
executor: jest.fn(),
producer: 'alerts',
minimumLicenseRequired: 'basic',
};
const registry = new AlertTypeRegistry(alertTypeRegistryParams);
registry.register(alertType);
Expand All @@ -157,7 +162,7 @@ describe('register()', () => {
});

test('throws if the custom recovery group is contained in the AlertType action groups', () => {
const alertType = {
const alertType: AlertType = {
id: 'test',
name: 'Test',
actionGroups: [
Expand All @@ -175,6 +180,7 @@ describe('register()', () => {
name: 'Back To Awesome',
},
defaultActionGroupId: 'default',
minimumLicenseRequired: 'basic',
executor: jest.fn(),
producer: 'alerts',
};
Expand All @@ -188,7 +194,7 @@ describe('register()', () => {
});

test('registers the executor with the task manager', () => {
const alertType = {
const alertType: AlertType = {
id: 'test',
name: 'Test',
actionGroups: [
Expand All @@ -198,6 +204,7 @@ describe('register()', () => {
},
],
defaultActionGroupId: 'default',
minimumLicenseRequired: 'basic',
executor: jest.fn(),
producer: 'alerts',
};
Expand Down Expand Up @@ -227,6 +234,7 @@ describe('register()', () => {
},
],
defaultActionGroupId: 'default',
minimumLicenseRequired: 'basic',
executor: jest.fn(),
producer: 'alerts',
};
Expand All @@ -248,6 +256,7 @@ describe('register()', () => {
},
],
defaultActionGroupId: 'default',
minimumLicenseRequired: 'basic',
executor: jest.fn(),
producer: 'alerts',
});
Expand All @@ -262,6 +271,7 @@ describe('register()', () => {
},
],
defaultActionGroupId: 'default',
minimumLicenseRequired: 'basic',
executor: jest.fn(),
producer: 'alerts',
})
Expand All @@ -282,6 +292,7 @@ describe('get()', () => {
},
],
defaultActionGroupId: 'default',
minimumLicenseRequired: 'basic',
executor: jest.fn(),
producer: 'alerts',
});
Expand All @@ -306,6 +317,7 @@ describe('get()', () => {
"defaultActionGroupId": "default",
"executor": [MockFunction],
"id": "test",
"minimumLicenseRequired": "basic",
"name": "Test",
"producer": "alerts",
"recoveryActionGroup": Object {
Expand Down Expand Up @@ -343,6 +355,7 @@ describe('list()', () => {
},
],
defaultActionGroupId: 'testActionGroup',
minimumLicenseRequired: 'basic',
executor: jest.fn(),
producer: 'alerts',
});
Expand All @@ -367,6 +380,7 @@ describe('list()', () => {
},
"defaultActionGroupId": "testActionGroup",
"id": "test",
"minimumLicenseRequired": "basic",
"name": "Test",
"producer": "alerts",
"recoveryActionGroup": Object {
Expand Down Expand Up @@ -414,11 +428,12 @@ describe('list()', () => {
});

function alertTypeWithVariables(id: string, context: string, state: string): AlertType {
const baseAlert = {
const baseAlert: AlertType = {
id,
name: `${id}-name`,
actionGroups: [],
defaultActionGroupId: id,
minimumLicenseRequired: 'basic',
async executor() {},
producer: 'alerts',
};
Expand Down
2 changes: 2 additions & 0 deletions x-pack/plugins/alerts/server/alert_type_registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ export class AlertTypeRegistry {
defaultActionGroupId,
actionVariables,
producer,
minimumLicenseRequired,
},
]: [string, NormalizedAlertType]) => ({
id,
Expand All @@ -155,6 +156,7 @@ export class AlertTypeRegistry {
defaultActionGroupId,
actionVariables,
producer,
minimumLicenseRequired,
})
)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ describe('aggregate()', () => {
actionGroups: [],
actionVariables: undefined,
defaultActionGroupId: 'default',
minimumLicenseRequired: 'basic',
recoveryActionGroup: RecoveredActionGroup,
id: 'myType',
name: 'myType',
Expand Down Expand Up @@ -104,6 +105,7 @@ describe('aggregate()', () => {
name: 'Test',
actionGroups: [{ id: 'default', name: 'Default' }],
defaultActionGroupId: 'default',
minimumLicenseRequired: 'basic',
recoveryActionGroup: RecoveredActionGroup,
producer: 'alerts',
authorizedConsumers: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,7 @@ describe('create()', () => {
threshold: schema.number({ min: 0, max: 1 }),
}),
},
minimumLicenseRequired: 'basic',
async executor() {},
producer: 'alerts',
});
Expand Down
2 changes: 2 additions & 0 deletions x-pack/plugins/alerts/server/alerts_client/tests/find.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ describe('find()', () => {
recoveryActionGroup: RecoveredActionGroup,
actionVariables: undefined,
defaultActionGroupId: 'default',
minimumLicenseRequired: 'basic',
id: 'myType',
name: 'myType',
producer: 'myApp',
Expand Down Expand Up @@ -115,6 +116,7 @@ describe('find()', () => {
actionGroups: [{ id: 'default', name: 'Default' }],
recoveryActionGroup: RecoveredActionGroup,
defaultActionGroupId: 'default',
minimumLicenseRequired: 'basic',
producer: 'alerts',
authorizedConsumers: {
myApp: { read: true, all: true },
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/alerts/server/alerts_client/tests/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ export function getBeforeSetup(
actionGroups: [{ id: 'default', name: 'Default' }],
recoveryActionGroup: RecoveredActionGroup,
defaultActionGroupId: 'default',
minimumLicenseRequired: 'basic',
async executor() {},
producer: 'alerts',
}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ describe('listAlertTypes', () => {
actionGroups: [],
actionVariables: undefined,
defaultActionGroupId: 'default',
minimumLicenseRequired: 'basic',
recoveryActionGroup: RecoveredActionGroup,
id: 'alertingAlertType',
name: 'alertingAlertType',
Expand All @@ -60,6 +61,7 @@ describe('listAlertTypes', () => {
actionGroups: [],
actionVariables: undefined,
defaultActionGroupId: 'default',
minimumLicenseRequired: 'basic',
recoveryActionGroup: RecoveredActionGroup,
id: 'myAppAlertType',
name: 'myAppAlertType',
Expand Down Expand Up @@ -99,6 +101,7 @@ describe('listAlertTypes', () => {
actionGroups: [],
actionVariables: undefined,
defaultActionGroupId: 'default',
minimumLicenseRequired: 'basic',
recoveryActionGroup: RecoveredActionGroup,
id: 'myType',
name: 'myType',
Expand All @@ -109,6 +112,7 @@ describe('listAlertTypes', () => {
name: 'Test',
actionGroups: [{ id: 'default', name: 'Default' }],
defaultActionGroupId: 'default',
minimumLicenseRequired: 'basic',
recoveryActionGroup: RecoveredActionGroup,
producer: 'alerts',
},
Expand All @@ -124,6 +128,7 @@ describe('listAlertTypes', () => {
name: 'Test',
actionGroups: [{ id: 'default', name: 'Default' }],
defaultActionGroupId: 'default',
minimumLicenseRequired: 'basic',
recoveryActionGroup: RecoveredActionGroup,
producer: 'alerts',
authorizedConsumers: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ describe('update()', () => {
name: 'Test',
actionGroups: [{ id: 'default', name: 'Default' }],
defaultActionGroupId: 'default',
minimumLicenseRequired: 'basic',
recoveryActionGroup: RecoveredActionGroup,
async executor() {},
producer: 'alerts',
Expand Down Expand Up @@ -682,6 +683,7 @@ describe('update()', () => {
name: 'Test',
actionGroups: [{ id: 'default', name: 'Default' }],
defaultActionGroupId: 'default',
minimumLicenseRequired: 'basic',
recoveryActionGroup: RecoveredActionGroup,
validate: {
params: schema.object({
Expand Down Expand Up @@ -1028,6 +1030,7 @@ describe('update()', () => {
name: 'Test',
actionGroups: [{ id: 'default', name: 'Default' }],
defaultActionGroupId: 'default',
minimumLicenseRequired: 'basic',
recoveryActionGroup: RecoveredActionGroup,
async executor() {},
producer: 'alerts',
Expand Down
Loading