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

[EuiProvider/Security Solution] Remove usage of deprecated modules for mounting React, Part II #182061

Conversation

tsullivan
Copy link
Member

@tsullivan tsullivan commented Apr 29, 2024

Summary

Partially addresses https://github.com/elastic/kibana-team/issues/805

These changes come up from searching in the code and finding where certain kinds of deprecated AppEx-SharedUX modules are imported. Reviewers: Please interact with critical paths through the UI components touched in this PR, ESPECIALLY in terms of testing dark mode and i18n.

This is the 2nd PR to focus on code within Security Solution, following #181099.

image

Note: this also makes inclusion of i18n and analytics dependencies consistent. Analytics is an optional dependency for the SharedUX modules, which wrap KibanaErrorBoundaryProvider and is designed to capture telemetry about errors that are caught in the error boundary.

Checklist

Delete any items that are not applicable to this PR.

@tsullivan tsullivan force-pushed the sharedux/cleanup-tomountpoint-deprecations-xii-threatintelligence branch 2 times, most recently from e1ff360 to c7b6273 Compare April 30, 2024 21:34
@tsullivan tsullivan force-pushed the sharedux/cleanup-tomountpoint-deprecations-xii-threatintelligence branch from c7b6273 to 913db5e Compare April 30, 2024 23:35
@tsullivan tsullivan changed the title [ThreatIntelligence] Remove usage of deprecated modules for mounting … [Security Solutions] Remove usage of deprecated modules for mounting … Apr 30, 2024
@tsullivan tsullivan force-pushed the sharedux/cleanup-tomountpoint-deprecations-xii-threatintelligence branch from 78f6bbc to b22e6c6 Compare May 1, 2024 22:24
@tsullivan tsullivan changed the title [Security Solutions] Remove usage of deprecated modules for mounting … [Security Solution] Remove usage of deprecated modules for mounting React, Part II May 2, 2024
@tsullivan tsullivan marked this pull request as ready for review May 2, 2024 23:32
@tsullivan tsullivan requested review from a team as code owners May 2, 2024 23:32
@tsullivan tsullivan added Team: SecuritySolution Security Solutions Team working on SIEM, Endpoint, Timeline, Resolver, etc. Team:Threat Hunting:Investigations Security Solution Investigations Team Team:Threat Hunting:Explore Team:Cloud Security Cloud Security team related Team:Detection Engine Security Solution Detection Engine Area labels May 2, 2024
@tsullivan tsullivan added the release_note:skip Skip the PR/issue when compiling release notes label May 2, 2024
@elasticmachine
Copy link
Contributor

Pinging @elastic/security-solution (Team: SecuritySolution)

@elasticmachine
Copy link
Contributor

Pinging @elastic/security-threat-hunting-explore (Team:Threat Hunting:Explore)

@elasticmachine
Copy link
Contributor

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

@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-cloud-security-posture (Team:Cloud Security)

@elasticmachine
Copy link
Contributor

Pinging @elastic/security-detection-engine (Team:Detection Engine)

@elasticmachine
Copy link
Contributor

Pinging @elastic/security-defend-workflows (Team:Defend Workflows)

Copy link
Member

@ashokaditya ashokaditya left a comment

Choose a reason for hiding this comment

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

