Implement Asset Inventory Bar Chart#210938
Conversation
2e98414 to
9c697ef
Compare
...solutions/security/plugins/security_solution/public/asset_inventory/components/bar_chart.tsx
Outdated
Show resolved
Hide resolved
|
Pinging @elastic/kibana-cloud-security-posture (Team:Cloud Security) |
There was a problem hiding this comment.
im requesting changes because the aggregation logic should be using es query instead of our own. also, rows could be limited in some way. for example in csp we have limited the amount of items to 500, but we probably want to show the chart for the entire data that we have.
if those assumptions are wrong lmk and so i can remove this block
...solutions/security/plugins/security_solution/public/asset_inventory/components/bar_chart.tsx
Outdated
Show resolved
Hide resolved
...solutions/security/plugins/security_solution/public/asset_inventory/components/bar_chart.tsx
Outdated
Show resolved
Hide resolved
x-pack/solutions/security/plugins/security_solution/public/asset_inventory/pages/all_assets.tsx
Outdated
Show resolved
Hide resolved
...solutions/security/plugins/security_solution/public/asset_inventory/components/bar_chart.tsx
Outdated
Show resolved
Hide resolved
...solutions/security/plugins/security_solution/public/asset_inventory/components/bar_chart.tsx
Outdated
Show resolved
Hide resolved
...solutions/security/plugins/security_solution/public/asset_inventory/components/bar_chart.tsx
Outdated
Show resolved
Hide resolved
9c697ef to
52a7c85
Compare
opauloh
left a comment
There was a problem hiding this comment.
as per the discussions I suggest we create a new fetcher function, with aggregated data by entity.type
3e4497c to
913f8e4
Compare
...ions/security/plugins/security_solution/public/asset_inventory/hooks/use_fetch_chart_data.ts
Outdated
Show resolved
Hide resolved
| notifications: { toasts }, | ||
| } = useKibana().services; | ||
| return useQuery( | ||
| ['asset_inventory_top_assets_chart', { params: options }], |
There was a problem hiding this comment.
nit: Consider extracting the React Query key into a constant to improve maintainability and avoid potential duplication.
There was a problem hiding this comment.
I'll tackle this and other minor changes in a refactor PR. But I totally agree with you 💯
...ecurity/plugins/security_solution/public/asset_inventory/components/top_assets_bar_chart.tsx
Outdated
Show resolved
Hide resolved
...ecurity/plugins/security_solution/public/asset_inventory/components/top_assets_bar_chart.tsx
Outdated
Show resolved
Hide resolved
| import type * as estypes from '@elastic/elasticsearch/lib/api/types'; | ||
| import { showErrorToast } from '@kbn/cloud-security-posture'; | ||
| import type { IKibanaSearchResponse, IKibanaSearchRequest } from '@kbn/search-types'; | ||
| import type { FindingsBaseEsQuery } from '@kbn/cloud-security-posture'; |
There was a problem hiding this comment.
Todo: I think we should rename FindingsBaseEsQuery to not be related to Findings, i.e something like BaseEsQuery (in a separate PR)
There was a problem hiding this comment.
(can be done in this PR as well if its just a simple rename)
x-pack/solutions/security/plugins/security_solution/public/asset_inventory/pages/all_assets.tsx
Outdated
Show resolved
Hide resolved
3edb714 to
0068237
Compare
0068237 to
7f8a6bc
Compare
|
/ci |
7f8a6bc to
03b3186
Compare
| size: 0, | ||
| index: ASSET_INVENTORY_INDEX_PATTERN, | ||
| aggs: { | ||
| '0': { |
There was a problem hiding this comment.
not sure i follow the 0/1/2 patterns that are repeating here, is this a part of ES? if its just a convenient naming pattern lets find a meaningful name for those
There was a problem hiding this comment.
It's part of ES. I used Lens to build a bar chart that splits bars by type and the aggregation payload used these numbers. I tried simplifying the payload and removing the value_count but the aggregation didn't work and returned errors.
There was a problem hiding this comment.
lens? im pretty sure we used eui charts and not lens. unless you mean in another PR we also have a lens graph?
regardless, what im asking is can 0 be renamed to something like "entityCategories", 1 to "entityTypes", 2 to "entityIds"
There was a problem hiding this comment.
I actually instructed Alberto on how to use Lens to build a chart and retrieve the ES Query, but I forgot to mention that we should rename the aggregations it generates to a more readable value, good call @JordanSh
| rawResponse: { aggregations }, | ||
| } = await lastValueFrom( | ||
| data.search.search<TopAssetsRequest, TopAssetsResponse>({ | ||
| params: getTopAssetsQuery(options) as TopAssetsRequest['params'], |
There was a problem hiding this comment.
do we actually need type casting here? would be nice if we could add a return type to getTopAssetsQuery
There was a problem hiding this comment.
yes, it's needed. Found the same type casting in several files:
packages/kbn-cloud-security-posture/public/src/hooks/use_misconfiguration_findings.tspackages/kbn-cloud-security-posture/public/src/hooks/use_misconfiguration_preview.tspackages/kbn-cloud-security-posture/public/src/hooks/use_vulnerabilities_findings.tspackages/kbn-cloud-security-posture/public/src/hooks/use_vulnerabilities_preview.tsplugins/cloud_security_posture/public/pages/vulnerabilities/hooks/use_latest_vulnerabilities.tsx
|
|
||
| const { | ||
| data: chartData, | ||
| // error: fetchChartDataError, |
## Summary Closes elastic#201711. Implement "Top 10 Asset Types" bar chart. - The X-axis shows all assets grouped by category (`entity.category` field), one category per bar - Each bar shows stacked subgroups of assets by source (`entity.type` field) - The Y-axis shows the counts of assets ### Depends on - elastic#208417 so that the chart renders data fetched dynamically. When it gets merged, this one will be rebased and will only contain the last commit as changes. ### Screenshots <details><summary>Loading state (animated spinner from <a href="https://eui.elastic.co/#/display/loading#chart" target="_blank">Elastic Charts</a>)</summary> <img width="1378" alt="Screenshot 2025-02-25 at 18 14 39" src="https://github.com/user-attachments/assets/553294e2-aaee-40c0-b1bb-de3e85f64d78" /> </details> <details><summary>Fetching state (animated progress bar)</summary> <img width="1376" alt="Screenshot 2025-02-25 at 18 14 58" src="https://github.com/user-attachments/assets/accdbc0e-40a2-4b30-9f4e-808a466be4d5" /> </details> <details><summary>Chart with fetched data</summary> <img width="1428" alt="Screenshot 2025-02-24 at 13 11 03" src="https://github.com/user-attachments/assets/3c455bc8-5bdd-4ea2-a946-53e138ae081b" /> </details> <details><summary>Chart with filtered, fetched data (by type: "Identity")</summary> <img width="1429" alt="Screenshot 2025-02-24 at 13 11 17" src="https://github.com/user-attachments/assets/a1e75210-757e-42d1-b852-945de5f3f44b" /> </details> <details><summary>Empty chart - no data</summary> <img width="1258" alt="Screenshot 2025-02-13 at 09 47 08" src="https://github.com/user-attachments/assets/c239a5a6-337e-41c9-a9a3-7cdc2c9b1e01" /> </details> ### Definition of done - [x] Add a bar chart titled "Top 10 Asset Types" to the "Asset Inventory" page. - [x] Use the `@elastic/charts` library to implement the visualization. - [x] Configure the chart with: - **X-axis:** Asset type categories - **Y-axis:** Count of assets - **Legend:** A color-coded key linking each bar to a specific category. - [x] Ensure the chart is responsive when resizing the screen and adheres to the [visual spec](https://www.figma.com/design/9zUqAhhglT1EGYG4LOl1X6/Asset-Management?node-id=2946-19648&t=FuD3BEY4FyxAKV38-4). - [x] Integrate the chart so that it updates based on the filters section and the Unified Header component. ### How to test Follow the instructions from [this PR](elastic#208417) to prepare the local env with data. Alternatively, open the `asset_inventory/components/top_assets_bar_chart.tsx` file and edit yourself the `data` prop that we pass into `<BarSeries>` with mocked data. The data must have the following shape: ```js [ { category: 'cloud-compute', source: 'gcp-compute', count: 500, }, { category: 'cloud-compute', source: 'aws-security', count: 300, }, { category: 'cloud-storage', source: 'gcp-compute', count: 221, }, { category: 'cloud-storage', source: 'aws-security', count: 117, }, ]; ``` ### Checklist - [x] This was checked for breaking HTTP API changes, and any breaking changes have been approved by the breaking-change committee. The `release_note:breaking` label should be applied in these situations. - [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) ### Identify risks No risks whatsoever.
## Summary Rename the `FindingsBaseEsQuery` interface exposed by the `@kibana/cloud-security-posture` package as well as all references where it's imported. Separating this renaming into its own PR also lets us tag it with `backport:prev-minor` and avoid potential merge conflicts in the future. ### Depends on - #210938 ### Checklist - [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) ### Identify risks No risk whatsoever.
Rename the `FindingsBaseEsQuery` interface exposed by the `@kibana/cloud-security-posture` package as well as all references where it's imported. Separating this renaming into its own PR also lets us tag it with `backport:prev-minor` and avoid potential merge conflicts in the future. - elastic#210938 - [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) No risk whatsoever. (cherry picked from commit aac8413)
## Summary Closes elastic#201711. Implement "Top 10 Asset Types" bar chart. - The X-axis shows all assets grouped by category (`entity.category` field), one category per bar - Each bar shows stacked subgroups of assets by source (`entity.type` field) - The Y-axis shows the counts of assets ### Depends on - elastic#208417 so that the chart renders data fetched dynamically. When it gets merged, this one will be rebased and will only contain the last commit as changes. ### Screenshots <details><summary>Loading state (animated spinner from <a href="https://eui.elastic.co/#/display/loading#chart" target="_blank">Elastic Charts</a>)</summary> <img width="1378" alt="Screenshot 2025-02-25 at 18 14 39" src="https://github.com/user-attachments/assets/553294e2-aaee-40c0-b1bb-de3e85f64d78" /> </details> <details><summary>Fetching state (animated progress bar)</summary> <img width="1376" alt="Screenshot 2025-02-25 at 18 14 58" src="https://github.com/user-attachments/assets/accdbc0e-40a2-4b30-9f4e-808a466be4d5" /> </details> <details><summary>Chart with fetched data</summary> <img width="1428" alt="Screenshot 2025-02-24 at 13 11 03" src="https://github.com/user-attachments/assets/3c455bc8-5bdd-4ea2-a946-53e138ae081b" /> </details> <details><summary>Chart with filtered, fetched data (by type: "Identity")</summary> <img width="1429" alt="Screenshot 2025-02-24 at 13 11 17" src="https://github.com/user-attachments/assets/a1e75210-757e-42d1-b852-945de5f3f44b" /> </details> <details><summary>Empty chart - no data</summary> <img width="1258" alt="Screenshot 2025-02-13 at 09 47 08" src="https://github.com/user-attachments/assets/c239a5a6-337e-41c9-a9a3-7cdc2c9b1e01" /> </details> ### Definition of done - [x] Add a bar chart titled "Top 10 Asset Types" to the "Asset Inventory" page. - [x] Use the `@elastic/charts` library to implement the visualization. - [x] Configure the chart with: - **X-axis:** Asset type categories - **Y-axis:** Count of assets - **Legend:** A color-coded key linking each bar to a specific category. - [x] Ensure the chart is responsive when resizing the screen and adheres to the [visual spec](https://www.figma.com/design/9zUqAhhglT1EGYG4LOl1X6/Asset-Management?node-id=2946-19648&t=FuD3BEY4FyxAKV38-4). - [x] Integrate the chart so that it updates based on the filters section and the Unified Header component. ### How to test Follow the instructions from [this PR](elastic#208417) to prepare the local env with data. Alternatively, open the `asset_inventory/components/top_assets_bar_chart.tsx` file and edit yourself the `data` prop that we pass into `<BarSeries>` with mocked data. The data must have the following shape: ```js [ { category: 'cloud-compute', source: 'gcp-compute', count: 500, }, { category: 'cloud-compute', source: 'aws-security', count: 300, }, { category: 'cloud-storage', source: 'gcp-compute', count: 221, }, { category: 'cloud-storage', source: 'aws-security', count: 117, }, ]; ``` ### Checklist - [x] This was checked for breaking HTTP API changes, and any breaking changes have been approved by the breaking-change committee. The `release_note:breaking` label should be applied in these situations. - [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) ### Identify risks No risks whatsoever.
## Summary Rename the `FindingsBaseEsQuery` interface exposed by the `@kibana/cloud-security-posture` package as well as all references where it's imported. Separating this renaming into its own PR also lets us tag it with `backport:prev-minor` and avoid potential merge conflicts in the future. ### Depends on - elastic#210938 ### Checklist - [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) ### Identify risks No risk whatsoever.
Summary
Closes #201711.
Implement "Top 10 Asset Types" bar chart.
entity.categoryfield), one category per barentity.typefield)Depends on
Screenshots
Loading state (animated spinner from Elastic Charts)
Fetching state (animated progress bar)
Chart with fetched data
Chart with filtered, fetched data (by type: "Identity")
Empty chart - no data
Definition of done
@elastic/chartslibrary to implement the visualization.How to test
Follow the instructions from this PR to prepare the local env with data.
Alternatively, open the
asset_inventory/components/top_assets_bar_chart.tsxfile and edit yourself thedataprop that we pass into<BarSeries>with mocked data. The data must have the following shape:Checklist
release_note:breakinglabel should be applied in these situations.release_note:*label is applied per the guidelinesIdentify risks
No risks whatsoever.