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] Alerts Datagrids for Contextual Flyout #199573

Conversation

animehart
Copy link
Contributor

@animehart animehart commented Nov 9, 2024

Summary

This PR is for Alerts Datagrid component in Contextual Flyout

This PR is for Alerts Datagrid in Contextual Flyout for User name and Host name
Screenshot 2024-11-14 at 9 08 26 AM

@animehart
Copy link
Contributor Author

/ci

@animehart
Copy link
Contributor Author

/ci

@animehart animehart marked this pull request as ready for review November 13, 2024 22:49
@animehart animehart requested review from a team as code owners November 13, 2024 22:49
@animehart animehart requested a review from machadoum November 13, 2024 22:49
@animehart
Copy link
Contributor Author

/ci

@animehart animehart added 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 labels Nov 13, 2024
@elasticmachine
Copy link
Contributor

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

@animehart animehart requested a review from a team as a code owner November 14, 2024 02:30
@animehart animehart requested a review from maxcold November 14, 2024 02:39
@animehart animehart removed the request for review from a team November 14, 2024 05:35
@@ -82,9 +107,120 @@ export const AlertsPreview = ({

const totalAlertsCount = alertStats.reduce((total, item) => total + item.count, 0);

const { data } = useMisconfigurationPreview({
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't understand why we need all this logic (getting misconfigs, vulnerabilities, riskScore) in the alert preview. From what I see we open the Alerts data grid in the left section of the flyout, this section doesn't have information about risk, misconfigs and vulnerabilities, then why all this data is needed?

Copy link
Contributor Author

@animehart animehart Nov 14, 2024

Choose a reason for hiding this comment

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

We need this to pass it to the openLeftPanel, if we don't have this then when user opens the left panel, it doesn't know if it also has to render Misconfiguration/Vulnerabilities/Risk Score tabs

this logic is also being used on the 2 other preview component

Copy link
Contributor

Choose a reason for hiding this comment

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

Follow up on our discussion in DM:

  1. First problem that we want to address is to encapsulate this logic in one place because right now it's copied over in 6 different places. We can start with one hook per piece of business logic (alerts, misconfigs, vulnerabilities, risk score) exposing and consuming only the pieces needed to a particular component. another possibility is to share this state through context
  2. Another question, probably post 8.17 FF is to check if it's a good idea to have all these props passed to openLeftPanel . We do similar things in 3 places: load data we don't need in the component only to pass it to openLeftPanel. Maybe it should be self aware and get the information required to show the tabs by itself instead of getting them from the props

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here is the followup PR point number 1 above

<VulnerabilitiesFindingsDetailsTable queryName={name} />
) : (
// <div>{'ALERTS HERE'}</div> //AlertsDetailsTable
Copy link
Contributor

Choose a reason for hiding this comment

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

leftover

@@ -112,6 +115,26 @@ export const UserPanel = ({

const hasMisconfigurationFindings = passedFindings > 0 || failedFindings > 0;

const { signalIndexName } = useSignalIndex();
Copy link
Contributor

Choose a reason for hiding this comment

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

you have this logic duplicated in multiple places, we need to abstract it

<MisconfigurationsPreview
name={name}
fieldName={fieldName}
hasNonClosedAlerts={alertsCount > 0}
Copy link
Contributor

Choose a reason for hiding this comment

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

It feels conceptually incorrect that the Misconfiguration and Vulnerability preview should know about non-closed alerts. Why do we need it here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

same reason as the checking existence of Misconfiguration and Vulnerability in Alerts Preview, we need to pass this information when opening left panel so it knows what tabs gets rendered

Copy link
Member

@machadoum machadoum left a comment

Choose a reason for hiding this comment

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

EA team changes LGTM!

I left some minor comments. Could you please take a look?

Comment on lines 138 to 144
const alertsOpenCount = alertsData?.open?.total || 0;

const alertsAcknowledgedCount = alertsData?.acknowledged?.total || 0;

const alertsCount = alertsOpenCount + alertsAcknowledgedCount;

const hasNonClosedAlerts = alertsCount;
Copy link
Member

Choose a reason for hiding this comment

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

nit: When a variable name starts with "has", it is expected to be a boolean.

Suggested change
const alertsOpenCount = alertsData?.open?.total || 0;
const alertsAcknowledgedCount = alertsData?.acknowledged?.total || 0;
const alertsCount = alertsOpenCount + alertsAcknowledgedCount;
const hasNonClosedAlerts = alertsCount;
const hasNonClosedAlerts = (alertsData?.acknowledged?.total || 0 + alertsData?.open?.total || 0) > 0;

<VulnerabilitiesFindingsDetailsTable queryName={name} />
) : (
// <div>{'ALERTS HERE'}</div> //AlertsDetailsTable
Copy link
Member

Choose a reason for hiding this comment

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

You forgot some comments here.

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
securitySolution 6201 6202 +1

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 +7.3KB

History


const { openLeftPanel } = useExpandableFlyoutApi();

const goToEntityInsightTab = useCallback(() => {
Copy link
Contributor

Choose a reason for hiding this comment

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

let's also move this logic into own component/utility . You have this goToEntityInsightTab in all three preview component, and it's only different by subTab and the tooltip. So it can be just a hook that depending on the passed type (alerts, misconfiguration, vulnerability) returns the link

@maxcold
Copy link
Contributor

maxcold commented Nov 14, 2024

To not turn PR into huge refactoring PR, let's merge this one and do the refactoring of removing code duplication in a follow up. I tested the current logic, it works as expected

@animehart animehart merged commit ab965f7 into elastic:main Nov 14, 2024
43 checks passed
@kibanamachine
Copy link
Contributor

Starting backport for target branches: 8.x

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

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

This PR is for Alerts Datagrid component in Contextual Flyout

This PR is for Alerts Datagrid in Contextual Flyout for User name and
Host name
<img width="1480" alt="Screenshot 2024-11-14 at 9 08 26 AM"
src="https://github.com/user-attachments/assets/46a254c8-b7f1-4b63-9637-2b1c281d5502">

---------

Co-authored-by: kibanamachine <[email protected]>
(cherry picked from commit ab965f7)
@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 14, 2024
… (#200245)

# Backport

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

<!--- 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-14T19:07:26Z","message":"[Cloud
Security] Alerts Datagrids for Contextual Flyout (#199573)\n\n##
Summary\r\n\r\nThis PR is for Alerts Datagrid component in Contextual
Flyout\r\n\r\nThis PR is for Alerts Datagrid in Contextual Flyout for
User name and\r\nHost name\r\n<img width=\"1480\" alt=\"Screenshot
2024-11-14 at 9 08
26 AM\"\r\nsrc=\"https://github.com/user-attachments/assets/46a254c8-b7f1-4b63-9637-2b1c281d5502\">\r\n\r\n---------\r\n\r\nCo-authored-by:
kibanamachine
<[email protected]>","sha":"ab965f75a6bdfb75e2a29454d8f3830d0cf4cf18","branchLabelMapping":{"^v9.0.0$":"main","^v8.17.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","v9.0.0","Team:Cloud
Security","backport:prev-minor","v8.17.0"],"title":"[Cloud Security]
Alerts Datagrids for Contextual
Flyout","number":199573,"url":"https://github.com/elastic/kibana/pull/199573","mergeCommit":{"message":"[Cloud
Security] Alerts Datagrids for Contextual Flyout (#199573)\n\n##
Summary\r\n\r\nThis PR is for Alerts Datagrid component in Contextual
Flyout\r\n\r\nThis PR is for Alerts Datagrid in Contextual Flyout for
User name and\r\nHost name\r\n<img width=\"1480\" alt=\"Screenshot
2024-11-14 at 9 08
26 AM\"\r\nsrc=\"https://github.com/user-attachments/assets/46a254c8-b7f1-4b63-9637-2b1c281d5502\">\r\n\r\n---------\r\n\r\nCo-authored-by:
kibanamachine
<[email protected]>","sha":"ab965f75a6bdfb75e2a29454d8f3830d0cf4cf18"}},"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/199573","number":199573,"mergeCommit":{"message":"[Cloud
Security] Alerts Datagrids for Contextual Flyout (#199573)\n\n##
Summary\r\n\r\nThis PR is for Alerts Datagrid component in Contextual
Flyout\r\n\r\nThis PR is for Alerts Datagrid in Contextual Flyout for
User name and\r\nHost name\r\n<img width=\"1480\" alt=\"Screenshot
2024-11-14 at 9 08
26 AM\"\r\nsrc=\"https://github.com/user-attachments/assets/46a254c8-b7f1-4b63-9637-2b1c281d5502\">\r\n\r\n---------\r\n\r\nCo-authored-by:
kibanamachine
<[email protected]>","sha":"ab965f75a6bdfb75e2a29454d8f3830d0cf4cf18"}},{"branch":"8.x","label":"v8.17.0","branchLabelMappingKey":"^v8.17.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

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

This PR is for Alerts Datagrid component in Contextual Flyout

This PR is for Alerts Datagrid in Contextual Flyout for User name and
Host name
<img width="1480" alt="Screenshot 2024-11-14 at 9 08 26 AM"
src="https://github.com/user-attachments/assets/46a254c8-b7f1-4b63-9637-2b1c281d5502">

---------

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

This PR is for Alerts Datagrid component in Contextual Flyout

This PR is for Alerts Datagrid in Contextual Flyout for User name and
Host name
<img width="1480" alt="Screenshot 2024-11-14 at 9 08 26 AM"
src="https://github.com/user-attachments/assets/46a254c8-b7f1-4b63-9637-2b1c281d5502">

---------

Co-authored-by: kibanamachine <[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.17.0 v9.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants