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 5 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
16 changes: 16 additions & 0 deletions x-pack/plugins/alerts/server/alert_type_registry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { TaskRunnerFactory } from './task_runner';
import { AlertTypeRegistry } from './alert_type_registry';
import { AlertType } from './types';
import { taskManagerMock } from '../../task_manager/server/mocks';
import { LicenseType } from '../../licensing/server';

const taskManager = taskManagerMock.createSetup();
const alertTypeRegistryParams = {
Expand Down Expand Up @@ -35,6 +36,7 @@ describe('has()', () => {
},
],
defaultActionGroupId: 'default',
minimumLicenseRequired: 'basic',
executor: jest.fn(),
producer: 'alerts',
});
Expand All @@ -54,6 +56,7 @@ describe('register()', () => {
},
],
defaultActionGroupId: 'default',
minimumLicenseRequired: 'basic' as LicenseType,
Copy link
Contributor

Choose a reason for hiding this comment

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

optional nit: Any place that requires casting to LicenseType can usually be fixed by making the alerType typed to AlertType. In this case, changing const alertType = { to const alertType: AlertType = { would do the trick.

executor: jest.fn(),
producer: 'alerts',
};
Expand Down Expand Up @@ -85,6 +88,7 @@ describe('register()', () => {
},
],
defaultActionGroupId: 'default',
minimumLicenseRequired: 'basic' as LicenseType,
executor: jest.fn(),
producer: 'alerts',
};
Expand All @@ -110,6 +114,7 @@ describe('register()', () => {
},
],
defaultActionGroupId: 'default',
minimumLicenseRequired: 'basic' as LicenseType,
executor: jest.fn(),
producer: 'alerts',
};
Expand Down Expand Up @@ -139,6 +144,7 @@ describe('register()', () => {
},
executor: jest.fn(),
producer: 'alerts',
minimumLicenseRequired: 'basic' as LicenseType,
};
const registry = new AlertTypeRegistry(alertTypeRegistryParams);
registry.register(alertType);
Expand Down Expand Up @@ -175,6 +181,7 @@ describe('register()', () => {
name: 'Back To Awesome',
},
defaultActionGroupId: 'default',
minimumLicenseRequired: 'basic' as LicenseType,
executor: jest.fn(),
producer: 'alerts',
};
Expand All @@ -198,6 +205,7 @@ describe('register()', () => {
},
],
defaultActionGroupId: 'default',
minimumLicenseRequired: 'basic' as LicenseType,
executor: jest.fn(),
producer: 'alerts',
};
Expand Down Expand Up @@ -227,6 +235,7 @@ describe('register()', () => {
},
],
defaultActionGroupId: 'default',
minimumLicenseRequired: 'basic' as LicenseType,
executor: jest.fn(),
producer: 'alerts',
};
Expand All @@ -248,6 +257,7 @@ describe('register()', () => {
},
],
defaultActionGroupId: 'default',
minimumLicenseRequired: 'basic',
executor: jest.fn(),
producer: 'alerts',
});
Expand All @@ -262,6 +272,7 @@ describe('register()', () => {
},
],
defaultActionGroupId: 'default',
minimumLicenseRequired: 'basic',
executor: jest.fn(),
producer: 'alerts',
})
Expand All @@ -282,6 +293,7 @@ describe('get()', () => {
},
],
defaultActionGroupId: 'default',
minimumLicenseRequired: 'basic',
executor: jest.fn(),
producer: 'alerts',
});
Expand All @@ -306,6 +318,7 @@ describe('get()', () => {
"defaultActionGroupId": "default",
"executor": [MockFunction],
"id": "test",
"minimumLicenseRequired": "basic",
"name": "Test",
"producer": "alerts",
"recoveryActionGroup": Object {
Expand Down Expand Up @@ -343,6 +356,7 @@ describe('list()', () => {
},
],
defaultActionGroupId: 'testActionGroup',
minimumLicenseRequired: 'basic',
executor: jest.fn(),
producer: 'alerts',
});
Expand All @@ -367,6 +381,7 @@ describe('list()', () => {
},
"defaultActionGroupId": "testActionGroup",
"id": "test",
"minimumLicenseRequired": "basic",
"name": "Test",
"producer": "alerts",
"recoveryActionGroup": Object {
Expand Down Expand Up @@ -419,6 +434,7 @@ function alertTypeWithVariables(id: string, context: string, state: string): Ale
name: `${id}-name`,
actionGroups: [],
defaultActionGroupId: id,
minimumLicenseRequired: 'basic' as LicenseType,
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
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ beforeEach(() => {
name: 'Test',
actionGroups: [{ id: 'default', name: 'Default' }],
defaultActionGroupId: 'default',
minimumLicenseRequired: 'basic',
recoveryActionGroup: RecoveredActionGroup,
async executor() {},
producer: 'alerts',
Expand All @@ -342,6 +343,7 @@ beforeEach(() => {
name: 'Test',
actionGroups: [{ id: 'default', name: 'Default' }],
defaultActionGroupId: 'default',
minimumLicenseRequired: 'basic',
recoveryActionGroup: RecoveredActionGroup,
async executor() {},
producer: 'alerts',
Expand Down
Loading