Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

migrate libbeat pipeline #37725

Merged
merged 62 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
d85e193
migrate libbeat pipeline
Jan 24, 2024
35fa203
migrate libbeat pipeline
Jan 24, 2024
ac9ac7b
add hooks
Jan 24, 2024
8efb4f0
fix go-int tests
Jan 24, 2024
70bfa4e
fix go-int tests
Jan 25, 2024
9f5fd0d
revert mage dumpVariables
Jan 25, 2024
e76a97a
debug
Jan 25, 2024
bbe62dc
debug
Jan 25, 2024
4b9b801
debug
Jan 25, 2024
857f48d
debug
Jan 25, 2024
36ffb33
debug
Jan 25, 2024
22f4455
debug
Jan 25, 2024
e64c72c
debug Go Int Tests
Jan 25, 2024
6c1747f
debug Go Int Tests
Jan 25, 2024
6180a26
debug Go Int Tests
Jan 25, 2024
8282de0
debug Go Int Tests
Jan 25, 2024
01a3e61
debug Go Int Tests
Jan 25, 2024
383320e
full test
Jan 25, 2024
d95c25f
debug Python Int Tests
Jan 25, 2024
c1b2b35
debug Crosscompile
Jan 25, 2024
d688a5c
debug Crosscompile
Jan 25, 2024
7ab9718
debug Crosscompile
Jan 25, 2024
b23fc85
debug Crosscompile
Jan 25, 2024
dec018c
debug Crosscompile
Jan 25, 2024
3ffa0e7
full test
Jan 26, 2024
dff6341
Merge branch 'main' of github.com:sharbuz/beats into migrate-libbeat-…
Jan 26, 2024
0d5c9f8
debug stress tests
Jan 26, 2024
1fe6f20
debug stress tests
Jan 26, 2024
4af8233
debug stress tests
Jan 26, 2024
d1e5d55
full test
Jan 26, 2024
87ce234
full test
Jan 26, 2024
d684936
full test
Jan 26, 2024
da7b08a
full test - changed crosscompile options
Jan 26, 2024
0cf08cd
updates artifacts paths
Jan 29, 2024
ae8c545
Merge branch 'main' of github.com:sharbuz/beats into migrate-libbeat-…
Feb 3, 2024
9aa7c6c
conflict solving
Feb 3, 2024
411d9d4
change pre-command
Feb 3, 2024
708000d
add BEATS_PROJECT_NAME
Feb 3, 2024
af0b962
refactor libbeat
Feb 5, 2024
a562733
refactor libbeat/metricbeat conditions
Feb 5, 2024
b4efe61
fix dinamyc libbeat pipeline
Feb 5, 2024
6cd9880
change metricbeat dunamyc pipeline
Feb 5, 2024
a2c8826
full test
Feb 5, 2024
e03d2b3
full test
Feb 5, 2024
823a27c
full test
Feb 5, 2024
b1155e8
update catalog-info.yaml
Feb 5, 2024
0c4becf
change the instance type and fix typos
Feb 5, 2024
ca6c241
change instance types to c2d-highcpu-16
Feb 5, 2024
82ebbfa
Merge branch 'main' of github.com:sharbuz/beats into migrate-libbeat-…
Feb 5, 2024
3774483
change instance type for packaging
Feb 5, 2024
d5194bf
Update catalog-info.yaml
sharbuz Feb 6, 2024
f3317c6
fix remarks
Feb 6, 2024
b96a16c
Merge branch 'migrate-libbeat-pipeline' of github.com:sharbuz/beats i…
Feb 6, 2024
f151f98
revert makifile changes
Feb 6, 2024
6e57804
Merge branch 'main' into migrate-libbeat-pipeline
sharbuz Feb 6, 2024
6ee43ff
Update catalog-info.yaml
sharbuz Feb 6, 2024
5aaf276
Merge branch 'main' into migrate-libbeat-pipeline
sharbuz Feb 6, 2024
e2a2afb
windows 10 test
Feb 6, 2024
5d5ceb8
Merge branch 'migrate-libbeat-pipeline' of github.com:sharbuz/beats i…
Feb 6, 2024
adf168a
Merge branch 'main' into migrate-libbeat-pipeline
sharbuz Feb 6, 2024
5bfd917
Merge branch 'main' into migrate-libbeat-pipeline
sharbuz Feb 6, 2024
b272833
Merge branch 'main' into migrate-libbeat-pipeline
sharbuz Feb 7, 2024
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
53 changes: 53 additions & 0 deletions .buildkite/hooks/post-checkout
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/bin/bash

