Skip to content

Commit 0d54fa1

Browse files
committed
integrate security_detection_engine OOM testing pipeline
1 parent bc50f1f commit 0d54fa1

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
@@ -655,7 +655,7 @@ is_pr_affected() {
655655
return 1
656656
fi
657657
if ! is_supported_capability ; then
658-
echo "[${package}] PR is not affected: capabilities not mached with the project (${SERVERLESS_PROJECT})"
658+
echo "[${package}] PR is not affected: capabilities not matched with the project (${SERVERLESS_PROJECT})"
659659
return 1
660660
fi
661661
fi
@@ -680,10 +680,19 @@ is_pr_affected() {
680680
# Example:
681681
# https://buildkite.com/elastic/integrations/builds/25606
682682
# https://github.com/elastic/integrations/pull/13810
683-
if git diff --name-only "${commit_merge}" "${to}" | grep -E -v '^(packages/|\.github/(CODEOWNERS|ISSUE_TEMPLATE|PULL_REQUEST_TEMPLATE)|README\.md|docs/)' ; then
683+
if git diff --name-only "${commit_merge}" "${to}" | grep -E -v '^(packages/|\.github/(CODEOWNERS|ISSUE_TEMPLATE|PULL_REQUEST_TEMPLATE)|README\.md|docs/|scripts/packages/.+\.sh)' ; then
684684
echo "[${package}] PR is affected: found non-package files"
685685
return 0
686686
fi
687+
echoerr "[${package}] git-diff: check custom package checker script file (${commit_merge}..${to})"
688+
# 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"
689+
# Example:
690+
# https://buildkite.com/elastic/integrations/builds/25606
691+
# https://github.com/elastic/integrations/pull/13810
692+
if git diff --name-only "${commit_merge}" "${to}" | grep -E "^\.buildkite/scripts/packages/${package}.sh" > /dev/null; then
693+
echo "[${package}] PR is affected: found package checker script changes"
694+
return 0
695+
fi
687696
echo "[${package}] git-diff: check package files"
688697
# 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"
689698
# 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
@@ -42,4 +42,13 @@ if ! process_package "${package}" "${from}" "${to}"; then
4242
fi
4343
popd > /dev/null
4444

45-
exit "${exit_code}"
45+
if [ "${exit_code}" -ne 0 ] ; then
46+
exit "${exit_code}"
47+
fi
48+
49+
custom_package_checker_script_path="${SCRIPTS_BUILDKITE_PATH}/packages/${package}.sh"
50+
51+
if [ -x "$custom_package_checker_script_path" ]; then
52+
echo "--- [${package}] Run individual package checker"
53+
"$custom_package_checker_script_path"
54+
fi

0 commit comments

Comments
 (0)