Skip to content

Commit

Permalink
Merge branch '8.14' into mergify/bp/8.14/pr-38534
Browse files Browse the repository at this point in the history
  • Loading branch information
pierrehilbert authored Jun 3, 2024
2 parents e3f0d10 + de52d14 commit 66031aa
Show file tree
Hide file tree
Showing 52 changed files with 958 additions and 5,947 deletions.
83 changes: 50 additions & 33 deletions .buildkite/heartbeat/heartbeat-pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ steps:
- "heartbeat/build/*.json"
notify:
- github_commit_status:
context: "Heartbeat: Ubuntu Unit Tests"
context: "heartbeat: Ubuntu Unit Tests"

- label: ":rhel: Heartbeat Rhel9 Unit Tests"
command: |
Expand All @@ -64,9 +64,9 @@ steps:
- "heartbeat/build/*.json"
notify:
- github_commit_status:
context: "Heartbeat: Rhel9 Unit Tests"
context: "heartbeat: Rhel9 Unit Tests"

- label: ":windows: Heartbeat Win-2016 Unit Tests"
- label: ":windows: Win-2016 Unit Tests"
key: "windows-2016"
command: |
Set-Location -Path heartbeat
Expand All @@ -84,7 +84,7 @@ steps:
- "heartbeat/build/*.json"
notify:
- github_commit_status:
context: "Heartbeat: Win-2016 Unit Tests"
context: "heartbeat: Win-2016 Unit Tests"

- label: ":windows: Heartbeat Win-2022 Unit Test"
key: "windows-2022"
Expand All @@ -104,10 +104,19 @@ steps:
- "heartbeat/build/*.json"
notify:
- github_commit_status:
context: "Heartbeat: Win-2022 Unit Tests"
context: "heartbeat: Win-2022 Unit Tests"

- label: ":ubuntu: Heartbeat Go Integration Tests"
- label: ":ubuntu: Heartbeat Go (Module) Integration Tests"
command: |
set -euo pipefail
echo "~~~ Installing @elastic/synthetics"
npm install -g @elastic/synthetics
# defines the MODULE env var based on what's changed in a PR
source .buildkite/scripts/changesets.sh
defineModuleFromTheChangeSet heartbeat
echo "~~~ Running tests"
cd heartbeat
mage goIntegTest
retry:
Expand All @@ -122,10 +131,16 @@ steps:
- "heartbeat/build/*.json"
notify:
- github_commit_status:
context: "Heartbeat: Go Integration Tests"
context: "heartbeat: Go Integration Tests"

- label: ":ubuntu: Heartbeat Python Integration Tests"
- label: ":ubuntu: Heartbeat Python (Module) Integration Tests"
command: |
set -euo pipefail
# defines the MODULE env var based on what's changed in a PR
source .buildkite/scripts/changesets.sh
defineModuleFromTheChangeSet heartbeat
echo "~~~ Running tests"
cd heartbeat
mage pythonIntegTest
retry:
Expand All @@ -140,15 +155,16 @@ steps:
- "heartbeat/build/*.json"
notify:
- github_commit_status:
context: "Heartbeat: Python Integration Tests"
context: "heartbeat: Python Integration Tests"

- group: "Heartbeat ARM Tests"
key: "heartbeat-extended-tests-arm"
if: build.env("BUILDKITE_PULL_REQUEST") == "false" || build.env("GITHUB_PR_LABELS") =~ /.*arm.*/
- group: "Heartbeat Extended Tests"
key: "heartbeat-extended-tests"
if: build.env("BUILDKITE_PULL_REQUEST") == "false" || build.env("GITHUB_PR_LABELS") =~ /.*(macOS|arm).*/

steps:
- label: ":linux: Heartbeat ARM64 Unit Tests"
- label: ":linux: Heartbeat arm64 Unit Tests"
key: "arm-extended"
if: build.env("BUILDKITE_PULL_REQUEST") == "false" || build.env("GITHUB_PR_LABELS") =~ /.*arm.*/
command: |
cd heartbeat
mage build unitTest
Expand All @@ -162,14 +178,11 @@ steps:
artifact_paths: "heartbeat/build/*.xml"
notify:
- github_commit_status:
context: "Heartbeat: Ubuntu ARM64 Unit Tests"
context: "heartbeat: Linux arm64 Unit Tests"

- group: "Heartbeat Extended Testing MacOS"
key: "heartbeat-extended-tests-macos"
if: build.env("BUILDKITE_PULL_REQUEST") == "false" || build.env("GITHUB_PR_LABELS") =~ /.*macOS.*/
steps:
- label: ":mac: Heartbeat MacOS Unit Tests"
- label: ":mac: macOS x86_64 Unit Tests"
key: "macos-extended"
if: build.env("BUILDKITE_PULL_REQUEST") == "false" || build.env("GITHUB_PR_LABELS") =~ /.*macOS.*/
command: |
set -euo pipefail
source .buildkite/scripts/install_macos_tools.sh
Expand All @@ -186,10 +199,11 @@ steps:
- "metricbeat/build/*.json"
notify:
- github_commit_status:
context: "Heartbeat: MacOS Unit Tests"
context: "heartbeat: macOS x86_64 Unit Tests"

- label: ":mac: Heartbeat MacOS ARM Unit Tests"
- label: ":mac: macOS arm64 Unit Tests"
key: "macos-arm-extended"
if: build.env("BUILDKITE_PULL_REQUEST") == "false" || build.env("GITHUB_PR_LABELS") =~ /.*macOS.*/
command: |
set -euo pipefail
source .buildkite/scripts/install_macos_tools.sh
Expand All @@ -206,14 +220,14 @@ steps:
- "metricbeat/build/*.json"
notify:
- github_commit_status:
context: "Heartbeat: MacOS ARM Unit Tests"
context: "heartbeat: macOS arm64 Unit Tests"

- group: "Heartbeat Windows Extended Testing"
key: "heartbeat-extended-tests-win"
if: build.env("BUILDKITE_PULL_REQUEST") == "false" || build.env("GITHUB_PR_LABELS") =~ /.*[Ww]indows.*/

steps:
- label: ":windows: Heartbeat Win-2019 Unit Tests"
- label: ":windows: Win-2019 Unit Tests"
key: "heartbeat-win-extended-2019"
command: |
Set-Location -Path heartbeat
Expand All @@ -231,9 +245,9 @@ steps:
- "heartbeat/build/*.json"
notify:
- github_commit_status:
context: "Heartbeat: Win-2019 Unit Tests"
context: "heartbeat: Win-2019 Unit Tests"

- label: ":windows: Heartbeat Win-11 Unit Tests"
- label: ":windows: Win-11 Unit Tests"
key: "heartbeat-windows-extended-11"
command: |
Set-Location -Path heartbeat
Expand All @@ -251,9 +265,9 @@ steps:
- "heartbeat/build/*.json"
notify:
- github_commit_status:
context: "Heartbeat: Win-11 Unit Tests"
context: "heartbeat: Win-11 Unit Tests"

- label: ":windows: Heartbeat Win-10 Unit Tests"
- label: ":windows: Win-10 Unit Tests"
key: "heartbeat-windows-extended-10"
command: |
Set-Location -Path heartbeat
Expand All @@ -271,17 +285,20 @@ steps:
- "heartbeat/build/*.json"
notify:
- github_commit_status:
context: "Heartbeat: Win-10 Unit Tests"
context: "heartbeat: Win-10 Unit Tests"

- wait: ~
# with PRs, we want to run packaging only if mandatory tests succeed
# for other cases, e.g. merge commits, we want to run packaging (and publish) independently of other tests
# this allows building DRA artifacts even if there is flakiness in mandatory tests
if: build.env("BUILDKITE_PULL_REQUEST") != "false"
depends_on: "heartbeat-mandatory-tests"

- group: "Heartbeat Packaging"
key: "heartbeat-packaging"
steps:
- label: ":ubuntu: Heartbeat Packaging Linux X86"
key: "heartbeat-package-linux-x86"
- label: ":ubuntu: Heartbeat Packaging Linux"
key: "heartbeat-package-linux"
env:
PLATFORMS: "+all linux/amd64 linux/arm64 windows/amd64 darwin/amd64 darwin/arm64"
SNAPSHOT: true
Expand All @@ -298,9 +315,9 @@ steps:
machineType: "${GCP_HI_PERF_MACHINE_TYPE}"
notify:
- github_commit_status:
context: "Heartbeat: Packaging Ubuntu x86_64"
context: "heartbeat: Packaging Linux"

- label: ":linux: Heartbeat Packaging Linux ARM"
- label: ":linux: Heartbeat Packaging Linux arm64"
key: "heartbeat-package-linux-arm"
env:
PLATFORMS: "linux/arm64"
Expand All @@ -319,4 +336,4 @@ steps:
instanceType: "${AWS_ARM_INSTANCE_TYPE}"
notify:
- github_commit_status:
context: "Heartbeat: Packaging Ubuntu ARM"
context: "heartbeat: Packaging Linux arm64"
6 changes: 3 additions & 3 deletions .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ steps:
watch:
- path:
- x-pack/osquerybeat/**
- .buildkite/x-pack/pipeline.xpack.metricbeat.yml
- .buildkite/x-pack/pipeline.xpack.osquerybeat.yml
- .buildkite/scripts/**
- .buildkite/hooks/**
# x-pack
Expand Down Expand Up @@ -279,7 +279,7 @@ steps:
commit: "${BUILDKITE_COMMIT}"
branch: "${BUILDKITE_BRANCH}"

- label: "Trigger Xpack/Winlogbeat"
- label: "Trigger x-pack/winlogbeat"
if: build.pull_request.id != null
plugins:
- monorepo-diff#v1.0.1:
Expand All @@ -306,7 +306,7 @@ steps:
- BUILDKITE_PULL_REQUEST_BASE_BRANCH=${BUILDKITE_PULL_REQUEST_BASE_BRANCH}
- GITHUB_PR_LABELS=${GITHUB_PR_LABELS}

- label: "Triggering Build for Xpack/Winlogbeat"
- label: "Triggering Build for x-pack/winlogbeat"
if: build.pull_request.id == null
trigger: "beats-xpack-winlogbeat"
build:
Expand Down
101 changes: 45 additions & 56 deletions .buildkite/scripts/changesets.sh
Original file line number Diff line number Diff line change
@@ -1,77 +1,66 @@
#!/usr/bin/env bash

# This script contains helper functions related to what should be run depending on Git changes

set -euo pipefail

OSS_MODULE_PATTERN="^[a-z0-9]+beat\\/module\\/([^\\/]+)\\/.*"
XPACK_MODULE_PATTERN="^x-pack\\/[a-z0-9]+beat\\/module\\/([^\\/]+)\\/.*"

are_paths_changed() {
local patterns=("${@}")
local changelist=()
for pattern in "${patterns[@]}"; do
changed_files=($(git diff --name-only HEAD@{1} HEAD | grep -E "$pattern"))
if [ "${#changed_files[@]}" -gt 0 ]; then
changelist+=("${changed_files[@]}")
fi
done
definePattern() {
pattern="${OSS_MODULE_PATTERN}"

if [ "${#changelist[@]}" -gt 0 ]; then
echo "Files changed:"
echo "${changelist[*]}"
return 0
else
echo "No files changed within specified changeset:"
echo "${patterns[*]}"
return 1
if [[ "$beatPath" == *"x-pack/"* ]]; then
pattern="${XPACK_MODULE_PATTERN}"
fi
}

are_changed_only_paths() {
local patterns=("${@}")
local changed_files=($(git diff --name-only HEAD@{1} HEAD))
local matched_files=()
for pattern in "${patterns[@]}"; do
local matched=($(grep -E "${pattern}" <<< "${changed_files[@]}"))
if [ "${#matched[@]}" -gt 0 ]; then
matched_files+=("${matched[@]}")
fi
done
if [ "${#matched_files[@]}" -eq "${#changed_files[@]}" ] || [ "${#changed_files[@]}" -eq 0 ]; then
return 0
fi
return 1
defineExclusions() {
exclude="^$beatPath\/module\/(.*(?<!\.asciidoc|\.png))$"
}

defineModuleFromTheChangeSet() {
# This function sets a `MODULE` env var, required by IT tests, containing a comma separated list of modules for a given beats project (specified via the first argument).
# The list is built depending on directories that have changed under `modules/` excluding anything else such as asciidoc and png files.
# `MODULE` will empty if no changes apply.
local project_path=$1
local project_path_transformed=$(echo "$project_path" | sed 's/\//\\\//g')
local project_path_exclussion="((?!^${project_path_transformed}\\/).)*\$"
local exclude=("^(${project_path_exclussion}|((?!\\/module\\/).)*\$|.*\\.asciidoc|.*\\.png)")
defineFromCommit() {
local changeTarget=${BUILDKITE_PULL_REQUEST_BASE_BRANCH:-$BUILDKITE_BRANCH}

if [[ "$project_path" == *"x-pack/"* ]]; then
local pattern=("$XPACK_MODULE_PATTERN")
if [[ -z ${changeTarget+x} ]]; then
# If not a PR (no target branch) - use last commit
from=$(git rev-parse HEAD^)
else
local pattern=("$OSS_MODULE_PATTERN")
# If it's a PR - add "origin/"
from="origin/$changeTarget"
fi
local changed_modules=""
local module_dirs=$(find "$project_path/module" -mindepth 1 -maxdepth 1 -type d)
for module_dir in $module_dirs; do
if are_paths_changed $module_dir && ! are_changed_only_paths "${exclude[@]}"; then
if [[ -z "$changed_modules" ]]; then
changed_modules=$(basename "$module_dir")
else
changed_modules+=",$(basename "$module_dir")"
fi
}

getMatchingModules() {
local changedPaths
mapfile -t changedPaths < <(git diff --name-only "$from"..."$BUILDKITE_COMMIT" | grep -P "$exclude" | grep -oP "$pattern")
mapfile -t modulesMatched < <(printf "%s\n" "${changedPaths[@]}" | grep -o 'module/.*' | awk -F '/' '{print $2}' | sort -u)
}

addToModuleEnvVar() {
local module
for module in "${modulesMatched[@]}"; do
if [[ -z ${modules+x} ]]; then
modules="$module"
else
modules+=",$module"
fi
done
}

# export MODULE="" leads to an infinite loop https://github.com/elastic/ingest-dev/issues/2993
if [[ ! -z $changed_modules ]]; then
export MODULE="${changed_modules}"
echo "~~~ Set env var MODULE to [$MODULE]"
defineModuleFromTheChangeSet() {
beatPath=$1

definePattern
defineExclusions
defineFromCommit
getMatchingModules

if [ "${#modulesMatched[@]}" -gt 0 ]; then
addToModuleEnvVar
export MODULE=$modules
echo "~~~ Detected file changes for some modules. Setting env var MODULE to [$MODULE]"
echo "~~~ Resuming commands"
else
echo "~~~ No changes in modules for $beatPath"
fi
}
Loading

0 comments on commit 66031aa

Please sign in to comment.