From 7aa8bb222fb14e1d7e7b8a2ab83ffa9f0b5bbac0 Mon Sep 17 00:00:00 2001 From: Pavel Zorin Date: Tue, 8 Oct 2024 10:35:30 +0200 Subject: [PATCH] Ess terraform + run integration tests on BK agents (#5113) * ESS by terraforms * Use bk runners * added state to artifacts * Add common.sh to scripts * Add depends_on * Inlined paclage variables * tmp disbale unit tests * tmp disbale unit tests * install tf * install tf * install tf * install tf * fix ec creds * Added auto-approve * Test run * package again * package again * package again * package again * package * package * added mage build:testBinaries * Install mage * Install mage * Install mage * Install mage * Install mage * fix go * Merged * Merged * fix * fix * Fix tests * Debug * Use custom image * New suod tests * Test run * Test run * Test run * Debug * Debug * Debug * Debug * Debug * Cleanup * Using subshell in newgrp * Using subshell in newgrp * Test new custom VM image * Test new custom VM image * Set terraform version * Cleanup * terraform 1.9.3 * terraform 1.9.3 * Debug * Explicit image version * Explicit image version * Explicit image version * Sudo tests * +x * Try mage integration:local * Use gotestsum * Use gotestsum * Run sudo tests * Run sudo tests * Debug * Debug * Debug * Debug * Debug * Debug * Debug * Debug * Increased test timeout * Groupped sudo tests * Quoted regexps * BK steps by groups * BK steps by groups * BK steps by groups * BK steps by groups * fix param propagation * Debug * Big run * reuse EC_API_KEY * Debug test * Debug a test * Revert debug * Debug * Html report * groupping, auto-retry, packaging * removed reruns * Reuse the initial ESS stack. Start a new stack for retries * Fix ess start path * Fix ess start path * Fix ess start path * Fix ess start path * Debug * Debug * Debug * Fix EC_KEY recovery * Added lock to artifacts * Fix artifacts download path * Fix artifacts download path * Fix artifacts download path * Removed unnecessaru build dependencies * Added build id * Separated BK integration tests to a dedicated pipeline * CLeanup * Applied proposed changes * Applied proposed changes * Applied proposed changes --- .buildkite/bk.integration.pipeline.yml | 160 ++++++++++++++++++ .buildkite/scripts/common2.sh | 53 ++++++ .buildkite/scripts/retry.sh | 22 +++ .buildkite/scripts/steps/ess.sh | 75 ++++++++ .buildkite/scripts/steps/ess_down.sh | 8 + .buildkite/scripts/steps/ess_start.sh | 19 +++ .../scripts/steps/integration_tests_tf.sh | 21 +++ .../steps/integration_tests_tf_sudo.sh | 48 ++++++ .buildkite/scripts/sudo-integration-tests.sh | 29 ++++ dev-tools/mage/gotest.go | 1 + test_infra/ess/.gitignore | 4 + test_infra/ess/deployment.tf | 88 ++++++++++ test_infra/ess/output.tf | 25 +++ test_infra/ess/terraform.tf | 14 ++ 14 files changed, 567 insertions(+) create mode 100644 .buildkite/bk.integration.pipeline.yml create mode 100644 .buildkite/scripts/common2.sh create mode 100644 .buildkite/scripts/retry.sh create mode 100644 .buildkite/scripts/steps/ess.sh create mode 100755 .buildkite/scripts/steps/ess_down.sh create mode 100755 .buildkite/scripts/steps/ess_start.sh create mode 100755 .buildkite/scripts/steps/integration_tests_tf.sh create mode 100755 .buildkite/scripts/steps/integration_tests_tf_sudo.sh create mode 100755 .buildkite/scripts/sudo-integration-tests.sh create mode 100644 test_infra/ess/.gitignore create mode 100644 test_infra/ess/deployment.tf create mode 100644 test_infra/ess/output.tf create mode 100644 test_infra/ess/terraform.tf diff --git a/.buildkite/bk.integration.pipeline.yml b/.buildkite/bk.integration.pipeline.yml new file mode 100644 index 00000000000..a825a159a7c --- /dev/null +++ b/.buildkite/bk.integration.pipeline.yml @@ -0,0 +1,160 @@ +# yaml-language-server: $schema=https://raw.githubusercontent.com/buildkite/pipeline-schema/main/schema.json + +env: + DOCKER_REGISTRY: "docker.elastic.co" + VAULT_PATH: "kv/ci-shared/observability-ingest/cloud/gcp" + ASDF_MAGE_VERSION: 1.14.0 + ASDF_GOLANG_VERSION: 1.22.6 + ASDF_TERRAFORM_VERSION: 1.9.3 + +steps: + - label: "Integration tests: packaging" + key: "package-it" + command: ".buildkite/scripts/steps/integration-package.sh" + artifact_paths: + - build/distributions/** + agents: + provider: "gcp" + machineType: "n1-standard-8" + + - label: Start ESS stack for integration tests + key: integration-ess + depends_on: + - package-it + command: | + #!/usr/bin/env bash + set -euo pipefail + source .buildkite/scripts/steps/ess_start.sh + artifact_paths: + - test_infra/ess/*.tfstate + - test_infra/ess/*.lock.hcl + agents: + image: "docker.elastic.co/ci-agent-images/platform-ingest/buildkite-agent-beats-ci-with-hooks:0.5" + useCustomGlobalHooks: true + + - group: "Stateful IT (Sudo): Ubuntu" + key: integration-tests + depends_on: + - package-it + - integration-ess + steps: + - label: "Default" + key: stateful-ubuntu-default-sudo + command: | + buildkite-agent artifact download build/distributions/** . --step 'package-it' + .buildkite/scripts/steps/integration_tests_tf_sudo.sh "default" "^(TestAPMConfig|TestDiagnosticsOptionalValues|TestIsolatedUnitsDiagnosticsOptionalValues|TestDiagnosticsCommand|TestIsolatedUnitsDiagnosticsCommand|TestEventLogFile|TestFakeComponent|TestFakeIsolatedUnitsComponent|TestOtelFileProcessing|TestOtelLogsIngestion|TestOtelAPMIngestion|TestPackageVersion)$$" + artifact_paths: + - build/** + agents: + provider: "gcp" + imageProject: elastic-images-qa + machineType: "n1-standard-8" + image: "family/platform-ingest-elastic-agent-ubuntu-2204" + + - label: "Upgrade" + key: stateful-ubuntu-upgrade-sudo + command: | + buildkite-agent artifact download build/distributions/** . --step 'package-it' + .buildkite/scripts/steps/integration_tests_tf_sudo.sh "upgrade" "^(TestUpgradeBrokenPackageVersion|TestStandaloneUpgradeWithGPGFallback|TestStandaloneUpgradeWithGPGFallbackOneRemoteFailing|TestStandaloneUpgradeRollback|TestStandaloneUpgradeRollbackOnRestarts|TestStandaloneUpgradeFailsWhenUpgradeIsInProgress|TestStandaloneUpgradeRetryDownload|TestStandaloneUpgradeSameCommit|TestStandaloneUpgrade|TestStandaloneUpgradeUninstallKillWatcher)$$" + artifact_paths: + - build/** + agents: + provider: "gcp" + imageProject: elastic-images-qa + machineType: "n1-standard-8" + image: "family/platform-ingest-elastic-agent-ubuntu-2204" + + - label: "Fleet" + key: stateful-ubuntu-fleet-sudo + command: | + buildkite-agent artifact download build/distributions/** . --step 'package-it' + ls -lah build/distributions/ + .buildkite/scripts/steps/integration_tests_tf_sudo.sh "fleet" "^(TestLongRunningAgentForLeaks|TestDelayEnroll|TestDelayEnrollUnprivileged|TestInstallAndCLIUninstallWithEndpointSecurity|TestInstallAndUnenrollWithEndpointSecurity|TestInstallWithEndpointSecurityAndRemoveEndpointIntegration|TestEndpointSecurityNonDefaultBasePath|TestEndpointSecurityUnprivileged|TestEndpointSecurityCannotSwitchToUnprivileged|TestEndpointLogsAreCollectedInDiagnostics|TestForceInstallOverProtectedPolicy|TestSetLogLevelFleetManaged|TestLogIngestionFleetManaged|TestMetricsMonitoringCorrectBinaries|TestEndpointAgentServiceMonitoring|TestMonitoringPreserveTextConfig|TestMonitoringLivenessReloadable|TestComponentBuildHashInDiagnostics|TestProxyURL|TestFleetManagedUpgradeUnprivileged)$$" + artifact_paths: + - build/** + agents: + provider: "gcp" + imageProject: elastic-images-qa + machineType: "n1-standard-8" + image: "family/platform-ingest-elastic-agent-ubuntu-2204" + + - label: "FQDN" + key: stateful-ubuntu-fqdn-sudo + command: | + buildkite-agent artifact download build/distributions/** . --step 'package-it' + ls -lah build/distributions/ + .buildkite/scripts/steps/integration_tests_tf_sudo.sh "fqdn" "^(TestFQDN)$$" + artifact_paths: + - build/** + agents: + provider: "gcp" + imageProject: elastic-images-qa + machineType: "n1-standard-8" + image: "family/platform-ingest-elastic-agent-ubuntu-2204" + + - label: "Deb" + key: stateful-ubuntu-deb-sudo + command: | + buildkite-agent artifact download build/distributions/** . --step 'package-it' + ls -lah build/distributions/ + .buildkite/scripts/steps/integration_tests_tf_sudo.sh "deb" "^(TestDebLogIngestFleetManaged|TestDebFleetUpgrade)$$" + artifact_paths: + - build/** + agents: + provider: "gcp" + imageProject: elastic-images-qa + machineType: "n1-standard-8" + image: "family/platform-ingest-elastic-agent-ubuntu-2204" + + - label: "Fleet Airgapped" + key: stateful-ubuntu-fleet-airgapped-sudo + command: | + buildkite-agent artifact download build/distributions/** . --step 'package-it' + ls -lah build/distributions/ + .buildkite/scripts/steps/integration_tests_tf_sudo.sh "fleet-airgapped" "^(TestFleetAirGappedUpgradeUnprivileged)$$" + artifact_paths: + - build/** + agents: + provider: "gcp" + imageProject: elastic-images-qa + machineType: "n1-standard-8" + image: "family/platform-ingest-elastic-agent-ubuntu-2204" + + - label: "Fleet Privileged" + key: stateful-ubuntu-fleet-privileged-sudo + command: | + buildkite-agent artifact download build/distributions/** . --step 'package-it' + ls -lah build/distributions/ + .buildkite/scripts/steps/integration_tests_tf_sudo.sh "fleet-privileged" "^(TestInstallFleetServerBootstrap|TestFleetManagedUpgradePrivileged)$$" + artifact_paths: + - build/** + agents: + provider: "gcp" + imageProject: elastic-images-qa + machineType: "n1-standard-8" + image: "family/platform-ingest-elastic-agent-ubuntu-2204" + + - label: "Fleet Airgapped Privileged" + key: stateful-ubuntu-fleet-airgapped-privileged-sudo + command: | + buildkite-agent artifact download build/distributions/** . --step 'package-it' + ls -lah build/distributions/ + .buildkite/scripts/steps/integration_tests_tf_sudo.sh "fleet-airgapped-privileged" "^(TestFleetAirGappedUpgradePrivileged)$$" + artifact_paths: + - build/** + agents: + provider: "gcp" + imageProject: elastic-images-qa + machineType: "n1-standard-8" + image: "family/platform-ingest-elastic-agent-ubuntu-2204" + + - label: ESS stack cleanup + depends_on: integration-tests + allow_dependency_failure: true + command: | + buildkite-agent artifact download "test_infra/ess/**" . --step "integration-ess" + ls -lah test_infra/ess + .buildkite/scripts/steps/ess_down.sh + agents: + image: "docker.elastic.co/ci-agent-images/platform-ingest/buildkite-agent-beats-ci-with-hooks:0.5" + useCustomGlobalHooks: true diff --git a/.buildkite/scripts/common2.sh b/.buildkite/scripts/common2.sh new file mode 100644 index 00000000000..aed20eb7a8e --- /dev/null +++ b/.buildkite/scripts/common2.sh @@ -0,0 +1,53 @@ +#!/bin/bash + +set -euo pipefail + +if [[ -z "${WORKSPACE-""}" ]]; then + WORKSPACE=$(git rev-parse --show-toplevel) + export WORKSPACE +fi + +BEAT_VERSION=$(grep -oE '[0-9]+\.[0-9]+\.[0-9]+(\-[a-zA-Z]+[0-9]+)?' "${WORKSPACE}/version/version.go") +export BEAT_VERSION + +getOSOptions() { + case $(uname | tr '[:upper:]' '[:lower:]') in + linux*) + export AGENT_OS_NAME=linux + ;; + darwin*) + export AGENT_OS_NAME=darwin + ;; + msys*) + export AGENT_OS_NAME=windows + ;; + *) + export AGENT_OS_NAME=notset + ;; + esac + case $(uname -m | tr '[:upper:]' '[:lower:]') in + aarch64*) + export AGENT_OS_ARCH=arm64 + ;; + arm64*) + export AGENT_OS_ARCH=arm64 + ;; + amd64*) + export AGENT_OS_ARCH=amd64 + ;; + x86_64*) + export AGENT_OS_ARCH=amd64 + ;; + *) + export AGENT_OS_ARCH=notset + ;; + esac +} + +google_cloud_auth() { + local keyFile=$1 + + gcloud auth activate-service-account --key-file ${keyFile} 2> /dev/null + + export GOOGLE_APPLICATION_CREDENTIALS=${secretFileLocation} +} diff --git a/.buildkite/scripts/retry.sh b/.buildkite/scripts/retry.sh new file mode 100644 index 00000000000..ce073b0d5dc --- /dev/null +++ b/.buildkite/scripts/retry.sh @@ -0,0 +1,22 @@ +#!/bin/bash +set -euo pipefail + +retry() { + local retries=$1 + shift + + local count=0 + until "$@"; do + exit=$? + wait=$((2 ** count)) + count=$((count + 1)) + if [ $count -lt "$retries" ]; then + >&2 echo "Retry $count/$retries exited $exit, retrying in $wait seconds..." + sleep $wait + else + >&2 echo "Retry $count/$retries exited $exit, no more retries left." + return $exit + fi + done + return 0 +} \ No newline at end of file diff --git a/.buildkite/scripts/steps/ess.sh b/.buildkite/scripts/steps/ess.sh new file mode 100644 index 00000000000..29d1d80115e --- /dev/null +++ b/.buildkite/scripts/steps/ess.sh @@ -0,0 +1,75 @@ +#!/usr/bin/env bash +set -euo pipefail + +function ess_up() { + echo "~~~ Staring ESS Stack" + local WORKSPACE=$(git rev-parse --show-toplevel) + local TF_DIR="${WORKSPACE}/test_infra/ess/" + local STACK_VERSION=$1 + local ESS_REGION=${2:-"gcp-us-west2"} + + if [ -z "$STACK_VERSION" ]; then + echo "Error: Specify stack version: ess_up [stack_version]" >&2 + return 1 + fi + + export EC_API_KEY=$(retry 5 vault kv get -field=apiKey kv/ci-shared/platform-ingest/platform-ingest-ec-prod) + + if [[ -z "${EC_API_KEY}" ]]; then + echo "Error: Failed to get EC API key from vault" >&2 + exit 1 + fi + + BUILDKITE_BUILD_CREATOR="${BUILDKITE_BUILD_CREATOR:-"$(get_git_user_email)"}" + BUILDKITE_BUILD_NUMBER="${BUILDKITE_BUILD_NUMBER:-"0"}" + BUILDKITE_PIPELINE_SLUG="${BUILDKITE_PIPELINE_SLUG:-"elastic-agent-integration-tests"}" + + pushd "${TF_DIR}" + terraform init + terraform apply \ + -auto-approve \ + -var="stack_version=${STACK_VERSION}" \ + -var="ess_region=${ESS_REGION}" \ + -var="creator=${BUILDKITE_BUILD_CREATOR}" \ + -var="buildkite_id=${BUILDKITE_BUILD_NUMBER}" \ + -var="pipeline=${BUILDKITE_PIPELINE_SLUG}" + + export ELASTICSEARCH_HOST=$(terraform output -raw es_host) + export ELASTICSEARCH_USERNAME=$(terraform output -raw es_username) + export ELASTICSEARCH_PASSWORD=$(terraform output -raw es_password) + export KIBANA_HOST=$(terraform output -raw kibana_endpoint) + export KIBANA_USERNAME=$ELASTICSEARCH_USERNAME + export KIBANA_PASSWORD=$ELASTICSEARCH_PASSWORD + popd +} + +function ess_down() { + echo "~~~ Tearing down the ESS Stack" + local WORKSPACE=$(git rev-parse --show-toplevel) + local TF_DIR="${WORKSPACE}/test_infra/ess/" + if [ -z "${EC_API_KEY:-}" ]; then + export EC_API_KEY=$(retry 5 vault kv get -field=apiKey kv/ci-shared/platform-ingest/platform-ingest-ec-prod) + fi + + pushd "${TF_DIR}" + terraform init + terraform destroy -auto-approve + popd +} + +function get_git_user_email() { + if ! git rev-parse --is-inside-work-tree &>/dev/null; then + echo "unknown" + return + fi + + local email + email=$(git config --get user.email) + + if [ -z "$email" ]; then + echo "unknown" + else + echo "$email" + fi +} + diff --git a/.buildkite/scripts/steps/ess_down.sh b/.buildkite/scripts/steps/ess_down.sh new file mode 100755 index 00000000000..cbcbf06776b --- /dev/null +++ b/.buildkite/scripts/steps/ess_down.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env bash +set -euo pipefail + +source .buildkite/scripts/common2.sh + +source .buildkite/scripts/steps/ess.sh + +ess_down || echo "Failed to stop ESS stack" >&2 diff --git a/.buildkite/scripts/steps/ess_start.sh b/.buildkite/scripts/steps/ess_start.sh new file mode 100755 index 00000000000..d0700c5473c --- /dev/null +++ b/.buildkite/scripts/steps/ess_start.sh @@ -0,0 +1,19 @@ +#!/usr/bin/env bash +set -euo pipefail + +source .buildkite/scripts/common2.sh + +source .buildkite/scripts/steps/ess.sh + +OVERRIDE_STACK_VERSION="$(cat .package-version)" +OVERRIDE_STACK_VERSION=${OVERRIDE_STACK_VERSION}"-SNAPSHOT" + +ess_up $OVERRIDE_STACK_VERSION || echo "Failed to start ESS stack" >&2 + +echo "ES_HOST: ${ELASTICSEARCH_HOST}" +buildkite-agent meta-data set "es.host" $ELASTICSEARCH_HOST +buildkite-agent meta-data set "es.username" $ELASTICSEARCH_USERNAME +buildkite-agent meta-data set "es.pwd" $ELASTICSEARCH_PASSWORD +buildkite-agent meta-data set "kibana.host" $KIBANA_HOST +buildkite-agent meta-data set "kibana.username" $KIBANA_USERNAME +buildkite-agent meta-data set "kibana.pwd" $KIBANA_PASSWORD diff --git a/.buildkite/scripts/steps/integration_tests_tf.sh b/.buildkite/scripts/steps/integration_tests_tf.sh new file mode 100755 index 00000000000..c2d1239e887 --- /dev/null +++ b/.buildkite/scripts/steps/integration_tests_tf.sh @@ -0,0 +1,21 @@ +#!/usr/bin/env bash +set -euo pipefail + +source .buildkite/scripts/common2.sh +source .buildkite/scripts/steps/ess.sh + + +# Override the agent package version using a string with format .. +# There is a time when the snapshot is not built yet, so we cannot use the latest version automatically +# This file is managed by an automation (mage integration:UpdateAgentPackageVersion) that check if the snapshot is ready. +OVERRIDE_AGENT_PACKAGE_VERSION="$(cat .package-version)" +OVERRIDE_TEST_AGENT_VERSION=${OVERRIDE_AGENT_PACKAGE_VERSION}"-SNAPSHOT" + +echo "~~~ Bulding test binaries" +mage build:testBinaries + +ess_up $OVERRIDE_TEST_AGENT_VERSION || echo "Failed to start ESS stack" >&2 +trap 'ess_down' EXIT + +echo "~~~ Running integration tests" +AGENT_VERSION="8.16.0-SNAPSHOT" SNAPSHOT=true TEST_DEFINE_PREFIX=non_sudo_linux gotestsum --no-color -f standard-verbose --junitfile build/TEST-go-integration.xml --jsonfile build/TEST-go-integration.out.json -- -tags integration github.com/elastic/elastic-agent/testing/integration diff --git a/.buildkite/scripts/steps/integration_tests_tf_sudo.sh b/.buildkite/scripts/steps/integration_tests_tf_sudo.sh new file mode 100755 index 00000000000..295787d5fa1 --- /dev/null +++ b/.buildkite/scripts/steps/integration_tests_tf_sudo.sh @@ -0,0 +1,48 @@ +#!/usr/bin/env bash +set -euo pipefail + +source .buildkite/scripts/common2.sh + +source .buildkite/scripts/steps/ess.sh + +GROUP_NAME=$1 +if [ -z "$GROUP_NAME" ]; then + echo "Error: Specify the group name: sudo-integration-tests.sh [group_name] [tests_to_run]" >&2 + exit 1 +fi +TESTS_TO_RUN=$2 +if [ -z "$TESTS_TO_RUN" ]; then + echo "Error: Specify the tests to run: sudo-integration-tests.sh [group_name] [tests_to_run]" >&2 + exit 1 +fi + +# Override the agent package version using a string with format .. +# There is a time when the snapshot is not built yet, so we cannot use the latest version automatically +# This file is managed by an automation (mage integration:UpdateAgentPackageVersion) that check if the snapshot is ready. +OVERRIDE_STACK_VERSION="$(cat .package-version)" +OVERRIDE_STACK_VERSION=${OVERRIDE_STACK_VERSION}"-SNAPSHOT" + +echo "~~~ Building test binaries" +mage build:testBinaries + +# If the step is retried, we start the stack again. +# BUILDKITE_RETRY_COUNT == "0" for the first run +# BUILDKITE_RETRY_COUNT > 0 for the retries +if [[ "${BUILDKITE_RETRY_COUNT}" -gt 0 ]]; then + echo "~~~ The steps is retried, starting the ESS stack again" + ess_up $OVERRIDE_STACK_VERSION || echo "Failed to start ESS stack" >&2 + trap 'ess_down' EXIT +else + # For the first run, we start the stack in the start_ess.sh step and it sets the meta-data + echo "~~~ Receiving ESS stack metadata" + export ELASTICSEARCH_HOST=$(buildkite-agent meta-data get "es.host") + export ELASTICSEARCH_USERNAME=$(buildkite-agent meta-data get "es.username") + export ELASTICSEARCH_PASSWORD=$(buildkite-agent meta-data get "es.pwd") + export KIBANA_HOST=$(buildkite-agent meta-data get "kibana.host") + export KIBANA_USERNAME=$(buildkite-agent meta-data get "kibana.username") + export KIBANA_PASSWORD=$(buildkite-agent meta-data get "kibana.pwd") +fi + +# Run integration tests +echo "~~~ Running integration tests" +sudo -E .buildkite/scripts/sudo-integration-tests.sh $@ diff --git a/.buildkite/scripts/sudo-integration-tests.sh b/.buildkite/scripts/sudo-integration-tests.sh new file mode 100755 index 00000000000..c2ac96566b6 --- /dev/null +++ b/.buildkite/scripts/sudo-integration-tests.sh @@ -0,0 +1,29 @@ +#!/usr/bin/env bash + +# The script is used to run integration tests with sudo +source /opt/buildkite-agent/hooks/pre-command +source .buildkite/hooks/pre-command || echo "No pre-command hook found" + +GROUP_NAME=$1 +TESTS_TO_RUN=$2 + +echo "~~~ Running integration tests as $USER" +echo "~~~ Integration tests: ${GROUP_NAME}" +# TODO: Pass the actual version of the agen +gotestsum --version +set +e +SNAPSHOT=true TEST_DEFINE_PREFIX="sudo_${GROUP_NAME}_ubuntu" gotestsum --no-color -f standard-quiet --junitfile "build/${GROUP_NAME}.integration.xml" --jsonfile "build/${GROUP_NAME}.integration.out.json" -- -tags integration -test.shuffle on -test.timeout 2h0m0s -test.run "${TESTS_TO_RUN}" github.com/elastic/elastic-agent/testing/integration +TESTS_EXIT_STATUS=$? +set -e + +# HTML report +outputXML="build/${GROUP_NAME}.integration.xml" + +if [ -f "$outputXML" ]; then + go install github.com/alexec/junit2html@latest + junit2html < "$outputXML" > build/TEST-report.html +else + echo "Cannot generate HTML test report: $outputXML not found" +fi + +exit $TESTS_EXIT_STATUS diff --git a/dev-tools/mage/gotest.go b/dev-tools/mage/gotest.go index 939a4eaa4ba..134f6022d9d 100644 --- a/dev-tools/mage/gotest.go +++ b/dev-tools/mage/gotest.go @@ -281,6 +281,7 @@ func GoTest(ctx context.Context, params GoTestArgs) error { testArgs = append(testArgs, params.Packages...) args := append(gotestsumArgs, append([]string{"--"}, testArgs...)...) + fmt.Println(">> ARGS:", params.LogName, "Command:", "gotestsum", strings.Join(args, " ")) goTest := makeCommand(ctx, params.Env, "gotestsum", args...) // Wire up the outputs. diff --git a/test_infra/ess/.gitignore b/test_infra/ess/.gitignore new file mode 100644 index 00000000000..78f930ca9fe --- /dev/null +++ b/test_infra/ess/.gitignore @@ -0,0 +1,4 @@ +.terraform +terraform.tfstate +terraform.tfstate.backup +.terraform.lock.hcl \ No newline at end of file diff --git a/test_infra/ess/deployment.tf b/test_infra/ess/deployment.tf new file mode 100644 index 00000000000..b8e938c3624 --- /dev/null +++ b/test_infra/ess/deployment.tf @@ -0,0 +1,88 @@ +variable "stack_version" { + type = string + default = "latest" + description = "the stack version to use" +} + +variable "ess_region" { + type = string + default = "" + description = "The ESS region to use" +} + +variable "deployment_template_id" { + type = string + default = "" + description = "The ess deployment template to use" +} + +variable "creator" { + type = string + default = "" + description = "This is the name who created this deployment" +} + +variable "buildkite_id" { + type = string + default = "" + description = "The buildkite build id associated with this deployment" +} + +variable "pipeline" { + type = string + default = "" + description = "The buildkite pipeline slug, useful for in combination with the build id to trace back to the pipeline" +} + +resource "random_uuid" "deployment_suffix" { +} + +locals { + deployment_name = join("-", ["elastic-agent-ci", substr("${random_uuid.deployment_suffix.result}", 0, 8)]) + deployment_version = data.ec_stack.latest.version + + ess_region = coalesce(var.ess_region, "gcp-us-east1") + deployment_template_id = coalesce(var.deployment_template_id, "gcp-cpu-optimized-v7") +} + +# If we have defined a stack version, validate that this version exists on that region and return it. +data "ec_stack" "latest" { + version_regex = var.stack_version + region = local.ess_region +} + +resource "ec_deployment" "integration-testing" { + name = local.deployment_name + alias = local.deployment_name + region = local.ess_region + deployment_template_id = local.deployment_template_id + version = local.deployment_version + + elasticsearch = { + autoscale = false + + hot = { + autoscaling = {} + size = "4g" + zone_count = 1 + } + } + kibana = { + size = "1g" + zone_count = 1 + } + + integrations_server = { + topology = { + size = "1g" + zone_count = 1 + } + } + + tags = { + "provisioner" = "elastic-agent-integration-tests" + "creator" = var.creator + "buildkite_id" = var.buildkite_id + "pipeline" = var.pipeline + } +} diff --git a/test_infra/ess/output.tf b/test_infra/ess/output.tf new file mode 100644 index 00000000000..4c6427e0f22 --- /dev/null +++ b/test_infra/ess/output.tf @@ -0,0 +1,25 @@ +output "cloud_id" { + value = ec_deployment.integration-testing.elasticsearch.cloud_id + description = "Cloud ID (cloud_id)" +} + +output "es_password" { + value = ec_deployment.integration-testing.elasticsearch_password + description = "Password (cloud_id)" + sensitive = true +} + +output "es_username" { + value = ec_deployment.integration-testing.elasticsearch_username + description = "Password (cloud_id)" + sensitive = true +} + +output "es_host" { + value = ec_deployment.integration-testing.elasticsearch.https_endpoint + description = "" +} + +output "kibana_endpoint" { + value = ec_deployment.integration-testing.kibana.https_endpoint +} diff --git a/test_infra/ess/terraform.tf b/test_infra/ess/terraform.tf new file mode 100644 index 00000000000..7e05b553458 --- /dev/null +++ b/test_infra/ess/terraform.tf @@ -0,0 +1,14 @@ +terraform { + required_version = ">= 1.0.0" + + required_providers { + ec = { + source = "elastic/ec" + version = ">= 0.10.0" + } + random = { + source = "hashicorp/random" + version = "~> 3.5" + } + } +}