Skip to content

Commit 3818eaf

Browse files
authored
Upload safe logs (#1184)
Update safe logs to an internal Google storage bucket
1 parent 4bf0b7e commit 3818eaf

File tree

5 files changed

+88
-21
lines changed

5 files changed

+88
-21
lines changed

.buildkite/hooks/pre-command

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,15 @@ GITHUB_TOKEN_VAULT_PATH=kv/ci-shared/platform-ingest/github_token
2828
JENKINS_API_TOKEN_PATH=kv/ci-shared/platform-ingest/jenkins_api_tokens
2929
SIGNING_PACKAGES_GCS_CREDENTIALS_PATH=kv/ci-shared/platform-ingest/signing_packages_gcs_artifacts_credentials
3030
PACKAGE_UPLOADER_GCS_CREDENTIALS_PATH=kv/ci-shared/platform-ingest/package_storage_uploader
31+
PRIVATE_CI_GCS_CREDENTIALS_PATH=kv/ci-shared/platform-ingest/private_ci_artifacts_gcs_credentials
3132

3233
# Secrets must be redacted
3334
# https://buildkite.com/docs/pipelines/managing-log-output#redacted-environment-variables
3435

36+
if [[ "$BUILDKITE_PIPELINE_SLUG" == "elastic-package" && "$BUILDKITE_STEP_KEY" =~ ^integration-parallel ]]; then
37+
export PRIVATE_CI_GCS_CREDENTIALS_SECRET=$(retry 5 vault kv get -field plaintext ${PRIVATE_CI_GCS_CREDENTIALS_PATH})
38+
fi
39+
3540
if [[ "$BUILDKITE_PIPELINE_SLUG" == "elastic-package" && "$BUILDKITE_STEP_KEY" == "integration-parallel-gcp" ]]; then
3641
export ELASTIC_PACKAGE_GCP_PROJECT_SECRET=$(retry 5 vault read -field projectId ${GCP_SERVICE_ACCOUNT_SECRET_PATH})
3742
export ELASTIC_PACKAGE_GCP_CREDENTIALS_SECRET=$(retry 5 vault read -field credentials ${GCP_SERVICE_ACCOUNT_SECRET_PATH})

.buildkite/pipeline.trigger.integration.tests.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ for package in $(find . -maxdepth 1 -mindepth 1 -type d) ; do
5656
echo " - label: \":go: Running integration test: ${package_name}\""
5757
echo " key: \"integration-parallel-${package_name}\""
5858
echo " command: ./.buildkite/scripts/integration_tests.sh -t test-check-packages-parallel -p ${package_name}"
59+
echo " env:"
60+
echo " UPLOAD_SAFE_LOGS: 1"
5961
echo " agents:"
6062
echo " provider: \"gcp\""
6163
echo " artifact_paths:"

.buildkite/scripts/install_deps.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ set -euo pipefail
44

55
source .buildkite/scripts/tooling.sh
66

7+
add_bin_path(){
8+
export PATH="${WORKSPACE}/bin:${PATH}"
9+
}
10+
711
with_kubernetes() {
812
mkdir -p ${WORKSPACE}/bin
913
retry 5 curl -sSLo ${WORKSPACE}/bin/kind "https://github.com/kubernetes-sigs/kind/releases/download/${KIND_VERSION}/kind-linux-amd64"
@@ -25,6 +29,7 @@ with_go() {
2529
eval "$(gvm $(cat .go-version))"
2630
go version
2731
which go
32+
export PATH="$(go env GOPATH)/bin:${PATH}"
2833
}
2934

3035
with_docker_compose() {

.buildkite/scripts/integration_tests.sh

Lines changed: 64 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
#!/bin/bash
2-
32
set -euo pipefail
43

5-
PARALLEL_TARGET="test-check-packages-parallel"
6-
KIND_TARGET="test-check-packages-with-kind"
4+
WORKSPACE="$(pwd)"
5+
TMP_FOLDER_TEMPLATE_BASE="tmp.elastic-package"
6+
7+
cleanup() {
8+
echo "Deleting temporal files..."
9+
cd ${WORKSPACE}
10+
rm -rf "${TMP_FOLDER_TEMPLATE_BASE}.*"
11+
echo "Done."
12+
}
13+
trap cleanup EXIT
714

815
usage() {
916
echo "$0 [-t <target>] [-h]"
@@ -14,6 +21,17 @@ usage() {
1421
}
1522

1623
source .buildkite/scripts/install_deps.sh
24+
source .buildkite/scripts/tooling.sh
25+
26+
PARALLEL_TARGET="test-check-packages-parallel"
27+
KIND_TARGET="test-check-packages-with-kind"
28+
TMP_FOLDER_TEMPLATE="${TMP_FOLDER_TEMPLATE_BASE}.XXXXXXXXX"
29+
GOOGLE_CREDENTIALS_FILENAME="google-cloud-credentials.json"
30+
31+
JOB_GCS_BUCKET_INTERNAL="fleet-ci-temp-internal"
32+
33+
REPO_NAME=$(repoName "${BUILDKITE_REPO}")
34+
REPO_BUILD_TAG="${REPO_NAME}/${BUILDKITE_BUILD_NUMBER}"
1735

1836
TARGET=""
1937
PACKAGE=""
@@ -48,14 +66,39 @@ if [[ "${TARGET}" == "" ]]; then
4866
exit 1
4967
fi
5068

51-
echo "Current path: $(pwd)"
52-
WORKSPACE="$(pwd)"
53-
export PATH="${WORKSPACE}/bin:${PATH}"
54-
echo "Path: $PATH"
69+
google_cloud_auth_safe_logs() {
70+
local gsUtilLocation=$(mktemp -d -p . -t ${TMP_FOLDER_TEMPLATE})
71+
local secretFileLocation=${gsUtilLocation}/${GOOGLE_CREDENTIALS_FILENAME}
72+
73+
echo "${PRIVATE_CI_GCS_CREDENTIALS_SECRET}" > ${secretFileLocation}
74+
75+
google_cloud_auth "${secretFileLocation}"
76+
77+
echo "${gsUtilLocation}"
78+
}
79+
80+
upload_safe_logs() {
81+
local bucket="$1"
82+
local source="$2"
83+
local target="$3"
84+
85+
if ! ls ${source} 2>&1 > /dev/null ; then
86+
echo "upload_safe_logs: artifacts files not found, nothing will be archived"
87+
return
88+
fi
89+
90+
local gsUtilLocation=$(google_cloud_auth_safe_logs)
91+
92+
gsutil cp ${source} "gs://${bucket}/buildkite/${REPO_BUILD_TAG}/${target}"
93+
94+
rm -rf "${gsUtilLocation}"
95+
unset GOOGLE_APPLICATIONS_CREDENTIALS
96+
}
97+
98+
add_bin_path
5599

56100
echo "--- install go"
57101
with_go
58-
export PATH="$(go env GOPATH)/bin:${PATH}"
59102

60103
echo "--- install docker-compose"
61104
with_docker_compose
@@ -69,6 +112,19 @@ echo "--- Run integration test ${TARGET}"
69112
if [[ "${TARGET}" == "${PARALLEL_TARGET}" ]]; then
70113
make install
71114
make PACKAGE_UNDER_TEST=${PACKAGE} ${TARGET}
115+
116+
if [[ "${UPLOAD_SAFE_LOGS}" -eq 1 ]] ; then
117+
upload_safe_logs \
118+
"${JOB_GCS_BUCKET_INTERNAL}" \
119+
"build/elastic-stack-dump/check-${PACKAGE}/logs/elastic-agent-internal/*" \
120+
"insecure-logs/${PACKAGE}/"
121+
122+
upload_safe_logs \
123+
"${JOB_GCS_BUCKET_INTERNAL}" \
124+
"build/container-logs/*.log" \
125+
"insecure-logs/${PACKAGE}/container-logs/"
126+
fi
127+
make check-git-clean
72128
exit 0
73129
fi
74130

.buildkite/scripts/signAndPublishPackage.sh

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ set -euo pipefail
44
WORKSPACE="$(pwd)"
55
TMP_FOLDER_TEMPLATE_BASE="tmp.elastic-package"
66

7+
source .buildkite/scripts/install_deps.sh
8+
source .buildkite/scripts/tooling.sh
9+
710
cleanup() {
811
echo "Deleting temporal files..."
912
cd ${WORKSPACE}
@@ -13,19 +16,6 @@ cleanup() {
1316

1417
trap cleanup EXIT
1518

16-
export PATH="${WORKSPACE}/bin:${PATH}"
17-
18-
echo "Checking gsutil command..."
19-
if ! command -v gsutil &> /dev/null ; then
20-
echo "⚠️ gsutil is not installed"
21-
exit 1
22-
else
23-
echo "✅ gsutil is installed"
24-
fi
25-
26-
source .buildkite/scripts/install_deps.sh
27-
source .buildkite/scripts/tooling.sh
28-
2919
isAlreadyPublished() {
3020
local packageZip=$1
3121

@@ -37,6 +27,13 @@ isAlreadyPublished() {
3727
return 1
3828
}
3929

30+
echo "Checking gsutil command..."
31+
if ! command -v gsutil &> /dev/null ; then
32+
echo "⚠️ gsutil is not installed"
33+
exit 1
34+
fi
35+
36+
4037
REPO_NAME=$(repoName "${BUILDKITE_REPO}")
4138
BUILD_TAG="buildkite-${BUILDKITE_PIPELINE_SLUG}-${BUILDKITE_BUILD_NUMBER}"
4239

@@ -142,6 +139,8 @@ publishPackage() {
142139
rm -r "${gsUtilLocation}"
143140
}
144141

142+
add_bin_path
143+
145144
# Required to trigger Jenkins job
146145
with_go
147146

0 commit comments

Comments
 (0)