set -euo pipefail

checkout_merge() {
local target_branch=$1
local pr_commit=$2
local merge_branch=$3

if [[ -z "${target_branch}" ]]; then
echo "No pull request target branch"
exit 1
fi

git fetch -v origin "${target_branch}"
git checkout FETCH_HEAD
echo "Current branch: $(git rev-parse --abbrev-ref HEAD)"

# create temporal branch to merge the PR with the target branch
git checkout -b ${merge_branch}
echo "New branch created: $(git rev-parse --abbrev-ref HEAD)"

# set author identity so it can be run git merge
git config user.name "github-merged-pr-post-checkout"
git config user.email "auto-merge@buildkite"

git merge --no-edit "${BUILDKITE_COMMIT}" || {
local merge_result=$?
echo "Merge failed: ${merge_result}"
git merge --abort
exit ${merge_result}
}
}

pull_request="${BUILDKITE_PULL_REQUEST:-false}"

if [[ "${pull_request}" == "false" ]]; then
echo "Not a pull request, skipping"
exit 0
fi

TARGET_BRANCH="${BUILDKITE_PULL_REQUEST_BASE_BRANCH:-master}"
PR_COMMIT="${BUILDKITE_COMMIT}"
PR_ID=${BUILDKITE_PULL_REQUEST}
MERGE_BRANCH="pr_merge_${PR_ID}"

checkout_merge "${TARGET_BRANCH}" "${PR_COMMIT}" "${MERGE_BRANCH}"

echo "Commit information"
git --no-pager log --format=%B -n 1

# Ensure buildkite groups are rendered
echo ""
8 changes: 8 additions & 0 deletions .buildkite/hooks/pre-command
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

set -euo pipefail

echo "Golang version:"
GO_VERSION=$(cat .go-version)
export GO_VERSION
echo "GO_VERSION: ${GO_VERSION}"
75 changes: 73 additions & 2 deletions .buildkite/libbeat/pipeline.libbeat.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,76 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/buildkite/pipeline-schema/main/schema.json
env:
SETUP_GVM_VERSION: "v0.5.1"
SETUP_MAGE_VERSION: "1.13.0"
SETUP_WIN_PYTHON_VERSION: "3.11.0"
IMAGE_UBUNTU_X86_64: "family/core-ubuntu-2204"
IMAGE_UBUNTU_ARM_64: "core-ubuntu-2004-aarch64"
IMAGE_WIN_2016: "family/core-windows-2016"
IMAGE_WIN_2019: "family/core-windows-2019"
IMAGE_WIN_2022: "family/core-windows-2022"
sharbuz marked this conversation as resolved.
Show resolved Hide resolved
IMAGE_MACOS_X86_64: "generic-13-ventura-x64"
sharbuz marked this conversation as resolved.
Show resolved Hide resolved
GO_AGENT_IMAGE: "golang:${GO_VERSION}"
DOCKER_COMPOSE_VERSION: "1.21.0"
PIPELINE_NAME: "libbeat"

steps:
- label: "Example test"
command: echo "Hello!"

- group: "Mandatory Tests"
key: "mandatory-tests"
steps:
- label: ":linux: Ubuntu Unit Tests"
key: "mandatory-linux-unit-test"
command: ".buildkite/scripts/unit_tests.sh ${PIPELINE_NAME}"
agents:
provider: "gcp"
image: "${IMAGE_UBUNTU_X86_64}"
machineType: "c2-standard-16"
artifact_paths: "libbeat/build/*.*"

