diff --git a/.buildkite/hooks/pre-command b/.buildkite/hooks/pre-command index b905f053121b..7401e3ce8242 100644 --- a/.buildkite/hooks/pre-command +++ b/.buildkite/hooks/pre-command @@ -18,6 +18,11 @@ if [[ "$BUILDKITE_PIPELINE_SLUG" == "beats-xpack-packetbeat" && "$BUILDKITE_STEP export PRIVATE_CI_GCS_CREDENTIALS_SECRET fi +if [[ "$BUILDKITE_PIPELINE_SLUG" == "beats-xpack-agentbeat" ]]; then + AGENTBEAT_PATH=$(.buildkite/scripts/agentbeat/setup_agentbeat.py) + export AGENTBEAT_PATH +fi + CPU_ARCH=$(uname -m) PLATFORM_TYPE=$(uname) diff --git a/.buildkite/scripts/agentbeat/prepare_env.py b/.buildkite/scripts/agentbeat/setup_agentbeat.py similarity index 80% rename from .buildkite/scripts/agentbeat/prepare_env.py rename to .buildkite/scripts/agentbeat/setup_agentbeat.py index d17c3cdd0e10..95e22889e866 100755 --- a/.buildkite/scripts/agentbeat/prepare_env.py +++ b/.buildkite/scripts/agentbeat/setup_agentbeat.py @@ -4,7 +4,6 @@ import subprocess import sys import tarfile -import os import re PATH = 'x-pack/agentbeat/build/distributions' @@ -46,7 +45,6 @@ def get_artifact_pattern() -> str: def download_agentbeat(pattern, path) -> str: - log('--- Downloading agentbeat') try: subprocess.run( ['buildkite-agent', 'artifact', 'download', pattern, '.', @@ -70,14 +68,12 @@ def get_filename(path) -> str: def extract_agentbeat(filename): - log('~~~ Extracting agentbeat') filepath = PATH + '/' + filename if filepath.endswith('.zip'): unzip_agentbeat(filepath) else: untar_agentbeat(filepath) - log('Successfully extracted agentbeat') def unzip_agentbeat(filepath): @@ -100,33 +96,18 @@ def untar_agentbeat(filepath): exit(1) -def add_to_path(filepath): +def get_path_to_executable(filepath) -> str: pattern = r'(.*)(?=\.zip|.tar\.gz)' match = re.match(pattern, filepath) if match: path = f'../build/distributions/{match.group(1)}/agentbeat' - log("--- PATH: " + str(path)) - os.environ['AGENTBEAT_PATH'] = str(path) + return path else: log_err("No agentbeat executable found") exit(1) -def install_synthetics(): - log('--- Installing @elastic/synthetics') - - try: - subprocess.run( - ['npm', 'install', '-g', '@elastic/synthetics'], - check=True - ) - except subprocess.CalledProcessError: - log_err('Failed to install @elastic/synthetics') - exit(1) - - artifact_pattern = get_artifact_pattern() archive = download_agentbeat(artifact_pattern, PATH) extract_agentbeat(archive) -add_to_path(archive) -install_synthetics() +log(get_path_to_executable(archive)) diff --git a/.buildkite/x-pack/pipeline.xpack.agentbeat.yml b/.buildkite/x-pack/pipeline.xpack.agentbeat.yml index b6225577b846..b3b9bbae3513 100644 --- a/.buildkite/x-pack/pipeline.xpack.agentbeat.yml +++ b/.buildkite/x-pack/pipeline.xpack.agentbeat.yml @@ -110,8 +110,6 @@ steps: # depends_on: # - agentbeat-package-linux command: | - set -euo pipefail - ./.buildkite/scripts/agentbeat/prepare_env.py cd x-pack/agentbeat mage -v testWithSpec agents: @@ -126,7 +124,6 @@ steps: # depends_on: # - agentbeat-package-linux command: | - ./.buildkite/scripts/agentbeat/prepare_env.py cd x-pack/agentbeat mage -v testWithSpec agents: @@ -142,7 +139,7 @@ steps: # - agentbeat-package-linux # command: | # set -euo pipefail -# ./.buildkite/scripts/agentbeat/prepare_env.py +# ./.buildkite/scripts/agentbeat/setup_agentbeat.py # agents: # provider: "orka" # imagePrefix: "${IMAGE_MACOS_X86_64}" @@ -153,7 +150,7 @@ steps: # - agentbeat-package-linux # command: | # set -euo pipefail -# ./.buildkite/scripts/agentbeat/prepare_env.py +# ./.buildkite/scripts/agentbeat/setup_agentbeat.py # agents: # provider: "orka" # imagePrefix: "${IMAGE_MACOS_ARM}" diff --git a/dev-tools/mage/spec.go b/dev-tools/mage/spec.go index 4afca22d5253..af0527fd6196 100644 --- a/dev-tools/mage/spec.go +++ b/dev-tools/mage/spec.go @@ -45,17 +45,7 @@ type command struct { } // SpecCommands parses agent.beat.spec.yml and collects commands for tests -func SpecCommands() []string { - specPath := os.Getenv("AGENTBEAT_SPEC") - if specPath == "" { - log.Fatal("AGENTBEAT_SPEC is not defined") - } - - platform := os.Getenv("PLATFORM") - if platform == "" { - log.Fatal("PLATFORM is not defined") - } - +func SpecCommands(specPath string, platform string) []string { spec, _ := parseToObj(specPath) filteredInputs := filter(spec.Inputs, func(input input) bool { diff --git a/x-pack/agentbeat/magefile.go b/x-pack/agentbeat/magefile.go index c52e122efdb0..e6422bf7d300 100644 --- a/x-pack/agentbeat/magefile.go +++ b/x-pack/agentbeat/magefile.go @@ -9,6 +9,7 @@ package main import ( "context" "fmt" + "log" "os" "os/exec" "path/filepath" @@ -217,7 +218,17 @@ func PythonIntegTest(ctx context.Context) error { // TestWithSpec executes unique commands from agentbeat.spec.yml and validates that app haven't exited with non-zero func TestWithSpec(ctx context.Context) { - var commands = devtools.SpecCommands() + specPath := os.Getenv("AGENTBEAT_SPEC") + if specPath == "" { + log.Fatal("AGENTBEAT_SPEC is not defined") + } + + platform := os.Getenv("PLATFORM") + if platform == "" { + log.Fatal("PLATFORM is not defined") + } + + var commands = devtools.SpecCommands(specPath, platform) agentbeatPath := os.Getenv("AGENTBEAT_PATH") fmt.Printf("--- AGENTBEAT_PATH: %s", agentbeatPath)