Skip to content

Commit 1680efa

Browse files
authored
Merge pull request #4367 from esl/compress-logs-on-s3-ct
Optimize (compress) ct_report logs on CI and read them using a service worker in Browser This PR addresses MIM-2283 "Optimize (compress) ct_report logs somehow on CI" Proposed changes include: Compress files into tar.gz. We use https://github.com/esl/html-zip-reader to read the archive and serve it using a service worker. The logic for the service worker could be reviewed in this PR: esl/html-zip-reader#1 We can maybe stop using s3-parallel-put (unless it is smaller than awscli tools). But in a separate PR :)
2 parents 0ee4c89 + 3fea460 commit 1680efa

11 files changed

+102
-179
lines changed

Diff for: .circleci/template.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ commands:
310310
name: Upload results
311311
when: always
312312
command: |
313-
tools/circleci-prepare-log-dir.sh
313+
tools/prepare-log-dir.sh
314314
if [ -n "${AWS_SECRET_ACCESS_KEY}" ]; then tools/circleci-upload-to-s3.sh; fi
315315
report_failed_test_cases_to_ga4:
316316
steps:

Diff for: tools/circle-publish-github-comment.sh

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env bash
22

3-
source tools/circleci-helpers.sh
3+
source tools/helpers.sh
44

55
set -e
66

@@ -72,7 +72,7 @@ function rewrite_log_links_to_s3
7272
local CT_REPORT=big_tests/ct_report
7373
local CT_REPORT_ABS=$(./tools/abs_dirpath.sh "$CT_REPORT")
7474
local CT_REPORTS=$(ct_reports_dir)
75-
local BIG_TESTS_URL="$(direct_s3_url ${CT_REPORTS})/big"
75+
local BIG_TESTS_URL="$(archive_reader_url big ${CT_REPORTS})"
7676
cp /tmp/ct_markdown /tmp/ct_markdown_original
7777
replace_string "$CT_REPORT_ABS" "$BIG_TESTS_URL" /tmp/ct_markdown
7878
# URL escape for s3_reports.html script
@@ -97,15 +97,15 @@ function small_suite_path
9797
function ct_run_url
9898
{
9999
local CT_REPORTS=$(ct_reports_dir)
100-
local BIG_TESTS_URL="$(direct_s3_url ${CT_REPORTS})/big"
100+
local BIG_TESTS_URL="$(archive_reader_url big ${CT_REPORTS})"
101101
local RUN_PART=$(echo "$(last_ct_run_name)" | sed "s/@/%40/g")
102102
echo "$BIG_TESTS_URL/$RUN_PART/index.html"
103103
}
104104

105105
function ct_small_url
106106
{
107107
local CT_REPORTS=$(ct_reports_dir)
108-
local SMALL_TESTS_URL="$(direct_s3_url ${CT_REPORTS})/small"
108+
local SMALL_TESTS_URL="$(archive_reader_url small ${CT_REPORTS})"
109109
local SUFFIX=$(small_suite_path)
110110
echo "$SMALL_TESTS_URL/$SUFFIX"
111111
}

Diff for: tools/circleci-helpers.sh

-32
This file was deleted.

Diff for: tools/circleci-prepare-log-dir.sh

-64
This file was deleted.

Diff for: tools/circleci-upload-to-s3.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22

3-
source tools/circleci-helpers.sh
3+
source tools/helpers.sh
44

55
set -euo pipefail
66

Diff for: tools/gh-upload-to-s3.sh

+2
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,6 @@ prefix="GH/${GITHUB_RUN_ID}/${GITHUB_RUN_ATTEMPT}/${PRESET}.${RANDOM}/${dest_dir
2929
echo "directory '${dir}' is uploaded here:"
3030
echo " https://esl.github.io/circleci-mim-results/s3_reports.html?prefix=${prefix}"
3131

32+
# TODO: add links for tar.gz viewers
33+
3234
time aws s3 cp "$dir" s3://circleci-mim-results/"${prefix}" --acl public-read --recursive --quiet

Diff for: tools/helpers.sh

+38-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,31 @@
11
ct_reports_dir() {
2+
if [[ "$CIRCLECI" == true ]]; then
3+
ct_reports_dir_circleci
4+
else
5+
ct_reports_dir_github
6+
fi
7+
}
8+
9+
ct_reports_dir_circleci() {
10+
local BUILD_NO=${CIRCLE_BUILD_NUM:-ct_reports}
11+
local PRESET_NAME=${PRESET:-default}
12+
OTP_VERSION=`cat otp_version`
13+
local ERLANG=${OTP_VERSION:-default}
14+
local CT_REPORTS="${BUILD_NO}/${PRESET_NAME}.${ERLANG}"
15+
local BRANCH=${CIRCLE_BRANCH:-master}
16+
PR_NUM=`basename $CI_PULL_REQUEST`
17+
local PR=${PR_NUM:-false}
18+
19+
20+
if [ ${PR} == false ]; then
21+
echo "branch/${BRANCH}/${CT_REPORTS}"
22+
else
23+
echo "PR/${PR}/${CT_REPORTS}"
24+
fi
25+
}
26+
27+
ct_reports_dir_github() {
28+
# Note, that tools/gh-upload-to-s3.sh uploads to a different random prefix
229
local BUILD_NO=${GITHUB_RUN_NUMBER:-ct_reports}
330
local PRESET_NAME=${PRESET:-default}
431
# @TODO CI:
@@ -13,21 +40,27 @@ ct_reports_dir() {
1340
local PR=${CI_PULL_REQUEST:-false}
1441

1542
if [ ${PR} == false ]; then
16-
echo "branch/${BRANCH}/${CT_REPORTS}"
43+
echo "branch/${BRANCH}/${CT_REPORTS}"
1744
else
18-
echo "PR/${PR}/${CT_REPORTS}"
45+
echo "PR/${PR}/${CT_REPORTS}"
1946
fi
20-
2147
}
2248

2349
# Works for directories only
2450
# Allows to list directories content
51+
2552
s3_url() {
2653
local CT_REPORTS=${1:-}
27-
echo "http://esl.github.io/mongooseim-ct-reports/s3_reports.html?prefix=${CT_REPORTS}"
54+
echo "http://esl.github.io/circleci-mim-results/s3_reports.html?prefix=${CT_REPORTS}"
2855
}
2956

3057
direct_s3_url() {
3158
local CT_REPORTS=${1:-}
32-
echo "https://mongooseim-ct-results.s3-eu-west-1.amazonaws.com/${CT_REPORTS}"
59+
echo "https://circleci-mim-results.s3.eu-central-1.amazonaws.com/${CT_REPORTS}"
60+
}
61+
62+
archive_reader_url() {
63+
local TEST_TYPE=$1
64+
local CT_REPORTS=${2:-}
65+
echo "https://esl.github.io/html-zip-reader/${CT_REPORTS}/${TEST_TYPE}.tar.gz/"
3366
}

Diff for: tools/prepare-log-dir.sh

+50-27
Original file line numberDiff line numberDiff line change
@@ -2,41 +2,64 @@
22

33
source tools/helpers.sh
44

5+
REPO_DIR=$(pwd)
6+
57
set -euo pipefail
68
IFS=$'\n\t'
79

10+
# Relative directory name
811
CT_REPORTS=$(ct_reports_dir)
9-
mkdir -p ${CT_REPORTS}/small
10-
mkdir -p ${CT_REPORTS}/big
11-
12-
if [ -d _build/test/logs ]; then
13-
cp -Rp _build/test/logs/* ${CT_REPORTS}/small
14-
fi
15-
16-
CT_REPORT=big_tests/ct_report
17-
18-
if [ -d ${CT_REPORT} ] && [ "$(ls -A ${CT_REPORT})" ]; then
19-
cp -Rp ${CT_REPORT}/* ${CT_REPORTS}/big
20-
fi
21-
22-
cat > ${CT_REPORTS}/index.html << EOL
23-
<html>
24-
<head></head>
25-
<body>
26-
<p><a href="small/index.html">Small tests (test/)</a></p>
27-
<p><a href="big/index.html">Big tests (big_tests/)</a></p>
28-
</body>
29-
</html>
30-
EOL
12+
mkdir -p "$CT_REPORTS"
13+
CT_REPORTS_FULL=$(cd "$CT_REPORTS" && pwd)
3114

3215
now=`date +'%Y-%m-%d_%H.%M.%S'`
33-
LOG_DIR_ROOT=${CT_REPORTS}/logs/${now}
16+
# Replace all occurrences of / with _
17+
PREFIX="${CT_REPORTS//\//_}"
18+
19+
# Optimize naming, so it is easy to extract on MacOS just by clicking it
20+
# and with reasonable directory names
21+
LOG_DIR_ROOT=${CT_REPORTS}/logs/${PREFIX}_${now}
22+
LOG_ZIP=${CT_REPORTS_FULL}/logs_${PREFIX}_${now}.tar.gz
3423
for dev_node_logs_path in `find _build -name log -type d`; do
3524
dev_node=$(basename $(dirname $(dirname $(dirname ${dev_node_logs_path}))))
36-
LOG_DIR=${LOG_DIR_ROOT}/${dev_node}/log
25+
LOG_DIR=${LOG_DIR_ROOT}/${dev_node}/
3726
mkdir -p ${LOG_DIR}
38-
cp ${dev_node_logs_path}/* ${LOG_DIR}
27+
mv ${dev_node_logs_path}/* ${LOG_DIR}
3928
done
4029

41-
cp *.log ${LOG_DIR_ROOT}
42-
cp big_tests/*.log ${LOG_DIR_ROOT}
30+
mv *.log ${LOG_DIR_ROOT}
31+
mv big_tests/*.log ${LOG_DIR_ROOT} || true
32+
33+
# cd so we don't include nested dirs in the archive (for example, PR/4366/236412)
34+
cd "$LOG_DIR_ROOT/.."
35+
36+
# Zip to safe space
37+
tar -czf "$LOG_ZIP" "$(basename "$LOG_DIR_ROOT")"
38+
39+
cd "$REPO_DIR"
40+
41+
# Slightly faster than removing
42+
mv "$LOG_DIR_ROOT" /tmp/
43+
44+
# Compress big ct_reports
45+
BIG_REPORTS_DIR="$(pwd)/big_tests/ct_report"
46+
SMALL_REPORTS_DIR="$(pwd)/_build/test/logs"
47+
48+
if [ -f ${BIG_REPORTS_DIR}/index.html ]; then
49+
cd ${BIG_REPORTS_DIR}
50+
# Ignore GDPR extracted logs
51+
# They are primarily empty files
52+
tar \
53+
--exclude='./ct_run*/*.logs/last_link.html' \
54+
--exclude='./ct_run*/*.logs/last_name' \
55+
--exclude='./ct_run*/*.unzipped' \
56+
-czf "${CT_REPORTS_FULL}/big.tar.gz" .
57+
fi
58+
59+
if [ -f ${SMALL_REPORTS_DIR}/index.html ]; then
60+
cd ${SMALL_REPORTS_DIR}
61+
tar \
62+
--exclude='./ct_run*/*.logs/last_link.html' \
63+
--exclude='./ct_run*/*.logs/last_name' \
64+
-czf "${CT_REPORTS_FULL}/small.tar.gz" .
65+
fi

Diff for: tools/publish-github-comment.sh

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#!/usr/bin/env bash
22

3+
# TODO: publish comment with errors to a separate dedicated issue on GitHub,
4+
# if Github Actions fails
5+
36
source tools/helpers.sh
47

58
set -e
@@ -67,7 +70,7 @@ function rewrite_log_links_to_s3
6770
local CT_REPORT=big_tests/ct_report
6871
local CT_REPORT_ABS=$(./tools/abs_dirpath.sh "$CT_REPORT")
6972
local CT_REPORTS=$(ct_reports_dir)
70-
local BIG_TESTS_URL="$(direct_s3_url ${CT_REPORTS})/big"
73+
local BIG_TESTS_URL="$(archive_reader_url big ${CT_REPORTS})"
7174
cp /tmp/ct_markdown /tmp/ct_markdown_original
7275
replace_string "$CT_REPORT_ABS" "$BIG_TESTS_URL" /tmp/ct_markdown
7376
# URL escape for s3_reports.html script
@@ -92,15 +95,15 @@ function small_suite_path
9295
function ct_run_url
9396
{
9497
local CT_REPORTS=$(ct_reports_dir)
95-
local BIG_TESTS_URL="$(direct_s3_url ${CT_REPORTS})/big"
98+
local BIG_TESTS_URL="$(archive_reader_url big ${CT_REPORTS})"
9699
local RUN_PART=$(echo "$(last_ct_run_name)" | sed "s/@/%40/g")
97100
echo "$BIG_TESTS_URL/$RUN_PART/index.html"
98101
}
99102

100103
function ct_small_url
101104
{
102105
local CT_REPORTS=$(ct_reports_dir)
103-
local SMALL_TESTS_URL="$(direct_s3_url ${CT_REPORTS})/small"
106+
local SMALL_TESTS_URL="$(archive_reader_url small ${CT_REPORTS})"
104107
local SUFFIX=$(small_suite_path)
105108
echo "$SMALL_TESTS_URL/$SUFFIX"
106109
}

Diff for: tools/test.sh

-5
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,7 @@ while getopts ":p:s:e:c:h:" opt; do
4646
done
4747

4848
source tools/common-vars.sh
49-
50-
if [ ${CIRCLECI} ]; then
51-
source tools/circleci-helpers.sh
52-
else
5349
source tools/helpers.sh
54-
fi
5550

5651
if [ "${AWS_SECRET_ACCESS_KEY}" ]; then
5752
CT_REPORTS=$(ct_reports_dir)

0 commit comments

Comments
 (0)