matrix: report homeserver up, latency and database size through existing collectors
tuwunel 1.9.4 exports no metrics. The host collector gets an httpcheck receiver on the gateway's /_matrix/client/versions (new services.hyperhive.otel.httpChecks, declared by hive-matrix), and a timer in the hive-matrix container pushes the database directory's size through the forwarder's OTLP port, as the attic cache-size unit does. The size step dereferences the state directory's symlink and pushes nothing for a result under 4096 bytes.
This commit is contained in:
parent
839dbd642a
commit
bef9d401a4
1 changed files with 311 additions and 0 deletions
74
nix/script-tests/database-size-push.sh
Normal file
74
nix/script-tests/database-size-push.sh
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
# Cases for ./database-size-push.nix. The directory is reached through a
|
||||
# symlink, as a dynamic user's state directory is. `curl` is a stub that
|
||||
# records the payload and the URL it is given.
|
||||
set -uo pipefail
|
||||
|
||||
failures=0
|
||||
|
||||
fail() {
|
||||
echo "FAILED: $case: $*" >&2
|
||||
failures=$((failures + 1))
|
||||
}
|
||||
|
||||
root=$(mktemp -d)
|
||||
mkdir -p "$root/bin" "$root/private/tuwunel"
|
||||
head -c 100000 /dev/zero >"$root/private/tuwunel/db"
|
||||
ln -s "$root/private/tuwunel" "$root/tuwunel"
|
||||
|
||||
cat >"$root/bin/curl" <<STUB
|
||||
#!$BASH
|
||||
printf '%s\n' "\$*" >"$root/curl.args"
|
||||
cat >"$root/curl.payload"
|
||||
STUB
|
||||
chmod +x "$root/bin/curl"
|
||||
|
||||
# Runs the script for \$1, returns its status; stdout and stderr land in files.
|
||||
run() {
|
||||
rm -f "$root/curl.args" "$root/curl.payload"
|
||||
sed "s|@DIR@|$1|" "$SCRIPT_LINK" >"$root/script.sh"
|
||||
PATH="$root/bin:$PATH" bash "$root/script.sh" >"$root/out" 2>"$root/err"
|
||||
}
|
||||
|
||||
case="a symlinked directory reports the target's size"
|
||||
want=$(du --summarize --bytes "$root/private/tuwunel/" | cut -f1)
|
||||
link=$(du --summarize --bytes "$root/tuwunel" | cut -f1)
|
||||
[ "$want" -ge 100000 ] || fail "fixture target is $want bytes"
|
||||
[ "$link" -lt 4096 ] || fail "fixture link measures $link bytes, so it does not tell the cases apart"
|
||||
if run "$root/tuwunel"; then
|
||||
grep -q "\"asInt\":\"$want\"" "$root/curl.payload" || fail "payload is $(cat "$root/curl.payload"), want asInt $want"
|
||||
grep -q 'hyperhive.matrix.database_bytes' "$root/curl.payload" || fail "no metric name in the payload"
|
||||
grep -q '127.0.0.1:8906/v1/metrics' "$root/curl.args" || fail "wrong url: $(cat "$root/curl.args")"
|
||||
else
|
||||
fail "the script failed: $(cat "$root/err")"
|
||||
fi
|
||||
|
||||
case="a real directory reports its own size"
|
||||
if run "$root/private/tuwunel"; then
|
||||
grep -q "\"asInt\":\"$want\"" "$root/curl.payload" || fail "payload is $(cat "$root/curl.payload"), want asInt $want"
|
||||
else
|
||||
fail "the script failed: $(cat "$root/err")"
|
||||
fi
|
||||
|
||||
# `du` stub answering a link-sized number, as an old command line would.
|
||||
case="an implausibly small size warns and pushes nothing"
|
||||
cat >"$root/bin/du" <<STUB
|
||||
#!$BASH
|
||||
printf '15\t%s\n' "\${@: -1}"
|
||||
STUB
|
||||
chmod +x "$root/bin/du"
|
||||
if run "$root/tuwunel"; then
|
||||
[ ! -e "$root/curl.payload" ] || fail "pushed $(cat "$root/curl.payload")"
|
||||
grep -q 'warning' "$root/err" || fail "no warning: $(cat "$root/err")"
|
||||
else
|
||||
fail "the script failed: $(cat "$root/err")"
|
||||
fi
|
||||
rm "$root/bin/du"
|
||||
|
||||
case="a missing directory fails and pushes nothing"
|
||||
if run "$root/absent"; then
|
||||
fail "the script succeeded"
|
||||
fi
|
||||
[ ! -e "$root/curl.payload" ] || fail "pushed on a missing directory"
|
||||
|
||||
[ "$failures" -eq 0 ] || exit 1
|
||||
echo "all cases passed"
|
||||
Loading…
Reference in a new issue