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] Replace EUI filtering with custom in-memory filtering in Add Rules and Rule Upgrade tables #159700

Merged
merged 4 commits into from
Jun 19, 2023

Conversation

jpdjere
Copy link
Contributor

@jpdjere jpdjere commented Jun 14, 2023

Summary

1. Replaces the EUI out-of-the-box filtering by rule name and tags used in the initial implementation with custom in-memory filtering.

This aligns the look-and-feel of the Rules Management table with the new Add Elastic Rules and Rule Upgrades table

image

image

2. Adds a CTA in the Add Elastic RUles table when all rules have been installed, that navigates the user back to the Rules Management table.

image

Checklist

Delete any items that are not applicable to this PR.

For maintainers

@jpdjere jpdjere added Team: SecuritySolution Security Solutions Team working on SIEM, Endpoint, Timeline, Resolver, etc. Team:Detection Rule Management Security Detection Rule Management Team labels Jun 14, 2023
@jpdjere jpdjere self-assigned this Jun 14, 2023
@jpdjere jpdjere added backport:skip This commit does not require backporting Team:Detections and Resp Security Detection Response Team Feature:Rule Management Security Solution Detection Rule Management Feature:Prebuilt Detection Rules Security Solution Prebuilt Detection Rules v8.9.0 labels Jun 14, 2023
@jpdjere jpdjere marked this pull request as ready for review June 14, 2023 13:51
@jpdjere jpdjere requested review from a team as code owners June 14, 2023 13:51
@jpdjere jpdjere requested a review from xcrzx June 14, 2023 13:51
@elasticmachine
Copy link
Contributor

Pinging @elastic/security-detections-response (Team:Detections and Resp)

@elasticmachine
Copy link
Contributor

Pinging @elastic/security-solution (Team: SecuritySolution)

@jpdjere jpdjere changed the title [Security Solution] [New Rule Install & Upgrade workflows] Replace EUI filtering with custom filtering [Security Solution] [New Rule Install & Upgrade workflows] Replace EUI filtering with custom in-memory filtering in Add Rules and Rule Upgrade tables Jun 14, 2023
@jpdjere jpdjere changed the title [Security Solution] [New Rule Install & Upgrade workflows] Replace EUI filtering with custom in-memory filtering in Add Rules and Rule Upgrade tables [Security Solution] Replace EUI filtering with custom in-memory filtering in Add Rules and Rule Upgrade tables Jun 14, 2023
@banderror banderror added release_note:skip Skip the PR/issue when compiling release notes and removed release_note:fix backport:skip This commit does not require backporting labels Jun 15, 2023
Copy link
Contributor

@xcrzx xcrzx left a comment

Choose a reason for hiding this comment

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

Thanks for the PR, @jpdjere! 👍 I've run some local tests and everything is working as expected. I've noted a few minor suggestions for further enhancements, but none of them are critical.

startTransaction({ name: ADD_PREBUILT_RULES_TABLE_ACTIONS.FILTER });
setFilterOptions((filters) => ({
...filters,
filter: filterString.trim(),
}));
Copy link
Contributor

Choose a reason for hiding this comment

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

Filtering is a synchronous operation that doesn't initiate HTTP requests. Therefore, starting an APM transaction just before this operation might inadvertently capture any unrelated HTTP requests that follow. I suggest we remove these transactions to avoid capturing irrelevant data.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks! fixing this


const handleSelectedTags = useCallback(
(newTags: string[]) => {
if (!isEqual(newTags, selectedTags)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm wondering whether this isEqual check is necessary. How frequently is the callback invoked with identical tags?

<EuiFilterGroup>
<TagsFilterPopover
onSelectedTagsChanged={handleSelectedTags}
selectedTags={selectedTags ?? []}
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: according to the provider code, selectedTags should never be undefined. Can we adjust our types to reflect that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, thanks. Fixed the types here 👍

Pick<FilterOptions, 'filter' | 'tags'>
>;

export const useFilterPrebuiltRulesToUpgrade = ({
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it possible for us to reuse the rule filtering method from the add rule context 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.

So I actually wanted to create a reusable hook for both adding and upgrading rules cause the filtering logic is the same. The problem is that the type of rules is slightly different in these two cases, because in the install case, all the properties of the rule (that I need to filter on) are top-level properties (i.e name and tags).

In the upgrade case, those are nested within rule:

export interface RuleUpgradeInfoForReview {
  id: RuleObjectId;
  rule_id: RuleSignatureId;
  rule: DiffableRule;
  diff: PartialRuleDiff;
  revision: number;
}

So I tried making it generic for both like:

export const useFilterPrebuiltRulesToInstallOrUpgrade = ({
  rules,
  filterOptions,
}: {
  rules: RuleInstallationInfoForReview[] | Array<RuleUpgradeInfoForReview['rule']>;
  filterOptions: AddOrUpgradePrebuiltRulesTableFilterOptions;
}) => {
  ...

but that means that the Rule Upgrade table will be populated by DiffableRule-type objects instead of RuleUpgradeInfoForReview, and that means additional changes among the context, which I think we don't want just to make this reusable.

I'd like to discuss this with you anyways to understand what are you thinking, but I'd rather merge this PR as is with two separate hooks and refactor next week after FF.

@jpdjere jpdjere force-pushed the change-eui-filter-for-custom branch from 7fef3a3 to e332470 Compare June 16, 2023 15:57
@jpdjere jpdjere force-pushed the change-eui-filter-for-custom branch from 18d7e79 to bc0c631 Compare June 19, 2023 11:48
@kibana-ci
Copy link
Collaborator

💛 Build succeeded, but was flaky

Failed CI Steps

Test Failures

  • [job] [logs] Security Solution Tests #7 / Prebuilt rules Actions with prebuilt rules Rules table "before each" hook for "Allows to delete all rules at once"

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
securitySolution 4188 4193 +5

Async chunks

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

id before after diff
securitySolution 10.9MB 10.9MB +3.9KB
Unknown metric groups

ESLint disabled line counts

id before after diff
enterpriseSearch 13 15 +2
securitySolution 411 415 +4
total +6

Total ESLint disabled count

id before after diff
enterpriseSearch 14 16 +2
securitySolution 494 498 +4
total +6

History

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

cc @jpdjere

@jpdjere jpdjere merged commit 2f0c12a into elastic:main Jun 19, 2023
@kibanamachine kibanamachine added the backport:skip This commit does not require backporting label Jun 19, 2023
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 Feature:Prebuilt Detection Rules Security Solution Prebuilt Detection Rules Feature:Rule Management Security Solution Detection Rule Management release_note:skip Skip the PR/issue when compiling release notes Team:Detection Rule Management Security Detection Rule Management Team Team:Detections and Resp Security Detection Response Team Team: SecuritySolution Security Solutions Team working on SIEM, Endpoint, Timeline, Resolver, etc. v8.9.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants