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] changed findings group by name to group by id #206379

Merged
merged 5 commits into from
Jan 16, 2025

Conversation

alexreal1314
Copy link
Contributor

@alexreal1314 alexreal1314 commented Jan 12, 2025

Summary

This PR fixes group by logic in the findings table to be based on resource.id instead of resource.name.

Screenshots

image

Closes

Definition of done

  • When grouping findings by Resource, the findings are grouped by resource.id
  • The group title should still contain resource.name for better UX in combination with the id
  • The label in the grouping properties should be Resource ID, not just Resource

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 added bug Fixes for quality problems that affect the customer experience good first issue low hanging fruit Team:Cloud Security Cloud Security team related labels Jan 12, 2025
@alexreal1314 alexreal1314 requested a review from a team as a code owner January 12, 2025 16:33
@elasticmachine
Copy link
Contributor

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

@alexreal1314 alexreal1314 added release_note:skip Skip the PR/issue when compiling release notes backport:prev-minor Backport to (9.0) the previous minor version (i.e. one version back from main) backport:skip This commit does not require backporting and removed backport:prev-minor Backport to (9.0) the previous minor version (i.e. one version back from main) labels Jan 12, 2025
@alexreal1314 alexreal1314 force-pushed the 9782-use-resource-id-group-by branch 2 times, most recently from 6205502 to b0e4fab Compare January 13, 2025 16:06
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 overall, could you also update the Cloud Security Posture dashboard resources URL to redirect to Group by resource.id page as well?

Screen.Recording.2025-01-14.at.9.21.31.PM.mov

Comment on lines +34 to +37
selectedGroup: string,
bucket: RawBucket<FindingsGroupingAggregation>,
nullGroupMessage: string | undefined,
isLoading: boolean | undefined
Copy link
Contributor

Choose a reason for hiding this comment

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

nice one!

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.

Would be great to implement @opauloh's suggestion but I'll approve the PR now

@alexreal1314 alexreal1314 force-pushed the 9782-use-resource-id-group-by branch from d6dfbf2 to 88ee317 Compare January 15, 2025 08:43
@alexreal1314
Copy link
Contributor Author

@albertoblaz fixed @opauloh comment.

Comment on lines 48 to 60
const getGroupPanelTitle = () => {
if (bucket.resourceName?.buckets) {
return (
<>
<strong>{bucket.resourceName.buckets[0]?.key}</strong> - {bucket.key_as_string}
</>
);
}

return <strong>{bucket.key_as_string}</strong>;
};
Copy link
Contributor

@JordanSh JordanSh Jan 15, 2025

Choose a reason for hiding this comment

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

note that an empty array in bucket.resourceName?.buckets can count as true, which will lead into undefined bucket.resourceName.buckets[0]?.key that will be presented in bold.

instead, i suggest to directly check that we have a bucket.resourceName.buckets[0]?.key to decide if we want to render it or just bucket.key_as_string.

i also suggest to add named constants for those values so it will be easier to understand what exactly are we rendering.

Suggested change
const getGroupPanelTitle = () => {
if (bucket.resourceName?.buckets) {
return (
<>
<strong>{bucket.resourceName.buckets[0]?.key}</strong> - {bucket.key_as_string}
</>
);
}
return <strong>{bucket.key_as_string}</strong>;
};
const getGroupPanelTitle = () => {
const resourceName = bucket.resourceName?.buckets[0]?.key;
const resourceId = bucket.key_as_string || 'Some default value like "Missing ID"';
return resourceName ? (
<>
<strong>{resourceName}</strong> - {resourceId}
</>
) : (
<strong>{resourceId}</strong>
);
};

Copy link
Contributor Author

@alexreal1314 alexreal1314 Jan 15, 2025

Choose a reason for hiding this comment

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

@JordanSh fixed, although i didnt use resourceName variable as it is not always resourceId.

Copy link
Contributor

Choose a reason for hiding this comment

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

can you elaborate? what else can it be?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@JordanSh account id for example. any category from the group by menu.

Comment on lines +89 to +92
case FINDINGS_GROUPING_OPTIONS.RESOURCE_ID:
return [
...aggMetrics,
getTermAggregation('resourceName', 'resource.id'),
getTermAggregation('resourceName', 'resource.name'),
Copy link
Contributor

Choose a reason for hiding this comment

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

can you provide some context around this change? wouldn't resource.id should be used in FINDINGS_GROUPING_OPTIONS.RESOURCE_ID?
just an observation as im not too familiar with this code

Copy link
Contributor

Choose a reason for hiding this comment

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

I believe this is required to get more data for the group, as we use resource.name in the group title, we need to aggregate by it

Copy link
Contributor

Choose a reason for hiding this comment

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

yes to what @maxcold said, this aggregation retrieves additional data used on this grouping visualization (.ie resources view will retrieve resources name so it can display the resource name under the resource id, cloud account view will retrieve the cloud provider and so on)

Comment on lines +89 to +92
case FINDINGS_GROUPING_OPTIONS.RESOURCE_ID:
return [
...aggMetrics,
getTermAggregation('resourceName', 'resource.id'),
getTermAggregation('resourceName', 'resource.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 believe this is required to get more data for the group, as we use resource.name in the group title, we need to aggregate by it

@alexreal1314 alexreal1314 force-pushed the 9782-use-resource-id-group-by branch from 41dd882 to 7b31986 Compare January 15, 2025 14:48
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! Great work

@alexreal1314 alexreal1314 force-pushed the 9782-use-resource-id-group-by branch from 1800e39 to cd4c937 Compare January 16, 2025 10:43
@elasticmachine
Copy link
Contributor

💛 Build succeeded, but was flaky

Failed CI Steps

Test Failures

  • [job] [logs] FTR Configs #5 / Alerting improving alert severity should correctly set severity_improving and previous_action_group data in alert document

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 521.4KB 521.5KB +136.0B

History

@alexreal1314 alexreal1314 force-pushed the 9782-use-resource-id-group-by branch 2 times, most recently from 00d1ab3 to 1fbe394 Compare January 16, 2025 13:16
@maxcold maxcold self-requested a review January 16, 2025 14:22
@alexreal1314 alexreal1314 force-pushed the 9782-use-resource-id-group-by branch from 1fbe394 to f96e01e Compare January 16, 2025 14:44
@alexreal1314 alexreal1314 merged commit 22e047a into main Jan 16, 2025
8 checks passed
@alexreal1314 alexreal1314 deleted the 9782-use-resource-id-group-by branch January 16, 2025 16:24
@alexreal1314
Copy link
Contributor Author

💚 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

alexreal1314 added a commit that referenced this pull request Jan 20, 2025
…206379) (#207170)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[Cloud Security] changed findings group by name to group by id
(#206379)](#206379)

<!--- Backport version: 9.6.4 -->

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

<!--BACKPORT [{"author":{"name":"Alex
Prozorov","email":"[email protected]"},"sourceCommit":{"committedDate":"2025-01-16T16:24:10Z","message":"[Cloud
Security] changed findings group by name to group by id (#206379)\n\n##
Summary\r\nThis PR fixes group by logic in the findings table to be
based on\r\nresource.id instead of resource.name.\r\n\r\n###
Screenshots\r\n\r\n![image](https://github.com/user-attachments/assets/5d480501-9f44-4395-82bd-e069b4a3c3f7)\r\n\r\n\r\n\r\n###
Closes\r\n-
https://github.com/elastic/security-team/issues/9782\r\n\r\n###
Definition of done\r\n- [x] When grouping findings by Resource, the
findings are grouped by\r\nresource.id\r\n- [x] The group title should
still contain resource.name for better UX\r\nin combination with the
id\r\n- [x] The label in the grouping properties should be Resource ID,
not\r\njust Resource\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":"22e047a1f62331cbf80b886b7a4275b1143b3446","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","backport:skip","v9.0.0","Team:Cloud
Security"],"title":"[Cloud Security] changed findings group by name to
group by
id","number":206379,"url":"https://github.com/elastic/kibana/pull/206379","mergeCommit":{"message":"[Cloud
Security] changed findings group by name to group by id (#206379)\n\n##
Summary\r\nThis PR fixes group by logic in the findings table to be
based on\r\nresource.id instead of resource.name.\r\n\r\n###
Screenshots\r\n\r\n![image](https://github.com/user-attachments/assets/5d480501-9f44-4395-82bd-e069b4a3c3f7)\r\n\r\n\r\n\r\n###
Closes\r\n-
https://github.com/elastic/security-team/issues/9782\r\n\r\n###
Definition of done\r\n- [x] When grouping findings by Resource, the
findings are grouped by\r\nresource.id\r\n- [x] The group title should
still contain resource.name for better UX\r\nin combination with the
id\r\n- [x] The label in the grouping properties should be Resource ID,
not\r\njust Resource\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":"22e047a1f62331cbf80b886b7a4275b1143b3446"}},"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/206379","number":206379,"mergeCommit":{"message":"[Cloud
Security] changed findings group by name to group by id (#206379)\n\n##
Summary\r\nThis PR fixes group by logic in the findings table to be
based on\r\nresource.id instead of resource.name.\r\n\r\n###
Screenshots\r\n\r\n![image](https://github.com/user-attachments/assets/5d480501-9f44-4395-82bd-e069b4a3c3f7)\r\n\r\n\r\n\r\n###
Closes\r\n-
https://github.com/elastic/security-team/issues/9782\r\n\r\n###
Definition of done\r\n- [x] When grouping findings by Resource, the
findings are grouped by\r\nresource.id\r\n- [x] The group title should
still contain resource.name for better UX\r\nin combination with the
id\r\n- [x] The label in the grouping properties should be Resource ID,
not\r\njust Resource\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":"22e047a1f62331cbf80b886b7a4275b1143b3446"}}]}]
BACKPORT-->
viduni94 pushed a commit to viduni94/kibana that referenced this pull request Jan 23, 2025
…ic#206379)

## Summary
This PR fixes group by logic in the findings table to be based on
resource.id instead of resource.name.

### Screenshots

![image](https://github.com/user-attachments/assets/5d480501-9f44-4395-82bd-e069b4a3c3f7)



### Closes
- elastic/security-team#9782

### Definition of done
- [x] When grouping findings by Resource, the findings are grouped by
resource.id
- [x] The group title should still contain resource.name for better UX
in combination with the id
- [x] The label in the grouping properties should be Resource ID, not
just Resource

### 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:skip This commit does not require backporting 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.

7 participants