-
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
[Security Solution] Add threshold
, machine_learning_job_id
and anomaly_threshold
editable fields
#200323
Merged
nikitaindik
merged 49 commits into
elastic:main
from
nikitaindik:machine-learning-fields
Dec 18, 2024
+1,152
−543
Merged
[Security Solution] Add threshold
, machine_learning_job_id
and anomaly_threshold
editable fields
#200323
Changes from 26 commits
Commits
Show all changes
49 commits
Select commit
Hold shift + click to select a range
11fe8b5
Add `machine_learning_job_id`
nikitaindik d57358b
Add `anomaly_threshold`
nikitaindik 6f74bda
Add `threshold`
nikitaindik 32b5477
Fix i18n
nikitaindik b6a9d92
Remove unused import
nikitaindik cc72aa9
Merge remote-tracking branch 'upstream/main' into machine-learning-fi…
nikitaindik 9991cbd
Fix failing test
nikitaindik 65e5266
Fix failing Jest tests
nikitaindik ef52eb1
Move `anomaly_threshold_edit.tsx` outside directory
nikitaindik 2ef3c64
Simplify `componentProps` in `MachineLearningJobSelector`
nikitaindik 7101058
Simplify validations
nikitaindik 19be452
Use `??` instead of `||`
nikitaindik 0e60504
Simplify `threshold` serialization and deserialization
nikitaindik 5e7fd29
Add `assertUnreachable` to `ThresholdRuleFieldEdit`
nikitaindik ca03da3
Use `??` instead of `||` in `ThresholdAdapter`
nikitaindik f0b7db6
Remove redundant serializers and deserializers
nikitaindik 27bc329
Refactor Machine Learning Job ID-related components
nikitaindik dc785d7
Merge remote-tracking branch 'upstream/main' into machine-learning-fi…
nikitaindik a9467b4
Remove `thresholdFields` from `StepDefineFieldsProps`
nikitaindik d161bf8
Fix failing ML HelpText test
nikitaindik a2b3c53
Make TS happy
nikitaindik 3d56412
Use container queries instead of `EuiAutoSizer` for responsive layout
nikitaindik f4907b4
Merge remote-tracking branch 'upstream/main' into machine-learning-fi…
nikitaindik 350ad19
Make validation work for ML job ID and move field config into edit co…
nikitaindik 664b5a4
Merge remote-tracking branch 'upstream/main' into machine-learning-fi…
nikitaindik 72b195a
Fix displaying long field names in Threshold input
nikitaindik 068f879
Merge remote-tracking branch 'upstream/main' into machine-learning-fi…
nikitaindik 9e231bb
Move "Create custom job" button margin outside of component
nikitaindik 0933e39
Move aggregatable fields computation into `ThresholdEdit`
nikitaindik 318b023
Merge branch 'main' into machine-learning-fields
nikitaindik 26e947a
Merge branch 'main' into machine-learning-fields
nikitaindik a4e0c6e
Merge branch 'main' into machine-learning-fields
nikitaindik 46daae5
Merge branch 'main' into machine-learning-fields
nikitaindik f30cb6d
Merge remote-tracking branch 'upstream/main' into machine-learning-fi…
nikitaindik c360516
Merge branch 'main' into machine-learning-fields
nikitaindik c175679
Merge branch 'main' into machine-learning-fields
nikitaindik 0993cc0
Update imports to reflect latest structure changes
nikitaindik 8a05118
Make sure alert suppression component updates when Threshold "Group b…
nikitaindik db6e424
Update `>=` operator styles
nikitaindik 7fa5e9f
Merge remote-tracking branch 'upstream/main' into machine-learning-fi…
nikitaindik 0e07340
Move files to match Sustainable Kibana Arch PR
nikitaindik 349f448
Delete duplicated test file
nikitaindik 0042063
Get rid of a custom margin in favour of EuiSpacer
nikitaindik 1014b62
Remove unused import
nikitaindik 8c786d5
Merge remote-tracking branch 'upstream/main' into machine-learning-fi…
nikitaindik dc59c29
Update styles
nikitaindik f1de5b6
Used fixed width for number inputs
nikitaindik 468a083
Update spacing for ML job creation button
nikitaindik 0975e4a
Merge remote-tracking branch 'upstream/main' into machine-learning-fi…
nikitaindik File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
12 changes: 12 additions & 0 deletions
12
x-pack/plugins/security_solution/public/common/utils/normalize_machine_learning_job_id.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,12 @@ | ||
/* | ||
* 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 type { MachineLearningJobId } from '../../../common/api/detection_engine'; | ||
|
||
export function normalizeMachineLearningJobId(jobId: MachineLearningJobId): string[] { | ||
return typeof jobId === 'string' ? [jobId] : jobId; | ||
} |
34 changes: 34 additions & 0 deletions
34
...tection_engine/rule_creation/components/anomaly_threshold_edit/anomaly_threshold_edit.tsx
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,34 @@ | ||
/* | ||
* 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 React from 'react'; | ||
import { UseField } from '../../../../shared_imports'; | ||
import { AnomalyThresholdSlider } from '../../../rule_creation_ui/components/anomaly_threshold_slider'; | ||
import * as i18n from './translations'; | ||
|
||
const componentProps = { | ||
describedByIds: ['anomalyThreshold'], | ||
}; | ||
|
||
interface AnomalyThresholdEditProps { | ||
path: string; | ||
} | ||
|
||
export function AnomalyThresholdEdit({ path }: AnomalyThresholdEditProps): JSX.Element { | ||
return ( | ||
<UseField | ||
path={path} | ||
config={ANOMALY_THRESHOLD_FIELD_CONFIG} | ||
component={AnomalyThresholdSlider} | ||
componentProps={componentProps} | ||
/> | ||
); | ||
} | ||
|
||
const ANOMALY_THRESHOLD_FIELD_CONFIG = { | ||
label: i18n.ANOMALY_THRESHOLD_LABEL, | ||
}; |
8 changes: 8 additions & 0 deletions
8
...solution/public/detection_engine/rule_creation/components/anomaly_threshold_edit/index.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,8 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
export { AnomalyThresholdEdit } from './anomaly_threshold_edit'; |
15 changes: 15 additions & 0 deletions
15
...n/public/detection_engine/rule_creation/components/anomaly_threshold_edit/translations.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,15 @@ | ||
/* | ||
* 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 { i18n } from '@kbn/i18n'; | ||
|
||
export const ANOMALY_THRESHOLD_LABEL = i18n.translate( | ||
'xpack.securitySolution.detectionEngine.createRule.stepDefineRule.fieldAnomalyThresholdLabel', | ||
{ | ||
defaultMessage: 'Anomaly score threshold', | ||
} | ||
); |
31 changes: 31 additions & 0 deletions
31
...c/detection_engine/rule_creation/components/create_ml_job_button/create_ml_job_button.tsx
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,31 @@ | ||
/* | ||
* 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 React from 'react'; | ||
import { css } from '@emotion/css'; | ||
import { EuiButton } from '@elastic/eui'; | ||
import { useKibana } from '../../../../common/lib/kibana'; | ||
import * as i18n from './translations'; | ||
|
||
const buttonClassName = css` | ||
margin-top: 20px; | ||
`; | ||
|
||
export function CreateCustomMlJobButton(): JSX.Element { | ||
const { navigateToApp } = useKibana().services.application; | ||
|
||
return ( | ||
<EuiButton | ||
className={buttonClassName} | ||
iconType="popout" | ||
iconSide="right" | ||
onClick={() => navigateToApp('ml', { openInNewTab: true })} | ||
> | ||
{i18n.CREATE_CUSTOM_JOB_BUTTON_TITLE} | ||
</EuiButton> | ||
); | ||
} |
15 changes: 15 additions & 0 deletions
15
...ion/public/detection_engine/rule_creation/components/create_ml_job_button/translations.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,15 @@ | ||
/* | ||
* 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 { i18n } from '@kbn/i18n'; | ||
|
||
export const CREATE_CUSTOM_JOB_BUTTON_TITLE = i18n.translate( | ||
'xpack.securitySolution.detectionEngine.mlSelectJob.createCustomJobButtonTitle', | ||
{ | ||
defaultMessage: 'Create custom job', | ||
} | ||
); |
8 changes: 8 additions & 0 deletions
8
...on/public/detection_engine/rule_creation/components/machine_learning_job_id_edit/index.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,8 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
export { MachineLearningJobIdEdit } from './machine_learning_job_id_edit'; |
53 changes: 53 additions & 0 deletions
53
...ne/rule_creation/components/machine_learning_job_id_edit/machine_learning_job_id_edit.tsx
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,53 @@ | ||
/* | ||
* 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 React, { useMemo } from 'react'; | ||
import { UseField, fieldValidators } from '../../../../shared_imports'; | ||
import { MlJobSelect } from '../ml_job_select'; | ||
nikitaindik marked this conversation as resolved.
Show resolved
Hide resolved
|
||
import { useSecurityJobs } from '../../../../common/components/ml_popover/hooks/use_security_jobs'; | ||
import * as i18n from './translations'; | ||
|
||
interface MachineLearningJobIdEditProps { | ||
path: string; | ||
shouldShowHelpText?: boolean; | ||
} | ||
|
||
export function MachineLearningJobIdEdit({ | ||
path, | ||
shouldShowHelpText, | ||
}: MachineLearningJobIdEditProps): JSX.Element { | ||
const { loading, jobs } = useSecurityJobs(); | ||
|
||
const componentProps = useMemo( | ||
() => ({ | ||
jobs, | ||
loading, | ||
shouldShowHelpText, | ||
}), | ||
[jobs, loading, shouldShowHelpText] | ||
); | ||
|
||
return ( | ||
<UseField | ||
path={path} | ||
config={MACHINE_LEARNING_JOB_ID_FIELD_CONFIG} | ||
component={MlJobSelect} | ||
componentProps={componentProps} | ||
/> | ||
); | ||
} | ||
|
||
const MACHINE_LEARNING_JOB_ID_FIELD_CONFIG = { | ||
label: i18n.MACHINE_LEARNING_JOB_ID_LABEL, | ||
validations: [ | ||
{ | ||
validator: fieldValidators.emptyField( | ||
i18n.MACHINE_LEARNING_JOB_ID_EMPTY_FIELD_VALIDATION_ERROR | ||
), | ||
}, | ||
], | ||
}; |
22 changes: 22 additions & 0 deletions
22
...ic/detection_engine/rule_creation/components/machine_learning_job_id_edit/translations.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,22 @@ | ||
/* | ||
* 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 { i18n } from '@kbn/i18n'; | ||
|
||
export const MACHINE_LEARNING_JOB_ID_LABEL = i18n.translate( | ||
'xpack.securitySolution.detectionEngine.createRule.stepDefineRule.fieldMachineLearningJobIdLabel', | ||
{ | ||
defaultMessage: 'Machine Learning job', | ||
} | ||
); | ||
|
||
export const MACHINE_LEARNING_JOB_ID_EMPTY_FIELD_VALIDATION_ERROR = i18n.translate( | ||
'xpack.securitySolution.detectionEngine.createRule.stepDefineRule.machineLearningJobIdRequired', | ||
{ | ||
defaultMessage: 'A Machine Learning job is required.', | ||
} | ||
); |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Magic number? Should we be referencing a theme variable instead?
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.
We need
20px
here to make the button flush with the dropdown.euiSizeM
is16px
,euiSizeL
is24px
.But now as you pointed this out, I think the margin should live outside of this component since it's related to an external thing.