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

[Actions] Notify only on action group change #82969

Merged
merged 60 commits into from
Dec 10, 2020
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
01c7c7d
plugged Task Manager lifecycle into status reactively
gmmorris Nov 3, 2020
e9f2cd0
fixed tests
gmmorris Nov 5, 2020
42395e9
Revert "fixed tests"
gmmorris Nov 5, 2020
6d00ce8
made action group fields optional
gmmorris Nov 5, 2020
2730301
Merge branch 'master' into alerts/assign-action-groups
gmmorris Nov 5, 2020
89deeca
revert deletion
gmmorris Nov 5, 2020
73fe0a8
again
gmmorris Nov 5, 2020
401d99f
Merge branch 'master' into alerts/assign-action-groups
gmmorris Nov 5, 2020
78873a1
extracted action type for mto its own component
gmmorris Nov 5, 2020
85a1068
extracted more sections of the action form to their own components
gmmorris Nov 5, 2020
44eb670
updated icon
gmmorris Nov 5, 2020
4b36391
added docs
gmmorris Nov 5, 2020
afc6e81
fixed always firing alert
gmmorris Nov 5, 2020
38fb659
fixed export of components
gmmorris Nov 5, 2020
6fe4ae4
fixed react warning
gmmorris Nov 6, 2020
f68763e
Merge branch 'master' of https://github.com/elastic/kibana into pr/82472
ymao1 Nov 6, 2020
9d1f594
Adding flag for notifying on state change
ymao1 Nov 6, 2020
9005c1e
Updating logic in task runner
ymao1 Nov 6, 2020
1422911
Starting to update tests
ymao1 Nov 6, 2020
7b7f3c8
Merge branch 'master' of https://github.com/elastic/kibana into alert…
ymao1 Nov 9, 2020
a0e3ac5
Merge branch 'master' of https://github.com/elastic/kibana into alert…
ymao1 Nov 9, 2020
d37288c
Adding tests
ymao1 Nov 9, 2020
e0fa427
Merging in master
ymao1 Nov 9, 2020
22b7a00
Fixing types check
ymao1 Nov 9, 2020
a075514
Tests and types
ymao1 Nov 9, 2020
8311ab8
Tests
ymao1 Nov 9, 2020
e21ea91
Tests
ymao1 Nov 9, 2020
5e0ee21
Tests
ymao1 Nov 9, 2020
f81b436
Tests
ymao1 Nov 9, 2020
df7d7af
Tests
ymao1 Nov 9, 2020
6fa36a2
Merging in master
ymao1 Nov 23, 2020
4896a35
Renaming field to a more descriptive name. Adding migrations
ymao1 Nov 23, 2020
13fea7b
Renaming field to a more descriptive name. Adding migrations
ymao1 Nov 23, 2020
8f94818
Merge branch 'master' of https://github.com/elastic/kibana into alert…
ymao1 Nov 23, 2020
2932b4e
Fixing tests
ymao1 Nov 24, 2020
4e65be8
Merge branch 'master' of https://github.com/elastic/kibana into alert…
ymao1 Dec 7, 2020
7b57ff8
Type check and tests
ymao1 Dec 8, 2020
f062f95
Moving schedule and notify interval to bottom of flyout. Implementing…
ymao1 Dec 8, 2020
a3eac70
Merge branch 'master' of https://github.com/elastic/kibana into alert…
ymao1 Dec 8, 2020
ff0ef3b
Changing boolean flag to enum type and updating in triggers_actions_ui
ymao1 Dec 8, 2020
e331498
Changing boolean flag to enum type and updating in alerts plugin
ymao1 Dec 8, 2020
d778639
Fixing types check
ymao1 Dec 8, 2020
e31ee56
Fixing monitoring jest tests
ymao1 Dec 8, 2020
01dbeb4
Changing last references to old variable names
ymao1 Dec 8, 2020
2e26609
Merging in master
ymao1 Dec 8, 2020
35f60eb
Moving form inputs back to the top
ymao1 Dec 8, 2020
819d959
Renaming to alert_notify_when
ymao1 Dec 8, 2020
f835ef1
Updating functional tests
ymao1 Dec 8, 2020
2b5c53c
Adding new functional test for notifyWhen onActionGroupChange
ymao1 Dec 8, 2020
9a4b5d4
Merge branch 'master' of https://github.com/elastic/kibana into alert…
ymao1 Dec 8, 2020
9697efd
Merging in master
ymao1 Dec 9, 2020
1adf049
Updating wording
ymao1 Dec 9, 2020
3b1813a
Merging in master
ymao1 Dec 9, 2020
38bd887
Merging in master
ymao1 Dec 10, 2020
b2f6610
Incorporating action subgroups into logic
ymao1 Dec 10, 2020
6765bab
PR fixes
ymao1 Dec 10, 2020
86deabd
Updating functional test
ymao1 Dec 10, 2020
85ed885
Fixing types check
ymao1 Dec 10, 2020
dd3b29a
Changing default throttle interval to hour
ymao1 Dec 10, 2020
46e8025
Fixing types check
ymao1 Dec 10, 2020
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
1 change: 1 addition & 0 deletions x-pack/plugins/alerts/common/alert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export interface Alert {
apiKey: string | null;
apiKeyOwner: string | null;
throttle: string | null;
notifyOnStateChange: boolean;
muteAll: boolean;
mutedInstanceIds: string[];
executionStatus: AlertExecutionStatus;
Expand Down
51 changes: 51 additions & 0 deletions x-pack/plugins/alerts/server/alert_instance/alert_instance.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,57 @@ describe('isThrottled', () => {
});
});

