From 99d381c442360ae9a738e66a41c8a5e7c891f10b Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Mon, 13 May 2024 13:34:23 +0300 Subject: [PATCH] [7.17](backport #39506) Remove hardcoded module definitions in CI (#39527) For reasons described in [^1], we hard coded `aws` or `kubernetes` for the env var `MODULE`, when no file changes were detected under `modules/` per project. This commit reverts this and allows all module tests to run if no changesets apply. As discussed in [^1], for the tests to run properly (and not go into an infinite loop) if there are no module changes the `MODULE` env var should **not** be set, rather than set to an empty string. This commit is an important fix as it covers a major delta in test coverage between Jenkins and Buildkite. Closes https://github.com/elastic/ingest-dev/issues/2993 [^1]: https://github.com/elastic/ingest-dev/issues/2993#issuecomment-2104741977 (cherry picked from commit c91503b4cb33b4d98befb1dcd9bdbd888d44d28b) --------- Co-authored-by: Dimitrios Liappis --- .buildkite/metricbeat/pipeline.yml | 13 +++++-------- .buildkite/scripts/changesets.psm1 | 16 ++++------------ .buildkite/scripts/changesets.sh | 13 +++++-------- .buildkite/x-pack/pipeline.xpack.auditbeat.yml | 2 +- .../x-pack/pipeline.xpack.dockerlogbeat.yml | 4 +--- .buildkite/x-pack/pipeline.xpack.filebeat.yml | 8 ++++---- .buildkite/x-pack/pipeline.xpack.metricbeat.yml | 8 ++++---- .buildkite/x-pack/pipeline.xpack.winlogbeat.yml | 4 +--- 8 files changed, 25 insertions(+), 43 deletions(-) diff --git a/.buildkite/metricbeat/pipeline.yml b/.buildkite/metricbeat/pipeline.yml index be37e855a83..405a1983b07 100644 --- a/.buildkite/metricbeat/pipeline.yml +++ b/.buildkite/metricbeat/pipeline.yml @@ -50,13 +50,10 @@ steps: key: "mandatory-int-test" command: | set -euo pipefail - - # TODO: uncomment all lines below (that set MODULE and install kind) when https://github.com/elastic/beats/issues/38874 has been resolved. - # TODO: Note that this problem exists ONLY on 7.17 branch - # # defines the MODULE env var based on what's changed in a PR - # source .buildkite/scripts/changesets.sh - # defineModuleFromTheChangeSet metricbeat - # echo "~~~ Will run tests with env var MODULE=$$MODULE" + # defines the MODULE env var based on what's changed in a PR + source .buildkite/scripts/changesets.sh + defineModuleFromTheChangeSet metricbeat + echo "~~~ Running tests" # TODO move this section to base image / pre-command hook # echo "~~~ Installing kind" @@ -90,7 +87,7 @@ steps: # defines the MODULE env var based on what's changed in a PR source .buildkite/scripts/changesets.sh defineModuleFromTheChangeSet metricbeat - echo "~~~ Running tests with env var MODULE=$$MODULE" + echo "~~~ Running tests" # TODO move this section to base image / pre-command hook echo "~~~ Installing kind" diff --git a/.buildkite/scripts/changesets.psm1 b/.buildkite/scripts/changesets.psm1 index 15fabd3eba5..10e4d31a8b6 100644 --- a/.buildkite/scripts/changesets.psm1 +++ b/.buildkite/scripts/changesets.psm1 @@ -56,17 +56,9 @@ function DefineModuleFromTheChangeSet($projectPath) { } } - # TODO: remove this conditional when issue https://github.com/elastic/ingest-dev/issues/2993 gets resolved - if(!$changedModules) { - if($Env:BUILDKITE_PIPELINE_SLUG -eq 'beats-xpack-metricbeat') { - $Env:MODULE = "aws" - } - else { - $Env:MODULE = "kubernetes" - } - } - else { - # TODO: once https://github.com/elastic/ingest-dev/issues/2993 gets resolved, this should be the only thing we export - $Env:MODULE = $changedModules + if ($changedModules) { + $env:MODULE = $changedModules + Write-Output "~~~ Set env var MODULE to [$env:MODULE]" + Write-Output "~~~ Resuming commands" } } diff --git a/.buildkite/scripts/changesets.sh b/.buildkite/scripts/changesets.sh index 3b7ed5d7ec0..5c6fd6c7b0d 100644 --- a/.buildkite/scripts/changesets.sh +++ b/.buildkite/scripts/changesets.sh @@ -68,13 +68,10 @@ defineModuleFromTheChangeSet() { fi done - if [[ -z "$changed_modules" ]]; then # TODO: remove this conditional when issue https://github.com/elastic/ingest-dev/issues/2993 gets resolved - if [[ "$BUILDKITE_PIPELINE_SLUG" == "beats-xpack-metricbeat" ]]; then - export MODULE="aws" - else - export MODULE="kubernetes" - fi - else - export MODULE="${changed_modules}" # TODO: once https://github.com/elastic/ingest-dev/issues/2993 gets resolved, this should be the only thing we export + # export MODULE="" leads to an infinite loop https://github.com/elastic/ingest-dev/issues/2993 + if [[ ! -z $changed_modules ]]; then + export MODULE="${changed_modules}" + echo "~~~ Set env var MODULE to [$MODULE]" + echo "~~~ Resuming commands" fi } diff --git a/.buildkite/x-pack/pipeline.xpack.auditbeat.yml b/.buildkite/x-pack/pipeline.xpack.auditbeat.yml index 18020c7d358..40ba75998c7 100644 --- a/.buildkite/x-pack/pipeline.xpack.auditbeat.yml +++ b/.buildkite/x-pack/pipeline.xpack.auditbeat.yml @@ -33,7 +33,7 @@ steps: # defines the MODULE env var based on what's changed in a PR source .buildkite/scripts/changesets.sh defineModuleFromTheChangeSet x-pack/auditbeat - echo "~~~ Will run tests with env var MODULE=$$MODULE" + echo "~~~ Running tests" cd x-pack/auditbeat mage update build test retry: diff --git a/.buildkite/x-pack/pipeline.xpack.dockerlogbeat.yml b/.buildkite/x-pack/pipeline.xpack.dockerlogbeat.yml index f45cbf486cf..cf5739e5026 100644 --- a/.buildkite/x-pack/pipeline.xpack.dockerlogbeat.yml +++ b/.buildkite/x-pack/pipeline.xpack.dockerlogbeat.yml @@ -52,11 +52,9 @@ steps: # defines the MODULE env var based on what's changed in a PR source .buildkite/scripts/changesets.sh defineModuleFromTheChangeSet x-pack/dockerlogbeat - echo "~~~ Running tests with env var MODULE=$$MODULE" + echo "~~~ Running tests" cd x-pack/dockerlogbeat mage goIntegTest - env: - MODULE: $MODULE retry: automatic: - limit: 3 diff --git a/.buildkite/x-pack/pipeline.xpack.filebeat.yml b/.buildkite/x-pack/pipeline.xpack.filebeat.yml index 9f3b76c574e..535afd3a768 100644 --- a/.buildkite/x-pack/pipeline.xpack.filebeat.yml +++ b/.buildkite/x-pack/pipeline.xpack.filebeat.yml @@ -51,7 +51,7 @@ steps: # defines the MODULE env var based on what's changed in a PR source .buildkite/scripts/changesets.sh defineModuleFromTheChangeSet x-pack/filebeat - echo "~~~ Will run tests with env var MODULE=$$MODULE" + echo "~~~ Running tests" cd x-pack/filebeat && mage goIntegTest retry: automatic: @@ -74,7 +74,7 @@ steps: # defines the MODULE env var based on what's changed in a PR source .buildkite/scripts/changesets.sh defineModuleFromTheChangeSet x-pack/filebeat - echo "~~~ Running tests with env var MODULE=$$MODULE" + echo "~~~ Running tests" cd x-pack/filebeat && mage pythonIntegTest retry: automatic: @@ -268,7 +268,7 @@ steps: # defines the MODULE env var based on what's changed in a PR source .buildkite/scripts/changesets.sh defineModuleFromTheChangeSet x-pack/filebeat - echo "~~~ Running tests with env var MODULE=$$MODULE" + echo "~~~ Running tests" .buildkite/scripts/cloud_tests.sh env: @@ -297,7 +297,7 @@ steps: # defines the MODULE env var based on what's changed in a PR source .buildkite/scripts/changesets.sh defineModuleFromTheChangeSet x-pack/filebeat - echo "~~~ Running tests with env var MODULE=$$MODULE" + echo "~~~ Running tests" .buildkite/scripts/cloud_tests.sh env: ASDF_TERRAFORM_VERSION: 1.0.2 diff --git a/.buildkite/x-pack/pipeline.xpack.metricbeat.yml b/.buildkite/x-pack/pipeline.xpack.metricbeat.yml index 267dbc8460e..720a6f86d0b 100644 --- a/.buildkite/x-pack/pipeline.xpack.metricbeat.yml +++ b/.buildkite/x-pack/pipeline.xpack.metricbeat.yml @@ -51,7 +51,7 @@ steps: # defines the MODULE env var based on what's changed in a PR source .buildkite/scripts/changesets.sh defineModuleFromTheChangeSet x-pack/metricbeat - echo "~~~ Will run tests with env var MODULE=$$MODULE" + echo "~~~ Running tests" cd x-pack/metricbeat && mage goIntegTest retry: automatic: @@ -74,7 +74,7 @@ steps: # defines the MODULE env var based on what's changed in a PR source .buildkite/scripts/changesets.sh defineModuleFromTheChangeSet x-pack/metricbeat - echo "~~~ Running tests with env var MODULE=$$MODULE" + echo "~~~ Running tests" cd x-pack/metricbeat && mage pythonIntegTest retry: automatic: @@ -253,7 +253,7 @@ steps: # defines the MODULE env var based on what's changed in a PR source .buildkite/scripts/changesets.sh defineModuleFromTheChangeSet x-pack/metricbeat - echo "~~~ Running tests with env var MODULE=$$MODULE" + echo "~~~ Running tests" .buildkite/scripts/cloud_tests.sh env: @@ -284,7 +284,7 @@ steps: # defines the MODULE env var based on what's changed in a PR source .buildkite/scripts/changesets.sh defineModuleFromTheChangeSet x-pack/metricbeat - echo "~~~ Running tests with env var MODULE=$$MODULE" + echo "~~~ Running tests" .buildkite/scripts/cloud_tests.sh env: ASDF_TERRAFORM_VERSION: 1.0.2 diff --git a/.buildkite/x-pack/pipeline.xpack.winlogbeat.yml b/.buildkite/x-pack/pipeline.xpack.winlogbeat.yml index e54e12cfe95..c5c4603de2a 100644 --- a/.buildkite/x-pack/pipeline.xpack.winlogbeat.yml +++ b/.buildkite/x-pack/pipeline.xpack.winlogbeat.yml @@ -25,11 +25,9 @@ steps: command: | Import-Module ./.buildkite/scripts/changesets.psm1 defineModuleFromTheChangeSet 'x-pack/winlogbeat' - Write-Output "~~~ Will run tests with env var MODULE=$$Env:MODULE" + Write-Output "~~~ Running tests" Set-Location -Path x-pack/winlogbeat mage build unitTest - env: - MODULE: $MODULE retry: automatic: - limit: 3