Skip to content

Commit

Permalink
added servrless tests step
Browse files Browse the repository at this point in the history
  • Loading branch information
oakrizan committed Nov 4, 2024
1 parent 8f433a3 commit 361616d
Show file tree
Hide file tree
Showing 68 changed files with 10,029 additions and 320 deletions.
4 changes: 2 additions & 2 deletions .buildkite/hooks/pre-command
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ fi
if [[ "$BUILDKITE_PIPELINE_SLUG" == "beats-xpack-agentbeat" && "$BUILDKITE_STEP_KEY" == *"agentbeat-it"* ]]; then
out=$(.buildkite/scripts/agentbeat/setup_agentbeat.py)
echo "$out"
AGENTBEAT_PATH=$(echo "$out" | tail -n 1)
export AGENTBEAT_PATH
AGENT_BUILD_DIR=$(echo "$out" | tail -n 1)
export AGENT_BUILD_DIR
fi

if [[ "$BUILDKITE_PIPELINE_SLUG" == "auditbeat" || \
Expand Down
205 changes: 94 additions & 111 deletions .buildkite/x-pack/pipeline.xpack.agentbeat.yml
Original file line number Diff line number Diff line change
@@ -1,43 +1,31 @@
env:
ASDF_MAGE_VERSION: 1.15.0
ASDF_NODEJS_VERSION: 18.17.1

GCP_HI_PERF_MACHINE_TYPE: "c2d-highcpu-16"
IMAGE_UBUNTU_X86_64: "family/platform-ingest-beats-ubuntu-2204"

AWS_ARM_INSTANCE_TYPE: "m6g.xlarge"
AWS_IMAGE_UBUNTU_ARM_64: "platform-ingest-beats-ubuntu-2204-aarch64"

IMAGE_MACOS_ARM: "generic-13-ventura-arm"
IMAGE_MACOS_X86_64: "generic-13-ventura-x64"

IMAGE_WIN_2022: "family/platform-ingest-beats-windows-2022"

IMAGE_BEATS_WITH_HOOKS_LATEST: "docker.elastic.co/ci-agent-images/platform-ingest/buildkite-agent-beats-ci-with-hooks:latest"

AGENTBEAT_SPEC: "./agentbeat.spec.yml"

steps:
- group: "Check/Update"
key: "x-pack-agentbeat-check-update"

steps:
- label: "agentbeat: Run pre-commit"
command: "pre-commit run --all-files"
agents:
image: "${IMAGE_BEATS_WITH_HOOKS_LATEST}"
memory: "2Gi"
useCustomGlobalHooks: true
notify:
- github_commit_status:
context: "agentbeat: pre-commit"

- wait: ~
# with PRs, we want to run mandatory tests only if check/update step succeed
# for other cases, e.g. merge commits, we want to run mundatory test (and publish) independently of other tests
# this allows building DRA artifacts even if there is flakiness in check/update step
if: build.env("BUILDKITE_PULL_REQUEST") != "false"
depends_on: "x-pack-agentbeat-check-update"
# - group: "Check/Update"
# key: "x-pack-agentbeat-check-update"
#
# steps:
# - label: "agentbeat: Run pre-commit"
# command: "pre-commit run --all-files"
# agents:
# image: "${IMAGE_BEATS_WITH_HOOKS_LATEST}"
# memory: "2Gi"
# useCustomGlobalHooks: true
# notify:
# - github_commit_status:
# context: "agentbeat: pre-commit"
#
# - wait: ~
# # with PRs, we want to run mandatory tests only if check/update step succeed
# # for other cases, e.g. merge commits, we want to run mundatory test (and publish) independently of other tests
# # this allows building DRA artifacts even if there is flakiness in check/update step
# if: build.env("BUILDKITE_PULL_REQUEST") != "false"
# depends_on: "x-pack-agentbeat-check-update"

- group: "Agentbeat tests"
key: "agentbeat-mandatory-tests"
Expand All @@ -47,6 +35,7 @@ steps:
key: "agentbeat-package-linux"
env:
PLATFORMS: "+all linux/amd64 linux/arm64 windows/amd64 darwin/amd64 darwin/arm64"
PACKAGES: tar.gz,zip
SNAPSHOT: true
command: |
set -euo pipefail
Expand All @@ -70,93 +59,87 @@ steps:
- github_commit_status:
context: "agentbeat: Packaging"

- label: ":ubuntu: x-pack/agentbeat: Ubuntu x86_64 Spec tests"
key: "agentbeat-it-linux-x86-64"
env:
PLATFORM: "linux/amd64"
# - label: ":linux: Agentbeat/Integration tests Linux"
# key: "agentbeat-it-linux"
# depends_on:
# - agentbeat-package-linux
# env:
# ASDF_NODEJS_VERSION: 18.17.1
# PLATFORMS: "+all linux/amd64 linux/arm64 windows/amd64 darwin/amd64 darwin/arm64"
# SNAPSHOT: true
# command: |
# set -euo pipefail
# echo "~~~ Downloading artifacts"
# buildkite-agent artifact download x-pack/agentbeat/build/distributions/** . --step 'agentbeat-package-linux'
# ls -lah x-pack/agentbeat/build/distributions/
# echo "~~~ Installing @elastic/synthetics with npm"
# npm install -g @elastic/synthetics
# echo "~~~ Running tests"
# cd x-pack/agentbeat
# mage goIntegTest
# artifact_paths:
# - x-pack/agentbeat/build/distributions/**/*
# - "x-pack/agentbeat/build/*.xml"
# - "x-pack/agentbeat/build/*.json"
# plugins:
# - test-collector#v1.10.2:
# files: "x-pack/agentbeat/build/TEST-*.xml"
# format: "junit"
# branches: "main"
# debug: true
# retry:
# automatic:
# - limit: 1
# timeout_in_minutes: 60
# agents:
# provider: "gcp"
# image: "${IMAGE_UBUNTU_X86_64}"
# machineType: "${GCP_HI_PERF_MACHINE_TYPE}"
# disk_size: 100
# disk_type: "pd-ssd"
# notify:
# - github_commit_status:
# context: "agentbeat: Integration tests"

- group: "Agentbeat: Servelress Tests"
key: "agentbeat-serverless-tests"

steps:
- label: ":ubuntu: Serverless tests"
key: "agentbeat-it-serverless"
depends_on:
- agentbeat-package-linux
env:
AGENT_STACK_VERSION: "8.16.0-SNAPSHOT"
TEST_INTEG_AUTH_GCP_DATACENTER: "us-central1-a"
GOFLAGS: "-buildvcs=false"
TEST_INTEG_CLEAN_ON_EXIT: true
TEST_PLATFORMS: "linux/amd64"
SNAPSHOT: true
command: |
cd x-pack/agentbeat
mage -v testWithSpec
mage serverlessTest metricbeat
artifact_paths:
- x-pack/agentbeat/build/TEST-**
- x-pack/agentbeat/build/diagnostics/*
plugins:
- test-collector#v1.10.2:
files: "x-pack/agentbeat/build/TEST-*.xml"
format: "junit"
branches: "main"
debug: true
retry:
automatic:
- limit: 1
timeout_in_minutes: 60
concurrency_group: elastic-agent-extended-testing/serverless-integration
concurrency: 8
agents:
provider: "gcp"
image: "${IMAGE_UBUNTU_X86_64}"
machineType: "${GCP_HI_PERF_MACHINE_TYPE}"
machineType: "${GCP_STANDARD_MACHINE_TYPE}"
disk_size: 100
disk_type: "pd-ssd"
notify:
- github_commit_status:
context: "agentbeat: Ubuntu x86_64 Spec tests"

- label: ":ubuntu: x-pack/agentbeat: Ubuntu arm64 Spec tests"
key: "agentbeat-it-linux-arm64"
env:
PLATFORM: "linux/arm64"
depends_on:
- agentbeat-package-linux
command: |
cd x-pack/agentbeat
mage -v testWithSpec
agents:
provider: "aws"
imagePrefix: "${AWS_IMAGE_UBUNTU_ARM_64}"
instanceType: "${AWS_ARM_INSTANCE_TYPE}"
notify:
- github_commit_status:
context: "agentbeat: Ubuntu arm64 Spec tests"

- label: ":windows: x-pack/agentbeat: Windows x86_64 Spec tests"
key: "agentbeat-it-windows"
env:
PLATFORM: "windows/amd64"
depends_on:
- agentbeat-package-linux
command: |
Set-Location -Path x-pack/agentbeat
mage -v testWithSpec
agents:
provider: "gcp"
image: "${IMAGE_WIN_2022}"
machine_type: "${GCP_WIN_MACHINE_TYPE}"
disk_size: 200
disk_type: "pd-ssd"
notify:
- github_commit_status:
context: "agentbeat: Windows x86_64 Spec tests"

- label: ":macos: x-pack/agentbeat: macOS x86_64 Spec tests"
key: "agentbeat-it-macos-x86-64"
depends_on:
- agentbeat-package-linux
env:
PLATFORM: "darwin/amd64"
command: |
set -euo pipefail
source .buildkite/scripts/install_macos_tools.sh
cd x-pack/agentbeat
mage -v testWithSpec
agents:
provider: "orka"
imagePrefix: "${IMAGE_MACOS_X86_64}"
notify:
- github_commit_status:
context: "agentbeat: macOS x86_64 Spec tests"

- label: ":macos: x-pack/agentbeat: macOS arm64 Spec tests"
key: "agentbeat-it-macos-arm64"
depends_on:
- agentbeat-package-linux
env:
PLATFORM: "darwin/arm64"
command: |
set -euo pipefail
source .buildkite/scripts/install_macos_tools.sh
cd x-pack/agentbeat
mage -v testWithSpec
agents:
provider: "orka"
imagePrefix: "${IMAGE_MACOS_ARM}"
notify:
- github_commit_status:
context: "agentbeat: macOS arm64 Spec tests"
context: "agentbeat: Serverless tests"
56 changes: 56 additions & 0 deletions dev-tools/mage/agentbeat-serverless.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you under
// the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

package mage

import (
"fmt"
"log"
"os"
)

// TestBeatServerless todo description
func TestBeatServerless(beat string) {
if beat == "" {
log.Fatal("Beat is not defined")
}

if os.Getenv("AGENT_BUILD_DIR") == "" {
log.Fatal("AGENT_BUILD_DIR is not defined")
}

setStackProvisioner()
setTestBinaryName(beat)

}

func setStackProvisioner() {
stackProvisioner := os.Getenv("STACK_PROVISIONER")
if stackProvisioner == "" {
if err := os.Setenv("STACK_PROVISIONER", "serverless"); err != nil {
log.Fatal("error setting serverless stack var: %w", err)
}
} else if stackProvisioner == "stateful" {
fmt.Println("--- Warning: running TestBeatServerless as stateful")
}
}

func setTestBinaryName(beat string) {
if err := os.Setenv("TEST_BINARY_NAME", beat); err != nil {
log.Fatal("error setting binary name: %w", err)
}
}
27 changes: 27 additions & 0 deletions dev-tools/mage/gotest.go
Original file line number Diff line number Diff line change
Expand Up @@ -428,3 +428,30 @@ func BuildSystemTestGoBinary(binArgs TestBinaryArgs) error {
}()
return sh.RunV("go", args...)
}

func GoTestBuild(ctx context.Context, params GoTestArgs) error {
if params.OutputFile == "" {
return fmt.Errorf("missing output file")
}

fmt.Println(">> go test:", params.TestName, "Building Test Binary")

args := []string{"test", "-c", "-o", params.OutputFile}

if len(params.Tags) > 0 {
params := strings.Join(params.Tags, " ")
if params != "" {
args = append(args, "-tags", params)
}
}

args = append(args, params.Packages...)

goTestBuild := makeCommand(ctx, params.Env, "go", args...)

err := goTestBuild.Run()
if err != nil {
return err
}
return nil
}
Loading

0 comments on commit 361616d

Please sign in to comment.