describe('actionGroupHasChanged()', () => {
test('should be false if no last scheduled and nothing scheduled', () => {
const alertInstance = new AlertInstance();
expect(alertInstance.actionGroupHasChanged()).toEqual(false);
});

test('should be false if group does not change', () => {
const alertInstance = new AlertInstance({
meta: {
lastScheduledActions: {
date: new Date(),
group: 'default',
},
},
});
alertInstance.scheduleActions('default');
expect(alertInstance.actionGroupHasChanged()).toEqual(false);
});

test('should be true if no last scheduled and group is scheduled', () => {
const alertInstance = new AlertInstance();
alertInstance.scheduleActions('default');
expect(alertInstance.actionGroupHasChanged()).toEqual(true);
});

test('should be true if last scheduled group and next action is undefined', () => {
const alertInstance = new AlertInstance({
meta: {
lastScheduledActions: {
date: new Date(),
group: 'default',
},
},
});
expect(alertInstance.actionGroupHasChanged()).toEqual(true);
});

test('should be true if group does change', () => {
const alertInstance = new AlertInstance({
meta: {
lastScheduledActions: {
date: new Date(),
group: 'default',
},
},
});
alertInstance.scheduleActions('penguin');
expect(alertInstance.actionGroupHasChanged()).toEqual(true);
});
});

