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

[Security Solution] Add Alert Suppression editable component #198673

Merged
merged 56 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
2ff98e3
unskip perform bulk action ESS FTR tests
maximpn Oct 24, 2024
24dae89
improve tests transparency
maximpn Oct 28, 2024
f8c8d89
normalize i18n keys
maximpn Oct 28, 2024
b4b5073
add alert suppression editable component
maximpn Oct 28, 2024
36180c4
extract alert suppression fields validation
maximpn Oct 31, 2024
a04bdcf
rename suppression frequency to duration
maximpn Oct 31, 2024
1fe9a0b
add alert suppression form wrapper
maximpn Oct 31, 2024
7f00387
extract field paths to constants
maximpn Oct 31, 2024
5870375
add threshold alert suppression edit component
maximpn Oct 31, 2024
6b49041
rectify machine learning rule alert suppression messages
maximpn Nov 1, 2024
4b0e3b2
add alert_suppression field for EQL rule type
maximpn Nov 1, 2024
0da7a59
avoid infinite ML rule config refetching
maximpn Nov 1, 2024
4e24d68
remove alert_suppression field upon fields removal
maximpn Nov 1, 2024
decb134
add @kbn/react-hooks
maximpn Nov 1, 2024
34b38c1
remove unused translations
maximpn Nov 1, 2024
2ce55f8
update OAS bundles
maximpn Nov 1, 2024
a501f60
shorten path file names to fit into 200 symbols limit
maximpn Nov 1, 2024
1aacd39
use coherent esql naming
maximpn Nov 2, 2024
fd841c6
simplify available fields extraction
maximpn Nov 2, 2024
c55453a
remove unnecessary used <></>
maximpn Nov 2, 2024
0af3274
split useDataView implementation for better reuse
maximpn Nov 2, 2024
b9e09be
display tooltip disabled message for the whole alert suppression fiel…
maximpn Nov 3, 2024
844a514
integrate extracted AlertSuppressionEdit into rule creation/editing f…
maximpn Nov 3, 2024
54f73bf
fix an ability to remove alert suppression for threshold rule type
maximpn Nov 3, 2024
70269f8
remove debug output
maximpn Nov 3, 2024
3d0ac92
fix alert suppression fields validation
maximpn Nov 3, 2024
e5d634f
correct i18n keys
maximpn Nov 3, 2024
000d883
clean up leftovers
maximpn Nov 3, 2024
3a4d0ab
use a proper field name
maximpn Nov 3, 2024
98d7e0c
fix form submission for threshold rule type
maximpn Nov 3, 2024
0f34583
properly display rule definition step readonly mode
maximpn Nov 3, 2024
3b91050
remove unused translations
maximpn Nov 3, 2024
bb6a03b
fix type issues
maximpn Nov 3, 2024
7ef3016
fix failed tests
maximpn Nov 4, 2024
4826e86
add default value to alert suppression edit component
maximpn Nov 4, 2024
fbb957f
remove outdated input prop
maximpn Nov 4, 2024
a5da899
fix threshold alert suppression duration type value
maximpn Nov 4, 2024
4d2f846
rename useDataViews() to useDataViewListItems() to avoid confusion wi…
maximpn Nov 4, 2024
ed45d5a
fix threshold rule cypress test
maximpn Nov 4, 2024
5f49987
replace UseMultiFields with UseField
maximpn Nov 4, 2024
e3a40a4
remove unused disabledText prop
maximpn Nov 5, 2024
4ea486f
remove unused translations
maximpn Nov 6, 2024
a71ef11
move out threshold alert suppression component into a separate folder
maximpn Nov 7, 2024
6236977
remove dependency on aggregatableFields
maximpn Nov 7, 2024
05a41d1
get rid of styled-components in duration input
maximpn Nov 7, 2024
405d2e8
persist alert suppression state when switching between different rule…
maximpn Nov 7, 2024
5e7db85
remove aggregatableFields unit tests since the function is trivial
maximpn Nov 7, 2024
302b19c
remove unused component
maximpn Nov 8, 2024
1efd8b2
improve files readability on alert_suppression_edit folder
maximpn Nov 8, 2024
71b48c6
add alert suppression state persistence tests
maximpn Nov 9, 2024
93057d5
memoize alert suppression label
maximpn Nov 9, 2024
98270dc
reduce import path length
maximpn Nov 9, 2024
7b61b6a
add duration unit selector's label
maximpn Nov 9, 2024
162b3a9
roll back terms aggregation fields for threshold rules
maximpn Nov 11, 2024
3ca73b1
Merge branch 'main' into add-alert-supression-editable-component
maximpn Nov 11, 2024
767d5a5
Merge branch 'main' into add-alert-supression-editable-component
maximpn Nov 12, 2024
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
13 changes: 8 additions & 5 deletions oas_docs/output/kibana.serverless.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39976,17 +39976,20 @@ components:
type: object
properties:
unit:
enum:
- s
- m
- h
type: string
$ref: >-
#/components/schemas/Security_Detections_API_AlertSuppressionDurationUnit
value:
minimum: 1
type: integer
required:
- value
- unit
Security_Detections_API_AlertSuppressionDurationUnit:
enum:
- s
- m
- h
type: string
Security_Detections_API_AlertSuppressionGroupBy:
items:
type: string
Expand Down
13 changes: 8 additions & 5 deletions oas_docs/output/kibana.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48220,17 +48220,20 @@ components:
type: object
properties:
unit:
enum:
- s
- m
- h
type: string
$ref: >-
#/components/schemas/Security_Detections_API_AlertSuppressionDurationUnit
value:
minimum: 1
type: integer
required:
- value
- unit
Security_Detections_API_AlertSuppressionDurationUnit:
enum:
- s
- m
- h
type: string
Security_Detections_API_AlertSuppressionGroupBy:
items:
type: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -555,10 +555,15 @@ export const RuleExceptionList = z.object({
namespace_type: z.enum(['agnostic', 'single']),
});