Did a code review only. LGTM. I would wait for @szwarckonrad or @tomsonpl to verify osquery changes.

}: GetColumnProps): Array<EuiTableFieldDataColumnType<CspBenchmarkRulesWithStates>> => [
{
field: 'action',
name: (
<EuiCheckbox
id={RULES_ROW_SELECT_ALL_CURRENT_PAGE}
checked={isCurrentPageRulesASubset(items, selectedRules) && isAllRulesSelectedThisPage}
onChange={(e) => {
onChange={(_e) => {
Copy link
Member

Choose a reason for hiding this comment

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

Should be safe to remove this unused param

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Contributor

@e40pud e40pud left a comment

Choose a reason for hiding this comment

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

DE changes LGTM

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.

desk tested and code LGTM for the Threat Hunting Investigations team!

Copy link
Member

@ashokaditya ashokaditya left a comment

Choose a reason for hiding this comment

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

Thanks for the changes.

Copy link
Contributor

@seanrathier seanrathier left a comment

Choose a reason for hiding this comment

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

Approved.
Tested on local environment.
1 non-blocking question

@@ -58,14 +58,15 @@ export const DetectionRuleCounter = ({ tags, createRuleFn }: DetectionRuleCounte
}, [history]);

const createDetectionRuleOnClick = useCallback(async () => {
const startServices = { analytics, notifications, i18n, theme };
Copy link
Contributor

Choose a reason for hiding this comment

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

Newbie question: I thought these service were started when Kibana loads the plugins when it starts up since these are CoreStartup services.

Is validating the services have started?
If some of these services are the Notification service dependencies, should that service start it instead of passing them as params?

Copy link
Member Author

@tsullivan tsullivan May 6, 2024

Choose a reason for hiding this comment

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

Newbie question: I thought these service were started when Kibana loads the plugins when it starts up since these are CoreStartup services.
Is validating the services have started?

This is a good question.

  • The services are started when Kibana loads up. My startServices variable is just a made-up name for a wrapper object of a few specific services that are available in CoreStart.
  • This PR focuses on updating the toMountPoint and KibanaRenderContextProvider components, which are owned by SharedUX. They need the analytics, i18n and theme services to be passed in. Rather than using a literal object of { analytics, i18n, theme }, I created a wrapper object, thinking that it's slightly less restrictive - more services could be needed for these components in the future..
  • The previous code was only making the notifications service usable for downstream code. This change makes a set of services usable by creating the startServices wrapper object.
  • These changes aren't about validating that the services have started.

If you're wondering, how does calling useKibana().services give us access to these services? They were stashed into a context in x-pack/plugins/cloud_security_posture/public/plugin.tsx with <KibanaContextProvider services={{ ...core, ...plugins, storage }}>. Therefore, everything nested under that provider can access these startup services from the context. Calling the hook to get the context saves us from having to pass down the services to every component through props.

If some of these services are the Notification service dependencies, should that service start it instead of passing them as params?

I take this to mean, couldn't we just call useKibana().services to fetch the services from context where they're needed? I chose to stick with the existing coding style and pass them down from here. Also, React hooks can only be called from React components, and showCreateDetectionRuleSuccessToast / showChangeBenchmarkRuleStatesSuccessToast are not React components.

Copy link
Member Author

Choose a reason for hiding this comment

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

@seanrathier while going through the code to address your question, I found a few places that could be cleaned up: e941e01

@tsullivan tsullivan enabled auto-merge (squash) May 6, 2024 21:45
@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
cloudSecurityPosture 438 453 +15
osquery 336 347 +11
timelines 121 138 +17
total +43

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
timelines 196 198 +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 452.6KB 454.7KB +2.1KB
osquery 1.0MB 1.0MB -582.0B
securitySolution 13.7MB 13.7MB +540.0B
threatIntelligence 57.1KB 57.3KB +259.0B
timelines 30.3KB 32.7KB +2.4KB
total +4.8KB

Page load bundle

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

id before after diff
cloudSecurityPosture 16.1KB 16.3KB +141.0B
osquery 51.1KB 53.6KB +2.4KB
timelines 108.9KB 109.3KB +370.0B
total +2.9KB
Unknown metric groups

API count

id before after diff
timelines 240 242 +2

References to deprecated APIs

id before after diff
cloudSecurityPosture 9 4 -5
osquery 22 9 -13
timelines 2 0 -2
total -20

History

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

cc @tsullivan

@tsullivan tsullivan merged commit a6ddf51 into elastic:main May 7, 2024
39 checks passed
@kibanamachine kibanamachine added v8.15.0 backport:skip This commit does not require backporting labels May 7, 2024
@tsullivan tsullivan deleted the sharedux/cleanup-tomountpoint-deprecations-xii-threatintelligence branch May 7, 2024 00:40
@tsullivan tsullivan changed the title [Security Solution] Remove usage of deprecated modules for mounting React, Part II [EuiProvider/Security Solution] Remove usage of deprecated modules for mounting React, Part II Jul 20, 2024
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:Cloud Security Cloud Security team related Team:Defend Workflows “EDR Workflows” sub-team of Security Solution Team:Detection Engine Security Solution Detection Engine Area Team: SecuritySolution Security Solutions Team working on SIEM, Endpoint, Timeline, Resolver, etc. Team:Threat Hunting:Explore Team:Threat Hunting:Investigations Security Solution Investigations Team technical debt Improvement of the software architecture and operational architecture v8.15.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants