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

[Security Solution] Use CellActions registry in Discover data grid #157201

Merged
merged 37 commits into from
Jun 23, 2023

Conversation

semd
Copy link
Contributor

@semd semd commented May 9, 2023

Summary

closes: #157191

Enables Discover DataGrid to use registered cell actions instead of the default static actions.

New cellActionsTriggerId prop

This PR introduces a new cellActionsTriggerId optional prop in the DataGrid component:

/**
* Optional triggerId to retrieve the column cell actions that will override the default ones
*/
cellActionsTriggerId?: string;

When this prop is defined, the component queries the trigger's registry to retrieve the cellActions attached to it, using the CellActions package' useDataGridColumnsCellActions hook. This hook returns the cellActions array ready to be passed for each column to the EuiDataGrid component.
When (non-empty) actions are found in the registry, they are used, replacing all of the default static Discover actions. Otherwise, the default cell actions are used.

This new prop also allows other instances of the Discover DataGrid to be configured with custom cell actions, which will probably be needed by Security Timeline integration with Discover.

New SEARCH_EMBEDDABLE_CELL_ACTIONS_TRIGGER Trigger

Along with the new cellActionsTriggerId prop the plugin also registers a new trigger for "saved search" embeddable:

uiActions.registerTrigger(SEARCH_EMBEDDABLE_CELL_ACTIONS_TRIGGER);

And it gets passed to the DataGrid component on the Embeddable creation:

cellActionsTriggerId: SEARCH_EMBEDDABLE_CELL_ACTIONS_TRIGGER_ID,

Having this new trigger available allows solutions to attach custom actions to it, in order to be displayed in the saved search embeddables. Each action will be able to implement its isCompatible check to determine if they are going to be displayed in the embedded saved search DataGrid field, or not. If no compatible actions are found, DataGrid will render the default static actions.

ℹ️ In this implementation, the actions registered to this new "embeddable trigger" need to check if they are being rendered inside Security using the isCompatible function, to prevent them from being displayed in other solutions, resulting in a non-optimal architecture. This approach was needed since there's no plausible way to pass the cellActionsTriggerId property from the Dashboard Renderer used in Security, all the way down to the specific Discover "saved search" embeddable. However, the Dashboards team is planning to enable us to pass options to nested embeddables using a registry (#148933). When this new tool is available we will be able to delegate the trigger registering to Security and configure the "saved search" embeddables to use it. Therefore, the trigger will only be used by Security, so we won't have to worry about Security actions being rendered outside Security.

Videos

before:

regular_discover_actions.mov

after:

custom_discover_actions.mov

@semd semd self-assigned this May 9, 2023
@semd semd changed the title [Security Solution][PoC] Use CellActions registry in Discover [Security Solution] Use CellActions registry in Discover data grid May 10, 2023
@semd semd added release_note:skip Skip the PR/issue when compiling release notes Team:Threat Hunting Security Solution Threat Hunting Team Team:Threat Hunting:Explore v8.9.0 labels May 10, 2023
@semd semd marked this pull request as ready for review May 10, 2023 12:48
@semd semd requested review from a team as code owners May 10, 2023 12:48
@elasticmachine
Copy link
Contributor

Pinging @elastic/security-threat-hunting (Team:Threat Hunting)

@semd
Copy link
Contributor Author

semd commented May 11, 2023

@elasticmachine merge upstream

Copy link
Member

@kertal kertal left a comment

Choose a reason for hiding this comment

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

I think extending the cell actions of Discover data grid makes much sense 👍
We will have a closer look at it next week. Playing with it, I have an initial question. When I add something to a timeline, what does it mean in this cases? I've created a custom dashboard showing e-commerce orders, I've added some of the values to a timeline. Now those values are visible in the query builder, but that's it. Since the data view Alerts is selected, there are no entries visible in the table. I guess it's expected. But as a newbie user more familiar with Discover / Dashboards it's not 100% clear what add to "Add to timeline" means in this case

Copy link
Contributor

@jughosta jughosta left a comment

Choose a reason for hiding this comment

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

Looking good! Left some questions to clarify the details.

@semd
Copy link
Contributor Author

semd commented May 15, 2023

I think extending the cell actions of Discover data grid makes much sense 👍 We will have a closer look at it next week. Playing with it, I have an initial question. When I add something to a timeline, what does it mean in this cases? I've created a custom dashboard showing e-commerce orders, I've added some of the values to a timeline. Now those values are visible in the query builder, but that's it. Since the data view Alerts is selected, there are no entries visible in the table. I guess it's expected. But as a newbie user more familiar with Discover / Dashboards it's not 100% clear what add to "Add to timeline" means in this case

