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] Allow rewriting rule create props in Cypress tests #153474

Merged
merged 2 commits into from Mar 27, 2023

Conversation

maximpn
Copy link
Contributor

@maximpn maximpn commented Mar 22, 2023

Relates to: #150553

Summary

This PR is based on the review comments in #150553. It allows to rewrite rule create properties.

Details

Rule create properties are returned by helper functions like getNewRule(), getNewThresholdRule() and so on. So instead of createRule({ ...getNewRule(), index: undefined, data_view_id: DATA_VIEW_ID, rule_id: '1' }) it allows to use a concise and a much more readable structure createRule(getNewRule({ index: undefined, data_view_id: DATA_VIEW_ID, rule_id: '1' )).

Possible improvements

The PR doesn't implement deep / nested fields merge. High level fields completely rewrite default values. Deep merge would allow to extend defaults with the provided rewrites. For example, overriding nested properties become tiresome quickly, as shown in the following code snippet:

const rule = {
  ...getNewTermsRule(),
  rule_id: 'new_rule_id',
  runsEvery: {
    interval: '1',
    ...getNewTermsRule().runsEvery,
  },
};

If we implement deep merge, the readability could be greatly improved:

const rule = getNewTermsRule({
  rule_id: 'new_rule_id',
  runsEvery: {
    interval: '1',
  },
});

While it looks as a good idea we should take into consideration the fact that complete rewriting of default values can be a desired behavior. Engineers could tend to switch to createRule({ ...getNewRule(), index: undefined, data_view_id: DATA_VIEW_ID, rule_id: '1' }) to overcome deep merge. So it should be analysed carefully before implementing it.

@maximpn maximpn added enhancement New value added to drive a business result release_note:skip Skip the PR/issue when compiling release notes Team:Detections and Resp Security Detection Response Team Team: SecuritySolution Security Solutions Team working on SIEM, Endpoint, Timeline, Resolver, etc. Team:Detection Rule Management Security Detection Rule Management Team backport:prev-minor Backport to the previous minor version (i.e. one version back from main) v8.8.0 labels Mar 22, 2023
@maximpn maximpn self-assigned this Mar 22, 2023
@maximpn maximpn marked this pull request as ready for review March 22, 2023 22:52
@maximpn maximpn requested review from a team as code owners March 22, 2023 22:52
@elasticmachine
Copy link
Contributor

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

@maximpn maximpn requested review from a team as code owners March 22, 2023 22:52
@maximpn maximpn requested a review from spong March 22, 2023 22:52
@elasticmachine
Copy link
Contributor

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

@maximpn maximpn requested a review from xcrzx March 22, 2023 22:52
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.

Thank you for this refactoring, @maximpn 👍

Copy link
Contributor

@e40pud e40pud left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link
Contributor

@stephmilovic stephmilovic left a comment

Choose a reason for hiding this comment

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

LGTM on explore changes, thank you!

@kibana-ci
Copy link
Collaborator

💛 Build succeeded, but was flaky

Failed CI Steps

Test Failures

  • [job] [logs] Security Solution Tests #4 / Row renderers Selected renderer can be disabled and enabled

Metrics [docs]

Unknown metric groups

ESLint disabled line counts

id before after diff
securitySolution 433 436 +3

Total ESLint disabled count

id before after diff
securitySolution 513 516 +3

History

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

cc @maximpn

@banderror banderror removed the enhancement New value added to drive a business result label Mar 23, 2023
@banderror banderror added refactoring test-coverage issues & PRs for improving code test coverage labels Mar 23, 2023
@banderror banderror changed the title [Security Solution] Allow rewriting rule create props [Security Solution] Allow rewriting rule create props in tests Mar 23, 2023
@banderror
Copy link
Contributor

@maximpn please be mindful about backports 🙏

@banderror banderror changed the title [Security Solution] Allow rewriting rule create props in tests [Security Solution] Allow rewriting rule create props in Cypress tests Mar 24, 2023
@banderror banderror added test test_ui_functional technical debt Improvement of the software architecture and operational architecture and removed test-coverage issues & PRs for improving code test coverage labels Mar 24, 2023
Copy link
Member

@spong spong left a comment

Choose a reason for hiding this comment

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

Thank you for dev-ex optimization and detailed description here @maximpn 🙂 -- LGTM! 👍

@maximpn maximpn merged commit ca696ac into elastic:main Mar 27, 2023
10 checks passed
@maximpn maximpn deleted the rule-creator-prop-rewrites branch March 27, 2023 09:09
@maximpn maximpn restored the rule-creator-prop-rewrites branch March 27, 2023 09:09
@kibanamachine
Copy link
Contributor

💔 All backports failed

Status Branch Result
8.7 Backport failed because of merge conflicts

Manual backport

To create the backport manually run:

node scripts/backport --pr 153474

Questions ?

Please refer to the Backport tool documentation

@maximpn maximpn deleted the rule-creator-prop-rewrites branch March 27, 2023 09:17
maximpn added a commit to maximpn/kibana that referenced this pull request Apr 4, 2023
elastic#153474)

**Relates to:** elastic#150553

## Summary

This PR is based on the review comments in elastic#150553. It allows to rewrite rule create properties.

## Details

Rule create properties are returned by helper functions like `getNewRule()`, `getNewThresholdRule()` and so on. So instead of `createRule({ ...getNewRule(), index: undefined, data_view_id: DATA_VIEW_ID, rule_id: '1' })` it allows to use a concise and a much more readable structure `createRule(getNewRule({ index: undefined, data_view_id: DATA_VIEW_ID, rule_id: '1' ))`.

## Possible improvements

The PR doesn't implement deep / nested fields merge. High level fields completely rewrite default values. Deep merge would allow to extend defaults with the provided rewrites. For example, overriding nested properties become tiresome quickly, as shown in the following code snippet:

```ts
const rule = {
  ...getNewTermsRule(),
  rule_id: 'new_rule_id',
  runsEvery: {
    interval: '1',
    ...getNewTermsRule().runsEvery,
  },
};
```

If we implement deep merge, the readability could be greatly improved:

```ts
const rule = getNewTermsRule({
  rule_id: 'new_rule_id',
  runsEvery: {
    interval: '1',
  },
});
```

While it looks as a good idea we should take into consideration the fact that complete rewriting of default values can be a desired behavior. Engineers could tend to switch to `createRule({ ...getNewRule(), index: undefined, data_view_id: DATA_VIEW_ID, rule_id: '1' })` to overcome deep merge. So it should be analysed carefully before implementing it.

(cherry picked from commit ca696ac)

# Conflicts:
#	x-pack/plugins/security_solution/cypress/e2e/detection_alerts/alerts_charts.cy.ts
#	x-pack/plugins/security_solution/cypress/e2e/detection_alerts/detection_page_filters.cy.ts
#	x-pack/plugins/security_solution/cypress/e2e/exceptions/add_edit_flyout/flyout_validation.cy.ts
@maximpn
Copy link
Contributor Author

maximpn commented Apr 4, 2023

💚 All backports created successfully

Status Branch Result
8.7

Note: Successful backport PRs will be merged automatically after passing CI.

Questions ?

Please refer to the Backport tool documentation

maximpn added a commit that referenced this pull request Apr 4, 2023
…s tests (#153474) (#154332)

# Backport

This will backport the following commits from `main` to `8.7`:
- [[Security Solution] Allow rewriting rule create props in Cypress
tests (#153474)](#153474)

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

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

<!--BACKPORT [{"author":{"name":"Maxim
Palenov","email":"maxim.palenov@elastic.co"},"sourceCommit":{"committedDate":"2023-03-27T09:08:38Z","message":"[Security
Solution] Allow rewriting rule create props in Cypress tests
(#153474)\n\n**Relates to:**
#150553
Summary\r\n\r\nThis PR is based on the review comments in
#150553. It allows to rewrite rule
create properties.\r\n\r\n## Details\r\n\r\nRule create properties are
returned by helper functions like `getNewRule()`,
`getNewThresholdRule()` and so on. So instead of `createRule({
...getNewRule(), index: undefined, data_view_id: DATA_VIEW_ID, rule_id:
'1' })` it allows to use a concise and a much more readable structure
`createRule(getNewRule({ index: undefined, data_view_id: DATA_VIEW_ID,
rule_id: '1' ))`.\r\n\r\n## Possible improvements\r\n\r\nThe PR doesn't
implement deep / nested fields merge. High level fields completely
rewrite default values. Deep merge would allow to extend defaults with
the provided rewrites. For example, overriding nested properties become
tiresome quickly, as shown in the following code
snippet:\r\n\r\n```ts\r\nconst rule = {\r\n ...getNewTermsRule(),\r\n
rule_id: 'new_rule_id',\r\n runsEvery: {\r\n interval: '1',\r\n
...getNewTermsRule().runsEvery,\r\n },\r\n};\r\n```\r\n\r\nIf we
implement deep merge, the readability could be greatly
improved:\r\n\r\n```ts\r\nconst rule = getNewTermsRule({\r\n rule_id:
'new_rule_id',\r\n runsEvery: {\r\n interval: '1',\r\n
},\r\n});\r\n```\r\n\r\nWhile it looks as a good idea we should take
into consideration the fact that complete rewriting of default values
can be a desired behavior. Engineers could tend to switch to
`createRule({ ...getNewRule(), index: undefined, data_view_id:
DATA_VIEW_ID, rule_id: '1' })` to overcome deep merge. So it should be
analysed carefully before implementing
it.","sha":"ca696ac50c0591acf6723e130d2f9278c2d6ef65","branchLabelMapping":{"^v8.8.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["test","refactoring","test_ui_functional","technical
debt","release_note:skip","Team:Detections and Resp","Team:
SecuritySolution","Team:Detection
Rules","backport:prev-minor","v8.8.0"],"number":153474,"url":"#153474
Solution] Allow rewriting rule create props in Cypress tests
(#153474)\n\n**Relates to:**
#150553
Summary\r\n\r\nThis PR is based on the review comments in
#150553. It allows to rewrite rule
create properties.\r\n\r\n## Details\r\n\r\nRule create properties are
returned by helper functions like `getNewRule()`,
`getNewThresholdRule()` and so on. So instead of `createRule({
...getNewRule(), index: undefined, data_view_id: DATA_VIEW_ID, rule_id:
'1' })` it allows to use a concise and a much more readable structure
`createRule(getNewRule({ index: undefined, data_view_id: DATA_VIEW_ID,
rule_id: '1' ))`.\r\n\r\n## Possible improvements\r\n\r\nThe PR doesn't
implement deep / nested fields merge. High level fields completely
rewrite default values. Deep merge would allow to extend defaults with
the provided rewrites. For example, overriding nested properties become
tiresome quickly, as shown in the following code
snippet:\r\n\r\n```ts\r\nconst rule = {\r\n ...getNewTermsRule(),\r\n
rule_id: 'new_rule_id',\r\n runsEvery: {\r\n interval: '1',\r\n
...getNewTermsRule().runsEvery,\r\n },\r\n};\r\n```\r\n\r\nIf we
implement deep merge, the readability could be greatly
improved:\r\n\r\n```ts\r\nconst rule = getNewTermsRule({\r\n rule_id:
'new_rule_id',\r\n runsEvery: {\r\n interval: '1',\r\n
},\r\n});\r\n```\r\n\r\nWhile it looks as a good idea we should take
into consideration the fact that complete rewriting of default values
can be a desired behavior. Engineers could tend to switch to
`createRule({ ...getNewRule(), index: undefined, data_view_id:
DATA_VIEW_ID, rule_id: '1' })` to overcome deep merge. So it should be
analysed carefully before implementing
it.","sha":"ca696ac50c0591acf6723e130d2f9278c2d6ef65"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v8.8.0","labelRegex":"^v8.8.0$","isSourceBranch":true,"state":"MERGED","url":"#153474
Solution] Allow rewriting rule create props in Cypress tests
(#153474)\n\n**Relates to:**
#150553
Summary\r\n\r\nThis PR is based on the review comments in
#150553. It allows to rewrite rule
create properties.\r\n\r\n## Details\r\n\r\nRule create properties are
returned by helper functions like `getNewRule()`,
`getNewThresholdRule()` and so on. So instead of `createRule({
...getNewRule(), index: undefined, data_view_id: DATA_VIEW_ID, rule_id:
'1' })` it allows to use a concise and a much more readable structure
`createRule(getNewRule({ index: undefined, data_view_id: DATA_VIEW_ID,
rule_id: '1' ))`.\r\n\r\n## Possible improvements\r\n\r\nThe PR doesn't
implement deep / nested fields merge. High level fields completely
rewrite default values. Deep merge would allow to extend defaults with
the provided rewrites. For example, overriding nested properties become
tiresome quickly, as shown in the following code
snippet:\r\n\r\n```ts\r\nconst rule = {\r\n ...getNewTermsRule(),\r\n
rule_id: 'new_rule_id',\r\n runsEvery: {\r\n interval: '1',\r\n
...getNewTermsRule().runsEvery,\r\n },\r\n};\r\n```\r\n\r\nIf we
implement deep merge, the readability could be greatly
improved:\r\n\r\n```ts\r\nconst rule = getNewTermsRule({\r\n rule_id:
'new_rule_id',\r\n runsEvery: {\r\n interval: '1',\r\n
},\r\n});\r\n```\r\n\r\nWhile it looks as a good idea we should take
into consideration the fact that complete rewriting of default values
can be a desired behavior. Engineers could tend to switch to
`createRule({ ...getNewRule(), index: undefined, data_view_id:
DATA_VIEW_ID, rule_id: '1' })` to overcome deep merge. So it should be
analysed carefully before implementing
it.","sha":"ca696ac50c0591acf6723e130d2f9278c2d6ef65"}}]}] BACKPORT-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:prev-minor Backport to the previous minor version (i.e. one version back from main) refactoring 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. technical debt Improvement of the software architecture and operational architecture test_ui_functional test v8.7.1 v8.8.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet