Skip to content

Commit

Permalink
migrate xpack-winlogbeat pipeline (#38348)
Browse files Browse the repository at this point in the history
* migrate xpack-winlogbeat pipeline

* add generate_xpack_winlogbeat_pipeline.sh and cleanup setenv.sh

* full test

* full test

* test xpack-packetbeat packaging

* update comment
  • Loading branch information
sharbuz authored Mar 18, 2024
1 parent 093ab5e commit 8ccfa43
Show file tree
Hide file tree
Showing 8 changed files with 167 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .buildkite/hooks/pre-command
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ if [[ "$BUILDKITE_PIPELINE_SLUG" == "filebeat" || "$BUILDKITE_PIPELINE_SLUG" ==
fi
fi

if [[ "$BUILDKITE_PIPELINE_SLUG" == "beats-metricbeat" || "$BUILDKITE_PIPELINE_SLUG" == "beats-libbeat" || "$BUILDKITE_PIPELINE_SLUG" == "beats-packetbeat" || "$BUILDKITE_PIPELINE_SLUG" == "beats-winlogbeat" || "$BUILDKITE_PIPELINE_SLUG" == "beats-xpack-libbeat" || "$BUILDKITE_PIPELINE_SLUG" == "beats-xpack-metricbeat" || "$BUILDKITE_PIPELINE_SLUG" == "beats-xpack-packetbeat" ]]; then
if [[ "$BUILDKITE_PIPELINE_SLUG" == "beats-metricbeat" || "$BUILDKITE_PIPELINE_SLUG" == "beats-libbeat" || "$BUILDKITE_PIPELINE_SLUG" == "beats-packetbeat" || "$BUILDKITE_PIPELINE_SLUG" == "beats-winlogbeat" || "$BUILDKITE_PIPELINE_SLUG" == "beats-xpack-libbeat" || "$BUILDKITE_PIPELINE_SLUG" == "beats-xpack-metricbeat" || "$BUILDKITE_PIPELINE_SLUG" == "beats-xpack-packetbeat" || "$BUILDKITE_PIPELINE_SLUG" == "beats-xpack-winlogbeat" ]]; then
source .buildkite/scripts/setenv.sh
if [[ "${BUILDKITE_COMMAND}" =~ ^buildkite-agent ]]; then
echo "Skipped pre-command when running the Upload pipeline"
Expand Down
3 changes: 0 additions & 3 deletions .buildkite/scripts/cloud_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ set -euo pipefail

trap 'teardown || true; unset_secrets' EXIT

# Set the MODULE env variable if possible
defineModuleFromTheChangeSet "${BEATS_PROJECT_NAME}"

# Prepare the cloud resources using Terraform
startCloudTestEnv "${MODULE_DIR}"

Expand Down
12 changes: 12 additions & 0 deletions .buildkite/scripts/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ XPACK_MODULE_PATTERN="^x-pack\\/[a-z0-9]+beat\\/module\\/([^\\/]+)\\/.*"
[ -z "${run_metricbeat+x}" ] && run_metricbeat="$(buildkite-agent meta-data get run_metricbeat --default "false")"
[ -z "${run_packetbeat+x}" ] && run_packetbeat="$(buildkite-agent meta-data get run_packetbeat --default "false")"
[ -z "${run_winlogbeat+x}" ] && run_winlogbeat="$(buildkite-agent meta-data get run_winlogbeat --default "false")"
[ -z "${run_xpack_libbeat+x}" ] && run_xpack_libbeat="$(buildkite-agent meta-data get run_xpack_libbeat --default "false")"
[ -z "${run_xpack_metricbeat+x}" ] && run_xpack_metricbeat="$(buildkite-agent meta-data get run_xpack_metricbeat --default "false")"
[ -z "${run_xpack_packetbeat+x}" ] && run_xpack_packetbeat="$(buildkite-agent meta-data get run_xpack_packetbeat --default "false")"
[ -z "${run_xpack_winlogbeat+x}" ] && run_xpack_winlogbeat="$(buildkite-agent meta-data get run_xpack_winlogbeat --default "false")"
[ -z "${run_libbeat_arm_tests+x}" ] && run_libbeat_arm_tests="$(buildkite-agent meta-data get run_libbeat_arm_tests --default "false")"
[ -z "${run_packetbeat_arm_tests+x}" ] && run_packetbeat_arm_tests="$(buildkite-agent meta-data get run_packetbeat_arm_tests --default "false")"
[ -z "${run_metricbeat_macos_tests+x}" ] && run_metricbeat_macos_tests="$(buildkite-agent meta-data get run_metricbeat_macos_tests --default "false")"
Expand Down Expand Up @@ -110,6 +114,9 @@ case "${BUILDKITE_PIPELINE_SLUG}" in
"beats-xpack-packetbeat")
BEAT_CHANGESET_REFERENCE=${xpack_packetbeat_changeset[@]}
;;
"beats-xpack-winlogbeat")
BEAT_CHANGESET_REFERENCE=${xpack_winlogbeat_changeset[@]}
;;
*)
echo "The changeset for the ${BUILDKITE_PIPELINE_SLUG} pipeline hasn't been defined yet."
;;
Expand Down Expand Up @@ -501,4 +508,9 @@ if are_paths_changed "${packaging_changeset[@]}" ; then
export PACKAGING_CHANGES="true"
fi

if [[ "$BUILDKITE_STEP_KEY" == "xpack-winlogbeat-pipeline" || "$BUILDKITE_STEP_KEY" == "xpack-metricbeat-pipeline" || "$BUILDKITE_STEP_KEY" == "metricbeat-pipeline" ]]; then
# Set the MODULE env variable if possible, it should be defined before generating pipeline's steps. It is used in multiple pipelines.
defineModuleFromTheChangeSet "${BEATS_PROJECT_NAME}"
fi

check_and_set_beat_vars
6 changes: 6 additions & 0 deletions .buildkite/scripts/generate_xpack_metricbeat_pipeline.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ steps:
- label: ":go: Go Integration Tests"
key: "mandatory-int-test"
command: ".buildkite/scripts/go_int_tests.sh"
env:
MODULE: $MODULE
agents:
provider: "gcp"
image: "${DEFAULT_UBUNTU_X86_64_IMAGE}"
Expand All @@ -36,6 +38,8 @@ steps:
- label: ":python: Python Integration Tests"
key: "mandatory-python-int-test"
command: ".buildkite/scripts/py_int_tests.sh"
env:
MODULE: $MODULE
agents:
provider: "gcp"
image: "${DEFAULT_UBUNTU_X86_64_IMAGE}"
Expand Down Expand Up @@ -131,6 +135,8 @@ if are_conditions_met_aws_tests; then
- label: ":linux: Cloud Tests"
key: "extended-cloud-test"
command: ".buildkite/scripts/cloud_tests.sh"
env:
MODULE: $MODULE
agents:
provider: "gcp"
image: "${DEFAULT_UBUNTU_X86_64_IMAGE}"
Expand Down
110 changes: 110 additions & 0 deletions .buildkite/scripts/generate_xpack_winlogbeat_pipeline.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
#!/usr/bin/env bash

source .buildkite/scripts/common.sh

set -euo pipefail

pipelineName="pipeline.xpack-winlogbeat-dynamic.yml"

echo "Add the mandatory and extended tests without additional conditions into the pipeline"
if are_conditions_met_mandatory_tests; then
cat > $pipelineName <<- YAML
steps:
- group: "Mandatory Tests"
key: "mandatory-tests"
steps:
- label: ":windows: Windows 2019 Unit (MODULE) Tests"
key: "mandatory-win-2019-unit-tests"
command: ".buildkite/scripts/win_unit_tests.ps1"
env:
MODULE: $MODULE
agents:
provider: "gcp"
image: "${IMAGE_WIN_2019}"
machine_type: "${GCP_WIN_MACHINE_TYPE}"
disk_size: 100
disk_type: "pd-ssd"
artifact_paths: "${BEATS_PROJECT_NAME}/build/*.*"
- label: ":windows: Windows 2016/2022 Unit Tests - {{matrix.image}}"
command: ".buildkite/scripts/win_unit_tests.ps1"
key: "mandatory-win-unit-tests"
agents:
provider: "gcp"
image: "{{matrix.image}}"
machine_type: "${GCP_WIN_MACHINE_TYPE}"
disk_size: 100
disk_type: "pd-ssd"
matrix:
setup:
image:
- "${IMAGE_WIN_2016}"
- "${IMAGE_WIN_2022}"
artifact_paths: "${BEATS_PROJECT_NAME}/build/*.*"
# echo "Add the extended windows tests into the pipeline"
# TODO: ADD conditions from the main pipeline
- group: "Extended Windows Tests"
key: "extended-win-tests"
steps:
- label: ":windows: Windows Unit Tests - {{matrix.image}}"
command: ".buildkite/scripts/win_unit_tests.ps1"
key: "extended-win-unit-tests"
agents:
provider: "gcp"
image: "{{matrix.image}}"
machineType: "${GCP_WIN_MACHINE_TYPE}"
disk_size: 100
disk_type: "pd-ssd"
matrix:
setup:
image:
- "${IMAGE_WIN_10}"
- "${IMAGE_WIN_11}"
- "${IMAGE_WIN_2019}"
artifact_paths: "${BEATS_PROJECT_NAME}/build/*.*"
YAML
else
echo "The conditions don't match to requirements for generating pipeline steps."
exit 0
fi

echo "Check and add the Packaging into the pipeline"
if are_conditions_met_packaging; then
cat >> $pipelineName <<- YAML
- wait: ~
depends_on:
- step: "mandatory-tests"
allow_failure: false
- group: "Packaging" # TODO: check conditions for future the main pipeline migration: https://github.com/elastic/beats/pull/28589
key: "packaging"
steps:
- label: ":linux: Packaging Linux"
key: "packaging-linux"
command: "cd $BEATS_PROJECT_NAME && mage package"
agents:
provider: "gcp"
image: "${IMAGE_UBUNTU_X86_64}"
machineType: "${GCP_HI_PERF_MACHINE_TYPE}"
disk_size: 100
disk_type: "pd-ssd"
env:
PLATFORMS: "${PACKAGING_PLATFORMS}"
YAML
fi

echo "--- Printing dynamic steps" #TODO: remove if the pipeline is public
cat $pipelineName

echo "--- Loading dynamic steps"
buildkite-agent pipeline upload $pipelineName
2 changes: 1 addition & 1 deletion .buildkite/scripts/setenv.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ exportVars() {
fi
}

if [[ "$BUILDKITE_PIPELINE_SLUG" == "beats-metricbeat" || "$BUILDKITE_PIPELINE_SLUG" == "beats-xpack-metricbeat" ]]; then
if [[ "$BUILDKITE_PIPELINE_SLUG" == "beats-metricbeat" || "$BUILDKITE_PIPELINE_SLUG" == "beats-xpack-metricbeat" || "$BUILDKITE_PIPELINE_SLUG" == "beats-xpack-winlogbeat" ]]; then
exportVars
export RACE_DETECTOR="true"
export TEST_COVERAGE="true"
Expand Down
2 changes: 1 addition & 1 deletion .buildkite/x-pack/pipeline.xpack.metricbeat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ steps:
allow_dependency_failure: false

- label: ":linux: Load dynamic x-pack metricbeat pipeline"
key: "metricbeat-pipeline"
key: "xpack-metricbeat-pipeline"
command: ".buildkite/scripts/generate_xpack_metricbeat_pipeline.sh"
notify:
- github_commit_status:
Expand Down
38 changes: 36 additions & 2 deletions .buildkite/x-pack/pipeline.xpack.winlogbeat.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,39 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/buildkite/pipeline-schema/main/schema.json
name: "beats-xpack-winlogbeat"

env:
IMAGE_UBUNTU_X86_64: "family/platform-ingest-beats-ubuntu-2204"
IMAGE_WIN_10: "family/general-windows-10"
IMAGE_WIN_11: "family/general-windows-11"
IMAGE_WIN_2016: "family/core-windows-2016"
IMAGE_WIN_2019: "family/core-windows-2019"
IMAGE_WIN_2022: "family/core-windows-2022"
GCP_HI_PERF_MACHINE_TYPE: "c2d-highcpu-16"
GCP_WIN_MACHINE_TYPE: "n2-standard-8"
BEATS_PROJECT_NAME: "x-pack/winlogbeat"

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

- input: "Input Parameters"
key: "force-run-stages"
fields:
- select: "Winlogbeat - run_xpack_winlogbeat"
key: "run_xpack_winlogbeat"
options:
- label: "True"
value: "true"
- label: "False"
value: "false"
default: "false"
if: "build.source == 'ui'"

- wait: ~
if: "build.source == 'ui'"
allow_dependency_failure: false

- label: ":linux: Load dynamic x-pack winlogbeat pipeline"
key: "xpack-winlogbeat-pipeline"
command: ".buildkite/scripts/generate_xpack_winlogbeat_pipeline.sh"
notify:
- github_commit_status:
context: "${BEATS_PROJECT_NAME}: Load dynamic pipeline's steps"

0 comments on commit 8ccfa43

Please sign in to comment.