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] Get rid of goToRuleDetails() in favor of goToRuleDetailsOf() #165011

Merged
merged 16 commits into from
Sep 7, 2023

Conversation

maximpn
Copy link
Contributor

@maximpn maximpn commented Aug 28, 2023

Addresses: #164513

Summary

This PR gets rid of Rules Management goToRuleDetails() Cypress helper replacing it with goToRuleDetailsOf().

Details

The following has been done

  • goToRuleDetails() replaced with goToRuleDetailsOf() where it makes sense (rule creation, scenarios validating something on the rules management table and then on the rule details page and etc).

  • For quite a number of tests expectations are done on the rule details page but it's opened via rules management table page. In fact this unnecessary step may be flaky as rules table has auto resfresh feature and it should be ideally disabled as well as this requires loading of lazy UI resources and increases test's execution time. It can be avoided by directly opening the details page via

    createRule(getNewRule()).then((rule) =>
      visitWithoutDateRange(ruleDetailsUrl(rule.body.id))
    );

    goToRuleDetails() was removed from such tests in favor of opening the rule details page directly.

Does opening rule detail page directly make the tests less stable?

Yes, it can give such side effect but it will help to either find and fix some bugs in our code or make our tests more robust by adding an universal page ready expectation.

While working on this PR I had to fix a few problems on the rule details page caused by getting rid of unnecessary opening rule details page via rules management table but it fact it revealed rule details page's problems

  • If a test needs first thing to enable a rule like editing test for custom query rule the test may fail as -1 is sent as rule id. In fact it's a page loading problem. Rule switch become available while the rule isn't loaded yet and it can be easily reproduced in prod if the connection is slow. Disabling rule switch while rule isn't loaded yet solves the problem.
  • Rule exceptions tests turned to be flaky. Edit exception list item context menu closes on its own sometimes. In fact useEffect causing HTTP request fired much more often than it should due to exception list types defined in place and regenerated each render causing the list item to be in loading state while the request is in progress. It was fixed by moving the arrays to stable constants.

Flaky test runner

Security Solution Cypress tests (150 runs) (there is no indication of negative impact)

@maximpn maximpn added test 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. Feature:Rule Management Security Solution Detection Rule Management area Team:Detection Rule Management Security Detection Rule Management Team v8.11.0 labels Aug 28, 2023
@maximpn maximpn self-assigned this Aug 28, 2023
@maximpn maximpn force-pushed the refactor-go-to-tule-details branch 3 times, most recently from 9765fac to dd44054 Compare August 29, 2023 05:36
@maximpn maximpn changed the title [Security Solution] Refactor goToRuleDetails [Security Solution] Get rid of goToRuleDetails() in favor of goToRuleDetailsOf() Aug 29, 2023
@maximpn maximpn requested a review from MadameSheema August 29, 2023 10:28
@maximpn maximpn marked this pull request as ready for review August 29, 2023 10:28
@maximpn maximpn requested review from a team as code owners August 29, 2023 10:28
@maximpn maximpn requested a review from jpdjere August 29, 2023 10:28
@elasticmachine
Copy link
Contributor

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

@elasticmachine
Copy link
Contributor

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