export type AlertSuppressionDurationUnit = z.infer<typeof AlertSuppressionDurationUnit>;
export const AlertSuppressionDurationUnit = z.enum(['s', 'm', 'h']);
export type AlertSuppressionDurationUnitEnum = typeof AlertSuppressionDurationUnit.enum;
export const AlertSuppressionDurationUnitEnum = AlertSuppressionDurationUnit.enum;

export type AlertSuppressionDuration = z.infer<typeof AlertSuppressionDuration>;
export const AlertSuppressionDuration = z.object({
value: z.number().int().min(1),
unit: z.enum(['s', 'm', 'h']),
unit: AlertSuppressionDurationUnit,
});

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -581,18 +581,21 @@ components:
- type
- namespace_type

AlertSuppressionDurationUnit:
type: string
enum:
- s
- m
- h

AlertSuppressionDuration:
type: object
properties:
value:
type: integer
minimum: 1
unit:
type: string
enum:
- s
- m
- h
$ref: '#/components/schemas/AlertSuppressionDurationUnit'
required:
- value
- unit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1560,17 +1560,19 @@ components:
type: object
properties:
unit:
enum:
- s
- m
- h
type: string
$ref: '#/components/schemas/AlertSuppressionDurationUnit'
value:
minimum: 1
type: integer
required:
- value
- unit
AlertSuppressionDurationUnit:
enum:
- s
- m
- h
type: string
AlertSuppressionGroupBy:
items:
type: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -850,17 +850,19 @@ components:
type: object
properties:
unit:
enum:
- s
- m
- h
type: string
$ref: '#/components/schemas/AlertSuppressionDurationUnit'
value:
minimum: 1
type: integer
required:
- value
- unit
AlertSuppressionDurationUnit:
enum:
- s
- m
- h
type: string
AlertSuppressionGroupBy:
items:
type: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ export const uiPlugins = ({
insightsUpsellingMessage,
interactionsUpsellingMessage,
}: {
insightsUpsellingMessage: string | null;
interactionsUpsellingMessage: string | null;
insightsUpsellingMessage?: string;
interactionsUpsellingMessage?: string;
}) => {
const currentPlugins = nonStatefulUiPlugins.map((plugin) => plugin.name);
const insightPluginWithLicense = insightMarkdownPlugin.plugin({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ describe('plugin', () => {
});

it('show investigate message when insightsUpsellingMessage is not provided', () => {
const result = plugin({ insightsUpsellingMessage: null });
const result = plugin({ insightsUpsellingMessage: undefined });

expect(result.button.label).toEqual('Investigate');
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -541,11 +541,7 @@ const exampleInsight = `${insightPrefix}{
]
}}`;

export const plugin = ({
insightsUpsellingMessage,
}: {
insightsUpsellingMessage: string | null;
}) => {
export const plugin = ({ insightsUpsellingMessage }: { insightsUpsellingMessage?: string }) => {
return {
name: 'insights',
button: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ const OsqueryEditor = React.memo(OsqueryEditorComponent);
export const plugin = ({
interactionsUpsellingMessage,
}: {
interactionsUpsellingMessage: string | null;
interactionsUpsellingMessage?: string;
}) => {
return {
name: 'osquery',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ const TimelineEditor = memo(TimelineEditorComponent);
export const plugin = ({
interactionsUpsellingMessage,
}: {
interactionsUpsellingMessage: string | null;
interactionsUpsellingMessage?: string;
}): EuiMarkdownEditorUiPlugin => {
return {
name: ID,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ describe('use_upselling', () => {
expect(result.all.length).toBe(1); // assert that it should not cause unnecessary re-renders
});

test('useUpsellingMessage returns null when upsellingMessageId not found', () => {
test('useUpsellingMessage returns undefined when upsellingMessageId not found', () => {
const emptyMessages = {};
mockUpselling.setPages(emptyMessages);

Expand All @@ -81,6 +81,6 @@ describe('use_upselling', () => {
wrapper: RenderWrapper,
}
);
expect(result.current).toBe(null);
expect(result.current).toBeUndefined();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ export const useUpsellingComponent = (id: UpsellingSectionId): React.ComponentTy
return useMemo(() => upsellingSections?.get(id) ?? null, [id, upsellingSections]);
};

export const useUpsellingMessage = (id: UpsellingMessageId): string | null => {
export const useUpsellingMessage = (id: UpsellingMessageId): string | undefined => {
const upselling = useUpsellingService();
const upsellingMessages = useObservable(upselling.messages$, upselling.getMessagesValue());

return useMemo(() => upsellingMessages?.get(id) ?? null, [id, upsellingMessages]);
return useMemo(() => upsellingMessages?.get(id), [id, upsellingMessages]);
};

export const useUpsellingPage = (pageName: SecurityPageName): React.ComponentType | null => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* 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 { act, fireEvent, waitFor } from '@testing-library/react';

export function showEuiComboBoxOptions(comboBoxToggleButton: HTMLElement): Promise<void> {
fireEvent.click(comboBoxToggleButton);

return waitFor(() => {
const listWithOptionsElement = document.querySelector('[role="listbox"]');
const emptyListElement = document.querySelector('.euiComboBoxOptionsList__empty');

expect(listWithOptionsElement || emptyListElement).toBeInTheDocument();
});
}

type SelectEuiComboBoxOptionParameters =
| {
comboBoxToggleButton: HTMLElement;
optionIndex: number;
optionText?: undefined;
}
| {
comboBoxToggleButton: HTMLElement;
optionText: string;
optionIndex?: undefined;
};

export function selectEuiComboBoxOption({
comboBoxToggleButton,
optionIndex,
optionText,
}: SelectEuiComboBoxOptionParameters): Promise<void> {
return act(async () => {
await showEuiComboBoxOptions(comboBoxToggleButton);

const options = Array.from(
document.querySelectorAll('[data-test-subj*="comboBoxOptionsList"] [role="option"]')
);

if (typeof optionText === 'string') {
const optionToSelect = options.find((option) => option.textContent === optionText);

if (optionToSelect) {
fireEvent.click(optionToSelect);
} else {
throw new Error(
`Could not find option with text "${optionText}". Available options: ${options
.map((option) => option.textContent)
.join(', ')}`
);
}
} else {
fireEvent.click(options[optionIndex]);
}
});
}

export function selectFirstEuiComboBoxOption({
comboBoxToggleButton,
}: {
comboBoxToggleButton: HTMLElement;
}): Promise<void> {
return selectEuiComboBoxOption({ comboBoxToggleButton, optionIndex: 0 });
}

export function clearEuiComboBoxSelection({
clearButton,
}: {
clearButton: HTMLElement;
}): Promise<void> {
return act(async () => {
fireEvent.click(clearButton);
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* 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, { memo } from 'react';
import { EuiPanel, EuiText, EuiToolTip } from '@elastic/eui';
import type { DataViewFieldBase } from '@kbn/es-query';
import { useFormData } from '../../../../../shared_imports';
import { MissingFieldsStrategySelector } from './missing_fields_strategy_selector';
import { SuppressionDurationSelector } from './suppression_duration_selector';
import { SuppressionFieldsSelector } from './suppression_fields_selector';
import { ALERT_SUPPRESSION_FIELDS_FIELD_NAME } from '../constants/fields';

interface AlertSuppressionEditProps {
suppressibleFields: DataViewFieldBase[];
labelAppend?: React.ReactNode;
disabled?: boolean;
disabledText?: string;
warningText?: string;
}

export const AlertSuppressionEdit = memo(function AlertSuppressionEdit({
suppressibleFields,
labelAppend,
disabled,
disabledText,
warningText,
}: AlertSuppressionEditProps): JSX.Element {
const [{ [ALERT_SUPPRESSION_FIELDS_FIELD_NAME]: suppressionFields }] = useFormData<{
[ALERT_SUPPRESSION_FIELDS_FIELD_NAME]: string[];
}>({
watch: ALERT_SUPPRESSION_FIELDS_FIELD_NAME,
});
const hasSelectedFields = suppressionFields?.length > 0;
const content = (
<>
<SuppressionFieldsSelector
suppressibleFields={suppressibleFields}
labelAppend={labelAppend}
disabled={disabled}
/>
{warningText && (
<EuiText size="xs" color="warning" data-test-subj="alertSuppressionWarning">
{warningText}
</EuiText>
)}
<EuiPanel paddingSize="m" hasShadow={false}>
<SuppressionDurationSelector disabled={disabled || !hasSelectedFields} />
<MissingFieldsStrategySelector disabled={disabled || !hasSelectedFields} />
</EuiPanel>
</>
);

return disabled && disabledText ? (
<EuiToolTip position="right" content={disabledText}>
{content}
</EuiToolTip>
) : (
content
);
});
Loading