[Security Solution][Endpoint] Cypress test improvements to capture Agent diagnostics file when test fails#202965
Conversation
…the runtime env. first before attempting to use the setting from the cypress config
|
/ci |
|
/ci |
|
Pinging @elastic/security-defend-workflows (Team:Defend Workflows) |
maximpn
left a comment
There was a problem hiding this comment.
@paul-tavares Thanks for improving tests logging 🙏 I reviewed changed to x-pack/plugins/security_solution/scripts/run_cypress/parallel.ts and left comments.
| ) | ||
| .boolean('inspect'); | ||
|
|
||
| const USE_CHROME_BETA = process.env.USE_CHROME_BETA?.match(/(1|true)/i); |
There was a problem hiding this comment.
Isn't an ability to test in Chrome beta version required anymore?
There was a problem hiding this comment.
oh.... no no. this is mistake. I did not meant to remove this. Will add it back. Thanks for catching it.
| createToolingLogger.defaultLogLevel = cypressConfigFile.env.TOOLING_LOG_LEVEL; | ||
| // Adjust tooling log level based on the `TOOLING_LOG_LEVEL` property, which can be | ||
| // defined in the cypress config file or set in the `env` | ||
| { |
There was a problem hiding this comment.
It might be useful to have the same functionality for Serverless i.e. the same changes are required in x-pack/plugins/security_solution/scripts/run_cypress/parallel_serverless.ts.
Have you considered creation a separate file/function like createLogger() reading env variable under the hood?
There was a problem hiding this comment.
Ohhhh. Did not realize there was a serverless parallel runner. I will break this out into a utility and will call it from both parallel runners. Thanks for the feedback
|
|
||
| if (logLevel) { | ||
| _cliLogger.info(`Setting tooling log level to [${logLevel}]`); | ||
| createToolingLogger.defaultLogLevel = logLevel; |
There was a problem hiding this comment.
Is it expected behavior to affect all the instances created below in the execution flow?
As a safer option it might better to create a ToolingLog instance and pass it to prefixedOutputLogger.
There was a problem hiding this comment.
yeah... its expected. The goal is to ensure that all intances of ToolingLog (created by createToolingLogger()) uses by default the log level set via the env. variable or the cypress config file.
…also use it in the `parallel_serverless` runner
| * It will first check the NodeJs `process.env` to see if an Environment Variable was set | ||
| * and then, if provided, it will use the value defined in the Cypress Config. file. | ||
| */ | ||
| export const setDefaultToolingLoggingLevel = (cypressConfigFile?: any) => { |
There was a problem hiding this comment.
There is no point using any type here. cypressConfigFile in upstream parallel and parallel_serverless files already has type any. We could provide a more specific type for cypressConfigFile here like
interface CypressConfigFile {
env?: Record<string, string>;
}There was a problem hiding this comment.
I used any here because that matches the type I am seeing for the cypressConfigFile in the parallel modules:
And I set this type here to be any more specific I'll likely have to cast the value when I attempt to pass it to this function. I'll instead change the signature of the function to not require the entire config file and instead just pass in the value for TOOLING_LOG_LEVEL instead.
💚 Build Succeeded
Metrics [docs]Unknown metric groupsESLint disabled line counts
Total ESLint disabled count
History
|
maximpn
left a comment
There was a problem hiding this comment.
@paul-tavares Thanks for addressing my comments 🙏
Changes to x-pack/plugins/security_solution/scripts/run_cypress/parallel.ts and x-pack/plugins/security_solution/scripts/run_cypress/parallel_serverless.ts LGTM
| process.env.TOOLING_LOG_LEVEL || | ||
| process.env.CYPRESS_TOOLING_LOG_LEVEL || | ||
| defaultFallbackLoggingLevel || | ||
| ''; |
There was a problem hiding this comment.
nit: It looks like empty string isn't necessary here since if condition below is gonna check for all "falsable" values.
|
Starting backport for target branches: 8.x https://github.com/elastic/kibana/actions/runs/12299431737 |
💔 All backports failed
Manual backportTo create the backport manually run: Questions ?Please refer to the Backport tool documentation |
|
Friendly reminder: Looks like this PR hasn’t been backported yet. |
1 similar comment
|
Friendly reminder: Looks like this PR hasn’t been backported yet. |
💚 All backports created successfully
Note: Successful backport PRs will be merged automatically after passing CI. Questions ?Please refer to the Backport tool documentation |
…ent diagnostics file when test fails (elastic#202965) ## Summary - the Cypress `parallel` runner was updated to set tooling logging level first from Env. variables before falling back to the value defined in the Cypress configuration file - The env. value to set, if wanting to enable a specific logging level, is `TOOLING_LOG_LEVEL`. The values supported are the same as those used with `ToolingLog` ([here](https://github.com/elastic/kibana/blob/b6287708f687d4e3288851052c0c6ae4ade8ce60/packages/kbn-tooling-log/src/log_levels.ts#L10)): `silent`, `error`, `warning`, `success`, `info`, `debug`, `verbose` - This change makes it easier to run Cypress tests locally with (for example) a logging level of `verbose` for our tooling without having to modify the Cypress configuration file. Example: `export TOOLING_LOG_LEVEL=verbose && yarn cypress:dw:open` - Added two new methods to our scripting VM service clients (for Vagrant and Multipass): - `download`: allow you to pull files out of the VM and save them locally - `upload`: uploads a local file to the VM. (upload already existed as `transfer` - which has now been marked as deprecated). - Added new service function on our Fleet scripting module to enable us to set the logging level on a Fleet Agent - Cypress tests were adjusted to automatically set the agent logging to debug when running in CI - A new Cypress task that allows for an Agent Diagnostic file (which includes the Endpoint Log) to be retrieved from the host VM and stored with the CI job (under the artifacts tab) - A few tests were updated to include this step for failed test (cherry picked from commit 2ab8a5c) # Conflicts: # x-pack/plugins/security_solution/scripts/endpoint/common/fleet_services.ts
…ure Agent diagnostics file when test fails (#202965) (#204485) # Backport This will backport the following commits from `main` to `8.x`: - [[Security Solution][Endpoint] Cypress test improvements to capture Agent diagnostics file when test fails (#202965)](#202965) <!--- Backport version: 8.9.8 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"Paul Tavares","email":"56442535+paul-tavares@users.noreply.github.com"},"sourceCommit":{"committedDate":"2024-12-12T15:21:23Z","message":"[Security Solution][Endpoint] Cypress test improvements to capture Agent diagnostics file when test fails (#202965)\n\n## Summary\r\n\r\n- the Cypress `parallel` runner was updated to set tooling logging level\r\nfirst from Env. variables before falling back to the value defined in\r\nthe Cypress configuration file\r\n- The env. value to set, if wanting to enable a specific logging level,\r\nis `TOOLING_LOG_LEVEL`. The values supported are the same as those used\r\nwith `ToolingLog`\r\n([here](https://github.com/elastic/kibana/blob/b6287708f687d4e3288851052c0c6ae4ade8ce60/packages/kbn-tooling-log/src/log_levels.ts#L10)):\r\n`silent`, `error`, `warning`, `success`, `info`, `debug`, `verbose`\r\n- This change makes it easier to run Cypress tests locally with (for\r\nexample) a logging level of `verbose` for our tooling without having to\r\nmodify the Cypress configuration file. Example: `export\r\nTOOLING_LOG_LEVEL=verbose && yarn cypress:dw:open`\r\n- Added two new methods to our scripting VM service clients (for Vagrant\r\nand Multipass):\r\n- `download`: allow you to pull files out of the VM and save them\r\nlocally\r\n- `upload`: uploads a local file to the VM. (upload already existed as\r\n`transfer` - which has now been marked as deprecated).\r\n- Added new service function on our Fleet scripting module to enable us\r\nto set the logging level on a Fleet Agent\r\n- Cypress tests were adjusted to automatically set the agent logging to\r\ndebug when running in CI\r\n- A new Cypress task that allows for an Agent Diagnostic file (which\r\nincludes the Endpoint Log) to be retrieved from the host VM and stored\r\nwith the CI job (under the artifacts tab)\r\n - A few tests were updated to include this step for failed test","sha":"2ab8a5ced075da08f3aeb9526a76b60b1a964602","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","backport missing","v9.0.0","Team:Defend Workflows","backport:prev-minor","v8.18.0"],"number":202965,"url":"https://github.com/elastic/kibana/pull/202965","mergeCommit":{"message":"[Security Solution][Endpoint] Cypress test improvements to capture Agent diagnostics file when test fails (#202965)\n\n## Summary\r\n\r\n- the Cypress `parallel` runner was updated to set tooling logging level\r\nfirst from Env. variables before falling back to the value defined in\r\nthe Cypress configuration file\r\n- The env. value to set, if wanting to enable a specific logging level,\r\nis `TOOLING_LOG_LEVEL`. The values supported are the same as those used\r\nwith `ToolingLog`\r\n([here](https://github.com/elastic/kibana/blob/b6287708f687d4e3288851052c0c6ae4ade8ce60/packages/kbn-tooling-log/src/log_levels.ts#L10)):\r\n`silent`, `error`, `warning`, `success`, `info`, `debug`, `verbose`\r\n- This change makes it easier to run Cypress tests locally with (for\r\nexample) a logging level of `verbose` for our tooling without having to\r\nmodify the Cypress configuration file. Example: `export\r\nTOOLING_LOG_LEVEL=verbose && yarn cypress:dw:open`\r\n- Added two new methods to our scripting VM service clients (for Vagrant\r\nand Multipass):\r\n- `download`: allow you to pull files out of the VM and save them\r\nlocally\r\n- `upload`: uploads a local file to the VM. (upload already existed as\r\n`transfer` - which has now been marked as deprecated).\r\n- Added new service function on our Fleet scripting module to enable us\r\nto set the logging level on a Fleet Agent\r\n- Cypress tests were adjusted to automatically set the agent logging to\r\ndebug when running in CI\r\n- A new Cypress task that allows for an Agent Diagnostic file (which\r\nincludes the Endpoint Log) to be retrieved from the host VM and stored\r\nwith the CI job (under the artifacts tab)\r\n - A few tests were updated to include this step for failed test","sha":"2ab8a5ced075da08f3aeb9526a76b60b1a964602"}},"sourceBranch":"main","suggestedTargetBranches":["8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","labelRegex":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/202965","number":202965,"mergeCommit":{"message":"[Security Solution][Endpoint] Cypress test improvements to capture Agent diagnostics file when test fails (#202965)\n\n## Summary\r\n\r\n- the Cypress `parallel` runner was updated to set tooling logging level\r\nfirst from Env. variables before falling back to the value defined in\r\nthe Cypress configuration file\r\n- The env. value to set, if wanting to enable a specific logging level,\r\nis `TOOLING_LOG_LEVEL`. The values supported are the same as those used\r\nwith `ToolingLog`\r\n([here](https://github.com/elastic/kibana/blob/b6287708f687d4e3288851052c0c6ae4ade8ce60/packages/kbn-tooling-log/src/log_levels.ts#L10)):\r\n`silent`, `error`, `warning`, `success`, `info`, `debug`, `verbose`\r\n- This change makes it easier to run Cypress tests locally with (for\r\nexample) a logging level of `verbose` for our tooling without having to\r\nmodify the Cypress configuration file. Example: `export\r\nTOOLING_LOG_LEVEL=verbose && yarn cypress:dw:open`\r\n- Added two new methods to our scripting VM service clients (for Vagrant\r\nand Multipass):\r\n- `download`: allow you to pull files out of the VM and save them\r\nlocally\r\n- `upload`: uploads a local file to the VM. (upload already existed as\r\n`transfer` - which has now been marked as deprecated).\r\n- Added new service function on our Fleet scripting module to enable us\r\nto set the logging level on a Fleet Agent\r\n- Cypress tests were adjusted to automatically set the agent logging to\r\ndebug when running in CI\r\n- A new Cypress task that allows for an Agent Diagnostic file (which\r\nincludes the Endpoint Log) to be retrieved from the host VM and stored\r\nwith the CI job (under the artifacts tab)\r\n - A few tests were updated to include this step for failed test","sha":"2ab8a5ced075da08f3aeb9526a76b60b1a964602"}},{"branch":"8.x","label":"v8.18.0","labelRegex":"^v8.18.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}] BACKPORT-->
Summary
parallelrunner was updated to set tooling logging level first from Env. variables before falling back to the value defined in the Cypress configuration fileTOOLING_LOG_LEVEL. The values supported are the same as those used withToolingLog(here):silent,error,warning,success,info,debug,verboseverbosefor our tooling without having to modify the Cypress configuration file. Example:export TOOLING_LOG_LEVEL=verbose && yarn cypress:dw:opendownload: allow you to pull files out of the VM and save them locallyupload: uploads a local file to the VM. (upload already existed astransfer- which has now been marked as deprecated).Screen capture showing Agent Diagnostics zip file captured for failing test: