-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
258 additions
and
9 deletions.
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
x-pack/plugins/alerting/common/routes/rule/validation/validate_flapping/v1.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { validateFlapping } from './v1'; | ||
|
||
describe('validateFlapping', () => { | ||
test('should error if look back window exceeds the lower bound', () => { | ||
const result = validateFlapping({ | ||
look_back_window: 0, | ||
status_change_threshold: 10, | ||
}); | ||
|
||
expect(result).toEqual('look back window must be between 2 and 20'); | ||
}); | ||
|
||
test('should error if look back window exceeds the upper bound', () => { | ||
const result = validateFlapping({ | ||
look_back_window: 50, | ||
status_change_threshold: 10, | ||
}); | ||
|
||
expect(result).toEqual('look back window must be between 2 and 20'); | ||
}); | ||
|
||
test('should error if status change threshold exceeds the lower bound', () => { | ||
const result = validateFlapping({ | ||
look_back_window: 10, | ||
status_change_threshold: 1, | ||
}); | ||
|
||
expect(result).toEqual('status change threshold must be between 2 and 20'); | ||
}); | ||
|
||
test('should error if status change threshold exceeds the upper bound', () => { | ||
const result = validateFlapping({ | ||
look_back_window: 10, | ||
status_change_threshold: 50, | ||
}); | ||
|
||
expect(result).toEqual('status change threshold must be between 2 and 20'); | ||
}); | ||
|
||
test('should error if status change threshold is greater than the look back window', () => { | ||
const result = validateFlapping({ | ||
look_back_window: 10, | ||
status_change_threshold: 15, | ||
}); | ||
|
||
expect(result).toEqual( | ||
'lookBackWindow (10) must be equal to or greater than statusChangeThreshold (15)' | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
122 changes: 122 additions & 0 deletions
122
...rting/server/application/rule/transforms/transform_rule_domain_to_rule_attributes.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { RuleDomain } from '../types'; | ||
import { transformRuleDomainToRuleAttributes } from './transform_rule_domain_to_rule_attributes'; | ||
|
||
describe('transformRuleDomainToRuleAttributes', () => { | ||
const MOCK_API_KEY = Buffer.from('123:abc').toString('base64'); | ||
|
||
const defaultAction = { | ||
id: '1', | ||
uuid: 'test-uuid', | ||
group: 'default', | ||
actionTypeId: 'test', | ||
params: {}, | ||
}; | ||
|
||
const rule: RuleDomain<{}> = { | ||
id: 'test', | ||
enabled: false, | ||
name: 'my rule name', | ||
tags: ['foo'], | ||
alertTypeId: 'myType', | ||
consumer: 'myApp', | ||
schedule: { interval: '1m' }, | ||
actions: [defaultAction], | ||
params: {}, | ||
mapped_params: {}, | ||
createdBy: 'user', | ||
createdAt: new Date('2019-02-12T21:01:22.479Z'), | ||
updatedAt: new Date('2019-02-12T21:01:22.479Z'), | ||
legacyId: 'legacyId', | ||
muteAll: false, | ||
mutedInstanceIds: [], | ||
snoozeSchedule: [], | ||
scheduledTaskId: 'task-123', | ||
executionStatus: { | ||
lastExecutionDate: new Date('2019-02-12T21:01:22.479Z'), | ||
status: 'pending' as const, | ||
}, | ||
throttle: null, | ||
notifyWhen: null, | ||
revision: 0, | ||
updatedBy: 'user', | ||
apiKey: MOCK_API_KEY, | ||
apiKeyOwner: 'user', | ||
flapping: { | ||
lookBackWindow: 20, | ||
statusChangeThreshold: 20, | ||
}, | ||
}; | ||
|
||
test('should transform rule domain to rule attribute', () => { | ||
const result = transformRuleDomainToRuleAttributes({ | ||
rule, | ||
actionsWithRefs: [ | ||
{ | ||
group: 'default', | ||
actionRef: 'action_0', | ||
actionTypeId: 'test', | ||
uuid: 'test-uuid', | ||
params: {}, | ||
}, | ||
], | ||
params: { | ||
legacyId: 'test', | ||
paramsWithRefs: {}, | ||
}, | ||
}); | ||
|
||
expect(result).toMatchInlineSnapshot(` | ||
Object { | ||
"actions": Array [ | ||
Object { | ||
"actionRef": "action_0", | ||
"actionTypeId": "test", | ||
"group": "default", | ||
"params": Object {}, | ||
"uuid": "test-uuid", | ||
}, | ||
], | ||
"alertTypeId": "myType", | ||
"apiKey": "MTIzOmFiYw==", | ||
"apiKeyOwner": "user", | ||
"consumer": "myApp", | ||
"createdAt": "2019-02-12T21:01:22.479Z", | ||
"createdBy": "user", | ||
"enabled": false, | ||
"executionStatus": Object { | ||
"lastExecutionDate": "2019-02-12T21:01:22.479Z", | ||
"status": "pending", | ||
}, | ||
"flapping": Object { | ||
"lookBackWindow": 20, | ||
"statusChangeThreshold": 20, | ||
}, | ||
"legacyId": "test", | ||
"muteAll": false, | ||
"mutedInstanceIds": Array [], | ||
"name": "my rule name", | ||
"notifyWhen": null, | ||
"params": Object {}, | ||
"revision": 0, | ||
"schedule": Object { | ||
"interval": "1m", | ||
}, | ||
"scheduledTaskId": "task-123", | ||
"snoozeSchedule": Array [], | ||
"tags": Array [ | ||
"foo", | ||
], | ||
"throttle": null, | ||
"updatedAt": "2019-02-12T21:01:22.479Z", | ||
"updatedBy": "user", | ||
} | ||
`); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters