Skip to content

Commit

Permalink
Merge branch '8.x' into mergify/bp/8.x/pr-15360
Browse files Browse the repository at this point in the history
  • Loading branch information
mergify[bot] authored Jan 31, 2025
2 parents f48e0df + da60584 commit 00ed67e
Show file tree
Hide file tree
Showing 41 changed files with 779 additions and 499 deletions.
21 changes: 2 additions & 19 deletions .buildkite/hooks/pre-command
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,8 @@

set -eo pipefail

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
}
# shellcheck disable=SC1091
source .buildkite/scripts/utils.sh

get_os_details() {
case $(uname | tr '[:upper:]' '[:lower:]') in
Expand Down
81 changes: 24 additions & 57 deletions .buildkite/scripts/dra.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ set -eo pipefail
# Either staging or snapshot
TYPE="$1"

## Read current version without the qualifier
VERSION=$(make get-version-only)
# NOTE: load the shared functions
# shellcheck disable=SC1091
source .buildkite/scripts/utils.sh

echo "--- Restoring Artifacts"
buildkite-agent artifact download "build/**/*" .
Expand All @@ -34,48 +35,26 @@ fi
# by default it uses the buildkite branch
DRA_BRANCH="$BUILDKITE_BRANCH"
# by default it publishes the DRA artifacts, for such it uses the collect command.
dra_command=collect
DRA_COMMAND=collect
VERSION=$(make get-version-only)
BRANCHES_URL=https://storage.googleapis.com/artifacts-api/snapshots/branches.json
curl -s "${BRANCHES_URL}" > active-branches.json
# as long as `8.x` is not in the active branches, we will explicitly add the condition.
if [ "$BUILDKITE_BRANCH" == "8.x" ] || grep -q "\"$BUILDKITE_BRANCH\"" active-branches.json ; then
echo "--- :arrow_right: Release Manager only supports the current active branches and 8.x, running"
else
if ! grep -q "\"$BUILDKITE_BRANCH\"" active-branches.json ; then
# If no active branches are found, let's see if it is a feature branch.
echo "--- :arrow_right: Release Manager only supports the current active branches, skipping"
echo "BUILDKITE_BRANCH=$BUILDKITE_BRANCH"
echo "BUILDKITE_COMMIT=$BUILDKITE_COMMIT"
echo "VERSION=$VERSION"
echo "Supported branches:"
cat active-branches.json
if [[ $BUILDKITE_BRANCH =~ "feature/" ]]; then
buildkite-agent annotate "${BUILDKITE_BRANCH} will list DRA artifacts. Feature branches are not supported. Look for the supported branches in ${BRANCHES_URL}" --style 'info' --context 'ctx-info'
dra_command=list

# use a different branch since DRA does not support feature branches but main/release branches
# for such we will use the VERSION and https://storage.googleapis.com/artifacts-api/snapshots/<major.minor>.json
# to know if the branch was branched out from main or the release branches.
MAJOR_MINOR=${VERSION%.*}
if curl -s "https://storage.googleapis.com/artifacts-api/snapshots/main.json" | grep -q "$VERSION" ; then
DRA_BRANCH=main
else
if curl -s "https://storage.googleapis.com/artifacts-api/snapshots/$MAJOR_MINOR.json" | grep -q "$VERSION" ; then
DRA_BRANCH="$MAJOR_MINOR"
else
buildkite-agent annotate "It was not possible to know the original base branch for ${BUILDKITE_BRANCH}. This won't fail - this is a feature branch." --style 'info' --context 'ctx-info-feature-branch'
exit 0
fi
fi
else
buildkite-agent annotate "${BUILDKITE_BRANCH} is not supported yet. Look for the supported branches in ${BRANCHES_URL}" --style 'warning' --context 'ctx-warn'
exit 1
fi
dra_process_other_branches
fi

echo "--- :arrow_right: Release Manager only supports the current active branches"
echo "BUILDKITE_BRANCH=$BUILDKITE_BRANCH"
echo "BUILDKITE_COMMIT=$BUILDKITE_COMMIT"
echo "VERSION=$VERSION"
echo "Supported branches:"
cat active-branches.json

dra() {
local workflow=$1
local command=$2
local qualifier=${ELASTIC_QUALIFIER:-""}
local qualifier=${3:-""}
echo "--- Run release manager $workflow (DRA command: $command)"
set -x
docker run --rm \
Expand All @@ -94,32 +73,20 @@ dra() {
--qualifier "$qualifier" \
--version $VERSION | tee rm-output.txt
set +x
# Create Buildkite annotation similarly done in Beats:
# https://github.com/elastic/beats/blob/90f9e8f6e48e76a83331f64f6c8c633ae6b31661/.buildkite/scripts/dra.sh#L74-L81
if [[ "$command" == "collect" ]]; then
# extract the summary URL from a release manager output line like:
# Report summary-18.22.0.html can be found at https://artifacts-staging.elastic.co/apm-server/18.22.0-ABCDEFGH/summary-18.22.0.html
SUMMARY_URL=$(grep -E '^Report summary-.* can be found at ' rm-output.txt | grep -oP 'https://\S+' | awk '{print $1}')
rm rm-output.txt

# and make it easily clickable as a Builkite annotation
printf "**${workflow} summary link:** [${SUMMARY_URL}](${SUMMARY_URL})\n" | buildkite-agent annotate --style=success --append
fi
create_annotation_dra_summary "$command" "$workflow" rm-output.txt
}

if [[ "${TYPE}" == "staging" ]]; then
qualifier=$(fetch_elastic_qualifier "$DRA_BRANCH")
# TODO: main and 8.x are not needed to run the DRA for staging
# but main is needed until we do alpha1 releases of 9.0.0
if [[ "${DRA_BRANCH}" != "8.x" ]]; then
echo "${DRA_BRANCH} is not '8.x'"
if [[ "${DRA_BRANCH}" == "main" ]] ; then
# NOTE: qualifier is needed for main/staging at the moment. Skip builds if no ELASTIC_QUALIFIER
if [[ -n "${ELASTIC_QUALIFIER}" ]]; then
dra "${TYPE}" "$dra_command"
fi
else
dra "${TYPE}" "$dra_command"
fi
dra "${TYPE}" "$DRA_COMMAND" "${qualifier}"
fi
else
fi

if [[ "${TYPE}" == "snapshot" ]]; then
# NOTE: qualifier is not needed for snapshots, let's unset it.
dra "snapshot" "$dra_command" ""
dra "${TYPE}" "$DRA_COMMAND" ""
fi
11 changes: 11 additions & 0 deletions .buildkite/scripts/package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,17 @@ if [[ ${TYPE} == "snapshot" ]]; then
MAKE_GOAL="${MAKE_GOAL}-snapshot"
fi

if [[ ${TYPE} == "staging" ]]; then
echo "--- Prepare the Elastic Qualifier"
# NOTE: load the shared functions
# shellcheck disable=SC1091
source .buildkite/scripts/utils.sh
dra_process_other_branches
ELASTIC_QUALIFIER=$(fetch_elastic_qualifier "$DRA_BRANCH")
export ELASTIC_QUALIFIER
fi

echo "--- Run $MAKE_GOAL for $DRA_BRANCH"
make $MAKE_GOAL

ls -l build/distributions/
80 changes: 80 additions & 0 deletions .buildkite/scripts/utils.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# An opinionated approach to manage the Elatic Qualifier for the DRA in a Google Bucket
# Instead of using the ELASTIC_QUALIFIER env variable.
fetch_elastic_qualifier() {
local branch=$1
qualifier=""
URL="https://storage.googleapis.com/dra-qualifier/$branch"
if curl -sf -o /dev/null "$URL" ; then
qualifier=$(curl -s "$URL")
fi
echo "$qualifier"
}

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
}

#
# An opinionated approach to detect if unsupported Unified Release branches
# can be used, this is handy for testing feature branches in dry-run mode
# It produces the below environment variables:
# - VERSION
# - DRA_COMMAND
# - DRA_BRANCH
dra_process_other_branches() {
## Read current version without the qualifier
VERSION=$(make get-version-only)
DRA_BRANCH="$BUILDKITE_BRANCH"
if [[ $BUILDKITE_BRANCH =~ "feature/" ]]; then
buildkite-agent annotate "${BUILDKITE_BRANCH} will list DRA artifacts. Feature branches are not supported. Look for the supported branches in ${BRANCHES_URL}" --style 'info' --context 'ctx-info'
DRA_COMMAND=list

# use a different branch since DRA does not support feature branches but main/release branches
# for such we will use the VERSION and https://storage.googleapis.com/artifacts-api/snapshots/<major.minor>.json
# to know if the branch was branched out from main or the release branches.
MAJOR_MINOR=${VERSION%.*}
if curl -s "https://storage.googleapis.com/artifacts-api/snapshots/main.json" | grep -q "$VERSION" ; then
DRA_BRANCH=main
else
if curl -s "https://storage.googleapis.com/artifacts-api/snapshots/$MAJOR_MINOR.json" | grep -q "$VERSION" ; then
DRA_BRANCH="$MAJOR_MINOR"
else
buildkite-agent annotate "It was not possible to know the original base branch for ${BUILDKITE_BRANCH}. This won't fail - this is a feature branch." --style 'info' --context 'ctx-info-feature-branch'
fi
fi
fi
export DRA_BRANCH DRA_COMMAND VERSION
}

# Create Buildkite annotation similarly done in Beats:
# https://github.com/elastic/beats/blob/90f9e8f6e48e76a83331f64f6c8c633ae6b31661/.buildkite/scripts/dra.sh#L74-L81
create_annotation_dra_summary() {
local command=$1
local workflow=$2
local output=$3
if [[ "$command" == "collect" ]]; then
# extract the summary URL from a release manager output line like:
# Report summary-18.22.0.html can be found at https://artifacts-staging.elastic.co/apm-server/18.22.0-ABCDEFGH/summary-18.22.0.html
SUMMARY_URL=$(grep -E '^Report summary-.* can be found at ' "$output" | grep -oP 'https://\S+' | awk '{print $1}')
rm "$output"

# and make it easily clickable as a Builkite annotation
printf "**${workflow} summary link:** [${SUMMARY_URL}](${SUMMARY_URL})\n" | buildkite-agent annotate --style=success --append
fi
}
14 changes: 10 additions & 4 deletions .github/workflows/benchmarks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,14 @@ on:
description: 'Set the expression that matches the benchmark scenarios to run'
required: false
type: string
pgoExport:
description: 'Run the benchmarks with PGO export'
required: false
type: boolean
default: false
schedule:
- cron: '0 17 * * *' # Scheduled regular benchmarks.
- cron: '0 5 */5 * *' # Scheduled PGO benchmarks.
- cron: '0 0 1 * *' # Scheduled PGO benchmarks.

env:
PNG_REPORT_FILE: out.png
Expand All @@ -61,10 +66,11 @@ jobs:
SSH_KEY: ./id_rsa_terraform
TF_VAR_private_key: ./id_rsa_terraform
TF_VAR_public_key: ./id_rsa_terraform.pub
TF_VAR_run_standalone: ${{ inputs.runStandalone || github.event.schedule=='0 5 */5 * *' }}
TF_VAR_run_standalone: ${{ inputs.runStandalone || github.event.schedule=='0 0 1 * *' }}
TF_VAR_apm_server_tail_sampling: ${{ inputs.enableTailSampling || 'false' }} # set the default again otherwise schedules won't work
TF_VAR_apm_server_tail_sampling_storage_limit: ${{ inputs.tailSamplingStorageLimit || '10GB' }} # set the default again otherwise schedules won't work
RUN_STANDALONE: ${{ inputs.runStandalone || github.event.schedule=='0 5 */5 * *' }}
RUN_STANDALONE: ${{ inputs.runStandalone || github.event.schedule=='0 0 1 * *' }}
PGO_EXPORT: ${{ inputs.pgoExport || github.event.schedule=='0 0 1 * *' }}
TFVARS_SOURCE: ${{ inputs.profile || 'system-profiles/8GBx1zone.tfvars' }} # // Default to use an 8gb profile
TF_VAR_BUILD_ID: ${{ github.run_id }}
TF_VAR_ENVIRONMENT: ci
Expand Down Expand Up @@ -234,7 +240,7 @@ jobs:
git_commit_gpgsign: true

- name: Open PGO PR
if: ${{ env.RUN_STANDALONE == 'true' }}
if: ${{ env.PGO_EXPORT == 'true' }}
run: ${{ github.workspace }}/.ci/scripts/push-pgo-pr.sh
env:
WORKSPACE_PATH: ${{ github.workspace }}
Expand Down
20 changes: 20 additions & 0 deletions .github/workflows/prepare-release/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ runs:
VERSION: ${{ inputs.version }}
shell: 'bash'

- name: validate version format (major only)
if: ${{ inputs.type == 'major' && ! endsWith(inputs.version, '.0.0') }}
run: |-
FAILURE_MESSAGE='version is not a major one but a patch (only support for <major>.0.0)'
echo "FAILURE_MESSAGE=${FAILURE_MESSAGE}" >> "$GITHUB_ENV"
echo "::error::${FAILURE_MESSAGE}" ; exit 1
shell: 'bash'

- name: validate version format (minor only)
if: ${{ inputs.type == 'minor' && ! endsWith(inputs.version, '0') }}
run: |-
Expand All @@ -65,6 +73,18 @@ runs:
echo "::error::${FAILURE_MESSAGE}" ; exit 1
shell: 'bash'

- name: validate if branch already exists (major only)
if: ${{ inputs.type == 'major' }}
run: |-
if git ls-remote --exit-code --heads "https://github.com/${GITHUB_REPOSITORY}.git" "$BRANCH" > /dev/null ; then
echo "FAILURE_MESSAGE=${FAILURE_MESSAGE}" >> "$GITHUB_ENV"
echo "::error::${FAILURE_MESSAGE}" ; exit 1
fi
shell: 'bash'
env:
BRANCH: ${{ steps.generate.outputs.release-branch }}
FAILURE_MESSAGE: Branch already exists. This is not a major release.

- name: validate if branch already exists (minor only)
if: ${{ inputs.type == 'minor' }}
run: |-
Expand Down
Loading

0 comments on commit 00ed67e

Please sign in to comment.