-
Notifications
You must be signed in to change notification settings - Fork 8.5k
[Security Solution] Rule Preview Follow-up #121249
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
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
6cf8904
fix some bugs and add error component
dplumlee ae2c182
fixes tests
dplumlee 27d2cbd
fixes rest of tests
dplumlee af7da73
fixes display
dplumlee d888da7
update api based on comments
dplumlee 113a8b0
fixes type errors
dplumlee 9e4b3da
fixes tests
dplumlee c74607b
fixes empty filtering
dplumlee 7199078
addresses comments
dplumlee d3447d2
updates type:
dplumlee 967660f
fixes date bug
dplumlee 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
This file contains hidden or 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
24 changes: 0 additions & 24 deletions
24
.../security_solution/public/detections/components/rules/rule_preview/callout_group.test.tsx
This file was deleted.
Oops, something went wrong.
32 changes: 0 additions & 32 deletions
32
...ugins/security_solution/public/detections/components/rules/rule_preview/callout_group.tsx
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
111 changes: 111 additions & 0 deletions
111
...lugins/security_solution/public/detections/components/rules/rule_preview/preview_logs.tsx
This file contains hidden or 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,111 @@ | ||
| /* | ||
| * 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, { Fragment, useMemo } from 'react'; | ||
| import { EuiCallOut, EuiText, EuiSpacer, EuiAccordion } from '@elastic/eui'; | ||
| import { RulePreviewLogs } from '../../../../../common/detection_engine/schemas/request'; | ||
| import * as i18n from './translations'; | ||
|
|
||
| interface PreviewLogsComponentProps { | ||
| logs: RulePreviewLogs[]; | ||
| hasNoiseWarning: boolean; | ||
| } | ||
|
|
||
| interface SortedLogs { | ||
| startedAt?: string; | ||
| logs: string[]; | ||
| } | ||
|
|
||
| interface LogAccordionProps { | ||
| logs: SortedLogs[]; | ||
| isError?: boolean; | ||
| } | ||
|
|
||
| const addLogs = (startedAt: string | undefined, logs: string[], allLogs: SortedLogs[]) => | ||
| logs.length ? [{ startedAt, logs }, ...allLogs] : allLogs; | ||
|
|
||
| export const PreviewLogsComponent: React.FC<PreviewLogsComponentProps> = ({ | ||
| logs, | ||
| hasNoiseWarning, | ||
| }) => { | ||
| const sortedLogs = useMemo( | ||
| () => | ||
| logs.reduce<{ | ||
| errors: SortedLogs[]; | ||
| warnings: SortedLogs[]; | ||
| }>( | ||
| ({ errors, warnings }, curr) => ({ | ||
| errors: addLogs(curr.startedAt, curr.errors, errors), | ||
| warnings: addLogs(curr.startedAt, curr.warnings, warnings), | ||
| }), | ||
| { errors: [], warnings: [] } | ||
| ), | ||
| [logs] | ||
| ); | ||
| return ( | ||
| <> | ||
| <EuiSpacer size="s" /> | ||
| {hasNoiseWarning ?? <CalloutGroup logs={[i18n.QUERY_PREVIEW_NOISE_WARNING]} />} | ||
| <LogAccordion logs={sortedLogs.errors} isError /> | ||
| <LogAccordion logs={sortedLogs.warnings} /> | ||
| </> | ||
| ); | ||
| }; | ||
|
|
||
| const LogAccordion: React.FC<LogAccordionProps> = ({ logs, isError }) => { | ||
| const firstLog = logs[0]; | ||
| const restOfLogs = logs.slice(1); | ||
| return firstLog ? ( | ||
| <> | ||
| <CalloutGroup logs={firstLog.logs} startedAt={firstLog.startedAt} isError={isError} /> | ||
| {restOfLogs.length > 0 ? ( | ||
| <EuiAccordion | ||
| id={isError ? 'previewErrorAccordion' : 'previewWarningAccordion'} | ||
| buttonContent={ | ||
| isError ? i18n.QUERY_PREVIEW_SEE_ALL_ERRORS : i18n.QUERY_PREVIEW_SEE_ALL_WARNINGS | ||
| } | ||
| > | ||
| {restOfLogs.map((log, key) => ( | ||
|
||
| <CalloutGroup | ||
| key={`accordion-log-${key}`} | ||
| logs={log.logs} | ||
| startedAt={log.startedAt} | ||
| isError={isError} | ||
| /> | ||
| ))} | ||
| </EuiAccordion> | ||
| ) : null} | ||
| <EuiSpacer size="m" /> | ||
| </> | ||
| ) : null; | ||
| }; | ||
|
|
||
| export const CalloutGroup: React.FC<{ | ||
| logs: string[]; | ||
| startedAt?: string; | ||
| isError?: boolean; | ||
| }> = ({ logs, startedAt, isError }) => { | ||
| return logs.length > 0 ? ( | ||
dplumlee marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| <> | ||
| {logs.map((log, i) => ( | ||
| <Fragment key={i}> | ||
| <EuiCallOut | ||
| color={isError ? 'danger' : 'warning'} | ||
| iconType="alert" | ||
| data-test-subj={isError ? 'preview-error' : 'preview-warning'} | ||
| title={startedAt != null ? `[${startedAt}]` : null} | ||
| > | ||
| <EuiText> | ||
| <p>{log}</p> | ||
| </EuiText> | ||
| </EuiCallOut> | ||
| <EuiSpacer size="s" /> | ||
| </Fragment> | ||
| ))} | ||
| </> | ||
| ) : null; | ||
| }; | ||
This file contains hidden or 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.
Is there a reference somewhere that we're using to decide on these noisy thresholds?
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.
Going based off this comment, I think it was the spec in the original feature as well but we should get product to sign off for certain sure
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.
a quick git blame show the 1 alert per hour logic committed 14 months ago