- label: ":go: Go Intergration Tests"
key: "mandatory-int-test"
command: ".buildkite/scripts/go_int_tests.sh ${PIPELINE_NAME}"
agents:
provider: "gcp"
image: "${IMAGE_UBUNTU_X86_64}"
machineType: "c2-standard-16"
artifact_paths: "libbeat/build/*.*"

- label: ":python: Python Integration Tests"
key: "mandatory-python-int-test"
command: ".buildkite/scripts/py_int_tests.sh ${PIPELINE_NAME}"
agents:
provider: "gcp"
image: "${IMAGE_UBUNTU_X86_64}"
machineType: "c2-standard-16"
artifact_paths: "libbeat/build/*.*"

- label: ":negative_squared_cross_mark: Cross compile"
key: "mandatory-cross-compile"
command: ".buildkite/scripts/crosscompile.sh ${PIPELINE_NAME}"
agents:
provider: "gcp"
image: "${IMAGE_UBUNTU_X86_64}"
machineType: "c2-standard-16"
artifact_paths: "libbeat/build/*.*"

- label: ":negative_squared_cross_mark: Stress Tests"
key: "mandatory-stress-test"
command: ".buildkite/scripts/stress_tests.sh ${PIPELINE_NAME}"
agents:
provider: "gcp"
image: "${IMAGE_UBUNTU_X86_64}"
machineType: "c2-standard-16"
artifact_paths: "libbeat/build/*.*"

- group: "Extended Tests"
key: "extended-tests"
steps:
- label: ":mac: Arm64 Unit Tests"
key: "extended-arm64-unit-tests"
command: ".buildkite/scripts/unit_tests.sh ${PIPELINE_NAME}"
agents:
provider: "aws"
imagePrefix: "${IMAGE_UBUNTU_ARM_64}"
instanceType: "t4g.xlarge"
artifact_paths: "libbeat/build/*.*"
140 changes: 140 additions & 0 deletions .buildkite/scripts/common.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
#!/bin/bash
set -euo pipefail

WORKSPACE=${WORKSPACE:-"$(pwd)"}
BIN="${WORKSPACE}/bin"
platform_type="$(uname)"
platform_type_lowercase=$(echo "$platform_type" | tr '[:upper:]' '[:lower:]')
arch_type="$(uname -m)"
pipeline_name="metricbeat"
DEBIAN_FRONTEND="noninteractive"
sudo mkdir -p /etc/needrestart
echo "\$nrconf{restart} = 'a';" | sudo tee -a /etc/needrestart/needrestart.conf > /dev/null

with_docker_compose() {
local version=$1
echo "Setting up the Docker-compose environment..."
create_workspace
retry 5 curl -sSL -o ${BIN}/docker-compose "https://github.com/docker/compose/releases/download/${version}/docker-compose-${platform_type_lowercase}-${arch_type}"
chmod +x ${BIN}/docker-compose
docker-compose version
}

create_workspace() {
if [[ ! -d "${BIN}" ]]; then
mkdir -p "${BIN}"
fi
}

add_bin_path() {
echo "Adding PATH to the environment variables..."
create_workspace
export PATH="${PATH}:${BIN}"
}

check_platform_architeture() {
case "${arch_type}" in
"x86_64")
arch_type="amd64"
;;
"aarch64")
arch_type="arm64"
;;
"arm64")
arch_type="arm64"
;;
*)
echo "The current platform/OS type is unsupported yet"
;;
esac
}

with_mage() {
local install_packages=(
"github.com/magefile/mage"
"github.com/elastic/go-licenser"
"golang.org/x/tools/cmd/goimports"
"github.com/jstemmer/go-junit-report"
"gotest.tools/gotestsum"
)
create_workspace
for pkg in "${install_packages[@]}"; do
go install "${pkg}@latest"
done
}

