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 Sollution][Alerts] fixes rule preview issue for new terms field #145707

Merged
merged 8 commits into from
Nov 28, 2022

Conversation

vitaliidm
Copy link
Contributor

@vitaliidm vitaliidm commented Nov 18, 2022

Summary

Before

Screen.Recording.2022-11-01.at.13.00.46.mov

After

Screen.Recording.2022-11-18.at.10.50.31.mov

@vitaliidm vitaliidm self-assigned this Nov 18, 2022
@vitaliidm vitaliidm added bug Fixes for quality problems that affect the customer experience Team:Detections and Resp Security Detection Response Team Team: SecuritySolution Security Solutions Team working on SIEM, Endpoint, Timeline, Resolver, etc. Team:Detection Alerts Security Detection Alerts Area Team v8.6.0 v8.7.0 labels Nov 18, 2022
@vitaliidm vitaliidm marked this pull request as ready for review November 21, 2022 12:23
@vitaliidm vitaliidm requested review from a team as code owners November 21, 2022 12:23
@vitaliidm vitaliidm requested a review from jpdjere November 21, 2022 12:23
@elasticmachine
Copy link
Contributor

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

@elasticmachine
Copy link
Contributor

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

@vitaliidm vitaliidm added the backport:prev-minor Backport to (8.x) the previous minor version (i.e. one version back from main) label Nov 21, 2022
Copy link
Contributor

@jpdjere jpdjere left a comment

Choose a reason for hiding this comment

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

Detection Rules LGTM