@maximpn maximpn changed the title [Security Solution] Get rid of goToRuleDetails() in favor of goToRuleDetailsOf() [Security Solution] Get rid of goToRuleDetails() in favor of goToRuleDetailsOf() Aug 29, 2023
@maximpn maximpn force-pushed the refactor-go-to-tule-details branch from 739ad46 to 8343dab Compare August 31, 2023 10:48
@@ -603,6 +610,7 @@ const RuleDetailsPageComponent: React.FC<DetectionEngineComponentProps> = ({
<RuleSwitch
id={rule?.id ?? '-1'}
isDisabled={
!rule?.id ||
Copy link
Contributor

Choose a reason for hiding this comment

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

Great catch! :+1

@@ -316,7 +318,7 @@ describe('Custom query rules', { tags: ['@ess', '@brokenInServerless'] }, () =>
const initialNumberOfRules = rules.length;
const expectedNumberOfRulesAfterDeletion = initialNumberOfRules - 1;

goToTheRuleDetailsOf('New Rule Test');
goToRuleDetailsOf('New Rule Test');
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we create a variable with the test details and use RULE.name here?

duplicateFirstRule();
goBackToRuleDetails();
goBackToRulesTable();
checkDuplicatedRule('Indicator rule duplicate test [Duplicate]');
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here, can we do somthing like:

checkDuplicatedRule(`${RULE_NAME} [Duplicate]`);

login();
visitWithoutDateRange(DETECTIONS_RULE_MANAGEMENT_URL);
goToRuleDetails();
cy.get(RULE_STATUS).should('have.text', '—');
Copy link
Contributor

Choose a reason for hiding this comment

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

This test is skipped anyway, but are we sure this assertion:

cy.get(RULE_STATUS).should('have.text', '—');

Is not important and safe to be removed?

Copy link
Contributor Author

@maximpn maximpn Sep 2, 2023

Choose a reason for hiding this comment

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

It's hard to say as the test is skipped. I'd say it waits for the page to be loaded and we ideally need to incapsulate it in a helper function but I revert this line just in case.

@@ -106,8 +106,8 @@ export const goToEndpointExceptionsTab = () => {
};

export const openEditException = (index = 0) => {
cy.get(EXCEPTION_ITEM_ACTIONS_BUTTON).eq(index).click({ force: true });
cy.get(EDIT_EXCEPTION_BTN).eq(index).click({ force: true });
cy.get(EXCEPTION_ITEM_ACTIONS_BUTTON).eq(index).click();
Copy link
Contributor

Choose a reason for hiding this comment

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

Great to see we don't need this force anymore

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.

Rules Management LGTM! And thanks for this refactor, super valuable; great fixes.

@maximpn maximpn force-pushed the refactor-go-to-tule-details branch from a098da1 to 1ee4b72 Compare September 4, 2023 14:53
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.

DE changes LGTM, left a few comments

@@ -603,6 +610,7 @@ const RuleDetailsPageComponent: React.FC<DetectionEngineComponentProps> = ({
<RuleSwitch
id={rule?.id ?? '-1'}
isDisabled={
!rule ||
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we could show some loading state instead of the rule's details UI while rule is not available?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Global loader is considered as bad UX nowadays and skeleton loading is much more preferable. We display as much as we can as early as possible to avoid the loader flickering. If you still think it's worth to show some loader instead I suggest to discuss it out of scope of this PR.

};

export const goToTheRuleDetailsOf = (ruleName: string) => {
export const goToRuleDetailsOf = (ruleName: string) => {
cy.contains(RULE_NAME, ruleName).click();
Copy link
Contributor

Choose a reason for hiding this comment

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

Just curious how this will work if we have several rules with exactly same name or if we have two rules named "Test Rule" and "Test Rule 1" and we go to details of the rule "Test Rule". Won't it potentially find another rule in those cases?

Just trying to understand if we can safely use same names in tests

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@e40pud you are right about the pitfalls. If goToRuleDetailsOf() is used the rule names should be unique and distinguishable. If there are Test Rule and Test Rule 1 rules then goToRuleDetailsOf('Test Rule') opens the first rule in the table. So it has to be take into account.

In the case of exactly same names goToRuleDetailsOf() shouldn't be used. it rather resembles how users distinguish rules. Despite id identifies rules uniquely it takes much more effort than just compare names so obviously user expect unique rule names.

it('Only modifies rule active status on enable/disable', () => {
enablesRule();
const editedRuleData = getEditedRule();
const expectedEditedtags = editedRuleData.tags?.join('');
Copy link
Contributor

Choose a reason for hiding this comment

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

We could rename expectedEditedtags into expectedEditedTags to follow the rest of the names

@maximpn maximpn force-pushed the refactor-go-to-tule-details branch 5 times, most recently from db04d46 to 60eadb2 Compare September 7, 2023 16:13
@maximpn maximpn enabled auto-merge (squash) September 7, 2023 16:53
@maximpn maximpn force-pushed the refactor-go-to-tule-details branch from f7a8dbd to b788ee0 Compare September 7, 2023 19:04
@kibana-ci
Copy link
Collaborator

kibana-ci commented Sep 7, 2023

💔 Build Failed

Failed CI Steps

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 12.6MB 12.6MB +17.0B

History

  • 💔 Build #157364 failed f7a8dbddb91853716404f8e5f77799433e9e3009
  • 💔 Build #157345 failed 60eadb27f269c2299e3c0b1e6ac6026d819b00ff
  • 💔 Build #157052 failed db04d4614e9cb9d1deb1e8160802c69689c3475a
  • 💔 Build #157039 failed bfb695fe7bd837d2356657ec68366d664ae16f5c
  • 💔 Build #157008 failed f52278441bcaff1879dfc31f0c4b470a9b388cd8

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

cc @maximpn

@maximpn maximpn merged commit 79c3fae into elastic:main Sep 7, 2023
@kibanamachine kibanamachine added the backport:skip This commit does not require backporting label Sep 7, 2023
@maximpn maximpn deleted the refactor-go-to-tule-details branch September 7, 2023 20:27
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:Rule Management Security Solution Detection Rule Management area 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. test v8.11.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants