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] Fix a build step when there are no tests to execute #165929

Merged

Conversation

maximpn
Copy link
Contributor

@maximpn maximpn commented Sep 7, 2023

Summary

Fixes failed build steps when there are no tests to execute and hence no reports.

Details

Despite this PR fixes tests failure when there are no reports but yarn junit:merge tries to convert them to junit format the problem is partially stays as Failed Test Reporter runs for every build step meaning also for successful build steps. We don't need to handle failed test reports for successful build steps. There are cases when there are no tests to run so Cypress doesn't produce reports and nothing is converted to junit format so Failed Test Reporter fails and causes a build step to fails. It could be solved by defining an environment variable DISABLE_MISSING_TEST_REPORT_ERRORS=true but we need to make sure reports exist for failed tests. Taking this into account we can rely on BUILDKITE_COMMAND_EXIT_STATUS to avoid running Failed Test Reporter if the build step successed.

One may ask why don't skip Upload Artifacts too. We may need some build artifacts for successful build steps.

@maximpn maximpn self-assigned this Sep 7, 2023
@maximpn maximpn force-pushed the fix-buildkite-step-if-there-are-no-tests-to-run branch 2 times, most recently from b32be1b to 54c17f6 Compare September 7, 2023 07:38
@maximpn maximpn force-pushed the fix-buildkite-step-if-there-are-no-tests-to-run branch from 5663af7 to 54509e4 Compare September 7, 2023 10:36
@maximpn maximpn changed the title [Security Solution] Fix a build step if there are no tests to execute [Security Solution] Fix a build step when there are no tests to execute Sep 7, 2023
@maximpn maximpn marked this pull request as ready for review September 7, 2023 11:44
@maximpn maximpn requested a review from a team as a code owner September 7, 2023 11:44
@@ -31,8 +31,10 @@ if [[ "$IS_TEST_EXECUTION_STEP" == "true" ]]; then
buildkite-agent artifact upload '.es/**/*.hprof'
buildkite-agent artifact upload 'data/es_debug_*.tar.gz'

echo "--- Run Failed Test Reporter"
node scripts/report_failed_tests --build-url="${BUILDKITE_BUILD_URL}#${BUILDKITE_JOB_ID}" 'target/junit/**/*.xml'
if [ ${BUILDKITE_COMMAND_EXIT_STATUS} -ne 0 ]; then
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure if this will work on Buildkite, locally I can't use -ne with [ ] so I suggest:

Suggested change
if [ ${BUILDKITE_COMMAND_EXIT_STATUS} -ne 0 ]; then
if [[ ${BUILDKITE_COMMAND_EXIT_STATUS} -ne 0 ]]; then

@delanni
Copy link
Contributor

delanni commented Sep 7, 2023

Reading through the post_command, and subsequently the failed_test_reporter.ts I found this -

if (!reportPaths.length && DISABLE_MISSING_TEST_REPORT_ERRORS) {

Maybe we should set this flag in the post_command hooks: DISABLE_MISSING_TEST_REPORT_ERRORS=true, so this wouldn't cause an error. I think it might be a nicer way out of the errors (instead of skipping in whole), because there might be other things that the reporter does - it seems we're finding (and possibly reporting) some junit .xml files even in case of successful tests, which we would now skip. What do you think?

@maximpn
Copy link
Contributor Author

maximpn commented Sep 7, 2023

@delanni I considered using DISABLE_MISSING_TEST_REPORT_ERRORS=true but it won't help catching situations when reports are broken by some PR. If a PR breaks reports it must break the built so PR's author can take actions.

Regarding skipping Failed Test Reporter for successful tests. As the name suggests Failed Test Reporter handles failed tests. Reports for successful tests are presumably ignored for now. If the script does something useful with successful test reports it must be handled in a different way. At first rename it to something like report_tests and make the intentions transparently clear.

@maximpn maximpn added release_note:skip Skip the PR/issue when compiling release notes v8.11.0 labels Sep 7, 2023
@kibana-ci
Copy link
Collaborator

kibana-ci commented Sep 7, 2023

💔 Build Failed

Failed CI Steps

Test Failures

  • [job] [logs] Serverless Security Investigations Cypress Tests #1 / Bulk Investigate in Timeline Host -> Events Viewer "before all" hook for "Adding multiple events to the timeline should be successful" "before all" hook for "Adding multiple events to the timeline should be successful"
  • [job] [logs] Rules, Alerts and Exceptions ResponseOps Cypress Tests on Security Solution #2 / Detections > Callouts indicating read-only access to resources On Rule Details page When a user clicks Dismiss on the callouts We hide them and persist the dismissal We hide them and persist the dismissal
  • [job] [logs] Serverless Observability Examples Tests / serverless examples UI Unified Field List Examples Fields existence info "after all" hook in "Fields existence info"
  • [job] [logs] Serverless Observability Examples Tests / serverless examples UI Unified Field List Examples Fields existence info "before all" hook in "Fields existence info"
  • [job] [logs] Fleet Cypress Tests / When the user has All privileges for Integrations but None for for Fleet Integrations are visible but cannot be added
  • [job] [logs] Fleet Cypress Tests / When the user has Editor built-in role Integrations app are visible and can be added

Metrics [docs]

✅ unchanged

History

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

cc @maximpn

Copy link
Member

@jbudz jbudz left a comment

Choose a reason for hiding this comment

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

https://buildkite.com/elastic/kibana-pull-request/builds/157221#018a6fb8-a262-40ac-8d2a-e9e5a8ab06e3/279-290

This seems strange, command is exiting with a failure, report failed tests is correctly skipped but then the CI step is marked as a success. Is this intentional?

@maximpn
Copy link
Contributor Author

maximpn commented Sep 7, 2023

@jbudz this is an intentional behavior and a temporally fix done by this PR. Reporter merger/converter can't handle missing tests gracefully and exit with non zero code. A proper fix will take some time and I created a ticket for that. While you can see non zero exit code in the log in fact it's swallowed by || : resulting in zero exit code.

@mistic mistic merged commit 369d2fe 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 fix-buildkite-step-if-there-are-no-tests-to-run branch September 7, 2023 16:07
@banderror
Copy link
Contributor

💚 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

banderror pushed a commit to banderror/kibana that referenced this pull request Sep 25, 2023
…te (elastic#165929)

## Summary

Fixes failed build steps when there are no tests to execute and hence no
reports.

## Details

Despite this [PR](elastic#165824) fixes
tests failure when there are no reports but `yarn junit:merge` tries to
convert them to junit format the problem is partially stays as `Failed
Test Reporter` runs for every build step meaning also for successful
build steps. We don't need to handle failed test reports for successful
build steps. There are cases when there are no tests to run so Cypress
doesn't produce reports and nothing is converted to junit format so
`Failed Test Reporter` fails and causes a build step to fails. It could
be solved by defining an environment variable
`DISABLE_MISSING_TEST_REPORT_ERRORS=true` but we need to make sure
reports exist for failed tests. Taking this into account we can rely on
`BUILDKITE_COMMAND_EXIT_STATUS` to avoid running `Failed Test Reporter`
if the build step successed.

One may ask why don't skip `Upload Artifacts` too. We may need some
build artifacts for successful build steps.

---------

Co-authored-by: Tiago Costa <[email protected]>
(cherry picked from commit 369d2fe)
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 ci:all-cypress-suites release_note:skip Skip the PR/issue when compiling release notes v8.11.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants