Skip to content

Commit

Permalink
[yugabyte#13000] Rewrite test logs for better readability
Browse files Browse the repository at this point in the history
Summary:
Replacing tablet ids with something like `{mytable_tablet_id1}`
Replacing peer ids with something like `{m1_peer_id}`.
Also replacing some directories, such as `${YB_SRC_ROOT}`, `${BUILD_ROOT}`, and `${TEST_TMPDIR}`.
The list of substitutions is appended to the end of the log.
The rewriter script is implemented as a Python script that calls out to egrep and perl. Perl turned out to be better than sed and awk for straightforward replacement of multiple regular expressions.

To avoid rewriting the test log, specify the --skip-test-log-rewrite option to yb_build.sh, or set the YB_SKIP_TEST_LOG_REWRITE environment variable to 1.

Also rearranging the usage instructions in yb_build.sh to group options into categories better.

Test Plan: Jenkins

Reviewers: odeshmukh, steve.varnau

Reviewed By: steve.varnau

Subscribers: jason, ybase

Differential Revision: https://phabricator.dev.yugabyte.com/D17899
  • Loading branch information
mbautin committed Jul 8, 2022
1 parent d658df2 commit 75aa57f
Show file tree
Hide file tree
Showing 11 changed files with 1,636 additions and 38 deletions.
3 changes: 2 additions & 1 deletion .arclint
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"(^managed/src/main/public/swagger-ui/)",
"(^managed/src/main/resources/swagger.json$)",
"(^managed/build.sbt$)",
"(^managed/src/main/resources/aws_pricing/.*$)"
"(^managed/src/main/resources/aws_pricing/.*$)",
"(^python/yb/test_data/.*[.](log|out)$)"
],
"linters": {
"script-and-regex.script": {
Expand Down
1 change: 0 additions & 1 deletion build-support/common-build-env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1241,7 +1241,6 @@ download_toolchain() {
if [[ -z ${YB_LLVM_TOOLCHAIN_URL:-} &&
${YB_COMPILER_TYPE:-} =~ ^clang[0-9]+$ ]] && is_linux; then
YB_LLVM_TOOLCHAIN_URL=$(
activate_virtualenv;
python3 -m llvm_installer --print-url --llvm-major-version=${YB_COMPILER_TYPE#clang}
)
if [[ ${YB_LLVM_TOOLCHAIN_URL} != https://* ]]; then
Expand Down
34 changes: 31 additions & 3 deletions build-support/common-test-env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -909,7 +909,7 @@ run_one_cxx_test() {
try_set_ulimited_ulimit

if is_ctest_verbose; then
( set -x; "${test_wrapper_cmd_line[@]}" 2>&1 ) | tee "$test_log_path"
( set -x; "${test_wrapper_cmd_line[@]}" 2>&1 ) | tee "${test_log_path}"
# Propagate the exit code of the test process, not any of the filters. This will only exit
# this subshell, not the entire script calling this function.
exit "${PIPESTATUS[0]}"
Expand All @@ -921,7 +921,7 @@ run_one_cxx_test() {
set -e

# Useful for distributed builds in an NFS environment.
chmod g+w "$test_log_path"
chmod g+w "${test_log_path}"

# Test did not fail, no need to retry.
if [[ $test_exit_code -eq 0 ]]; then
Expand Down Expand Up @@ -964,6 +964,7 @@ handle_cxx_test_failure() {

if "$test_failed"; then
(
rewrite_test_log "${test_log_path}"
echo
echo "TEST FAILURE"
echo "Test command: ${test_cmd_line[*]}"
Expand Down Expand Up @@ -1020,10 +1021,34 @@ run_postproces_test_result_script() {
--fatal-details-path-prefix "$YB_FATAL_DETAILS_PATH_PREFIX"
)
fi
"$VIRTUAL_ENV/bin/python" "$YB_SRC_ROOT/python/yb/postprocess_test_result.py" \
"$VIRTUAL_ENV/bin/python" "${YB_SRC_ROOT}/python/yb/postprocess_test_result.py" \
"${args[@]}" "$@"
}

rewrite_test_log() {
expect_num_args 1 "$@"
if [[ ${YB_SKIP_TEST_LOG_REWRITE:-} == "1" ]]; then
return
fi
local test_log_path=$1
set +e
(
# TODO: we should just set PYTHONPATH globally, e.g. at the time we activate virtualenv.
set_pythonpath
"${VIRTUAL_ENV}/bin/python" "${YB_SRC_ROOT}/python/yb/rewrite_test_log.py" \
--input-log-path "${test_log_path}" \
--replace-original \
--yb-src-root "${YB_SRC_ROOT}" \
--build-root "${BUILD_ROOT}" \
--test-tmpdir "${TEST_TMPDIR}"
)
local exit_code=$?
set -e
if [[ ${exit_code} -ne 0 ]]; then
log "Test log rewrite script failed with exit code ${exit_code}"
fi
}

run_cxx_test_and_process_results() {
run_one_cxx_test
handle_cxx_test_failure
Expand Down Expand Up @@ -1716,6 +1741,9 @@ run_java_test() {
fi
fi

if [[ -f ${test_log_path} ]]; then
rewrite_test_log "${test_log_path}"
fi
if should_gzip_test_logs; then
gzip_if_exists "$test_log_path" "$mvn_output_path"
local per_test_method_log_path
Expand Down
1 change: 1 addition & 0 deletions codecheck.ini
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,6 @@ included_regex_list =
^python/yb/postprocess_test_result[.]py$
^python/yb/test_postprocess_test_result[.]py$
^python/yb/remote[.]py$
^python/yb/rewrite_test_log[.]py$
^bin/remote_build[.]py$
^bin/remote_release[.]py$
2 changes: 1 addition & 1 deletion python/yb/postprocess_test_result.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3

# Copyright (c) Yugabyte, Inc.
#
Expand Down
Loading

0 comments on commit 75aa57f

Please sign in to comment.