Skip to content

Commit 083ce78

Browse files
switch to stern for log collection. Also tar.gz the file (#16167)
* use stern for capturing logs * Update test/e2e-common.sh Co-authored-by: Nader Ziada <[email protected]> * don't mkdir -p on every logline --------- Co-authored-by: Nader Ziada <[email protected]>
1 parent 95dd834 commit 083ce78

File tree

5 files changed

+52
-22
lines changed

5 files changed

+52
-22
lines changed

test/e2e-common.sh

Lines changed: 52 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ export YTT_FILES=()
4949
export TMP_DIR="${TMP_DIR:-$(mktemp -d -t ci-$(date +%Y-%m-%d-%H-%M-%S)-XXXXXXXXXX)}"
5050

5151
readonly E2E_YAML_DIR=${E2E_YAML_DIR:-"${TMP_DIR}/e2e-yaml"}
52+
readonly STERN_PID_FILE=${TMP_DIR}/stern.pid
5253

5354
# This the namespace used to install Knative Serving. Use generated UUID as namespace.
5455
export SYSTEM_NAMESPACE="${SYSTEM_NAMESPACE:-$(uuidgen | tr 'A-Z' 'a-z')}"
@@ -422,21 +423,59 @@ function knative_teardown() {
422423

423424
# Create test resources and images
424425
function test_setup() {
426+
echo ">> Uploading test images..."
427+
${REPO_ROOT_DIR}/test/upload-test-images.sh || return 1
428+
425429
echo ">> Setting up logging..."
426430

427-
# Install kail if needed.
428-
if ! which kail > /dev/null; then
429-
go install github.com/boz/kail/cmd/[email protected]
431+
# Install stern if needed.
432+
if ! which stern > /dev/null; then
433+
go install github.com/stern/[email protected]
430434
fi
431435

436+
mkdir -p $(log_dir)
437+
432438
# Capture all logs.
433-
kail > "${ARTIFACTS}/k8s.log-$(basename "${E2E_SCRIPT}").txt" &
434-
local kail_pid=$!
435-
# Clean up kail so it doesn't interfere with job shutting down
436-
add_trap "kill $kail_pid || true" EXIT
439+
# We use stdbuf so that when we pipe logs to awk it flushes to the file
440+
stdbuf -oL stern . --all-namespaces --timestamps --max-log-requests 2000 2> "$(log_dir)/stern.stderr.log" | \
441+
stdbuf -oL awk -v logdir="$(log_dir)" '
442+
{
443+
ns=$1;
444+
pod=$2;
437445
438-
echo ">> Uploading test images..."
439-
${REPO_ROOT_DIR}/test/upload-test-images.sh || return 1
446+
gsub("/", "_", ns);
447+
gsub("/", "_", pod);
448+
449+
dir = logdir "/" ns
450+
451+
if (!(dir in seen_dirs)) {
452+
if (system("[ -d \"" dir "\" ] || mkdir -p \"" dir "\"") != 0) {
453+
print "Failed to create dir:", dir > "/dev/stderr"
454+
}
455+
seen_dirs[dir] = 1
456+
}
457+
458+
print $0 >> (logdir "/" ns "/" pod ".log");
459+
fflush(logdir "/" ns "/" pod ".log");
460+
}' &
461+
462+
echo $! > ${STERN_PID_FILE}
463+
464+
# Clean up stern so it doesn't interfere with job shutting down
465+
add_trap "stop_logging" EXIT SIGTERM
466+
}
467+
468+
function stop_logging() {
469+
kill $(cat ${STERN_PID_FILE})
470+
471+
pushd "$(dirname $(log_dir))"
472+
tar -czf "$(basename $(log_dir)).tar.gz" "$(basename $(log_dir))"
473+
rm -rf "$(basename $(log_dir))"
474+
popd
475+
}
476+
477+
function log_dir() {
478+
echo "${ARTIFACTS}/log-$(basename "${E2E_SCRIPT}" .sh)"
440479
}
441480

442481
# Dump more information when test fails.
@@ -635,3 +674,7 @@ function run_ytt() {
635674
function run_kapp() {
636675
go_run github.com/vmware-tanzu/carvel-kapp/cmd/[email protected] "$@"
637676
}
677+
678+
function on_success() {
679+
rm "${ARTIFACTS}"/log-*
680+
}

test/e2e-external-domain-tls-tests.sh

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,4 @@ fi
211211
subheader "Cleanup external domain tls"
212212
cleanup_external_domain_tls_common
213213

214-
# Remove the kail log file if the test flow passes.
215-
# This is for preventing too many large log files to be uploaded to GCS in CI.
216-
rm "${ARTIFACTS}/k8s.log-$(basename "${E2E_SCRIPT}").txt"
217214
success

test/e2e-tests.sh

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,4 @@ fi
170170

171171
(( failed )) && fail_test
172172

173-
# Remove the kail log file if the test flow passes.
174-
# This is for preventing too many large log files to be uploaded to GCS in CI.
175-
rm "${ARTIFACTS}/k8s.log-$(basename "${E2E_SCRIPT}").txt"
176-
177173
success

test/e2e-upgrade-tests.sh

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,4 @@ go_test_e2e -tags=upgrade -timeout=${TIMEOUT} \
5454
--disable-logstream \
5555
--resolvabledomain=$(use_resolvable_domain) || fail_test
5656

57-
# Remove the kail log file if the test flow passes.
58-
# This is for preventing too many large log files to be uploaded to GCS in CI.
59-
rm "${ARTIFACTS}/k8s.log-$(basename "${E2E_SCRIPT}").txt"
6057
success

test/presubmit-tests.sh

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@
2121
# Use the flags --build-tests, --unit-tests and --integration-tests
2222
# to run a specific set of tests.
2323

24-
export GO111MODULE=on
25-
export GOFLAGS=-mod=vendor
26-
2724
source $(dirname $0)/../vendor/knative.dev/hack/presubmit-tests.sh
2825

2926
# We use the default build, unit and integration test runners.

0 commit comments

Comments
 (0)