Skip to content

Commit

Permalink
[8.9] [Security Selection][Detection engine] fixes rule preview perfo…
Browse files Browse the repository at this point in the history
…rmance issues (elastic#164207) (elastic#164487)

# Backport

This will backport the following commits from `main` to `8.9`:
- [[Security Selection][Detection engine] fixes rule preview performance
issues (elastic#164207)](elastic#164207)

<!--- Backport version: 8.9.7 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Vitalii
Dmyterko","email":"[email protected]"},"sourceCommit":{"committedDate":"2023-08-22T17:05:15Z","message":"[Security
Selection][Detection engine] fixes rule preview performance issues
(elastic#164207)\n\n## Summary\r\n\r\nOn every single keyboard type on query
input, the whole preview part was\r\nre-rendering. If there are too many
alerts, it could take ~150ms-200ms,\r\nfor its re-render. Ultimately,
making form almost unusable\r\nSo, in this PR I'm adding memoization for
2 Preview components, to\r\nresolve this issue\r\n\r\n\r\n###
Before\r\n\r\n<img width=\"2529\" alt=\"Screenshot 2023-08-17 at 17 13
07\"\r\nsrc=\"https://github.com/elastic/kibana/assets/92328789/c0b137e6-828b-4068-b061-85a5b5ca99f1\">\r\n\r\n###
After\r\n\r\n<img width=\"2523\" alt=\"Screenshot 2023-08-17 at 17 07
56\"\r\nsrc=\"https://github.com/elastic/kibana/assets/92328789/06a0983c-d8e0-40c1-9b48-fd4bc106e922\">\r\n\r\n---------\r\n\r\nCo-authored-by:
kibanamachine
<[email protected]>","sha":"cd8a94ba3203022a7791e85a8dd8a6c16ae381ab","branchLabelMapping":{"^v8.11.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","Team:Detections
and Resp","Team: SecuritySolution","backport:prev-minor","Team:Detection
Engine","v8.10.0","v8.11.0","v8.9.2"],"number":164207,"url":"https://github.com/elastic/kibana/pull/164207","mergeCommit":{"message":"[Security
Selection][Detection engine] fixes rule preview performance issues
(elastic#164207)\n\n## Summary\r\n\r\nOn every single keyboard type on query
input, the whole preview part was\r\nre-rendering. If there are too many
alerts, it could take ~150ms-200ms,\r\nfor its re-render. Ultimately,
making form almost unusable\r\nSo, in this PR I'm adding memoization for
2 Preview components, to\r\nresolve this issue\r\n\r\n\r\n###
Before\r\n\r\n<img width=\"2529\" alt=\"Screenshot 2023-08-17 at 17 13
07\"\r\nsrc=\"https://github.com/elastic/kibana/assets/92328789/c0b137e6-828b-4068-b061-85a5b5ca99f1\">\r\n\r\n###
After\r\n\r\n<img width=\"2523\" alt=\"Screenshot 2023-08-17 at 17 07
56\"\r\nsrc=\"https://github.com/elastic/kibana/assets/92328789/06a0983c-d8e0-40c1-9b48-fd4bc106e922\">\r\n\r\n---------\r\n\r\nCo-authored-by:
kibanamachine
<[email protected]>","sha":"cd8a94ba3203022a7791e85a8dd8a6c16ae381ab"}},"sourceBranch":"main","suggestedTargetBranches":["8.10","8.9"],"targetPullRequestStates":[{"branch":"8.10","label":"v8.10.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.11.0","labelRegex":"^v8.11.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/164207","number":164207,"mergeCommit":{"message":"[Security
Selection][Detection engine] fixes rule preview performance issues
(elastic#164207)\n\n## Summary\r\n\r\nOn every single keyboard type on query
input, the whole preview part was\r\nre-rendering. If there are too many
alerts, it could take ~150ms-200ms,\r\nfor its re-render. Ultimately,
making form almost unusable\r\nSo, in this PR I'm adding memoization for
2 Preview components, to\r\nresolve this issue\r\n\r\n\r\n###
Before\r\n\r\n<img width=\"2529\" alt=\"Screenshot 2023-08-17 at 17 13
07\"\r\nsrc=\"https://github.com/elastic/kibana/assets/92328789/c0b137e6-828b-4068-b061-85a5b5ca99f1\">\r\n\r\n###
After\r\n\r\n<img width=\"2523\" alt=\"Screenshot 2023-08-17 at 17 07
56\"\r\nsrc=\"https://github.com/elastic/kibana/assets/92328789/06a0983c-d8e0-40c1-9b48-fd4bc106e922\">\r\n\r\n---------\r\n\r\nCo-authored-by:
kibanamachine
<[email protected]>","sha":"cd8a94ba3203022a7791e85a8dd8a6c16ae381ab"}},{"branch":"8.9","label":"v8.9.2","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Vitalii Dmyterko <[email protected]>
  • Loading branch information
kibanamachine and vitaliidm authored Aug 22, 2023
1 parent 2ac7591 commit e164e8a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { isEqual } from 'lodash';
import * as i18n from './translations';
import { usePreviewRoute } from './use_preview_route';
import { PreviewHistogram } from './preview_histogram';
import { PreviewLogsComponent } from './preview_logs';
import { PreviewLogs } from './preview_logs';
import { useKibana } from '../../../../common/lib/kibana';
import { LoadingHistogram } from './loading_histogram';
import { useStartTransaction } from '../../../../common/lib/apm/use_start_transaction';
Expand Down Expand Up @@ -274,7 +274,7 @@ const RulePreviewComponent: React.FC<RulePreviewProps> = ({
timeframeOptions={previewData.timeframeOptions}
/>
)}
<PreviewLogsComponent logs={logs} hasNoiseWarning={hasNoiseWarning} isAborted={isAborted} />
<PreviewLogs logs={logs} hasNoiseWarning={hasNoiseWarning} isAborted={isAborted} />
</>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ interface PreviewHistogramProps {

const DEFAULT_HISTOGRAM_HEIGHT = 300;

export const PreviewHistogram = ({
const PreviewHistogramComponent = ({
previewId,
addNoiseWarning,
spaceId,
Expand Down Expand Up @@ -262,3 +262,6 @@ export const PreviewHistogram = ({
</>
);
};

export const PreviewHistogram = React.memo(PreviewHistogramComponent);
PreviewHistogram.displayName = 'PreviewHistogram';
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { EuiCallOut, EuiText, EuiSpacer, EuiAccordion } from '@elastic/eui';
import type { RulePreviewLogs } from '../../../../../common/detection_engine/rule_schema';
import * as i18n from './translations';

interface PreviewLogsComponentProps {
interface PreviewLogsProps {
logs: RulePreviewLogs[];
hasNoiseWarning: boolean;
isAborted: boolean;
Expand Down Expand Up @@ -42,11 +42,7 @@ const addLogs = (
allLogs: SortedLogs[]
) => (logs.length ? [{ startedAt, logs, duration }, ...allLogs] : allLogs);

export const PreviewLogsComponent: React.FC<PreviewLogsComponentProps> = ({
logs,
hasNoiseWarning,
isAborted,
}) => {
const PreviewLogsComponent: React.FC<PreviewLogsProps> = ({ logs, hasNoiseWarning, isAborted }) => {
const sortedLogs = useMemo(
() =>
logs.reduce<{
Expand All @@ -73,6 +69,9 @@ export const PreviewLogsComponent: React.FC<PreviewLogsComponentProps> = ({
);
};

export const PreviewLogs = React.memo(PreviewLogsComponent);
PreviewLogs.displayName = 'PreviewLogs';

const LogAccordion: React.FC<LogAccordionProps> = ({ logs, isError, children }) => {
const firstLog = logs[0];
if (!(children || firstLog)) return null;
Expand Down

0 comments on commit e164e8a

Please sign in to comment.