-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[RAM][SECURITYSOLUTION][ALERTS] - Show warning that custom action intervals cannot be shorter than the rule's check interval #155684
base: main
Are you sure you want to change the base?
Changes from all commits
a12b25e
7ee3a3f
8903310
736e2c7
92f6090
ce925cb
07609ca
20b53c6
9e42376
2bf8f5b
b1974ff
567d278
a8b5dda
6344ac0
fc38954
5e886ff
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* | ||
* 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 { getTimeTypeValue } from './time_type_value'; | ||
|
||
describe('getTimeTypeValue', () => { | ||
[ | ||
{ interval: '1ms', value: 1, unit: 'ms' }, | ||
{ interval: '0s', value: 0, unit: 's' }, | ||
{ interval: '3s', value: 3, unit: 's' }, | ||
{ interval: '5m', value: 5, unit: 'm' }, | ||
{ interval: '7h', value: 7, unit: 'h' }, | ||
{ interval: '10d', value: 10, unit: 'd' }, | ||
].forEach(({ interval, value, unit }) => { | ||
it(`should correctly return time duration and time unit when 'interval' is ${interval}`, () => { | ||
const { value: actualValue, unit: actualUnit } = getTimeTypeValue(interval); | ||
expect(actualValue).toBe(value); | ||
expect(actualUnit).toBe(unit); | ||
}); | ||
}); | ||
|
||
[ | ||
{ interval: '-1ms', value: 1, unit: 'ms' }, | ||
{ interval: '-3s', value: 3, unit: 's' }, | ||
{ interval: '-5m', value: 5, unit: 'm' }, | ||
{ interval: '-7h', value: 7, unit: 'h' }, | ||
{ interval: '-10d', value: 10, unit: 'd' }, | ||
{ interval: '-1', value: 1, unit: 'ms' }, | ||
{ interval: '-3', value: 3, unit: 'ms' }, | ||
{ interval: '-5', value: 5, unit: 'ms' }, | ||
{ interval: '-7', value: 7, unit: 'ms' }, | ||
{ interval: '-10', value: 10, unit: 'ms' }, | ||
].forEach(({ interval, value, unit }) => { | ||
it(`should correctly return positive time duration and time unit when 'interval' is negative (${interval})`, () => { | ||
const { value: actualValue, unit: actualUnit } = getTimeTypeValue(interval); | ||
expect(actualValue).toBe(value); | ||
expect(actualUnit).toBe(unit); | ||
}); | ||
}); | ||
|
||
[ | ||
{ interval: 'ms', value: 0, unit: 'ms' }, | ||
{ interval: 's', value: 0, unit: 's' }, | ||
{ interval: 'm', value: 0, unit: 'm' }, | ||
{ interval: 'h', value: 0, unit: 'h' }, | ||
{ interval: 'd', value: 0, unit: 'd' }, | ||
{ interval: '-ms', value: 0, unit: 'ms' }, | ||
{ interval: '-s', value: 0, unit: 's' }, | ||
{ interval: '-m', value: 0, unit: 'm' }, | ||
{ interval: '-h', value: 0, unit: 'h' }, | ||
{ interval: '-d', value: 0, unit: 'd' }, | ||
].forEach(({ interval, value, unit }) => { | ||
it(`should correctly return time duration equal to '0' when 'interval' does not specify time duration (${interval})`, () => { | ||
const { value: actualValue, unit: actualUnit } = getTimeTypeValue(interval); | ||
expect(actualValue).toBe(value); | ||
expect(actualUnit).toBe(unit); | ||
}); | ||
}); | ||
|
||
[ | ||
{ interval: '0', value: 0, unit: 'ms' }, | ||
{ interval: '1', value: 1, unit: 'ms' }, | ||
{ interval: '3', value: 3, unit: 'ms' }, | ||
{ interval: '5', value: 5, unit: 'ms' }, | ||
{ interval: '7', value: 7, unit: 'ms' }, | ||
{ interval: '10', value: 10, unit: 'ms' }, | ||
].forEach(({ interval, value, unit }) => { | ||
it(`should correctly return time unit set to 'ms' as a default value when 'interval' does not specify it (${interval})`, () => { | ||
const { value: actualValue, unit: actualUnit } = getTimeTypeValue(interval); | ||
expect(actualValue).toBe(value); | ||
expect(actualUnit).toBe(unit); | ||
}); | ||
}); | ||
|
||
[ | ||
{ interval: '1f', value: 1, unit: 'ms' }, | ||
{ interval: '-3r', value: 3, unit: 'ms' }, | ||
{ interval: 'p', value: 0, unit: 'ms' }, | ||
].forEach(({ interval, value, unit }) => { | ||
it(`should correctly return time unit set to 'ms' as a default value when data is invalid (${interval})`, () => { | ||
const { value: actualValue, unit: actualUnit } = getTimeTypeValue(interval); | ||
expect(actualValue).toBe(value); | ||
expect(actualUnit).toBe(unit); | ||
}); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* 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 { isEmpty } from 'lodash/fp'; | ||
import type { Unit } from '@kbn/datemath'; | ||
|
||
export const getTimeTypeValue = (time: string): { unit: Unit; value: number } => { | ||
const timeObj: { unit: Unit; value: number } = { | ||
unit: 'ms', | ||
value: 0, | ||
}; | ||
const filterTimeVal = time.match(/\d+/g); | ||
const filterTimeType = time.match(/[a-zA-Z]+/g); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there some reason to match all letters here and check separately for It could be one regex like
to match an expected format strictly. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agree with Maxim here, with the additional doubt of why defaulting to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here. I just moved this method from another file x-pack/plugins/security_solution/public/detection_engine/rule_creation_ui/pages/rule_creation/helpers.ts :-) If I will have time before the release to address the concerns that you put, I will look into this as well. |
||
if (!isEmpty(filterTimeVal) && filterTimeVal != null && !isNaN(Number(filterTimeVal[0]))) { | ||
timeObj.value = Number(filterTimeVal[0]); | ||
} | ||
if ( | ||
!isEmpty(filterTimeType) && | ||
filterTimeType != null && | ||
['s', 'm', 'h', 'd'].includes(filterTimeType[0]) | ||
) { | ||
timeObj.unit = filterTimeType[0] as Unit; | ||
} | ||
return timeObj; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It'd be really helpful to have a comment with an expected time format.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
I worked last year on creating a
TimeDuration
io-ts type and added there some explanation of how the type works, that could be of inspiration:https://github.com/elastic/kibana/blob/main/packages/kbn-securitysolution-io-ts-types/src/time_duration/index.ts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just moved this method from another file
x-pack/plugins/security_solution/public/detection_engine/rule_creation_ui/pages/rule_creation/helpers.ts
:-)If I will have time before the release to address the concerns that you put, I will look into this as well.