// more details here: https://github.com/elastic/kibana/issues/144322#issuecomment-1321838136
// wrapping in setTimeout is a workaround until solution within forms-lib can be found
const isValid = await new Promise<boolean>((resolve) => {
setTimeout(async () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

The fix looks dirty but fine if it's temporary.

I just wanted to share my thoughts. Usually a necessity of setTimeout() usage says about design flaws and over-complication. In this case it looks possible to get rid of the problem by rethinking the approach to the data handling. For example I can see formHooks is used as a global variable and the value is reused the level up.
The cause of the problem is double validation which actually shouldn't happen.

I'm curious if an approach to redesign the components to handle validation in another way was considered as well.

Copy link
Contributor Author

@vitaliidm vitaliidm Nov 28, 2022

Choose a reason for hiding this comment

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

The fix looks dirty but fine if it's temporary.

I would recommend to read this section before writing comments like this.

I just wanted to share my thoughts. Usually a necessity of setTimeout() usage says about design flaws and over-complication. In this case it looks possible to get rid of the problem by rethinking the approach to the data handling. For example I can see formHooks is used as a global variable and the value is reused the level up.
#144322 (comment) is double validation which actually shouldn't happen.

What do you mean by 'double validation'?
I would expect once data in form is changed and available in onChange callback, it can be checked whether it's valid or not. But if you look into standalone example, it's not a case: data is changed, but its validity can not be established.
I would like to see forms-lib assessment of library behaviour before committing to any refactoring.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you for the explanation and pointing to the guidelines.

I didn't mean to offend but rather say that setTimeout usually is a red flag which signals there is something wrong.

You are right the problem in the the forms-lib. Though it's strange the popular scenario of accessing the validity state in the onChange callback wasn't covered already.

Copy link
Contributor Author

@vitaliidm vitaliidm Nov 28, 2022

Choose a reason for hiding this comment

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

rather say that setTimeout usually is a red flag which signals there is something wrong.

yes, I also commented that it's a workaround and put together ticket and links to it

// wrapping in setTimeout is a workaround until solution within forms-lib can be found

You are right, the problem is in the forms-lib. Though it's strange the popular scenario of accessing the validity state in the onChange callback wasn't covered already.

In this standalone example , it can be seen that in onChange, accessed validity is not correct. Very simple case, but the result is rather unexpected. Let's see what forms-lib will say on that.
I would expect if I get any data from callback: to either access validation status straight away or through running validate method. We did the latter in form(though through calling a submit before this change) and relied on its results. Which, as it turns out, are not correct in some cases.

@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

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
securitySolution 9.6MB 9.6MB +105.0B
Unknown metric groups

ESLint disabled in files

id before after diff
osquery 1 2 +1

ESLint disabled line counts

id before after diff
enterpriseSearch 19 21 +2
fleet 59 65 +6
osquery 109 115 +6
securitySolution 443 449 +6
total +20

Total ESLint disabled count

id before after diff
enterpriseSearch 20 22 +2
fleet 68 74 +6
osquery 110 117 +7
securitySolution 520 526 +6
total +21

History

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

cc @vitaliidm

@kibanamachine
Copy link
Contributor

💚 All backports created successfully

Status Branch Result
8.6

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 Nov 29, 2022
…erms field (#145707) (#146449)

# Backport

This will backport the following commits from `main` to `8.6`:
- [[Security Sollution][Alerts] fixes rule preview issue for new terms
field (#145707)](#145707)

<!--- Backport version: 8.9.7 -->

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

<!--BACKPORT [{"author":{"name":"Vitalii
Dmyterko","email":"92328789+vitaliidm@users.noreply.github.com"},"sourceCommit":{"committedDate":"2022-11-28T17:36:40Z","message":"[Security
Sollution][Alerts] fixes rule preview issue for new terms field
(#145707)\n\n## Summary\r\n\r\n- fixes
https://github.com/elastic/kibana/issues/144322\r\n- details on
underlying\r\n[issue](https://github.com/elastic/kibana/issues/144322#issuecomment-1321838136)\r\nwithin
form-lib\r\n\r\n###
Before\r\n\r\n\r\nhttps://user-images.githubusercontent.com/92328789/202687215-e9606bd0-5cfd-4a92-9abf-edaf90868505.mov\r\n\r\n###
After\r\n\r\n\r\nhttps://user-images.githubusercontent.com/92328789/202688418-7cb7d250-02f3-4020-bfa0-65191b8a529b.mov","sha":"c086220f1ba89c9db0fe2c7500d86e3375aeee86","branchLabelMapping":{"^v8.7.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["bug","release_note:fix","Team:Detections
and Resp","Team: SecuritySolution","Team:Detection
Alerts","backport:prev-minor","v8.6.0","v8.7.0"],"number":145707,"url":"https://github.com/elastic/kibana/pull/145707","mergeCommit":{"message":"[Security
Sollution][Alerts] fixes rule preview issue for new terms field
(#145707)\n\n## Summary\r\n\r\n- fixes
https://github.com/elastic/kibana/issues/144322\r\n- details on
underlying\r\n[issue](https://github.com/elastic/kibana/issues/144322#issuecomment-1321838136)\r\nwithin
form-lib\r\n\r\n###
Before\r\n\r\n\r\nhttps://user-images.githubusercontent.com/92328789/202687215-e9606bd0-5cfd-4a92-9abf-edaf90868505.mov\r\n\r\n###
After\r\n\r\n\r\nhttps://user-images.githubusercontent.com/92328789/202688418-7cb7d250-02f3-4020-bfa0-65191b8a529b.mov","sha":"c086220f1ba89c9db0fe2c7500d86e3375aeee86"}},"sourceBranch":"main","suggestedTargetBranches":["8.6"],"targetPullRequestStates":[{"branch":"8.6","label":"v8.6.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.7.0","labelRegex":"^v8.7.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/145707","number":145707,"mergeCommit":{"message":"[Security
Sollution][Alerts] fixes rule preview issue for new terms field
(#145707)\n\n## Summary\r\n\r\n- fixes
https://github.com/elastic/kibana/issues/144322\r\n- details on
underlying\r\n[issue](https://github.com/elastic/kibana/issues/144322#issuecomment-1321838136)\r\nwithin
form-lib\r\n\r\n###
Before\r\n\r\n\r\nhttps://user-images.githubusercontent.com/92328789/202687215-e9606bd0-5cfd-4a92-9abf-edaf90868505.mov\r\n\r\n###
After\r\n\r\n\r\nhttps://user-images.githubusercontent.com/92328789/202688418-7cb7d250-02f3-4020-bfa0-65191b8a529b.mov","sha":"c086220f1ba89c9db0fe2c7500d86e3375aeee86"}}]}]
BACKPORT-->

Co-authored-by: Vitalii Dmyterko <92328789+vitaliidm@users.noreply.github.com>
@vitaliidm vitaliidm deleted the alerts/preview-new-terms-issue branch March 4, 2024 17:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:prev-minor Backport to (8.x) the previous minor version (i.e. one version back from main) bug Fixes for quality problems that affect the customer experience release_note:fix Team:Detection Alerts Security Detection Alerts Area Team Team:Detections and Resp Security Detection Response Team Team: SecuritySolution Security Solutions Team working on SIEM, Endpoint, Timeline, Resolver, etc. v8.6.0 v8.7.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Security Solution][Alerts] Rule preview fails on new terms field validation
7 participants