Skip to content

Commit 0ce58e9

Browse files
committed
S3C-11127: POC-specific-code: worker.sh status reads the suite's pidfile names
The rig names a pidfile after a number, the demo suite names it after a number and the workgroup, and status did arithmetic on the whole suffix to get a probe port. Bash read the wg of worker1-wg-a as a variable and the command died under set -u on every suite worker. The number and the workgroup are now split: files stay keyed by the whole suffix, only the probe port is keyed by the number, and status lists every pidfile it finds with its workgroup rather than folding two workers onto one line. While there: it described the bare pool group unconditionally, which on any workgroup run printed a raw group-does-not-exist from the broker. It now lists whichever pool groups exist, with their lag.
1 parent d9b2013 commit 0ce58e9

1 file changed

Lines changed: 39 additions & 8 deletions

File tree

‎poc-demo/bin/worker.sh‎

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,31 @@ cf() { printf '%s\n' "$DEMO/run/worker$1.crashes"; }
4242
lf() { printf '%s\n' "$DEMO_LOG_DIR/worker$1.log"; }
4343
wpid() { cat "$(pf "$1")" 2>/dev/null | tr -d '\n '; }
4444

45+
# A worker is identified on disk by its whole suffix, which this rig writes
46+
# as a number (worker3.pid) and the demo suite writes as a number and the
47+
# workgroup it serves (worker3-wg-a.pid). Every file is named by the whole
48+
# suffix; only the probe port is derived from the number. So split the two
49+
# rather than assume the suffix is a number: doing arithmetic on "3-wg-a"
50+
# made bash read `wg` as a variable and `status` died on every suite worker.
51+
widx() { printf '%s\n' "${1%%-*}"; }
52+
wwg() { case "$1" in *-*) printf '%s\n' "${1#*-}" ;; *) printf '' ;; esac; }
53+
4554
status_one() {
46-
local n="$1" p port
47-
p=$(wpid "$n"); port=$(worker_probe_port "$n")
55+
local n="$1" p port i wg label
56+
i=$(widx "$n"); wg=$(wwg "$n")
57+
case "$i" in
58+
''|*[!0-9]*)
59+
warn "worker$n: no worker number in the name, skipping"
60+
return 0 ;;
61+
esac
62+
label="worker$n${wg:+ workgroup $wg}"
63+
p=$(wpid "$n"); port=$(worker_probe_port "$i")
4864
if alive "$p"; then
49-
say "worker$n RUNNING pid $p probe :$port live=$(worker_live "$n") delivered=$(worker_delivered "$n") exits=$(cnt "$(cf "$n")" ' EXIT rc=')"
50-
say " per destination: $(worker_metrics "$n" | grep '^s3_notification_delivery_worker_delivered_total' | sed -E 's/.*target="([^"]*)".*\} /\1=/' | tr '\n' ' ')"
65+
say "$label RUNNING pid $p probe :$port live=$(worker_live "$i") delivered=$(worker_delivered "$i") exits=$(cnt "$(cf "$n")" ' EXIT rc=')"
66+
say " per destination: $(worker_metrics "$i" | grep '^s3_notification_delivery_worker_delivered_total' | sed -E 's/.*target="([^"]*)".*\} /\1=/' | tr '\n' ' ')"
5167
say " assign/revoke: $(cnt "$(lf "$n")" 'rdkafka.assign')/$(cnt "$(lf "$n")" 'rdkafka.revoke')"
5268
else
53-
say "worker$n STOPPED$([ -f "$(hf "$n")" ] && printf ' (held dead)') exits=$(cnt "$(cf "$n")" ' EXIT rc=')"
69+
say "$label STOPPED$([ -f "$(hf "$n")" ] && printf ' (held dead)') exits=$(cnt "$(cf "$n")" ' EXIT rc=')"
5470
fi
5571
}
5672

@@ -137,17 +153,32 @@ signal)
137153
crashes) [ -n "$N" ] || die "usage: worker.sh crashes <n>"; cnt "$(cf "$N")" ' EXIT rc=' ;;
138154
status)
139155
if [ -n "$N" ]; then status_one "$N"; exit 0; fi
156+
# every distinct pidfile, not every distinct worker number: the suite
157+
# runs several workgroups at once and `sort -un` would fold worker3 and
158+
# worker3-wg-a into one line and hide whichever it dropped. Ordered by
159+
# number, then by workgroup.
140160
known=$(for f in "$DEMO"/run/worker*.pid "$DEMO"/run/worker*.crashes; do
141161
[ -e "$f" ] || continue
142162
n=$(basename "$f"); n=${n#worker}; printf '%s\n' "${n%%.*}"
143-
done | sort -un)
163+
done | sort -t- -k1,1n -k2,2 -u)
144164
if [ -z "$known" ]; then
145165
say "no worker has ever been started from this demo directory"
146166
else
147167
for n in $known; do status_one "$n"; done
148168
fi
149-
say "delivery group $DELIVERY_GROUP:"
150-
group_describe "$DELIVERY_GROUP" 2>/dev/null | sed 's/^/ /' | head -10
169+
# The pool joins one group per workgroup, <base>-<workgroup>-gen<G>, and
170+
# the bare base group only exists when workgroups are off. Describing the
171+
# base one unconditionally printed a raw "group does not exist" from the
172+
# broker on every workgroup run, so list whichever pool groups are there.
173+
pool_groups=$(group_list | grep -E "^${DELIVERY_GROUP}(-|$)" || true)
174+
if [ -z "$pool_groups" ]; then
175+
say "no pool consumer group on the broker yet"
176+
else
177+
say "pool consumer groups:"
178+
for g in $pool_groups; do
179+
say " $g lag $(group_lag "$g")"
180+
done
181+
fi
151182
;;
152183
*) die "usage: worker.sh start <n> [--workgroup <id>] | stop <n> | status | hold <n> | release <n> | signal <n> <SIG> | crashes <n>" ;;
153184
esac

0 commit comments

Comments
 (0)