describe('getScheduledActionOptions()', () => {
test('defaults to undefined', () => {
const alertInstance = new AlertInstance();
Expand Down
4 changes: 4 additions & 0 deletions x-pack/plugins/alerts/server/alert_instance/alert_instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ export class AlertInstance<
return false;
}

actionGroupHasChanged(): boolean {
return this.scheduledExecutionOptions?.actionGroup !== this.meta?.lastScheduledActions?.group;
}

getScheduledActionOptions() {
return this.scheduledExecutionOptions;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ interface UpdateOptions {
actions: NormalizedAlertAction[];
params: Record<string, unknown>;
throttle: string | null;
notifyOnStateChange: boolean;
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ function getMockData(overwrites: Record<string, unknown> = {}): CreateOptions['d
consumer: 'bar',
schedule: { interval: '10s' },
throttle: null,
notifyOnStateChange: false,
params: {
bar: true,
},
Expand Down Expand Up @@ -273,6 +274,7 @@ describe('create()', () => {
"muteAll": false,
"mutedInstanceIds": Array [],
"name": "abc",
"notifyOnStateChange": false,
"params": Object {
"bar": true,
},
Expand Down Expand Up @@ -321,6 +323,7 @@ describe('create()', () => {
"muteAll": false,
"mutedInstanceIds": Array [],
"name": "abc",
"notifyOnStateChange": false,
"params": Object {
"bar": true,
},
Expand Down Expand Up @@ -964,6 +967,7 @@ describe('create()', () => {
},
schedule: { interval: '10s' },
throttle: null,
notifyOnStateChange: false,
muteAll: false,
mutedInstanceIds: [],
tags: ['foo'],
Expand Down Expand Up @@ -1085,6 +1089,7 @@ describe('create()', () => {
},
schedule: { interval: '10s' },
throttle: null,
notifyOnStateChange: false,
muteAll: false,
mutedInstanceIds: [],
tags: ['foo'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ const BaseAlertInstanceSummarySavedObject: SavedObject<RawAlert> = {
apiKey: null,
apiKeyOwner: null,
throttle: null,
notifyOnStateChange: false,
muteAll: false,
mutedInstanceIds: [],
executionStatus: {
Expand Down
17 changes: 17 additions & 0 deletions x-pack/plugins/alerts/server/alerts_client/tests/update.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ describe('update()', () => {
scheduledTaskId: 'task-123',
params: {},
throttle: null,
notifyOnStateChange: false,
actions: [
{
group: 'default',
Expand Down Expand Up @@ -171,6 +172,7 @@ describe('update()', () => {
bar: true,
},
throttle: null,
notifyOnStateChange: false,
actions: [
{
group: 'default',
Expand Down Expand Up @@ -281,6 +283,7 @@ describe('update()', () => {
"versionApiKeyLastmodified": "v7.10.0",
},
"name": "abc",
"notifyOnStateChange": false,
"params": Object {
"bar": true,
},
Expand Down Expand Up @@ -386,6 +389,7 @@ describe('update()', () => {
bar: true,
},
throttle: '5m',
notifyOnStateChange: false,
actions: [
{
group: 'default',
Expand Down Expand Up @@ -447,6 +451,7 @@ describe('update()', () => {
"versionApiKeyLastmodified": "v7.10.0",
},
"name": "abc",
"notifyOnStateChange": false,
"params": Object {
"bar": true,
},
Expand Down Expand Up @@ -540,6 +545,7 @@ describe('update()', () => {
bar: true,
},
throttle: '5m',
notifyOnStateChange: false,
actions: [
{
group: 'default',
Expand Down Expand Up @@ -602,6 +608,7 @@ describe('update()', () => {
"versionApiKeyLastmodified": "v7.10.0",
},
"name": "abc",
"notifyOnStateChange": false,
"params": Object {
"bar": true,
},
Expand Down Expand Up @@ -657,6 +664,7 @@ describe('update()', () => {
bar: true,
},
throttle: null,
notifyOnStateChange: false,
actions: [
{
group: 'default',
Expand Down Expand Up @@ -785,6 +793,7 @@ describe('update()', () => {
bar: true,
},
throttle: null,
notifyOnStateChange: false,
actions: [
{
group: 'default',
Expand Down Expand Up @@ -892,6 +901,7 @@ describe('update()', () => {
bar: true,
},
throttle: '5m',
notifyOnStateChange: false,
actions: [
{
group: 'default',
Expand Down Expand Up @@ -953,6 +963,7 @@ describe('update()', () => {
bar: true,
},
throttle: null,
notifyOnStateChange: false,
actions: [
{
group: 'default',
Expand Down Expand Up @@ -1071,6 +1082,7 @@ describe('update()', () => {
bar: true,
},
throttle: null,
notifyOnStateChange: false,
actions: [
{
group: 'default',
Expand Down Expand Up @@ -1102,6 +1114,7 @@ describe('update()', () => {
bar: true,
},
throttle: null,
notifyOnStateChange: false,
actions: [
{
group: 'default',
Expand Down Expand Up @@ -1138,6 +1151,7 @@ describe('update()', () => {
bar: true,
},
throttle: null,
notifyOnStateChange: false,
actions: [
{
group: 'default',
Expand Down Expand Up @@ -1173,6 +1187,7 @@ describe('update()', () => {
bar: true,
},
throttle: null,
notifyOnStateChange: false,
actions: [
{
group: 'default',
Expand Down Expand Up @@ -1226,6 +1241,7 @@ describe('update()', () => {
bar: true,
},
throttle: null,
notifyOnStateChange: false,
actions: [],
},
});
Expand All @@ -1249,6 +1265,7 @@ describe('update()', () => {
bar: true,
},
throttle: null,
notifyOnStateChange: false,
actions: [],
},
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ async function update(success: boolean) {
tags: ['bar'],
params: { bar: true },
throttle: '10s',
notifyOnStateChange: false,
actions: [],
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,7 @@ const BaseAlert: SanitizedAlert = {
tags: [],
consumer: 'alert-consumer',
throttle: null,
notifyOnStateChange: false,
muteAll: false,
mutedInstanceIds: [],
params: { bar: true },
Expand Down
2 changes: 2 additions & 0 deletions x-pack/plugins/alerts/server/routes/create.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ describe('createAlertRoute', () => {
bar: true,
},
throttle: '30s',
notifyOnStateChange: false,
actions: [
{
group: 'default',
Expand Down Expand Up @@ -110,6 +111,7 @@ describe('createAlertRoute', () => {
"alertTypeId": "1",
"consumer": "bar",
"name": "abc",
"notifyOnStateChange": false,
"params": Object {
"bar": true,
},
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/alerts/server/routes/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export const bodySchema = schema.object({
}),
{ defaultValue: [] }
),
notifyOnStateChange: schema.boolean({ defaultValue: false }),
ymao1 marked this conversation as resolved.
Show resolved Hide resolved
});

export const createAlertRoute = (router: IRouter, licenseState: LicenseState) => {
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/alerts/server/routes/get.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ describe('getAlertRoute', () => {
tags: ['foo'],
enabled: true,
muteAll: false,
notifyOnStateChange: false,
createdBy: '',
updatedBy: '',
apiKey: '',
Expand Down
3 changes: 3 additions & 0 deletions x-pack/plugins/alerts/server/routes/update.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ describe('updateAlertRoute', () => {
},
},
],
notifyOnStateChange: false,
};

it('updates an alert with proper parameters', async () => {
Expand Down Expand Up @@ -78,6 +79,7 @@ describe('updateAlertRoute', () => {
},
},
],
notifyOnStateChange: false,
},
},
['ok']
Expand All @@ -100,6 +102,7 @@ describe('updateAlertRoute', () => {
},
],
"name": "abc",
"notifyOnStateChange": false,
"params": Object {
"otherField": false,
},
Expand Down
5 changes: 3 additions & 2 deletions x-pack/plugins/alerts/server/routes/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const bodySchema = schema.object({
}),
{ defaultValue: [] }
),
notifyOnStateChange: schema.boolean({ defaultValue: false }),
});

export const updateAlertRoute = (router: IRouter, licenseState: LicenseState) => {
Expand All @@ -62,11 +63,11 @@ export const updateAlertRoute = (router: IRouter, licenseState: LicenseState) =>
}
const alertsClient = context.alerting.getAlertsClient();
const { id } = req.params;
const { name, actions, params, schedule, tags, throttle } = req.body;
const { name, actions, params, schedule, tags, throttle, notifyOnStateChange } = req.body;
return res.ok({
body: await alertsClient.update({
id,
data: { name, actions, params, schedule, tags, throttle },
data: { name, actions, params, schedule, tags, throttle, notifyOnStateChange },
}),
});
})
Expand Down
3 changes: 3 additions & 0 deletions x-pack/plugins/alerts/server/saved_objects/mappings.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@
"throttle": {
"type": "keyword"
},
"notifyOnStateChange": {
ymao1 marked this conversation as resolved.
Show resolved Hide resolved
"type": "boolean"
},
"muteAll": {
"type": "boolean"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const alert: SanitizedAlert = {
updatedAt: new Date(),
apiKeyOwner: null,
throttle: null,
notifyOnStateChange: false,
muteAll: false,
mutedInstanceIds: [],
executionStatus: {
Expand Down
Loading