Skip to content

Commit 1c6c632

Browse files
authored
integrate security_detection_engine OOM testing pipeline (#16114)
1 parent 19f8850 commit 1c6c632

File tree

3 files changed

+91
-3
lines changed

3 files changed

+91
-3
lines changed

.buildkite/scripts/common.sh

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -728,7 +728,7 @@ is_pr_affected() {
728728
return 1
729729
fi
730730
if ! is_supported_capability ; then
731-
echo "[${package}] PR is not affected: capabilities not mached with the project (${SERVERLESS_PROJECT})"
731+
echo "[${package}] PR is not affected: capabilities not matched with the project (${SERVERLESS_PROJECT})"
732732
return 1
733733
fi
734734
if [[ "${package}" == "fleet_server" ]]; then
@@ -763,10 +763,19 @@ is_pr_affected() {
763763
# Example:
764764
# https://buildkite.com/elastic/integrations/builds/25606
765765
# https://github.com/elastic/integrations/pull/13810
766-
if git diff --name-only "${commit_merge}" "${to}" | grep -E -v '^(packages/|\.github/(CODEOWNERS|ISSUE_TEMPLATE|PULL_REQUEST_TEMPLATE|workflows/)|CODE_OF_CONDUCT\.md|README\.md|docs/|catalog-info\.yaml|\.buildkite/(pull-requests\.json|pipeline\.schedule-daily\.yml|pipeline\.schedule-weekly\.yml|pipeline\.backport\.yml))' > /dev/null; then
766+
if git diff --name-only "${commit_merge}" "${to}" | grep -E -v '^(packages/|\.github/(CODEOWNERS|ISSUE_TEMPLATE|PULL_REQUEST_TEMPLATE|workflows/)|CODE_OF_CONDUCT\.md|README\.md|docs/|catalog-info\.yaml|\.buildkite/(pull-requests\.json|pipeline\.schedule-daily\.yml|pipeline\.schedule-weekly\.yml|pipeline\.backport\.yml|scripts/packages/.+\.sh))' > /dev/null; then
767767
echo "[${package}] PR is affected: found non-package files"
768768
return 0
769769
fi
770+
echoerr "[${package}] git-diff: check custom package checker script file (${commit_merge}..${to})"
771+
# Avoid using "-q" in grep in this pipe, it could cause that some files updated are not detected due to SIGPIPE errors when "set -o pipefail"
772+
# Example:
773+
# https://buildkite.com/elastic/integrations/builds/25606
774+
# https://github.com/elastic/integrations/pull/13810
775+
if git diff --name-only "${commit_merge}" "${to}" | grep -E "^\.buildkite/scripts/packages/${package}.sh" > /dev/null; then
776+
echo "[${package}] PR is affected: found package checker script changes"
777+
return 0
778+
fi
770779
echoerr "[${package}] git-diff: check package files (${commit_merge}..${to})"
771780
# Avoid using "-q" in grep in this pipe, it could cause that some files updated are not detected due to SIGPIPE errors when "set -o pipefail"
772781
# Example:
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
5+
if [[ "${BUILDKITE_PULL_REQUEST}" == "false" ]]; then
6+
exit 0
7+
fi
8+
9+
# Fetch active Kibana versions
10+
ACTIVE_KIBANA_VERSIONS=$(curl -sL https://raw.githubusercontent.com/elastic/kibana/main/versions.json | yq '.versions[].version' | xargs)
11+
echo "Active Kibana versions: $ACTIVE_KIBANA_VERSIONS"
12+
13+
# Extract version spec from the manifest
14+
KIBANA_REQ=$(yq .conditions.kibana.version ./packages/security_detection_engine/manifest.yml)
15+
echo "Kibana requirement from the security_detection_engine manifest: $KIBANA_REQ"
16+
17+
# Dump a trivial Go program to filter by semver constrains
18+
TEMP_DIR=$(mktemp -d)
19+
SEMVER_FILTER_PATH="$TEMP_DIR/semver.go"
20+
21+
cat <<'GO' > "$SEMVER_FILTER_PATH"
22+
package main
23+
24+
import (
25+
"strings"
26+
"fmt"
27+
"os"
28+
"github.com/Masterminds/semver/v3"
29+
)
30+
31+
func main() {
32+
c, err := semver.NewConstraint(os.Args[1])
33+
if err != nil {
34+
panic(err)
35+
}
36+
37+
for _, s := range strings.Split(os.Args[2], " ") {
38+
if v, _ := semver.NewVersion(s); c.Check(v) {
39+
fmt.Println(s + "-SNAPSHOT")
40+
}
41+
}
42+
}
43+
GO
44+
45+
# Capture the "returned" array in STACK_VERSIONS
46+
read -r -a STACK_VERSIONS <<< "$(go run "${SEMVER_FILTER_PATH}" "${KIBANA_REQ}" "${ACTIVE_KIBANA_VERSIONS}" | xargs)"
47+
48+
if [[ ! -n "${STACK_VERSIONS+x}" ]]; then
49+
echo "There are no active versions satisfying the constraint ${KIBANA_REQ}."
50+
exit 0
51+
fi
52+
53+
# Trigger OOM testing pipeline for each stack version
54+
for STACK_VERSION in "${STACK_VERSIONS[@]}"
55+
do
56+
echo "--- [security_detection_engine] Trigger OOM testing pipeline against $STACK_VERSION ECH"
57+
58+
cat <<YAML | buildkite-agent pipeline upload
59+
steps:
60+
- key: 'run-oom-testing-$(echo "$STACK_VERSION" | sed 's/\./_/g')$BUILDKITE_BUILD_NUMBER'
61+
label: ":elastic-cloud::bar_chart: [security_detection_engine] Test for OOM issues against $STACK_VERSION ECH"
62+
trigger: "appex-qa-stateful-security-prebuilt-rules-ftr-oom-testing"
63+
async: false
64+
build:
65+
message: "Test security_detection_engine package against $STACK_VERSION ($GITHUB_PR_BASE_OWNER/$GITHUB_PR_BASE_REPO, branch: $GITHUB_PR_BRANCH, commit: $BUILDKITE_COMMIT)"
66+
env:
67+
STACK_VERSION: $STACK_VERSION
68+
ELASTIC_INTEGRATIONS_REPO_COMMIT: $BUILDKITE_COMMIT
69+
YAML
70+
done

.buildkite/scripts/test_one_package.sh

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,13 @@ if ! process_package "${package}" ; then
3535
fi
3636
popd > /dev/null
3737

38-
exit "${exit_code}"
38+
if [ "${exit_code}" -ne 0 ] ; then
39+
exit "${exit_code}"
40+
fi
41+
42+
custom_package_checker_script_path="${SCRIPTS_BUILDKITE_PATH}/packages/${package}.sh"
43+
44+
if [ -x "$custom_package_checker_script_path" ]; then
45+
echo "--- [${package}] Run individual package checker"
46+
"$custom_package_checker_script_path"
47+
fi

0 commit comments

Comments
 (0)