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] Unskip related integrations tests #164933

Merged
merged 8 commits into from
Aug 31, 2023

Conversation

maximpn
Copy link
Contributor

@maximpn maximpn commented Aug 27, 2023

Fixes: #154663
Fixes: #153684

Summary

This PR unskips Cypress rule related integration tests (related_integrations.cy.ts).

Details

Testing approach has changed. Instead of importing a rule and installing agent and package policies via Fleet UI the rule is created by mocking a prebuilt rule asset and Fleet API is used to install required integrations. Along the way it required to add and update some testing selectors as UI had changed while the tests were skipped.

Flaky test runner

related_integrations.cy.ts (150 runs) 🟢

@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.10.0 v8.11.0 labels Aug 27, 2023
@maximpn maximpn self-assigned this Aug 27, 2023
@maximpn maximpn requested a review from jpdjere August 27, 2023 10:41
@maximpn maximpn force-pushed the unskip-related-integrations-tests branch 4 times, most recently from 31abd6d to 6718a67 Compare August 28, 2023 06:16
@maximpn maximpn marked this pull request as ready for review August 28, 2023 06:16
@maximpn maximpn requested review from a team as code owners August 28, 2023 06:16
@elasticmachine
Copy link
Contributor

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

@elasticmachine
Copy link
Contributor

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

*
* - open `app/integrations/detail/aws-1.17.0/overview?integration=cloudfront`
* - click the button `Add Amazon CloudFront`
* - fill in `Query URL`
Copy link
Contributor

@jpdjere jpdjere Aug 29, 2023

Choose a reason for hiding this comment

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

Suggested change
* - fill in `Query URL`
* - fill in `Queue URL`

/**
* Agent policy and AWS package policy can be generated by Kibana by opening a page
* `app/integrations/detail/aws-1.17.0/overview?integration=cloudfront` then
* click the button `Add Amazon CloudFront` -> fill in `Query URL` -> press `Preview API request` at the bottom.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* click the button `Add Amazon CloudFront` -> fill in `Query URL` -> press `Preview API request` at the bottom.
* click the button `Add Amazon CloudFront` -> fill in `Queue URL` -> press `Preview API request` at the bottom.

@@ -195,6 +198,18 @@ export const preventPrebuiltRulesPackageInstallation = () => {
cy.intercept('POST', '/api/fleet/epm/packages/security_detection_engine/*', {});
};

export const addAvailableToInstallPrebuiltRules = (
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the name of the method is a little confusing, if you don't understand the whole idea of first installing the assets, and then installing those assets as prebuilt rules to Kibana.

What do you think about makeRulesAvailableForInstall?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I ended up with installPrebuiltRuleAssets(). It better reflects the process under the hood and an explanation comment should give some info. Generally speaking we can change business logic later on so installed assets aren't available to be installed without a flag or something and the function names makeRulesAvailableForInstall won't do it its name says.


if (installToKibana) {
cy.log('Install prebuilt rules', rules.length);
Copy link
Contributor

Choose a reason for hiding this comment

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

Now that we have addAvailableToInstallPrebuiltRules, or however we want to call it, I think createAndInstallMockedPrebuiltRules should always install the rules that were created as assets, without having the optional installToKibana flag as param. So if you don't actually want to install the rules, you should just use addAvailableToInstallPrebuiltRules.

Anyways, that is maybe out of scope of this PR, we can follow up on it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are right, this is what we want eventually but it's out of scope of this PR. I'll come up with a refactoring PR to get rid of installToKibana param.

Comment on lines 278 to 409
* The contents below is a shrunk copy from the flyout with the only required inputs.
*/
const AWS_PACKAGE_POLICY: PackagePolicyWithoutAgentPolicyId = {
package: {
name: 'aws',
version: '1.17.0',
},
name: 'aws-1',
namespace: 'default',
inputs: {
'cloudtrail-aws-s3': {
enabled: false,
streams: {
'aws.cloudtrail': {
enabled: true,
vars: {
fips_enabled: false,
tags: ['forwarded', 'aws-cloudtrail'],
preserve_original_event: false,
cloudtrail_regex: '/CloudTrail/',
cloudtrail_digest_regex: '/CloudTrail-Digest/',
cloudtrail_insight_regex: '/CloudTrail-Insight/',
max_number_of_messages: 5,
},
},
},
},
'elb-aws-s3': {
enabled: false,
streams: {
'aws.elb_logs': {
enabled: true,
vars: {
fips_enabled: false,
tags: ['forwarded', 'aws-elb-logs'],
preserve_original_event: false,
max_number_of_messages: 5,
},
},
},
},
'firewall-aws-s3': {
enabled: false,
streams: {
'aws.firewall_logs': {
enabled: true,
vars: {
fips_enabled: false,
tags: ['forwarded', 'aws-firewall-logs'],
preserve_original_event: false,
max_number_of_messages: 5,
},
},
},
},
's3-aws-s3': {
enabled: false,
streams: {
'aws.s3access': {
enabled: true,
vars: {
fips_enabled: false,
tags: ['forwarded', 'aws-s3access'],
preserve_original_event: false,
max_number_of_messages: 5,
},
},
},
},
'waf-aws-s3': {
enabled: false,
streams: {
'aws.waf': {
enabled: true,
vars: {
fips_enabled: false,
tags: ['forwarded', 'aws-waf'],
preserve_original_event: false,
max_number_of_messages: 5,
},
},
},
},
'cloudfront-aws-s3': {
enabled: true,
streams: {
'aws.cloudfront_logs': {
enabled: true,
vars: {
queue_url: 'https://example.com',
fips_enabled: false,
tags: ['forwarded', 'aws-cloudfront'],
preserve_original_event: false,
max_number_of_messages: 5,
},
},
},
},
},
};
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 move these types, utils and mocks to separate files from the main tests? Probably their own integrations.ts files in the /helpers and /tasks dir?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's related to this test only. Moving it somewhere will reduce test's transparency. It makes sense if there is another test reusing the same policy.

Comment on lines 162 to 166
cy.get(INTEGRATIONS_POPOVER).should(
'have.text',
`${rule.enabledIntegrations}/${rule.integrations.length} integrations`
`${RULE_RELATED_INTEGRATIONS.filter((x) => x.enabled).length}/${
RULE_RELATED_INTEGRATIONS.length
} integrations`
Copy link
Contributor

Choose a reason for hiding this comment

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

For readability:

Suggested change
cy.get(INTEGRATIONS_POPOVER).should(
'have.text',
`${rule.enabledIntegrations}/${rule.integrations.length} integrations`
`${RULE_RELATED_INTEGRATIONS.filter((x) => x.enabled).length}/${
RULE_RELATED_INTEGRATIONS.length
} integrations`
const enabledIntegrations = RULE_RELATED_INTEGRATIONS.filter((x) => x.enabled).length;
const totalIntegrations = RULE_RELATED_INTEGRATIONS.length;
cy.get(INTEGRATIONS_POPOVER).should(
'have.text',
`${enabledIntegrations}/${totalIntegrations} integrations`

cy.get(INTEGRATION_STATUS).should('have.length', RULE_RELATED_INTEGRATIONS.length);

RULE_RELATED_INTEGRATIONS.forEach((integration, index) => {
cy.get(INTEGRATION_LINK).eq(index).contains(getIntegrationName(integration), {
Copy link
Contributor

@jpdjere jpdjere Aug 29, 2023

Choose a reason for hiding this comment

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

Wondering about the use of eq(i) here (and in the rest of this file)

Can we guarantee that the order of the integrations links is always the same as defined in RULE_RELATED_INTEGRATIONS? Might it be a cause of flakiness in the future?

Copy link
Contributor Author

@maximpn maximpn Aug 29, 2023

Choose a reason for hiding this comment

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

As you can see prebuilt rule asset and tests reuse the same constant RULE_RELATED_INTEGRATIONS. Related integrations rendered in the popover are rendered based on rule.related_integrations array. This means the order is stable now and we catch any changes here if some refactoring happens in the future.

@maximpn maximpn force-pushed the unskip-related-integrations-tests branch from 6718a67 to a767094 Compare August 29, 2023 09:41
@maximpn maximpn requested a review from jpdjere August 29, 2023 09:53
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.

LGTM

Copy link
Contributor

@christineweng christineweng left a comment

Choose a reason for hiding this comment

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

Investigations changes LGTM!

@jpdjere jpdjere added the flake-docs Temp label to gather PRs used to create dev docs label Aug 30, 2023
@maximpn maximpn force-pushed the unskip-related-integrations-tests branch from 44fe524 to 7f84a6a Compare August 31, 2023 05:04
@kibana-ci
Copy link
Collaborator

💛 Build succeeded, but was flaky

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 +55.0B

History

  • 💛 Build #154430 was flaky 44fe5247a3bfb4bb486b1df4518a31d248acd2e9
  • 💛 Build #153960 was flaky 6718a670be10389825ba8e64b0e0c63aebaca14f
  • 💔 Build #153956 failed 31abd6d57cca8def342a8d534f8140a987518f5c
  • 💛 Build #153947 was flaky 24a71e503de563a88c2922651347a51d41ae7d42
  • 💔 Build #153945 failed e9d679aaa7233c93a5f2a0dbea6aac7454bbaeec
  • 💔 Build #153939 failed 53cf2bdee4bdaf94dfba5a97bd2c4ad48da020e3

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

cc @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.

DE changes LGTM

@maximpn maximpn merged commit 2c3464c into elastic:main Aug 31, 2023
@maximpn maximpn deleted the unskip-related-integrations-tests branch August 31, 2023 10:28
@kibanamachine
Copy link
Contributor

💔 All backports failed

Status Branch Result
8.10 Backport failed because of merge conflicts

Manual backport

To create the backport manually run:

node scripts/backport --pr 164933

Questions ?

Please refer to the Backport tool documentation

@maximpn
Copy link
Contributor Author

maximpn commented Aug 31, 2023

💚 All backports created successfully

Status Branch Result
8.10

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

Questions ?

Please refer to the Backport tool documentation

maximpn added a commit to maximpn/kibana that referenced this pull request Aug 31, 2023
**Fixes: elastic#154663
**Fixes: elastic#153684

## Summary

This PR unskips Cypress rule related integration tests ([related_integrations.cy.ts](https://github.com/elastic/kibana/blob/main/x-pack/test/security_solution_cypress/cypress/e2e/detection_response/rule_management/related_integrations/related_integrations.cy.ts)).

## Details

Testing approach has changed. Instead of importing a rule and installing agent and package policies via Fleet UI the rule is created by mocking a prebuilt rule asset and Fleet API is used to install required integrations. Along the way it required to add and update some testing selectors as UI had changed while the tests were skipped.

## Flaky test runner

[related_integrations.cy.ts (150 runs)](https://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/2995) 🟢

(cherry picked from commit 2c3464c)

# Conflicts:
#	x-pack/test/security_solution_cypress/cypress/e2e/detection_response/rule_management/related_integrations/related_integrations.cy.ts
#	x-pack/test/security_solution_cypress/cypress/tasks/api_calls/prebuilt_rules.ts
maximpn added a commit that referenced this pull request Aug 31, 2023
#165310)

# Backport

This will backport the following commits from `main` to `8.10`:
- [[Security Solution] Unskip related integrations tests
(#164933)](#164933)

<!--- Backport version: 8.9.8 -->

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

<!--BACKPORT [{"author":{"name":"Maxim
Palenov","email":"[email protected]"},"sourceCommit":{"committedDate":"2023-08-31T10:28:16Z","message":"[Security
Solution] Unskip related integrations tests (#164933)\n\n**Fixes:
https://github.com/elastic/kibana/issues/154663**\r\n**Fixes:
https://github.com/elastic/kibana/issues/153684**\r\n\r\n##
Summary\r\n\r\nThis PR unskips Cypress rule related integration tests
([related_integrations.cy.ts](https://github.com/elastic/kibana/blob/main/x-pack/test/security_solution_cypress/cypress/e2e/detection_response/rule_management/related_integrations/related_integrations.cy.ts)).\r\n\r\n##
Details\r\n\r\nTesting approach has changed. Instead of importing a rule
and installing agent and package policies via Fleet UI the rule is
created by mocking a prebuilt rule asset and Fleet API is used to
install required integrations. Along the way it required to add and
update some testing selectors as UI had changed while the tests were
skipped.\r\n\r\n## Flaky test runner\r\n\r\n[related_integrations.cy.ts
(150
runs)](https://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/2995)
🟢","sha":"2c3464ca8457e09f51852c6c0d60ab7f6e21afc0","branchLabelMapping":{"^v8.11.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["test","release_note:skip","Team:Detections
and Resp","Team: SecuritySolution","Feature:Rule
Management","Team:Detection Rule
Management","v8.10.0","v8.11.0","flake-docs"],"number":164933,"url":"https://github.com/elastic/kibana/pull/164933","mergeCommit":{"message":"[Security
Solution] Unskip related integrations tests (#164933)\n\n**Fixes:
https://github.com/elastic/kibana/issues/154663**\r\n**Fixes:
https://github.com/elastic/kibana/issues/153684**\r\n\r\n##
Summary\r\n\r\nThis PR unskips Cypress rule related integration tests
([related_integrations.cy.ts](https://github.com/elastic/kibana/blob/main/x-pack/test/security_solution_cypress/cypress/e2e/detection_response/rule_management/related_integrations/related_integrations.cy.ts)).\r\n\r\n##
Details\r\n\r\nTesting approach has changed. Instead of importing a rule
and installing agent and package policies via Fleet UI the rule is
created by mocking a prebuilt rule asset and Fleet API is used to
install required integrations. Along the way it required to add and
update some testing selectors as UI had changed while the tests were
skipped.\r\n\r\n## Flaky test runner\r\n\r\n[related_integrations.cy.ts
(150
runs)](https://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/2995)
🟢","sha":"2c3464ca8457e09f51852c6c0d60ab7f6e21afc0"}},"sourceBranch":"main","suggestedTargetBranches":["8.10"],"targetPullRequestStates":[{"branch":"8.10","label":"v8.10.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.11.0","labelRegex":"^v8.11.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/164933","number":164933,"mergeCommit":{"message":"[Security
Solution] Unskip related integrations tests (#164933)\n\n**Fixes:
https://github.com/elastic/kibana/issues/154663**\r\n**Fixes:
https://github.com/elastic/kibana/issues/153684**\r\n\r\n##
Summary\r\n\r\nThis PR unskips Cypress rule related integration tests
([related_integrations.cy.ts](https://github.com/elastic/kibana/blob/main/x-pack/test/security_solution_cypress/cypress/e2e/detection_response/rule_management/related_integrations/related_integrations.cy.ts)).\r\n\r\n##
Details\r\n\r\nTesting approach has changed. Instead of importing a rule
and installing agent and package policies via Fleet UI the rule is
created by mocking a prebuilt rule asset and Fleet API is used to
install required integrations. Along the way it required to add and
update some testing selectors as UI had changed while the tests were
skipped.\r\n\r\n## Flaky test runner\r\n\r\n[related_integrations.cy.ts
(150
runs)](https://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/2995)
🟢","sha":"2c3464ca8457e09f51852c6c0d60ab7f6e21afc0"}}]}] BACKPORT-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:Rule Management Security Solution Detection Rule Management area flake-docs Temp label to gather PRs used to create dev docs 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.10.0 v8.11.0
Projects
None yet
7 participants