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

[7.x] Added UI support for the default action group for Alert Type Model (#57603) #58365

Merged
merged 1 commit into from
Feb 24, 2020
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -54,6 +54,7 @@ export const getLicenseExpiration = (
}),
},
],
defaultActionGroupId: 'default',
async executor({
services,
params,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export const signalRulesAlertType = ({
}),
},
],
defaultActionGroupId: 'default',
validate: {
params: schema.object({
description: schema.string(),
Expand Down
5 changes: 5 additions & 0 deletions x-pack/plugins/alerting/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,8 @@
export * from './alert';
export * from './alert_instance';
export * from './alert_task_instance';

export interface ActionGroup {
id: string;
name: string;
}
56 changes: 50 additions & 6 deletions x-pack/plugins/alerting/server/alert_type_registry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,13 @@ describe('has()', () => {
registry.register({
id: 'foo',
name: 'Foo',
actionGroups: [],
actionGroups: [
{
id: 'default',
name: 'Default',
},
],
defaultActionGroupId: 'default',
executor: jest.fn(),
});
expect(registry.has('foo')).toEqual(true);
Expand All @@ -39,7 +45,13 @@ describe('register()', () => {
const alertType = {
id: 'test',
name: 'Test',
actionGroups: [],
actionGroups: [
{
id: 'default',
name: 'Default',
},
],
defaultActionGroupId: 'default',
executor: jest.fn(),
};
// eslint-disable-next-line @typescript-eslint/no-var-requires
Expand All @@ -64,14 +76,26 @@ describe('register()', () => {
registry.register({
id: 'test',
name: 'Test',
actionGroups: [],
actionGroups: [
{
id: 'default',
name: 'Default',
},
],
defaultActionGroupId: 'default',
executor: jest.fn(),
});
expect(() =>
registry.register({
id: 'test',
name: 'Test',
actionGroups: [],
actionGroups: [
{
id: 'default',
name: 'Default',
},
],
defaultActionGroupId: 'default',
executor: jest.fn(),
})
).toThrowErrorMatchingInlineSnapshot(`"Alert type \\"test\\" is already registered."`);
Expand All @@ -84,13 +108,25 @@ describe('get()', () => {
registry.register({
id: 'test',
name: 'Test',
actionGroups: [],
actionGroups: [
{
id: 'default',
name: 'Default',
},
],
defaultActionGroupId: 'default',
executor: jest.fn(),
});
const alertType = registry.get('test');
expect(alertType).toMatchInlineSnapshot(`
Object {
"actionGroups": Array [],
"actionGroups": Array [
Object {
"id": "default",
"name": "Default",
},
],
"defaultActionGroupId": "default",
"executor": [MockFunction],
"id": "test",
"name": "Test",
Expand Down Expand Up @@ -124,12 +160,20 @@ describe('list()', () => {
name: 'Test Action Group',
},
],
defaultActionGroupId: 'testActionGroup',
executor: jest.fn(),
});
const result = registry.list();
expect(result).toMatchInlineSnapshot(`
Array [
Object {
"actionGroups": Array [
Object {
"id": "testActionGroup",
"name": "Test Action Group",
},
],
"defaultActionGroupId": "testActionGroup",
"id": "test",
"name": "Test",
},
Expand Down
2 changes: 2 additions & 0 deletions x-pack/plugins/alerting/server/alert_type_registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ export class AlertTypeRegistry {
return Array.from(this.alertTypes).map(([alertTypeId, alertType]) => ({
id: alertTypeId,
name: alertType.name,
actionGroups: alertType.actionGroups,
defaultActionGroupId: alertType.defaultActionGroupId,
}));
}
}
12 changes: 11 additions & 1 deletion x-pack/plugins/alerting/server/alerts_client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ describe('create()', () => {
id: '123',
name: 'Test',
actionGroups: [{ id: 'default', name: 'Default' }],
defaultActionGroupId: 'default',
async executor() {},
});
});
Expand Down Expand Up @@ -522,7 +523,13 @@ describe('create()', () => {
alertTypeRegistry.get.mockReturnValue({
id: '123',
name: 'Test',
actionGroups: [],
actionGroups: [
{
id: 'default',
name: 'Default',
},
],
defaultActionGroupId: 'default',
validate: {
params: schema.object({
param1: schema.string(),
Expand Down Expand Up @@ -1885,6 +1892,7 @@ describe('update()', () => {
id: '123',
name: 'Test',
actionGroups: [{ id: 'default', name: 'Default' }],
defaultActionGroupId: 'default',
async executor() {},
});
});
Expand Down Expand Up @@ -2415,6 +2423,7 @@ describe('update()', () => {
id: '123',
name: 'Test',
actionGroups: [{ id: 'default', name: 'Default' }],
defaultActionGroupId: 'default',
validate: {
params: schema.object({
param1: schema.string(),
Expand Down Expand Up @@ -2647,6 +2656,7 @@ describe('update()', () => {
id: '123',
name: 'Test',
actionGroups: [{ id: 'default', name: 'Default' }],
defaultActionGroupId: 'default',
async executor() {},
});
savedObjectsClient.bulkGet.mockResolvedValueOnce({
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/alerting/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export type AlertsClient = PublicMethodsOf<AlertsClientClass>;

export {
AlertType,
ActionGroup,
AlertingPlugin,
AlertExecutorOptions,
AlertActionParams,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@ test('should return passed in params when validation not defined', () => {
{
id: 'my-alert-type',
name: 'My description',
actionGroups: [],
actionGroups: [
{
id: 'default',
name: 'Default',
},
],
defaultActionGroupId: 'default',
async executor() {},
},
{
Expand All @@ -27,7 +33,13 @@ test('should validate and apply defaults when params is valid', () => {
{
id: 'my-alert-type',
name: 'My description',
actionGroups: [],
actionGroups: [
{
id: 'default',
name: 'Default',
},
],
defaultActionGroupId: 'default',
validate: {
params: schema.object({
param1: schema.string(),
Expand All @@ -50,7 +62,13 @@ test('should validate and throw error when params is invalid', () => {
{
id: 'my-alert-type',
name: 'My description',
actionGroups: [],
actionGroups: [
{
id: 'default',
name: 'Default',
},
],
defaultActionGroupId: 'default',
validate: {
params: schema.object({
param1: schema.string(),
Expand Down
24 changes: 21 additions & 3 deletions x-pack/plugins/alerting/server/routes/list_alert_types.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,13 @@ describe('listAlertTypesRoute', () => {
{
id: '1',
name: 'name',
actionGroups: [],
actionGroups: [
{
id: 'default',
name: 'Default',
},
],
defaultActionGroupId: 'default',
},
];

Expand All @@ -50,7 +56,13 @@ describe('listAlertTypesRoute', () => {
Object {
"body": Array [
Object {
"actionGroups": Array [],
"actionGroups": Array [
Object {
"id": "default",
"name": "Default",
},
],
"defaultActionGroupId": "default",
"id": "1",
"name": "name",
},
Expand Down Expand Up @@ -128,7 +140,13 @@ describe('listAlertTypesRoute', () => {
{
id: '1',
name: 'name',
actionGroups: [],
actionGroups: [
{
id: 'default',
name: 'Default',
},
],
defaultActionGroupId: 'default',
},
];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const alertType: AlertType = {
{ id: 'default', name: 'Default' },
{ id: 'other-group', name: 'Other Group' },
],
defaultActionGroupId: 'default',
executor: jest.fn(),
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const alertType = {
id: 'test',
name: 'My test alert',
actionGroups: [{ id: 'default', name: 'Default' }],
defaultActionGroupId: 'default',
executor: jest.fn(),
};
let fakeTimer: sinon.SinonFakeTimers;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const alertType = {
id: 'test',
name: 'My test alert',
actionGroups: [{ id: 'default', name: 'Default' }],
defaultActionGroupId: 'default',
executor: jest.fn(),
};
let fakeTimer: sinon.SinonFakeTimers;
Expand Down
8 changes: 2 additions & 6 deletions x-pack/plugins/alerting/server/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { AlertInstance } from './alert_instance';
import { AlertTypeRegistry as OrigAlertTypeRegistry } from './alert_type_registry';
import { PluginSetupContract, PluginStartContract } from './plugin';
import { SavedObjectAttributes, SavedObjectsClientContract } from '../../../../src/core/server';
import { Alert, AlertActionParams } from '../common';
import { Alert, AlertActionParams, ActionGroup } from '../common';
import { AlertsClient } from './alerts_client';
export * from '../common';

Expand Down Expand Up @@ -52,18 +52,14 @@ export interface AlertExecutorOptions {
updatedBy: string | null;
}

export interface ActionGroup {
id: string;
name: string;
}

export interface AlertType {
id: string;
name: string;
validate?: {
params?: { validate: (object: any) => any };
};
actionGroups: ActionGroup[];
defaultActionGroupId: ActionGroup['id'];
executor: ({ services, params, state }: AlertExecutorOptions) => Promise<State | void>;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ describe('loadAlertTypes', () => {
name: 'Test',
actionVariables: ['var1'],
actionGroups: [{ id: 'default', name: 'Default' }],
defaultActionGroupId: 'default',
},
];
http.get.mockResolvedValueOnce(resolvedValue);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ describe('alert_form', () => {
alertTypeRegistry.has.mockReturnValue(true);
actionTypeRegistry.list.mockReturnValue([actionType]);
actionTypeRegistry.has.mockReturnValue(true);
actionTypeRegistry.get.mockReturnValue(actionType);

const initialAlert = ({
name: 'test',
Expand Down
Loading