Skip to content

Commit

Permalink
Define minimum license required for each alert type
Browse files Browse the repository at this point in the history
  • Loading branch information
YulNaumenko committed Dec 4, 2020
1 parent 3b92fa2 commit f426a70
Show file tree
Hide file tree
Showing 52 changed files with 213 additions and 17 deletions.
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',
async executor({ services, params }) {
const { outerSpaceCapacity, craft: craftToTriggerBy, op } = params;
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 @@ -171,6 +171,7 @@ server.newPlatform.setup.plugins.alerts.registerType({
{ name: 'cpuUsage', description: 'CPU usage' },
],
},
minimumLicenseRequired: 'basic',
async executor({
alertId,
startedAt,
Expand Down Expand Up @@ -238,6 +239,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,13 +4,16 @@
* 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;
actionGroups: ActionGroup[];
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',
producer: 'alerts',
},
];
Expand All @@ -45,6 +46,7 @@ describe('loadAlertType', () => {
actionVariables: ['var1'],
actionGroups: [{ id: 'default', name: 'Default' }],
defaultActionGroupId: 'default',
minimumLicenseRequired: 'basic',
producer: 'alerts',
};
http.get.mockResolvedValueOnce([alertType]);
Expand All @@ -65,6 +67,7 @@ describe('loadAlertType', () => {
actionVariables: [],
actionGroups: [{ id: 'default', name: 'Default' }],
defaultActionGroupId: 'default',
minimumLicenseRequired: 'basic',
producer: 'alerts',
};
http.get.mockResolvedValueOnce([alertType]);
Expand All @@ -80,6 +83,7 @@ describe('loadAlertType', () => {
actionVariables: [],
actionGroups: [{ id: 'default', name: 'Default' }],
defaultActionGroupId: 'default',
minimumLicenseRequired: 'basic',
producer: 'alerts',
},
]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const mockAlertType = (id: string): AlertType => ({
actionVariables: [],
defaultActionGroupId: 'default',
producer: 'alerts',
minimumLicenseRequired: 'basic',
});

describe('AlertNavigationRegistry', () => {
Expand Down
12 changes: 12 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,
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 All @@ -133,6 +138,7 @@ describe('register()', () => {
},
],
defaultActionGroupId: 'default',
minimumLicenseRequired: 'basic' as LicenseType,
executor: jest.fn(),
producer: 'alerts',
};
Expand Down Expand Up @@ -162,6 +168,7 @@ describe('register()', () => {
},
],
defaultActionGroupId: 'default',
minimumLicenseRequired: 'basic' as LicenseType,
executor: jest.fn(),
producer: 'alerts',
};
Expand All @@ -183,6 +190,7 @@ describe('register()', () => {
},
],
defaultActionGroupId: 'default',
minimumLicenseRequired: 'basic',
executor: jest.fn(),
producer: 'alerts',
});
Expand All @@ -197,6 +205,7 @@ describe('register()', () => {
},
],
defaultActionGroupId: 'default',
minimumLicenseRequired: 'basic',
executor: jest.fn(),
producer: 'alerts',
})
Expand All @@ -217,6 +226,7 @@ describe('get()', () => {
},
],
defaultActionGroupId: 'default',
minimumLicenseRequired: 'basic',
executor: jest.fn(),
producer: 'alerts',
});
Expand Down Expand Up @@ -274,6 +284,7 @@ describe('list()', () => {
},
],
defaultActionGroupId: 'testActionGroup',
minimumLicenseRequired: 'basic',
executor: jest.fn(),
producer: 'alerts',
});
Expand Down Expand Up @@ -346,6 +357,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
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ describe('aggregate()', () => {
actionGroups: [],
actionVariables: undefined,
defaultActionGroupId: 'default',
minimumLicenseRequired: 'basic',
id: 'myType',
name: 'myType',
producer: 'myApp',
Expand Down Expand Up @@ -102,6 +103,7 @@ describe('aggregate()', () => {
name: 'Test',
actionGroups: [{ id: 'default', name: 'Default' }],
defaultActionGroupId: 'default',
minimumLicenseRequired: 'basic',
producer: 'alerts',
authorizedConsumers: {
myApp: { read: true, all: true },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,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 @@ -54,6 +54,7 @@ describe('find()', () => {
actionGroups: [],
actionVariables: undefined,
defaultActionGroupId: 'default',
minimumLicenseRequired: 'basic',
id: 'myType',
name: 'myType',
producer: 'myApp',
Expand Down Expand Up @@ -109,6 +110,7 @@ describe('find()', () => {
name: 'Test',
actionGroups: [{ id: 'default', name: 'Default' }],
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 @@ -83,6 +83,7 @@ export function getBeforeSetup(
name: 'Test',
actionGroups: [{ id: 'default', name: 'Default' }],
defaultActionGroupId: 'default',
minimumLicenseRequired: 'basic',
async executor() {},
producer: 'alerts',
}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ describe('listAlertTypes', () => {
actionGroups: [],
actionVariables: undefined,
defaultActionGroupId: 'default',
minimumLicenseRequired: 'basic',
id: 'alertingAlertType',
name: 'alertingAlertType',
producer: 'alerts',
Expand All @@ -58,6 +59,7 @@ describe('listAlertTypes', () => {
actionGroups: [],
actionVariables: undefined,
defaultActionGroupId: 'default',
minimumLicenseRequired: 'basic',
id: 'myAppAlertType',
name: 'myAppAlertType',
producer: 'myApp',
Expand Down Expand Up @@ -96,6 +98,7 @@ describe('listAlertTypes', () => {
actionGroups: [],
actionVariables: undefined,
defaultActionGroupId: 'default',
minimumLicenseRequired: 'basic',
id: 'myType',
name: 'myType',
producer: 'myApp',
Expand All @@ -105,6 +108,7 @@ describe('listAlertTypes', () => {
name: 'Test',
actionGroups: [{ id: 'default', name: 'Default' }],
defaultActionGroupId: 'default',
minimumLicenseRequired: 'basic',
producer: 'alerts',
},
]);
Expand All @@ -119,6 +123,7 @@ describe('listAlertTypes', () => {
name: 'Test',
actionGroups: [{ id: 'default', name: 'Default' }],
defaultActionGroupId: 'default',
minimumLicenseRequired: 'basic',
producer: 'alerts',
authorizedConsumers: {
myApp: { read: true, all: true },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ describe('update()', () => {
name: 'Test',
actionGroups: [{ id: 'default', name: 'Default' }],
defaultActionGroupId: 'default',
minimumLicenseRequired: 'basic',
async executor() {},
producer: 'alerts',
});
Expand Down Expand Up @@ -676,6 +677,7 @@ describe('update()', () => {
name: 'Test',
actionGroups: [{ id: 'default', name: 'Default' }],
defaultActionGroupId: 'default',
minimumLicenseRequired: 'basic',
validate: {
params: schema.object({
param1: schema.string(),
Expand Down Expand Up @@ -1021,6 +1023,7 @@ describe('update()', () => {
name: 'Test',
actionGroups: [{ id: 'default', name: 'Default' }],
defaultActionGroupId: 'default',
minimumLicenseRequired: 'basic',
async executor() {},
producer: 'alerts',
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@ beforeEach(() => {
name: 'Test',
actionGroups: [{ id: 'default', name: 'Default' }],
defaultActionGroupId: 'default',
minimumLicenseRequired: 'basic',
async executor() {},
producer: 'alerts',
}));
Expand All @@ -340,6 +341,7 @@ beforeEach(() => {
name: 'Test',
actionGroups: [{ id: 'default', name: 'Default' }],
defaultActionGroupId: 'default',
minimumLicenseRequired: 'basic',
async executor() {},
producer: 'alerts',
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ beforeEach(() => {
name: 'My Alert Type',
actionGroups: [{ id: 'default', name: 'Default' }],
defaultActionGroupId: 'default',
minimumLicenseRequired: 'basic',
async executor() {},
producer: 'myApp',
}));
Expand Down Expand Up @@ -534,6 +535,7 @@ describe('AlertsAuthorization', () => {
actionGroups: [],
actionVariables: undefined,
defaultActionGroupId: 'default',
minimumLicenseRequired: 'basic',
id: 'myOtherAppAlertType',
name: 'myOtherAppAlertType',
producer: 'alerts',
Expand All @@ -542,6 +544,7 @@ describe('AlertsAuthorization', () => {
actionGroups: [],
actionVariables: undefined,
defaultActionGroupId: 'default',
minimumLicenseRequired: 'basic',
id: 'myAppAlertType',
name: 'myAppAlertType',
producer: 'myApp',
Expand All @@ -550,6 +553,7 @@ describe('AlertsAuthorization', () => {
actionGroups: [],
actionVariables: undefined,
defaultActionGroupId: 'default',
minimumLicenseRequired: 'basic',
id: 'mySecondAppAlertType',
name: 'mySecondAppAlertType',
producer: 'myApp',
Expand Down Expand Up @@ -824,6 +828,7 @@ describe('AlertsAuthorization', () => {
actionGroups: [],
actionVariables: undefined,
defaultActionGroupId: 'default',
minimumLicenseRequired: 'basic',
id: 'myOtherAppAlertType',
name: 'myOtherAppAlertType',
producer: 'myOtherApp',
Expand All @@ -832,6 +837,7 @@ describe('AlertsAuthorization', () => {
actionGroups: [],
actionVariables: undefined,
defaultActionGroupId: 'default',
minimumLicenseRequired: 'basic',
id: 'myAppAlertType',
name: 'myAppAlertType',
producer: 'myApp',
Expand Down
Loading

0 comments on commit f426a70

Please sign in to comment.