with_go() {
echo "Setting up the Go environment..."
create_workspace
check_platform_architeture
retry 5 curl -sL -o "${BIN}/gvm" "https://github.com/andrewkroh/gvm/releases/download/${SETUP_GVM_VERSION}/gvm-${platform_type_lowercase}-${arch_type}"
chmod +x "${BIN}/gvm"
eval "$(gvm $GO_VERSION)"
go version
which go
local go_path="$(go env GOPATH):$(go env GOPATH)/bin"
export PATH="${PATH}:${go_path}"
go mod download
}

with_python() {
if [ "${platform_type}" == "Linux" ]; then
sudo apt-get update
sudo apt-get install -y python3-pip python3-venv libsystemd-dev libpcap-dev
elif [ "${platform_type}" == "Darwin" ]; then
brew update
pip3 install virtualenv libpcap
ulimit -Sn 10000
fi
}

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
}

config_git() {
if [ -z "$(git config --get user.email)" ]; then
git config --global user.email "beatsmachine@users.noreply.github.com"
git config --global user.name "beatsmachine"
fi
}


echo "--- Env preparation"

if command -v docker-compose &> /dev/null
then
set +e
echo "Found docker-compose. Checking version.."
FOUND_DOCKER_COMPOSE_VERSION=$(docker-compose --version|awk '{print $3}'|sed s/\,//)
if [ $FOUND_DOCKER_COMPOSE_VERSION == $DOCKER_COMPOSE_VERSION ]; then
echo "Versions match. No need to install docker-compose. Exiting."
else
echo "Versions don't match. Need to install the correct version of docker-compose."
with_docker_compose "${DOCKER_COMPOSE_VERSION}"
fi
set -e
fi

add_bin_path
with_go "${GO_VERSION}"
with_mage
with_python
config_git

mage dumpVariables
10 changes: 10 additions & 0 deletions .buildkite/scripts/crosscompile.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

source .buildkite/scripts/common.sh

set -euo pipefail

beats_subfilder=$1
sharbuz marked this conversation as resolved.
Show resolved Hide resolved

echo "--- Run Crosscompile for $beats_subfilder"
make -C $beats_subfilder crosscompile
14 changes: 14 additions & 0 deletions .buildkite/scripts/go_int_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash

source .buildkite/scripts/common.sh

set -euo pipefail

beats_subfilder=$1

echo "--- Run Go Intergration Tests for $beats_subfilder"
sudo chmod -R go-w "${beats_subfilder}/"
pushd "${beats_subfilder}" > /dev/null
mage goIntegTest

popd > /dev/null
14 changes: 14 additions & 0 deletions .buildkite/scripts/py_int_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash

source .buildkite/scripts/common.sh

set -euo pipefail

beats_subfilder=$1

echo "--- Run Python Intergration Tests for $beats_subfilder"
pushd "${beats_subfilder}" > /dev/null

mage pythonIntegTest

popd > /dev/null
10 changes: 10 additions & 0 deletions .buildkite/scripts/stress_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

source .buildkite/scripts/common.sh

set -euo pipefail

beats_subfilder=$1

echo "--- Run Stress Tests for $beats_subfilder"
make STRESS_TEST_OPTIONS='-timeout=20m -race -v -parallel 1' -C $beats_subfilder stress-tests
14 changes: 14 additions & 0 deletions .buildkite/scripts/unit_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash

source .buildkite/scripts/common.sh

set -euo pipefail

beats_subfilder=$1

echo "--- Run Unit Tests"
sudo chmod -R go-w "${beats_subfilder}/"
pushd "${beats_subfilder}" > /dev/null
umask 0022
Copy link
Contributor

Choose a reason for hiding this comment

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

can we add a small #TODO remove when custom vm images are used as we have fixed this e.g. in the Logstash base images https://docs.google.com/document/d/1IDM9FEyrlrKmjZge3iBa-maaOFeK_ONjxLBMEXkwLI0/edit#bookmark=id.x7640ku6nmd3

(I assume this script will run on Linux, I am not sure if we need to also cover for macOS, in which case, custom images won't help, as we can't have custom images yet for the macos provider)

mage build unitTest
popd > /dev/null
Loading
Loading