Skip to content

Commit b0de9e8

Browse files
authored
feat: live logs (#12271)
We publish denoise logs to redis every 5s.
1 parent 52ae8cc commit b0de9e8

File tree

3 files changed

+34
-21
lines changed

3 files changed

+34
-21
lines changed

ci3/denoise

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@ if [ "$#" != 1 ]; then
88
exit 1
99
fi
1010

11+
cmd=$1
12+
1113
if [[ "${DENOISE:-0}" -eq 0 ]] || [[ "${BUILD_SYSTEM_DEBUG:-0}" -eq 1 ]]; then
1214
set -e
13-
bash -c "$1"
15+
bash -c "$cmd"
1416
exit 0
1517
fi
1618

@@ -25,15 +27,39 @@ export FORCE_COLOR=${FORCE_COLOR:-1}
2527
[ -t 1 ] && realtime=1 || realtime=0
2628

2729
key=$(uuid)
30+
url=http://ci.aztec-labs.com/$key
2831
outfile=/tmp/$key
2932
trap 'rm -f $outfile' EXIT
3033
touch $outfile
3134

35+
function publish_log {
36+
if [ "$CI_REDIS_AVAILABLE" -eq 0 ]; then
37+
return
38+
fi
39+
40+
{
41+
echo -e "Command: $cmd (exit: $status)\n"
42+
cat $outfile
43+
} | redis_setexz $key $CI_REDIS_EXPIRE
44+
}
45+
46+
function live_publish_log {
47+
while [ -f $outfile ]; do
48+
publish_log
49+
sleep 5
50+
done
51+
}
52+
53+
if [ "$CI_REDIS_AVAILABLE" -eq 1 ]; then
54+
live_publish_log &
55+
log_info="(${yellow}${url}${reset})"
56+
fi
57+
3258
# Execute the command and process the output, allow for errors.
3359
set +e
34-
echo -e "Executing: $1 (${yellow}ci llog $key${reset})"
60+
echo -e "Executing: $cmd ${log_info:-}"
3561
echo -n " 0 "
36-
bash -c "$1" 2>&1 | while IFS= read -r line; do
62+
bash -c "$cmd" 2>&1 | while IFS= read -r line; do
3763
((dot_count++))
3864
[ $realtime -eq 1 ] && printf "."
3965
if [[ "$dots_per_line" -gt 0 && $((dot_count % dots_per_line)) -eq 0 ]]; then
@@ -45,26 +71,15 @@ done;
4571
# Get the exit status of the command
4672
status=${PIPESTATUS[0]}
4773

48-
if [ "$CI_REDIS_AVAILABLE" -eq 1 ]; then
49-
{
50-
echo "Command: $1 (exit: $status)"
51-
cat $outfile
52-
} | redis_setexz $key $CI_REDIS_EXPIRE
53-
fi
74+
publish_log
5475

5576
# Handle non-zero exit status
5677
if [ "$status" -ne 0 ]; then
5778
echo -e "\nCommand exited with status $status. Dumping output:"
5879
cat $outfile
59-
echo -e -n ". ${red}failed${reset} (${SECONDS}s)"
80+
echo -e ". ${red}failed${reset} (${SECONDS}s) ${log_info:-}"
6081
else
61-
echo -e -n ". ${green}done${reset} (${SECONDS}s)"
62-
fi
63-
64-
if [ "$CI_REDIS_AVAILABLE" -eq 1 ]; then
65-
url=http://ci.aztec-labs.com/$key
66-
echo -e -n " (${yellow}${url}${reset})"
82+
echo -e ". ${green}done${reset} (${SECONDS}s)"
6783
fi
68-
echo
6984

7085
exit $status

ci3/parallelise

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@ if [ -t 1 ]; then
2222
fi
2323
set -e
2424
else
25-
# TODO: Reinstate once better live logging.
26-
# denoise "parallel $parallel_args 'run_test_cmd {}'"
27-
parallel $parallel_args 'run_test_cmd {}'
25+
denoise "parallel $parallel_args 'run_test_cmd {}'"
2826
fi
2927

3028
slow_jobs=$(cat joblog.txt | \

ci3/source_redis

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Declare CI_REDIS host, allowing override.
44
export CI_REDIS=${CI_REDIS:-localhost}
55

6-
# If we haven't yet checked for redis availablility.
6+
# If we haven't yet checked for redis availability.
77
if [ -z "${CI_REDIS_AVAILABLE:-}" ]; then
88
# Start by setting it as not available.
99
export CI_REDIS_AVAILABLE=0

0 commit comments

Comments
 (0)