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

[Cloud Security] Refactor Contextual Flyout #200291

Merged
merged 12 commits into from
Nov 21, 2024

Conversation

animehart
Copy link
Contributor

@animehart animehart commented Nov 15, 2024

Summary

This PR is for reducing code duplication by Encapsulating Hooks, Functions, constants that are used multiple times in a same manner accross multiple files

@animehart
Copy link
Contributor Author

/ci

@animehart
Copy link
Contributor Author

/ci

@animehart
Copy link
Contributor Author

/ci

1 similar comment
@animehart
Copy link
Contributor Author

/ci

@animehart animehart marked this pull request as ready for review November 18, 2024 02:26
@animehart animehart requested review from a team as code owners November 18, 2024 02:26
@animehart animehart requested a review from tiansivive November 18, 2024 02:26
@animehart animehart added the Team:Cloud Security Cloud Security team related label Nov 18, 2024
@elasticmachine
Copy link
Contributor

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

@animehart animehart added release_note:skip Skip the PR/issue when compiling release notes v8.17.0 v9.0.0 backport:prev-minor Backport to (8.x) the previous minor version (i.e. one version back from main) labels Nov 18, 2024
@animehart animehart requested a review from maxcold November 18, 2024 02:28
Copy link
Contributor

@tiansivive tiansivive left a comment

Choose a reason for hiding this comment

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

LGTM from Entity Analytics

Copy link
Contributor

@albertoblaz albertoblaz left a comment

Choose a reason for hiding this comment

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

Very nice work encapsulating a lot of repititions into these hooks. I'm still not familiar with the code and how these hooks work, but I added some comments. Feel free to disregard if they don't make sense

