Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .buildkite/hooks/pre-command
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ GO_VERSION=$(cat .go-version)
export GO_VERSION

export SERVERLESS=${SERVERLESS:-"false"}
export UPLOAD_SAFE_LOGS=${UPLOAD_SAFE_LOGS:-"0"}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

By default, logs are not uploaded to the private bucket.


WORKSPACE=$(pwd)
export WORKSPACE

Expand All @@ -22,7 +24,7 @@ branch_name_label() {

if [[ "${BUILDKITE_PULL_REQUEST}" != "false" ]] ; then
# remove fork from branch name
branch=$(echo $branch | cut -d : -f 2)
branch=$(echo "$branch" | cut -d : -f 2)
fi

# From Jenkins
Expand All @@ -31,7 +33,7 @@ branch_name_label() {
branch=$(echo "$branch" | tr '[:upper:]' '[:lower:]' | tr '_/\:. ' '-')

# truncate up to 63 characters limit
echo $branch | head -c 63
echo "$branch" | head -c 63
}

BRANCH_NAME_LOWER_CASE=$(branch_name_label "$BUILDKITE_BRANCH")
Expand Down
172 changes: 94 additions & 78 deletions .buildkite/scripts/integration_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ usage() {
echo -e "\t-h: Show this message"
}

export UPLOAD_SAFE_LOGS=${UPLOAD_SAFE_LOGS:-"0"}

PARALLEL_TARGET="test-check-packages-parallel"
FALSE_POSITIVES_TARGET="test-check-packages-false-positives"
KIND_TARGET="test-check-packages-with-kind"
LOGSTASH_TARGET="test-check-packages-with-logstash"
SYSTEM_TEST_FLAGS_TARGET="test-system-test-flags"
TEST_BUILD_ZIP_TARGET="test-build-zip"
TEST_BUILD_INSTALL_ZIP_TARGET="test-build-install-zip"
Expand Down Expand Up @@ -61,24 +62,71 @@ if [[ "${TARGET}" == "" ]]; then
exit 1
fi

if [[ "${SERVERLESS}" == "true" && "${TARGET}" != "${PARALLEL_TARGET}" ]]; then
# Just tested parallel target to run with Serverless projects, other Makefile targets
# have not been tested yet and could fail unexpectedly. For instance, "test-check-package-false-positives"
# target would require a different management to not stop Elastic stack after each package test.
echo "Target ${TARGET} is not supported for Serverless testing"
usage
exit 1
fi
upload_package_test_logs() {
local retry_count=0
local package_folder=""
local target=""

if [[ "${PACKAGE}" == "" ]]; then
echo "No package specified, skipping upload of safe logs"
return
fi

echo "--- Uploading safe logs to GCP bucket ${JOB_GCS_BUCKET_INTERNAL}"

retry_count=${BUILDKITE_RETRY_COUNT:-"0"}
# Add target as part of the package folder name to allow to distinguish
# different test runs for the same package in different Makefile targets.
# Currently, just for test-check-packages-* targets, but could be extended
# to other targets in the future.
target=${TARGET#"test-check-packages-"}
package_folder="${target}.${PACKAGE}"
Comment on lines +82 to +83
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added as part of the package folder the target that it is running.

If it is required to add with-logstash target to be run in parallel steps, there is a package that would be duplicated. system_benchmark is located twice in with-logstash and benchmarks folders.

That makes me think that if we create two packages with the same folder name in the the folders as:

  • test/packages/parallel/mypackage
  • test/packages/false_positives/mypackage

Logs from both executions would be uploaded to the same folder:
buildkite/elastic-package/PR-1234-456/insecure-logs/mypackage

Adding the target this would become:

  • buildkite/elastic-package/PR-1234-456/insecure-logs/parallel.mypackage
  • buildkite/elastic-package/PR-1234-456/insecure-logs/false-positivies.mypackage

Not added the full target name (test-check-packages-parallel or test-check-packages-false-positives) to be easier to find the files in the UI.


if [[ "${ELASTIC_PACKAGE_TEST_ENABLE_INDEPENDENT_AGENT:-""}" == "false" ]]; then
package_folder="${package_folder}-stack_agent"
fi

if [[ "${ELASTIC_PACKAGE_FIELD_VALIDATION_TEST_METHOD:-""}" != "" ]]; then
package_folder="${package_folder}-${ELASTIC_PACKAGE_FIELD_VALIDATION_TEST_METHOD}"
fi

if [[ "${retry_count}" -ne 0 ]]; then
package_folder="${package_folder}_retry_${retry_count}"
fi

upload_safe_logs \
"${JOB_GCS_BUCKET_INTERNAL}" \
"build/elastic-stack-dump/check-${PACKAGE}/logs/elastic-agent-internal/*.*" \
"insecure-logs/${package_folder}/elastic-agent-logs/"

# required for <8.6.0
upload_safe_logs \
"${JOB_GCS_BUCKET_INTERNAL}" \
"build/elastic-stack-dump/check-${PACKAGE}/logs/elastic-agent-internal/default/*" \
"insecure-logs/${package_folder}/elastic-agent-logs/default/"

upload_safe_logs \
"${JOB_GCS_BUCKET_INTERNAL}" \
"build/container-logs/*.log" \
"insecure-logs/${package_folder}/container-logs/"
}

add_bin_path
install_required_tools() {
local target="${1}"

if [[ "${SERVERLESS}" == "true" ]]; then
# If packages are tested with Serverless, these action are already performed
# here: .buildkite/scripts/test_packages_with_serverless.sh
echo "Skipping installation of required tools for Serverless testing"
return
fi

add_bin_path

if [[ "$SERVERLESS" == "false" ]]; then
# If packages are tested with Serverless, these actions are already performed
# here: .buildkite/scripts/test_packages_with_serverless.sh
echo "--- Install go"
with_go

if [[ "${TARGET}" != "${TEST_BUILD_ZIP_TARGET}" ]]; then
if [[ "${target}" != "${TEST_BUILD_ZIP_TARGET}" ]]; then
# Not supported in Macos ARM
echo "--- Install docker"
with_docker
Expand All @@ -87,87 +135,55 @@ if [[ "$SERVERLESS" == "false" ]]; then
with_docker_compose_plugin
fi

case "${target}" in
"${KIND_TARGET}" | "${SYSTEM_TEST_FLAGS_TARGET}")
echo "--- Install kind"
with_kubernetes
;;
"${FALSE_POSITIVES_TARGET}" | "${TEST_BUILD_INSTALL_ZIP_TARGET}")
echo "--- Install yq"
with_yq
;;
esac

# In Serverless pipeline, elastic-package is installed in advance here:
# .buildkite/scripts/test_packages_with_serverless.sh
# No need to install it again for every package.
echo "--- Install elastic-package"
make install
fi
}

if [[ "${TARGET}" == "${KIND_TARGET}" || "${TARGET}" == "${SYSTEM_TEST_FLAGS_TARGET}" ]]; then
echo "--- Install kubectl & kind"
with_kubernetes
if [[ "${SERVERLESS}" == "true" && "${TARGET}" != "${PARALLEL_TARGET}" ]]; then
# Just tested parallel target to run with Serverless projects, other Makefile targets
# have not been tested yet and could fail unexpectedly. For instance, "test-check-packages-false-positives"
# target would require a different management to not stop Elastic stack after each package test.
echo "Target ${TARGET} is not supported for Serverless testing"
usage
exit 1
fi

if [[ "${TARGET}" == "${TEST_BUILD_INSTALL_ZIP_TARGET}" || "${TARGET}" == "${FALSE_POSITIVES_TARGET}" ]]; then
echo "--- Install yq"
with_yq
fi
install_required_tools "${TARGET}"

label="${TARGET}"
if [ -n "${PACKAGE}" ]; then
label="${label} - ${PACKAGE}"
fi

echo "--- Run integration test ${label}"
test_each_package=false
case "${TARGET}" in
"${PARALLEL_TARGET}" | "${FALSE_POSITIVES_TARGET}" | "${LOGSTASH_TARGET}")
test_each_package=true
;;
esac
if [[ "${test_each_package}" == "true" ]]; then
Comment on lines -113 to -119
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Simplified this code to call directly make target with the corresponding variables.
This would help to set up a new target to run in parallel their test packages.

make install
# allow to fail this command, to be able to upload safe logs
set +e
make SERVERLESS="${SERVERLESS}" PACKAGE_UNDER_TEST="${PACKAGE}" "${TARGET}"
testReturnCode=$?
set -e


if [[ "${UPLOAD_SAFE_LOGS}" -eq 1 ]] ; then
retry_count=${BUILDKITE_RETRY_COUNT:-"0"}
package_folder="${PACKAGE}"

if [[ "${ELASTIC_PACKAGE_TEST_ENABLE_INDEPENDENT_AGENT:-""}" == "false" ]]; then
package_folder="${package_folder}-stack_agent"
fi

if [[ "${ELASTIC_PACKAGE_FIELD_VALIDATION_TEST_METHOD:-""}" != "" ]]; then
package_folder="${package_folder}-${ELASTIC_PACKAGE_FIELD_VALIDATION_TEST_METHOD}"
fi

if [[ "${retry_count}" -ne 0 ]]; then
package_folder="${package_folder}_retry_${retry_count}"
fi

echo "--- Uploading safe logs to GCP bucket ${JOB_GCS_BUCKET_INTERNAL}"

upload_safe_logs \
"${JOB_GCS_BUCKET_INTERNAL}" \
"build/elastic-stack-dump/check-${PACKAGE}/logs/elastic-agent-internal/*.*" \
"insecure-logs/${package_folder}/elastic-agent-logs/"

# required for <8.6.0
upload_safe_logs \
"${JOB_GCS_BUCKET_INTERNAL}" \
"build/elastic-stack-dump/check-${PACKAGE}/logs/elastic-agent-internal/default/*" \
"insecure-logs/${package_folder}/elastic-agent-logs/default/"

upload_safe_logs \
"${JOB_GCS_BUCKET_INTERNAL}" \
"build/container-logs/*.log" \
"insecure-logs/${package_folder}/container-logs/"
fi
# allow to fail this command, to be able to upload safe logs
set +e
make SERVERLESS="${SERVERLESS}" PACKAGE_UNDER_TEST="${PACKAGE}" "${TARGET}"
testReturnCode=$?
set -e

if [[ "${UPLOAD_SAFE_LOGS}" -eq 1 ]] ; then
upload_package_test_logs
fi

if [ $testReturnCode != 0 ]; then
echo "make SERVERLESS=${SERVERLESS} PACKAGE_UNDER_TEST=${PACKAGE} ${TARGET} failed with ${testReturnCode}"
exit ${testReturnCode}
fi
else
make "${TARGET}"
if [ $testReturnCode != 0 ]; then
echo "make SERVERLESS=${SERVERLESS} PACKAGE_UNDER_TEST=${PACKAGE} ${TARGET} failed with ${testReturnCode}"
exit ${testReturnCode}
fi

echo "--- Check git clean"
make check-git-clean
exit 0