Hi @kertal
Yes you are right, the scenario you described is the expected behavior. However, these actions will only be visible inside Security, where the dashboards are expected to contain Security-related data. The "add to timeline" action is meant to make it easy for Security analysts to pivot to Timeline investigations on an specific value, probably from the alerts index.
It does not make much sense to have e-commerce orders in a Security dashboards, nevertheless, it is also possible to change the Data View in the Timeline, so we are not limited to render alerts only.

@kertal
Copy link
Member

kertal commented May 15, 2023

Hi @kertal Yes you are right, the scenario you described is the expected behavior. However, these actions will only be visible inside Security, where the dashboards are expected to contain Security-related data. The "add to timeline" action is meant to make it easy for Security analysts to pivot to Timeline investigations on an specific value, probably from the alerts index. It does not make much sense to have e-commerce orders in a Security dashboards, nevertheless, it is also possible to change the Data View in the Timeline, so we are not limited to render alerts only.

@semd Thx, this makes sense. Quick follow up, what's the quickest way to generate test data for the security related data?
@lukasolson could you also have a look, this PR has some overlapping with your work to extend the doc viewer , many thx

Bildschirmfoto 2023-05-15 um 15 24 04

@semd
Copy link
Contributor Author

semd commented May 15, 2023

@kertal What I usually do to generate some alerts data locally is executing the test generator with:

cd x-pack/plugins/security_solution
yarn test:generate -s resolver --gen 3 --pr 100 --pt 100

And then create a new rule in the UI (/app/security/rules/create) that takes everything * using the default index patterns, to generate the alerts.

@kertal
Copy link
Member

kertal commented May 16, 2023

@kertal What I usually do to generate some alerts data locally is executing the test generator with:

cd x-pack/plugins/security_solution
yarn test:generate -s resolver --gen 3 --pr 100 --pt 100

And then create a new rule in the UI (/app/security/rules/create) that takes everything * using the default index patterns, to generate the alerts.

@semd thx, now it makes much more sense for me, and looking at it, I think we should align styling and wording, here's a screen to compare

Bildschirmfoto 2023-05-16 um 09 24 01

@machadoum
Copy link
Member

Hey team! As Sergi mentioned, I am taking it over from here.

First of all, thank you for helping us improve CellActions ❤️

I pushed code with KBN types allowlist. We are only going to display CellActions for the types: date, ip, string, and number. Could you please take a look 5e4ac31?

@davismcphee I tried to reproduce the response field bug step-by-step, but it works for me. I suspect that a previous change fixed it. Could you try to reproduce it one more time with the current changes?

Jun-20-2023.15-23-26.mp4

Copy link
Contributor

@jughosta jughosta left a comment

Choose a reason for hiding this comment

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

Hi @machadoum,
Thanks for continuing the work and planning on extending cell actions package with more types!

