monitoring: richer colour for ok/info/warn/error lines
This commit is contained in:
parent
d6f4f649c1
commit
3d4e883cdb
1 changed files with 53 additions and 49 deletions
|
|
@ -352,17 +352,19 @@ koopa_ssh_python() {
|
||||||
with_timeout "$t" ssh "${SSH_BASE_OPTS[@]}" "${KOOPA_SSH}" python3 -
|
with_timeout "$t" ssh "${SSH_BASE_OPTS[@]}" "${KOOPA_SSH}" python3 -
|
||||||
}
|
}
|
||||||
|
|
||||||
# ANSI colours for tags (green OK / yellow WARN / red ERROR·BLOCKER / cyan INFO).
|
# ANSI colours — tag + body (label bold, detail dim). Off: NO_COLOR=1 or CLICOLOR=0.
|
||||||
# Default: always on so pasted logs keep visible tags. Disable: NO_COLOR=1 or CLICOLOR=0.
|
|
||||||
if [ "${NO_COLOR:-0}" = "1" ] || [ "${CLICOLOR:-1}" = "0" ]; then
|
if [ "${NO_COLOR:-0}" = "1" ] || [ "${CLICOLOR:-1}" = "0" ]; then
|
||||||
G= R= Y= C= N= B=
|
G= R= Y= C= M= D= W= B= N=
|
||||||
else
|
else
|
||||||
G=$'\e[1;32m' # bold green [OK]
|
G=$'\e[1;32m' # bold green [OK]
|
||||||
R=$'\e[1;31m' # bold red [ERROR] [BLOCKER]
|
R=$'\e[1;31m' # bold red [ERROR]
|
||||||
Y=$'\e[1;33m' # bold yellow [WARN]
|
Y=$'\e[1;33m' # bold yellow [WARN]
|
||||||
C=$'\e[1;36m' # bold cyan [INFO]
|
C=$'\e[1;36m' # bold cyan [INFO]
|
||||||
B=$'\e[1m'
|
M=$'\e[1;35m' # bold magenta [BLOCKER]
|
||||||
N=$'\e[0m'
|
D=$'\e[2m' # dim tid / detail / sep
|
||||||
|
W=$'\e[1;37m' # bold white main label text
|
||||||
|
B=$'\e[1m' # bold section headers
|
||||||
|
N=$'\e[0m' # reset
|
||||||
fi
|
fi
|
||||||
|
|
||||||
PASS_N=0
|
PASS_N=0
|
||||||
|
|
@ -392,47 +394,54 @@ _take_tid() {
|
||||||
TEST_N=$((TEST_N + 1))
|
TEST_N=$((TEST_N + 1))
|
||||||
LAST_TID=$(printf '%s-%03d' "$TEST_AREA" "$TEST_N")
|
LAST_TID=$(printf '%s-%03d' "$TEST_AREA" "$TEST_N")
|
||||||
}
|
}
|
||||||
|
# Dim test id: "www-001 " or empty
|
||||||
_fmt_tid() {
|
_fmt_tid() {
|
||||||
# prefix "www-001 " or empty
|
|
||||||
if [ -n "${LAST_TID:-}" ]; then
|
if [ -n "${LAST_TID:-}" ]; then
|
||||||
printf '%s ' "$LAST_TID"
|
printf '%s%s%s ' "$D" "$LAST_TID" "$N"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
# One concrete line: [TAG] tid label · detail
|
||||||
|
# $1=tag colour $2=tag text $3=label colour $4=label $5=detail (optional)
|
||||||
|
_msg_line() {
|
||||||
|
local tcol="$1" tag="$2" lcol="$3" label="$4" detail="${5:-}"
|
||||||
|
# Fixed-width tag column: "[OK] " / "[BLOCKER]" (8 chars inside incl. brackets)
|
||||||
|
local tcell
|
||||||
|
tcell=$(printf '%-9s' "[${tag}]")
|
||||||
|
if [ -n "$detail" ]; then
|
||||||
|
printf '%s%s%s %s%s%s%s %s·%s %s%s%s\n' \
|
||||||
|
"$tcol" "$tcell" "$N" "$(_fmt_tid)" "$lcol" "$label" "$N" "$D" "$N" "$D" "$detail" "$N"
|
||||||
|
else
|
||||||
|
printf '%s%s%s %s%s%s%s\n' \
|
||||||
|
"$tcol" "$tcell" "$N" "$(_fmt_tid)" "$lcol" "$label" "$N"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
ok() {
|
ok() {
|
||||||
# Forms (same idea as info/warn):
|
# ok "what is good" ["concrete evidence: HTTP 200 · 12ms · …"]
|
||||||
# ok "what passed"
|
|
||||||
# ok "what passed" "detail / ms / bytes / …"
|
|
||||||
local label="$1" detail="${2:-}"
|
local label="$1" detail="${2:-}"
|
||||||
_take_tid
|
_take_tid
|
||||||
if [ -n "$detail" ]; then
|
_msg_line "$G" "OK" "$W" "$label" "$detail"
|
||||||
printf '%s[OK]%s %s%s — %s\n' "$G" "$N" "$(_fmt_tid)" "$label" "$detail"
|
|
||||||
else
|
|
||||||
printf '%s[OK]%s %s%s\n' "$G" "$N" "$(_fmt_tid)" "$label"
|
|
||||||
fi
|
|
||||||
PASS_N=$((PASS_N + 1))
|
PASS_N=$((PASS_N + 1))
|
||||||
}
|
}
|
||||||
# component-scoped error: err bank "libeufin down" "detail"
|
# component-scoped error: err bank "what failed" "why / HTTP / path"
|
||||||
err() {
|
err() {
|
||||||
local comp="$1" msg="$2" detail="${3:-}"
|
local comp="$1" msg="$2" detail="${3:-}"
|
||||||
_take_tid
|
_take_tid
|
||||||
printf '%s[ERROR]%s %s%s: %s%s\n' "$R" "$N" "$(_fmt_tid)" "$comp" "$msg" "${detail:+ — $detail}"
|
_msg_line "$R" "ERROR" "$W" "${comp}: ${msg}" "$detail"
|
||||||
FAIL_N=$((FAIL_N + 1))
|
FAIL_N=$((FAIL_N + 1))
|
||||||
ERRORS+=("${LAST_TID:+$LAST_TID }[$comp] $msg${detail:+ — $detail}")
|
ERRORS+=("${LAST_TID:+$LAST_TID }[$comp] $msg${detail:+ · $detail}")
|
||||||
}
|
}
|
||||||
# legacy fail label ...
|
# fail "what failed" ["why / HTTP code / path"]
|
||||||
fail() {
|
fail() {
|
||||||
local label="$1" detail="${2:-}"
|
local label="$1" detail="${2:-}"
|
||||||
_take_tid
|
_take_tid
|
||||||
printf '%s[ERROR]%s %s%s%s\n' "$R" "$N" "$(_fmt_tid)" "$label" "${detail:+ — $detail}"
|
_msg_line "$R" "ERROR" "$W" "$label" "$detail"
|
||||||
FAIL_N=$((FAIL_N + 1))
|
FAIL_N=$((FAIL_N + 1))
|
||||||
ERRORS+=("${LAST_TID:+$LAST_TID }$label${detail:+ — $detail}")
|
ERRORS+=("${LAST_TID:+$LAST_TID }$label${detail:+ · $detail}")
|
||||||
}
|
}
|
||||||
warn() {
|
warn() {
|
||||||
# Forms (same idea as err; always try to state the problem):
|
# warn "what is soft-bad" ["why still ok to continue"]
|
||||||
# warn "problem"
|
# warn component "what" "why"
|
||||||
# warn "problem" "why / context"
|
|
||||||
# warn component "problem" "why / context"
|
|
||||||
local a1="${1:-}" a2="${2:-}" a3="${3:-}"
|
local a1="${1:-}" a2="${2:-}" a3="${3:-}"
|
||||||
local head detail
|
local head detail
|
||||||
_take_tid
|
_take_tid
|
||||||
|
|
@ -446,56 +455,51 @@ warn() {
|
||||||
head="$a1"
|
head="$a1"
|
||||||
detail=""
|
detail=""
|
||||||
fi
|
fi
|
||||||
if [ -n "$detail" ]; then
|
_msg_line "$Y" "WARN" "$W" "$head" "$detail"
|
||||||
printf '%s[WARN]%s %s%s — %s\n' "$Y" "$N" "$(_fmt_tid)" "$head" "$detail"
|
|
||||||
else
|
|
||||||
printf '%s[WARN]%s %s%s\n' "$Y" "$N" "$(_fmt_tid)" "$head"
|
|
||||||
fi
|
|
||||||
WARN_N=$((WARN_N + 1))
|
WARN_N=$((WARN_N + 1))
|
||||||
}
|
}
|
||||||
info() {
|
info() {
|
||||||
|
# info "topic" ["concrete fact / value / next step"]
|
||||||
local label="$1" detail="${2:-}"
|
local label="$1" detail="${2:-}"
|
||||||
_take_tid
|
_take_tid
|
||||||
if [ -n "$detail" ]; then
|
_msg_line "$C" "INFO" "$W" "$label" "$detail"
|
||||||
printf '%s[INFO]%s %s%s — %s\n' "$C" "$N" "$(_fmt_tid)" "$label" "$detail"
|
|
||||||
else
|
|
||||||
printf '%s[INFO]%s %s%s\n' "$C" "$N" "$(_fmt_tid)" "$label"
|
|
||||||
fi
|
|
||||||
INFO_N=$((INFO_N + 1))
|
INFO_N=$((INFO_N + 1))
|
||||||
}
|
}
|
||||||
blocker() {
|
blocker() {
|
||||||
# Payment/withdraw path cannot proceed because of this
|
# Hard stop on pay/withdraw path: blocker "step" "why it cannot continue"
|
||||||
local step="$1" msg="$2"
|
local step="$1" msg="$2"
|
||||||
_take_tid
|
_take_tid
|
||||||
printf '%s[BLOCKER]%s %s%s: %s\n' "$R$B" "$N" "$(_fmt_tid)" "$step" "$msg"
|
_msg_line "$M" "BLOCKER" "$W" "${step}" "$msg"
|
||||||
BLOCKERS+=("${LAST_TID:+$LAST_TID }[$step] $msg")
|
BLOCKERS+=("${LAST_TID:+$LAST_TID }[$step] $msg")
|
||||||
FAIL_N=$((FAIL_N + 1))
|
FAIL_N=$((FAIL_N + 1))
|
||||||
ERRORS+=("BLOCKER ${LAST_TID:+$LAST_TID }[$step] $msg")
|
ERRORS+=("BLOCKER ${LAST_TID:+$LAST_TID }[$step] $msg")
|
||||||
}
|
}
|
||||||
section() { printf '\n%s== %s ==%s\n' "$B" "$*" "$N"; }
|
section() {
|
||||||
|
printf '\n%s==%s %s%s%s %s==%s\n' "$D" "$N" "$B" "$*" "$N" "$D" "$N"
|
||||||
|
}
|
||||||
|
|
||||||
summary() {
|
summary() {
|
||||||
echo ""
|
echo ""
|
||||||
if [ "${#BLOCKERS[@]}" -gt 0 ]; then
|
if [ "${#BLOCKERS[@]}" -gt 0 ]; then
|
||||||
printf '%s--- BLOCKERS (fix/withdraw path) ---%s\n' "$R$B" "$N"
|
printf '%s--- BLOCKERS%s %s(pay/withdraw cannot finish)%s %s---%s\n' "$M" "$N" "$D" "$N" "$M" "$N"
|
||||||
local b
|
local b
|
||||||
for b in "${BLOCKERS[@]}"; do
|
for b in "${BLOCKERS[@]}"; do
|
||||||
printf '%s • %s%s\n' "$R" "$b" "$N"
|
printf '%s •%s %s%s%s\n' "$M" "$N" "$W" "$b" "$N"
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
if [ "${#ERRORS[@]}" -gt 0 ] && [ "${#BLOCKERS[@]}" -lt "${#ERRORS[@]}" ]; then
|
if [ "${#ERRORS[@]}" -gt 0 ] && [ "${#BLOCKERS[@]}" -lt "${#ERRORS[@]}" ]; then
|
||||||
printf '%s--- ERRORS ---%s\n' "$R" "$N"
|
printf '%s--- ERRORS%s %s(failed checks)%s %s---%s\n' "$R" "$N" "$D" "$N" "$R" "$N"
|
||||||
local e
|
local e
|
||||||
for e in "${ERRORS[@]}"; do
|
for e in "${ERRORS[@]}"; do
|
||||||
case "$e" in BLOCKER*) continue ;; esac
|
case "$e" in BLOCKER*) continue ;; esac
|
||||||
printf '%s • %s%s\n' "$R" "$e" "$N"
|
printf '%s •%s %s%s%s\n' "$R" "$N" "$W" "$e" "$N"
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
printf 'totals: %s%d OK%s' "$G" "$PASS_N" "$N"
|
printf '%stotals:%s %s%d OK%s' "$D" "$N" "$G" "$PASS_N" "$N"
|
||||||
[ "$FAIL_N" -gt 0 ] && printf ', %s%d ERROR%s' "$R" "$FAIL_N" "$N"
|
[ "$FAIL_N" -gt 0 ] && printf ', %s%d ERROR%s' "$R" "$FAIL_N" "$N"
|
||||||
[ "$WARN_N" -gt 0 ] && printf ', %s%d WARN%s' "$Y" "$WARN_N" "$N"
|
[ "$WARN_N" -gt 0 ] && printf ', %s%d WARN%s' "$Y" "$WARN_N" "$N"
|
||||||
[ "$INFO_N" -gt 0 ] && printf ', %d INFO' "$INFO_N"
|
[ "$INFO_N" -gt 0 ] && printf ', %s%d INFO%s' "$C" "$INFO_N" "$N"
|
||||||
[ "${#BLOCKERS[@]}" -gt 0 ] && printf ', %s%d BLOCKER%s' "$R" "${#BLOCKERS[@]}" "$N"
|
[ "${#BLOCKERS[@]}" -gt 0 ] && printf ', %s%d BLOCKER%s' "$M" "${#BLOCKERS[@]}" "$N"
|
||||||
printf '\n'
|
printf '\n'
|
||||||
[ "$FAIL_N" -eq 0 ]
|
[ "$FAIL_N" -eq 0 ]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue