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

[Response Ops] [Alerts table] Cell context alert table performance #180016

Merged

Conversation

kqualters-elastic
Copy link
Contributor

Summary

This pr makes use of a new prop (and some generic memoization fixes) in 2 eui prs merged recently (elastic/eui#7556 and elastic/eui#7374) to improve the performance of the alerts table. Mainly, the cellContext prop is now available to consumers of the triggersActionsUi alerts table to pass in custom props in a way that allows the renderCellValue/rowCellRender functions of the various EuiDataGrid prop apis to remain referentially stable across re-renders. There are also some various changes to various hooks and props found throughout plugins that use the table to improve performance. There should be no change in functionality, just a moderate to substantial reduction in time the app spends rendering the alerts table in various scenarios. Below will be some react dev tools performance profiles, main compared to this branch, with the exact same set of generated data.

Main, switching from 10-100 rows:
main_alerts_table

This branch 10-100 rows:
context_alerts_table

Pretty modest gain here, 1 render is slower than any others on main, but overall less time spent rendering by about a second.

Main, opening the cell popover on 2 cells
main_open_cell_popover

This branch, opening cellpopover
context_open_cell_popover

Again nothing crazy here, modest improvement.

Main opening timeline and hitting refresh

main_open_timeline

This branch, opening timeline and hitting refresh

context_open_timeline

This is the case that brought this about in the first place, as security solution shares a lot of code between tables, the alerts table recreating all cells on every render was destroying performance of the timeline rendering in a flyout/modal while users were on alerts page or the rule detail page, which is probably the most common use case. 93ms in this branch vs 2500+ ms in main. This type of performance hit happens when almost any action is taken in timeline.

Main, selecting 3 alerts 1 at a time
main_actions

This branch selecting 3 alerts 1 at a time

context_actions

Pretty substantial improvement here as well, ~2000ms vs 67ms.

Apologies if some of the gifs are cut off, please try the branch vs main on your own! This was done on a local kibana in dev mode, so things like emotion are eating up more cpu than they would for a user, but there still should be improvement, and I can't think of any circumstance where things will be worse. Also this branch was a little longer lived than I would have liked, so if you are reviewing and changed something around these files recently please double check I didn't miss anything.

Checklist

@kqualters-elastic kqualters-elastic added release_note:skip Skip the PR/issue when compiling release notes Theme: rac label obsolete Team:Threat Hunting:Investigations Security Solution Investigations Team v8.14.0 labels Apr 4, 2024
@kqualters-elastic kqualters-elastic requested review from a team as code owners April 4, 2024 07:28
@elasticmachine
Copy link
Contributor

Pinging @elastic/security-threat-hunting-investigations (Team:Threat Hunting:Investigations)

@botelastic botelastic bot added the Team:obs-ux-management Observability Management User Experience Team label Apr 4, 2024
@elasticmachine
Copy link
Contributor

Pinging @elastic/obs-ux-management-team (Team:obs-ux-management)

browserFields={browserFields}
columnId={columnId}
data={finalData}
ecsData={ecsData}
eventId={eventId}
header={myHeader}
isDetails={isDetails}
isDraggable={isDraggable}
isDraggable={false}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this correct? I see isDraggable is still a valid prop in EuiDataGridCellProps['cellContext'] type

@kqualters-elastic
Copy link
Contributor Author

remaining test failures seem to be occurring in main as well

@darnautov darnautov self-requested a review April 12, 2024 09:59
return valuesField ? values : value;
case ALERT_REASON:
const dataFieldEs = data.reduce((acc, d) => ({ ...acc, [d.field]: d.value }), {});
if (!observabilityRuleTypeRegistry) return <>{value}</>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like git picked up this whole switch block because it changed indentation, but I think this is the only line that is actually different between the old switch and this one (this line has been added)

Comment on lines 115 to 133
return (
<EuiLink
data-test-subj="o11yGetRenderCellValueLink"
css={{ display: 'contents' }}
onClick={() => setFlyoutAlert && setFlyoutAlert(alert.fields[ALERT_UUID])}
>
{alert.reason}
</EuiLink>
);
case ALERT_RULE_NAME:
const ruleCategory = getMappedNonEcsValue({
data,
fieldName: ALERT_RULE_CATEGORY,
});
const tooltipContent = getRenderValue(ruleCategory);
return <CellTooltip value={value} tooltipContent={tooltipContent} />;
default:
return <>{value}</>;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just for reference, seems to be no substantive differences between these blocks, just indentation change.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the react.memo is doing that I think

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah something above changed the indentation, it happens. I just wanted to flag it for whoever on my team takes a look at this tomorrow. 👍

Copy link
Contributor

@XavierM XavierM left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested locally and review code!
Good perf improvement and thank you for doing it!

Copy link
Contributor

@PhilippeOberti PhilippeOberti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

code LGTM and desk tested. What an improvement! On tables with 100 rows displayed the difference is truly huge, awesome work @kqualters-elastic!! I couldn't find anything broken during testing!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry for the stupid question, but could you explain (for my own knowledge) why making the changes in this file? Why moving the constant within each useCallback is a good thing here? Thanks!

alertTagsItems,
alertTagsPanels,
};
return useMemo(() => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

feel free to ignore this comment but for those simple returns I like writing them this way

return useMemo(
    () => ({
      alertTagsItems,
      alertTagsPanels,
    }),
    [alertTagsItems, alertTagsPanels]
  );

There are many similar changes in this PR

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should undo this change, while it's not bad, it doesn't really bring anything valuable to this PR

Copy link
Contributor

@benakansara benakansara left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Obs-ux-management code changes LGTM. Tested locally, everything worked with nice performance improvement! 🎉

Copy link
Contributor

@darnautov darnautov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ML changes LGTM

@kqualters-elastic kqualters-elastic enabled auto-merge (squash) April 16, 2024 15:55
@kibana-ci
Copy link
Collaborator

💛 Build succeeded, but was flaky

Failed CI Steps

Test Failures

  • [job] [logs] FTR Configs #59 / Agents fleet_list_agent should return correct status summary if showUpgradeable is provided

Metrics [docs]

Public APIs missing comments

Total count of every public API that lacks a comment. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats comments for more detailed information.

id before after diff
triggersActionsUi 569 567 -2

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
cloudSecurityPosture 451.2KB 451.3KB +31.0B
ml 4.1MB 4.1MB -1.0B
observability 284.8KB 284.8KB +81.0B
securitySolution 17.5MB 17.5MB +2.7KB
triggersActionsUi 1.6MB 1.6MB +2.4KB
total +5.2KB

Public APIs missing exports

Total count of every type that is part of your API that should be exported but is not. This will cause broken links in the API documentation system. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats exports for more detailed information.

id before after diff
triggersActionsUi 60 58 -2

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
cases 153.0KB 153.0KB +76.0B
Unknown metric groups

API count

id before after diff
triggersActionsUi 595 593 -2

ESLint disabled line counts

id before after diff
triggersActionsUi 128 127 -1

Total ESLint disabled count

id before after diff
triggersActionsUi 134 133 -1

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

Copy link
Contributor

@semd semd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@kqualters-elastic kqualters-elastic merged commit 91c8270 into elastic:main Apr 16, 2024
37 checks passed
@kibanamachine kibanamachine added the backport:skip This commit does not require backporting label Apr 16, 2024
@michaelolo24 michaelolo24 added this to the 8.14 milestone Apr 17, 2024
@kqualters-elastic kqualters-elastic deleted the cell-context-alert-table branch April 23, 2024 03:29
opauloh added a commit that referenced this pull request May 29, 2024
…e in the useGetGroupSelector hook (#184165)

## Summary

This PR fixes a regression from PR #180016 where the support to the
custom title on the `useGetGroupSelector` hook was dropped and the
Findings DataTables was displaying "Group alerts by" instead of "Group
findings by". Unit tests were added to prevent further regressions.


## Screenshots


![image](https://github.com/elastic/kibana/assets/19270322/97ac29f7-d314-4df9-a4d8-9a11b198f021)


![image](https://github.com/elastic/kibana/assets/19270322/6e6a3eef-fd4e-4619-a460-a3b0fb46ec37)


![image](https://github.com/elastic/kibana/assets/19270322/e6bcd40c-45e6-4444-8905-7c7c2c900926)
rshen91 pushed a commit to rshen91/kibana that referenced this pull request May 30, 2024
…e in the useGetGroupSelector hook (elastic#184165)

## Summary

This PR fixes a regression from PR elastic#180016 where the support to the
custom title on the `useGetGroupSelector` hook was dropped and the
Findings DataTables was displaying "Group alerts by" instead of "Group
findings by". Unit tests were added to prevent further regressions.


## Screenshots


![image](https://github.com/elastic/kibana/assets/19270322/97ac29f7-d314-4df9-a4d8-9a11b198f021)


![image](https://github.com/elastic/kibana/assets/19270322/6e6a3eef-fd4e-4619-a460-a3b0fb46ec37)


![image](https://github.com/elastic/kibana/assets/19270322/e6bcd40c-45e6-4444-8905-7c7c2c900926)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:skip This commit does not require backporting release_note:skip Skip the PR/issue when compiling release notes Team:obs-ux-management Observability Management User Experience Team Team:Threat Hunting:Investigations Security Solution Investigations Team Theme: rac label obsolete v8.14.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet