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] fix incorrect number of groups when there is a null group #207360

Merged
merged 5 commits into from
Jan 23, 2025

Conversation

alexreal1314
Copy link
Contributor

@alexreal1314 alexreal1314 commented Jan 21, 2025

Summary

This PR fixes group by logic regarding calculation of groups count when there is a null group.

Video Recording with the fix

Screen.Recording.2025-01-21.at.18.06.49.mov

BUG description

The checking of null group is scoped to the findings on a specific page, for example if we have two pages and the null group appears on the second page the number of groups will not be correct on the first page because the null group of was subtracted from the total number of groups. On the second page the number is correct because the null group was fetched in the second page.

Closes

Definition of done

  • number of groups should be correct across all pages

Checklist

  • Unit or functional tests were updated or added to match the most common scenarios
  • The PR description includes the appropriate Release Notes section, and the correct release_note:* label is applied per the guidelines

@alexreal1314 alexreal1314 requested review from a team as code owners January 21, 2025 13:50
@alexreal1314 alexreal1314 added bug Fixes for quality problems that affect the customer experience good first issue low hanging fruit release_note:skip Skip the PR/issue when compiling release notes Team:Cloud Security Cloud Security team related backport:prev-minor Backport to (9.0) the previous minor version (i.e. one version back from main) ci:cloud-deploy Create or update a Cloud deployment labels Jan 21, 2025
@elasticmachine
Copy link
Contributor

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

Copy link
Contributor

@JordanSh JordanSh left a comment

Choose a reason for hiding this comment

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

LGTM, worth adding a test case before merging

@alexreal1314
Copy link
Contributor Author

@JordanSh yes, ill add, just wanted to let the CI pipeline start running to see if there are any issues.

@JordanSh
Copy link
Contributor

@JordanSh yes, ill add, just wanted to let the CI pipeline start running to see if there are any issues.

Next time you can open the PR in draft, a gh bot will allow you to run the pipeline by ticking some boxes.
Also, I generally suggest to add images/videos to your PRs, it really makes it easier to understand the context

@alexreal1314 alexreal1314 force-pushed the 188138-incorrect-group-number branch from b6a42d6 to fb2fec0 Compare January 22, 2025 07:04
@alexreal1314 alexreal1314 changed the title fix incorrect number of groups when there is a null group [Cloud Security] fix incorrect number of groups when there is a null group Jan 22, 2025
@alexreal1314 alexreal1314 removed the ci:cloud-deploy Create or update a Cloud deployment label Jan 22, 2025
@maxcold
Copy link
Contributor

maxcold commented Jan 22, 2025

@alexreal1314 do we have the same issue with Vulnerabilities in x-pack/solutions/security/plugins/cloud_security_posture/public/pages/vulnerabilities/hooks/use_latest_vulnerabilities_grouping.tsx ? It looks like the logic there is the same as for Misconfiguration Findings

@alexreal1314
Copy link
Contributor Author

@alexreal1314 do we have the same issue with Vulnerabilities in x-pack/solutions/security/plugins/cloud_security_posture/public/pages/vulnerabilities/hooks/use_latest_vulnerabilities_grouping.tsx ? It looks like the logic there is the same as for Misconfiguration Findings

thanks, I'll check it.

@alexreal1314 alexreal1314 force-pushed the 188138-incorrect-group-number branch from fb2fec0 to c7e47b5 Compare January 22, 2025 13:57
@alexreal1314
Copy link
Contributor Author

@maxcold added same logic for vulnerabilities page as well.

Copy link
Member

@umbopepato umbopepato left a comment

Choose a reason for hiding this comment

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

Left a comment, the rest LGTM! 🙂

@@ -103,13 +103,10 @@ const GroupingComponent = <T,>({

const groupCount = useMemo(() => data?.groupsCount?.value ?? 0, [data?.groupsCount?.value]);
const groupCountText = useMemo(() => {
const hasNullGroup =
data?.groupByFields?.buckets?.some(
Copy link
Member

Choose a reason for hiding this comment

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

@alexreal1314 do you mind if we keep this old condition ||'ed with the new one? We're currently not using it in the printed text, but it feels wrong to only take into account nullGroupItems since other grouping users rely on this condition to detect null groups

Copy link
Contributor Author

@alexreal1314 alexreal1314 Jan 22, 2025

Choose a reason for hiding this comment

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

@umbopepato fixed. also added more test cases to check it

Copy link
Member

Choose a reason for hiding this comment

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

Awesome, thanks! 😊

@opauloh
Copy link
Contributor

opauloh commented Jan 23, 2025

Hi @alexreal1314, I noticed the fix works only for pre-defined groups, such as Cloud Account ID, Resource ID, Rule name and Kubernetes cluster ID. Would it be possible to include the fix for the custom field option as well?

Screen.Recording.2025-01-23.at.1.01.43.AM.mov

feel free to address that in a separate PR in case the fix is not straightforward

@alexreal1314
Copy link
Contributor Author

Hi @alexreal1314, I noticed the fix works only for pre-defined groups, such as Cloud Account ID, Resource ID, Rule name and Kubernetes cluster ID. Would it be possible to include the fix for the custom field option as well?

Screen.Recording.2025-01-23.at.1.01.43.AM.mov
feel free to address that in a separate PR in case the fix is not straightforward

Hi @opauloh thanks for letting me know, I see that when grouping custom fields it uses the totalCount instead of calculated groupsCounted, this is your change as far as I see, is there any reason for that?
https://github.com/elastic/kibana/blob/d6967b8bce617ac7694b2b8b28dc68c0577ad8c4/x-pack/solutions/security/plugins/cloud_security_posture/public/pages/configurations/latest_findings/constants.ts#L50

@opauloh
Copy link
Contributor

opauloh commented Jan 23, 2025

Hi @alexreal1314, I noticed the fix works only for pre-defined groups, such as Cloud Account ID, Resource ID, Rule name and Kubernetes cluster ID. Would it be possible to include the fix for the custom field option as well?
Screen.Recording.2025-01-23.at.1.01.43.AM.mov
feel free to address that in a separate PR in case the fix is not straightforward

Hi @opauloh thanks for letting me know, I see that when grouping custom fields it uses the totalCount instead of calculated groupsCounted, this is your change as far as I see, is there any reason for that? https://github.com/elastic/kibana/blob/d6967b8bce617ac7694b2b8b28dc68c0577ad8c4/x-pack/solutions/security/plugins/cloud_security_posture/public/pages/configurations/latest_findings/constants.ts#L50

thanks for spotting this, my only guess is that was a product requirement from the beginning that the "null group" also count as a "group" for custom fields groupings.

cc @smriti0321 could you confirm what should be the correct behavior for counting custom fields?

Copy link
Contributor

@opauloh opauloh left a comment

Choose a reason for hiding this comment

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

lgtm!

@smriti0321
Copy link

@opauloh The grouping behaviour including counting for custom and pre defined grouping fields should be consistent.

@alexreal1314 alexreal1314 force-pushed the 188138-incorrect-group-number branch from a253aec to c7746fe Compare January 23, 2025 13:08
@elasticmachine
Copy link
Contributor

💛 Build succeeded, but was flaky

Failed CI Steps

Test Failures

  • [job] [logs] FTR Configs #21 / Fleet Endpoints fleet_proxies_crud PUT /proxies/{itemId} should allow to update an existing fleet proxy

Metrics [docs]

Async chunks

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

id before after diff
cloudSecurityPosture 522.3KB 522.6KB +237.0B
observability 482.1KB 482.2KB +116.0B
securitySolution 21.3MB 21.3MB +116.0B
total +469.0B

History

@alexreal1314 alexreal1314 merged commit a5051b4 into main Jan 23, 2025
8 checks passed
@alexreal1314 alexreal1314 deleted the 188138-incorrect-group-number branch January 23, 2025 14:47
@kibanamachine
Copy link
Contributor

Starting backport for target branches: 8.x

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

kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Jan 23, 2025
…group (elastic#207360)

## Summary
This PR fixes group by logic regarding calculation of groups count when
there is a null group.

## Video Recording with the fix

https://github.com/user-attachments/assets/14e82bf3-b8d3-4287-8f90-04372be23cf2

## BUG description
The checking of null group is scoped to the findings on a specific page,
for example if we have two pages and the null group appears on the
second page the number of groups will not be correct on the first page
because the null group of was subtracted from the total number of
groups. On the second page the number is correct because the null group
was fetched in the second page.

### Closes
- elastic#188138

### Definition of done
- [x] number of groups should be correct across all pages

### Checklist
- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
- [x] The PR description includes the appropriate Release Notes section,
and the correct release_note:* label is applied per the
[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)

(cherry picked from commit a5051b4)
@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 Jan 23, 2025
… null group (#207360) (#208070)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[Cloud Security] fix incorrect number of groups when there is a null
group (#207360)](#207360)

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

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

<!--BACKPORT [{"author":{"name":"Alex
Prozorov","email":"[email protected]"},"sourceCommit":{"committedDate":"2025-01-23T14:47:05Z","message":"[Cloud
Security] fix incorrect number of groups when there is a null group
(#207360)\n\n## Summary\r\nThis PR fixes group by logic regarding
calculation of groups count when\r\nthere is a null group.\r\n\r\n##
Video Recording with the
fix\r\n\r\nhttps://github.com/user-attachments/assets/14e82bf3-b8d3-4287-8f90-04372be23cf2\r\n\r\n##
BUG description\r\nThe checking of null group is scoped to the findings
on a specific page,\r\nfor example if we have two pages and the null
group appears on the\r\nsecond page the number of groups will not be
correct on the first page\r\nbecause the null group of was subtracted
from the total number of\r\ngroups. On the second page the number is
correct because the null group\r\nwas fetched in the second
page.\r\n\r\n### Closes\r\n-
https://github.com/elastic/kibana/issues/188138\r\n\r\n### Definition of
done\r\n- [x] number of groups should be correct across all
pages\r\n\r\n### Checklist\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n- [x] The PR
description includes the appropriate Release Notes section,\r\nand the
correct release_note:* label is applied per
the\r\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)","sha":"a5051b48a9d1af6f2caae747a2ee2af0e5ccf0df","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["bug","good
first issue","release_note:skip","v9.0.0","Team:Cloud
Security","backport:prev-minor"],"title":"[Cloud Security] fix incorrect
number of groups when there is a null
group","number":207360,"url":"https://github.com/elastic/kibana/pull/207360","mergeCommit":{"message":"[Cloud
Security] fix incorrect number of groups when there is a null group
(#207360)\n\n## Summary\r\nThis PR fixes group by logic regarding
calculation of groups count when\r\nthere is a null group.\r\n\r\n##
Video Recording with the
fix\r\n\r\nhttps://github.com/user-attachments/assets/14e82bf3-b8d3-4287-8f90-04372be23cf2\r\n\r\n##
BUG description\r\nThe checking of null group is scoped to the findings
on a specific page,\r\nfor example if we have two pages and the null
group appears on the\r\nsecond page the number of groups will not be
correct on the first page\r\nbecause the null group of was subtracted
from the total number of\r\ngroups. On the second page the number is
correct because the null group\r\nwas fetched in the second
page.\r\n\r\n### Closes\r\n-
https://github.com/elastic/kibana/issues/188138\r\n\r\n### Definition of
done\r\n- [x] number of groups should be correct across all
pages\r\n\r\n### Checklist\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n- [x] The PR
description includes the appropriate Release Notes section,\r\nand the
correct release_note:* label is applied per
the\r\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)","sha":"a5051b48a9d1af6f2caae747a2ee2af0e5ccf0df"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/207360","number":207360,"mergeCommit":{"message":"[Cloud
Security] fix incorrect number of groups when there is a null group
(#207360)\n\n## Summary\r\nThis PR fixes group by logic regarding
calculation of groups count when\r\nthere is a null group.\r\n\r\n##
Video Recording with the
fix\r\n\r\nhttps://github.com/user-attachments/assets/14e82bf3-b8d3-4287-8f90-04372be23cf2\r\n\r\n##
BUG description\r\nThe checking of null group is scoped to the findings
on a specific page,\r\nfor example if we have two pages and the null
group appears on the\r\nsecond page the number of groups will not be
correct on the first page\r\nbecause the null group of was subtracted
from the total number of\r\ngroups. On the second page the number is
correct because the null group\r\nwas fetched in the second
page.\r\n\r\n### Closes\r\n-
https://github.com/elastic/kibana/issues/188138\r\n\r\n### Definition of
done\r\n- [x] number of groups should be correct across all
pages\r\n\r\n### Checklist\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n- [x] The PR
description includes the appropriate Release Notes section,\r\nand the
correct release_note:* label is applied per
the\r\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)","sha":"a5051b48a9d1af6f2caae747a2ee2af0e5ccf0df"}}]}]
BACKPORT-->

Co-authored-by: Alex Prozorov <[email protected]>
viduni94 pushed a commit to viduni94/kibana that referenced this pull request Jan 23, 2025
…group (elastic#207360)

## Summary
This PR fixes group by logic regarding calculation of groups count when
there is a null group.

## Video Recording with the fix

https://github.com/user-attachments/assets/14e82bf3-b8d3-4287-8f90-04372be23cf2

## BUG description
The checking of null group is scoped to the findings on a specific page,
for example if we have two pages and the null group appears on the
second page the number of groups will not be correct on the first page
because the null group of was subtracted from the total number of
groups. On the second page the number is correct because the null group
was fetched in the second page.

### Closes
- elastic#188138

### Definition of done
- [x] number of groups should be correct across all pages

### Checklist
- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
- [x] The PR description includes the appropriate Release Notes section,
and the correct release_note:* label is applied per the
[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)
qn895 pushed a commit to qn895/kibana that referenced this pull request Jan 23, 2025
…group (elastic#207360)

## Summary
This PR fixes group by logic regarding calculation of groups count when
there is a null group.

## Video Recording with the fix

https://github.com/user-attachments/assets/14e82bf3-b8d3-4287-8f90-04372be23cf2

## BUG description
The checking of null group is scoped to the findings on a specific page,
for example if we have two pages and the null group appears on the
second page the number of groups will not be correct on the first page
because the null group of was subtracted from the total number of
groups. On the second page the number is correct because the null group
was fetched in the second page.

### Closes
- elastic#188138

### Definition of done
- [x] number of groups should be correct across all pages

### Checklist
- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
- [x] The PR description includes the appropriate Release Notes section,
and the correct release_note:* label is applied per the
[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)
JoseLuisGJ pushed a commit to JoseLuisGJ/kibana that referenced this pull request Jan 27, 2025
…group (elastic#207360)

## Summary
This PR fixes group by logic regarding calculation of groups count when
there is a null group.

## Video Recording with the fix

https://github.com/user-attachments/assets/14e82bf3-b8d3-4287-8f90-04372be23cf2

## BUG description
The checking of null group is scoped to the findings on a specific page,
for example if we have two pages and the null group appears on the
second page the number of groups will not be correct on the first page
because the null group of was subtracted from the total number of
groups. On the second page the number is correct because the null group
was fetched in the second page.

### Closes
- elastic#188138

### Definition of done
- [x] number of groups should be correct across all pages

### Checklist
- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
- [x] The PR description includes the appropriate Release Notes section,
and the correct release_note:* label is applied per the
[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:prev-minor Backport to (9.0) the previous minor version (i.e. one version back from main) bug Fixes for quality problems that affect the customer experience good first issue low hanging fruit 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.

Grouped by Cloud account shows an incorrect number when there are multiple pages
8 participants