signalIndexName,
queryId: `${DETECTION_RESPONSE_ALERTS_BY_STATUS_ID}HOST_NAME_RIGHT`,
const { hasNonClosedAlerts } = useNonClosedAlerts({
fieldName: 'host.name',
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd put host.name in a constant because this literal is passed down to all these hooks

(isRiskScoreExist ||
hasMisconfigurationFindings ||
hasVulnerabilitiesFindings ||
hasNonClosedAlerts)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are you adding hasNonClosedAlerts here? Is it fixing a bug? We should try not to mix changes of functionality in refactor PRs

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi !, yes this is to fix a small bug that I found when refactoring the code

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have created a separate PR for this small fix as this PR is too big and risky to be included before FF, but this fix should be small enough and safe

Copy link
Contributor

Choose a reason for hiding this comment

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

Awesome! I just approved that PR. I'd ship it separately and remove hasNonClosedAlerts from here. That way, we'll have a clean refactor-only change-set on this PR

Comment on lines -51 to -56
const { data } = useVulnerabilitiesPreview({
query: buildEntityFlyoutPreviewQuery(fieldName, name),
sort: [],
enabled: true,
pageSize: 1,
});
Copy link
Contributor

Choose a reason for hiding this comment

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

it seems we didn't use ignore_unavailable here, but we'll do so now with the hook. How will that affect the behavior?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

useVulnerabilitiesPreview doesnt use the ignore_unavailable field so it should have no effect

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, wrong line. I meant the other useMisconfigurationsPreview.

I saw you removed ignore_unavailable from the hook, so 👍

Comment on lines -106 to -111
const { data: dataMisconfiguration } = useMisconfigurationPreview({
query: buildEntityFlyoutPreviewQuery('host.name', name),
sort: [],
enabled: true,
pageSize: 1,
});
Copy link
Contributor

Choose a reason for hiding this comment

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

it seems we didn't use ignore_unavailable here, but we'll do so now with the hook. How will that affect the behavior?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good catch, I left this one when debugging an issue, will remove it

@albertoblaz
Copy link
Contributor

You might want to add a backport:versions tag if you're specifically targeting v8.17 and v9. Or isn't it necessary?

@albertoblaz albertoblaz added the backport:version Backport to applied version labels label Nov 19, 2024
@maxcold maxcold removed backport:version Backport to applied version labels v8.17.0 labels Nov 19, 2024
@maxcold
Copy link
Contributor

maxcold commented Nov 19, 2024

@albertoblaz @animehart I suggest we wait till 8.17 is branched out to have this refactoring in 8.18 to be on the safe side. Not sure if merging it in 8.17 on the day of the FF is a good idea

@maxcold maxcold self-requested a review November 19, 2024 10:59
Copy link
Contributor

@maxcold maxcold left a comment

Choose a reason for hiding this comment

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

blocking until the 8.17 is branched out, just to be in the safe side

@maxcold
Copy link
Contributor

maxcold commented Nov 21, 2024

Unblocking as 8.17 has been branched out and 8.x now pointing to 8.18

@elasticmachine
Copy link
Contributor

💛 Build succeeded, but was flaky

Failed CI Steps

Test Failures

  • [job] [logs] Jest Tests #3 / PackagePolicyActionsMenu Should disable upgrade button if package does not have upgrade

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
securitySolution 6218 6223 +5

Async chunks

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

id before after diff
securitySolution 13.4MB 13.4MB -1.5KB

History

@animehart animehart merged commit c842db5 into elastic:main Nov 21, 2024
46 checks passed
@kibanamachine
Copy link
Contributor

Starting backport for target branches: 8.x

https://github.com/elastic/kibana/actions/runs/11961194600

kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Nov 21, 2024
## Summary

This PR is for reducing code duplication by Encapsulating Hooks,
Functions, constants that are used multiple times in a same manner
accross multiple files

---------

Co-authored-by: kibanamachine <[email protected]>
Co-authored-by: Maxim Kholod <[email protected]>
(cherry picked from commit c842db5)
@kibanamachine
Copy link
Contributor

💚 All backports created successfully

Status Branch Result
8.x

Note: Successful backport PRs will be merged automatically after passing CI.

Questions ?

Please refer to the Backport tool documentation

kibanamachine added a commit that referenced this pull request Nov 21, 2024
# Backport

This will backport the following commits from `main` to `8.x`:
- [[Cloud Security] Refactor Contextual Flyout
(#200291)](#200291)

<!--- Backport version: 9.4.3 -->

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

<!--BACKPORT [{"author":{"name":"Rickyanto
Ang","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-11-21T20:33:30Z","message":"[Cloud
Security] Refactor Contextual Flyout (#200291)\n\n## Summary\r\n\r\nThis
PR is for reducing code duplication by Encapsulating
Hooks,\r\nFunctions, constants that are used multiple times in a same
manner\r\naccross multiple files\r\n\r\n---------\r\n\r\nCo-authored-by:
kibanamachine
<[email protected]>\r\nCo-authored-by:
Maxim Kholod
<[email protected]>","sha":"c842db549ac55238499d63033f046d744ee18ba1","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","v9.0.0","Team:Cloud
Security","backport:prev-minor","v8.18.0"],"title":"[Cloud Security]
Refactor Contextual
Flyout","number":200291,"url":"https://github.com/elastic/kibana/pull/200291","mergeCommit":{"message":"[Cloud
Security] Refactor Contextual Flyout (#200291)\n\n## Summary\r\n\r\nThis
PR is for reducing code duplication by Encapsulating
Hooks,\r\nFunctions, constants that are used multiple times in a same
manner\r\naccross multiple files\r\n\r\n---------\r\n\r\nCo-authored-by:
kibanamachine
<[email protected]>\r\nCo-authored-by:
Maxim Kholod
<[email protected]>","sha":"c842db549ac55238499d63033f046d744ee18ba1"}},"sourceBranch":"main","suggestedTargetBranches":["8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/200291","number":200291,"mergeCommit":{"message":"[Cloud
Security] Refactor Contextual Flyout (#200291)\n\n## Summary\r\n\r\nThis
PR is for reducing code duplication by Encapsulating
Hooks,\r\nFunctions, constants that are used multiple times in a same
manner\r\naccross multiple files\r\n\r\n---------\r\n\r\nCo-authored-by:
kibanamachine
<[email protected]>\r\nCo-authored-by:
Maxim Kholod
<[email protected]>","sha":"c842db549ac55238499d63033f046d744ee18ba1"}},{"branch":"8.x","label":"v8.18.0","branchLabelMappingKey":"^v8.18.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Rickyanto Ang <[email protected]>
paulinashakirova pushed a commit to paulinashakirova/kibana that referenced this pull request Nov 26, 2024
## Summary

This PR is for reducing code duplication by Encapsulating Hooks,
Functions, constants that are used multiple times in a same manner
accross multiple files

---------

Co-authored-by: kibanamachine <[email protected]>
Co-authored-by: Maxim Kholod <[email protected]>
CAWilson94 pushed a commit to CAWilson94/kibana that referenced this pull request Dec 12, 2024
## Summary

This PR is for reducing code duplication by Encapsulating Hooks,
Functions, constants that are used multiple times in a same manner
accross multiple files

---------

Co-authored-by: kibanamachine <[email protected]>
Co-authored-by: Maxim Kholod <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:prev-minor Backport to (8.x) the previous minor version (i.e. one version back from main) release_note:skip Skip the PR/issue when compiling release notes Team:Cloud Security Cloud Security team related v8.18.0 v9.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants