豆豆友情提示:这是一个非官方 GitHub 代理镜像,主要用于网络测试或访问加速。请勿在此进行登录、注册或处理任何敏感信息。进行这些操作请务必访问官方网站 github.com。 Raw 内容也通过此代理提供。
Skip to content

Commit 3808997

Browse files
authored
[Security Rules] Integrate security_detection_engine OOM testing pipeline (#15829)
**Partially addresses:** elastic/kibana#188090 ## Summary This PR integrates [Prebuilt Rules OOM testing Buildkite pipeline](https://buildkite.com/elastic/appex-qa-stateful-security-prebuilt-rules-ftr-oom-testing) into the Pull Request Buildkite pipeline. ## Details Pull Request Builkite pipeline script have been extended in a generic way to support custom package checker scripts located under `<repo-root>/.buildkite/scripts/packages/<package-name>.sh`. It allows to run any custom verification and testing logic specific to a package. This PR adds `.buildkite/scripts/packages/security_detection_engine.sh` script file. This script runs only for **security_detection_engine** package and triggers the [Prebuilt Rules Out-Of-Memory testing pipeline](https://buildkite.com/elastic/appex-qa-stateful-security-prebuilt-rules-ftr-oom-testing). The triggered pipeline performs e2e testing to reveal potential blockers due to Kibana Out-Of-Memory instance failures when performing actions upon the package (installing the package, review prebuilt rules available in the package, installing prebuilt rules from the package etc.). ### Tested stack versions For now `.buildkite/scripts/packages/security_detection_engine.sh` triggers [Prebuilt Rules OOM testing Buildkite pipeline](https://buildkite.com/elastic/appex-qa-stateful-security-prebuilt-rules-ftr-oom-testing) against compatible minor versions under development. The decision is made based on Kibana's [versions.json](https://github.com/raw-content/elastic/kibana/main/versions.json). While compatibility is determined via `conditions.kibana.version` field in the package's `manifest.yml`. For example `conditions.kibana.version` has `^9.2.0` restriction and we have `9.2.2` and `9.3.0` under development. It means the OOM tests will run against `9.2.2-SNAPSHOT` and `9.3.0-SNAPSHOT`. We consider extending the testing surface to the latest release patch versions after collecting more data in the CI runs. ## Affected teams @elastic/threat-research-and-detection-engineering, FYI this PR will affect **security_detection_engine** package release process. Every PR containing changes to the **security_detection_engine** package will trigger [Prebuilt Rules OOM testing ECH Buildkite pipeline](https://buildkite.com/elastic/appex-qa-stateful-security-prebuilt-rules-ftr-oom-testing). ## Further improvements - Pushing commits to this repo in a quick succession may lead to leaving rouge resources in the cloud. It happens due to `cancel_intermediate_builds: true` configuration at the Integrations PR Buildkite build. Pushing a fresh commit cancels the currently running PR build leading to cancelling the triggered build. Eventually the clean up steps in the triggered build can't execute and clean up resources in the cloud. - We may speed up the build by using an **elastic-package** Docker container published to `docker.elastic.co`. **elastic-package** installation is a complex process requiring a chain on installations GVM -> Go -> elastic-package. And it takes in average **3 minutes** per each integration (integrations build in parallel). On top of that [Prebuilt Rules OOM testing Buildkite pipeline](https://buildkite.com/elastic/appex-qa-stateful-security-prebuilt-rules-ftr-oom-testing) has to install **elastic-package** as well. It sums up to **6 minutes** which could be reduced.
1 parent 5e8fad9 commit 3808997

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://github.com/raw-content/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)