() =>
cellActionsTriggerId && !isPlainRecord
? visibleColumns.map((columnName) => {
const field = dataView.getFieldByName(columnName)?.spec;
Copy link
Contributor

Choose a reason for hiding this comment

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

Can be simplified. Also mock changes might be unnecessary.

Suggested change
const field = dataView.getFieldByName(columnName)?.spec;
const field = dataView.getFieldByName(columnName);

if (
!field?.type ||
!SUPPORTED_CELL_ACTIONS_TYPES.includes(field.type as KBN_FIELD_TYPES)
) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This logic could be probably extracted into a function inside @kbn/cell-actions package: for example, isSupportedByCellActions(field).

Copy link
Contributor

Choose a reason for hiding this comment

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

Would be great to cover it with tests.

@jughosta jughosta self-requested a review June 20, 2023 19:23
Copy link
Contributor

@jughosta jughosta left a comment

Choose a reason for hiding this comment

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

Unblocking the PR 👍

@jughosta jughosta requested a review from davismcphee June 20, 2023 19:27
Copy link
Contributor

@davismcphee davismcphee left a comment

Choose a reason for hiding this comment

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

@machadoum Thanks for the updates, the allowlist change looks good to me! Overall this PR seems just about ready to merge, except I'm still encountering the issue with adding saved searches containing a flattened field to a Dashboard.

Here's a quick video of what I'm doing from start to finish to reproduce the issue: https://github.com/elastic/kibana/assets/25592674/5904ba82-f015-4263-98f3-e02da83ff696

@davismcphee I tried to reproduce the response field bug step-by-step, but it works for me. I suspect that a previous change fixed it. Could you try to reproduce it one more time with the current changes?

I'm now thinking this might just be a misunderstanding on my part and maybe this is expected. I notice in your video there's a search bar above the dashboard, but I'm not seeing one when I view my dashboard, which probably explains why clicking the filter actions don't do anything for me:
dashboard

This one is less of a concern for me anyway since it doesn't have an impact outside of Security, so I'd be happy to merge with the current behaviour if it's working as expected for your team. The only thing left I'd like to make sure we figure out before I approve is the blank saved search panel since it impacts any dashboard configured this way.

@machadoum
Copy link
Member

machadoum commented Jun 21, 2023

Hey @davismcphee!
Thank you for the video. It was very helpful. I managed to reproduce the bug. It happened when the data view had no time field. I noticed that before this PR, there was an extra validation for it, so I added it back here. Good catch!

[edited] I don't know why you can't see the search bar on the dashboards page. Do you get any errors on the console? You are right, the filter action adds the field to the search bar. If you can't see the search bar you can't see the effect.

[edited2] The search bar doesn't show up when you don't have security solution indices. That explains the mystery. But it is a weird scenario, I will double-check with the team.

Copy link
Contributor

@davismcphee davismcphee left a comment

Choose a reason for hiding this comment

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

I tested with the latest changes and the blank panel issue is fixed! Also thanks for adding those tests to help prevent it in the future. I'm glad you were able to get to the bottom of the missing search bar, I'll leave it to you to decide if that's something you need to address in this PR or not. Thanks for all the work on this, LGTM 👍

@machadoum machadoum added v8.10.0 and removed v8.9.0 labels Jun 22, 2023
@machadoum machadoum enabled auto-merge (squash) June 22, 2023 14:47
@machadoum machadoum disabled auto-merge June 22, 2023 15:00
@machadoum machadoum force-pushed the poc_discover_custom_cell_actions branch from af336de to 680ba4d Compare June 23, 2023 09:14
@machadoum machadoum enabled auto-merge (squash) June 23, 2023 09:15
@machadoum
Copy link
Member

@elasticmachine merge upstream

@machadoum machadoum force-pushed the poc_discover_custom_cell_actions branch from 8743a60 to 74767dd Compare June 23, 2023 12:50
@kibana-ci
Copy link
Collaborator

💛 Build succeeded, but was flaky

Failed CI Steps

Test Failures

  • [job] [logs] Security Solution Tests #7 / Shared exception lists - read only "before each" hook for "Displays missing privileges primary callout"
  • [job] [logs] FTR Configs #27 / Synthetics API Tests PrivateLocationAddMonitor handles is_tls_enabled false

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
discover 559 589 +30
securitySolution 4212 4216 +4
total +34

Public APIs missing comments

Total count of every public API that lacks a comment. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats comments for more detailed information.

id before after diff
@kbn/cell-actions 43 44 +1
discover 67 68 +1
total +2

Async chunks

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

id before after diff
discover 513.7KB 527.3KB +13.6KB
securitySolution 11.0MB 11.0MB -8.8KB
total +4.9KB

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
discover 28.9KB 29.3KB +419.0B
securitySolution 52.0KB 52.1KB +138.0B
total +557.0B
Unknown metric groups

API count

id before after diff
@kbn/cell-actions 57 62 +5
discover 87 88 +1
total +6

ESLint disabled line counts

id before after diff
enterpriseSearch 13 15 +2
securitySolution 416 420 +4
total +6

Total ESLint disabled count

id before after diff
enterpriseSearch 14 16 +2
securitySolution 497 501 +4
total +6

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

cc @machadoum @semd

@machadoum machadoum merged commit f4159c4 into elastic:main Jun 23, 2023
@kibanamachine kibanamachine added the backport:skip This commit does not require backporting label Jun 23, 2023
machadoum added a commit that referenced this pull request Jun 26, 2023
…ctions (#160095)

## Summary
Add support for `Boolean` and `Number` types to CellActions and update
Security Actions accordingly.
It also fixes the copy-to-clipboard action for fields of the type number
(`process.parent.pid`).

issue: #159298

- [x] Remove discover fields value casting if it gets merged after the
[discover PR](#157201)


### How to test it?

The quickest way is to find an alert field that is a boolean or number
on the alerts page and check if security solution actions still work.
But all boolean fields that I tested are actually strings. 🤷
Alternatively, you could render the `<SecurityCellActions />` with fake
data (boolean and number).

### 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

---------

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
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 release_note:skip Skip the PR/issue when compiling release notes Team:Threat Hunting:Explore Team:Threat Hunting Security Solution Threat Hunting Team v8.10.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Security Solution] Use CellActions in Discover saved search embeddable