chadtmiller.com/knotless
git that lives in your Atmosphere account
1
10
just logs runner reads the runner host's runner
deploy/logs.sh+29−8
| @@ -1,25 +1,38 @@ | ||
#!/usr/bin/env bash | ||
# Reads what knotless logs on the host (deploy/README.md, Logs): | ||
# | ||
# deploy/logs.sh [serve|run|pages|deploys] [--since 30m] [--follow] [jq filter] | ||
# deploy/logs.sh [serve|run|runner|pages|deploys] [--since 30m] [--follow] [jq filter] | ||
# | ||
# deploy/logs.sh serve 'select(.duration_ms > 1000)' | ||
# deploy/logs.sh serve --since 2h 'select(.level == "WARN" or .level == "ERROR")' | ||
# deploy/logs.sh run --follow | ||
# deploy/logs.sh runner --since 1h 'select(.message == "batch started")' | ||
# deploy/logs.sh deploys | ||
# | ||
# They are read from the host's journal, so a container a rollout removed | ||
# is read too. serve and run log JSON lines, each run through the jq | ||
# filter (`.` if none); lines that are not JSON are left out. pages logs | ||
# plain text, and deploys is the host's /var/log/knotless-deploy.log, | ||
# is read too. serve and the runners log JSON lines, each run through the | ||
# jq filter (`.` if none); lines that are not JSON are left out. pages | ||
# logs plain text, and deploys is the host's /var/log/knotless-deploy.log, | ||
# each shown as is. | ||
# The host is KNOTLESS_HOST, from deploy/local.env, else knotless.dev. | ||
# The host is KNOTLESS_HOST, from deploy/local.env, else knotless.dev: run | ||
# is a runner there. runner is the runner host's instead | ||
# (deploy/runner-host): KNOTLESS_RUNNER_HOST, else runner.knotless.dev, | ||
# its runner named by KNOTLESS_RUNNER_NAME (knotless-runner). As | ||
# deploy/runner-host/deploy.sh does, KNOTLESS_RUNNER_ENV names a file | ||
# read in place of deploy/local.env, for another runner such as the | ||
# trusted one: `KNOTLESS_RUNNER_ENV=deploy/ci.env deploy/logs.sh runner`. | ||
| ||
set -euo pipefail | ||
cd "$(dirname "$0")/.." | ||
[ -f deploy/local.env ] && { set -a; . deploy/local.env; set +a; } | ||
DEST="${KNOTLESS_HOST:-root@knotless.dev}" | ||
SVC="${1:-serve}" | ||
if [ "$SVC" = runner ] && [ -n "${KNOTLESS_RUNNER_ENV:-}" ]; then | ||
set -a; . "$KNOTLESS_RUNNER_ENV"; set +a | ||
elif [ -f deploy/local.env ]; then | ||
set -a; . deploy/local.env; set +a | ||
fi | ||
DEST="${KNOTLESS_HOST:-root@knotless.dev}" | ||
if [ "$SVC" = runner ]; then | ||
DEST="${KNOTLESS_RUNNER_HOST:-root@runner.knotless.dev}" | ||
fi | ||
[ $# -eq 0 ] || shift | ||
SINCE=30m | ||
FOLLOW= | ||
| @@ -47,6 +60,14 @@ case "$SVC" in | ||
$SSH "$JOURNAL COM_DOCKER_COMPOSE_SERVICE='$SVC'" | | ||
jq -R -c --unbuffered "fromjson? | $FILTER" | ||
;; | ||
runner) | ||
# The runner host tags each line with its container's name, which a | ||
# deploy that replaces the container keeps, and the host's clock may | ||
# not be in UTC: `--since` is relative, so it reads the same anywhere. | ||
# shellcheck disable=SC2029 | ||
$SSH "journalctl --no-pager -o cat --since '-$SINCE' ${FOLLOW:+--follow} CONTAINER_TAG='${KNOTLESS_RUNNER_NAME:-knotless-runner}-run-1'" | | ||
jq -R -c --unbuffered "fromjson? | $FILTER" | ||
;; | ||
pages) | ||
# shellcheck disable=SC2029 | ||
$SSH "$JOURNAL COM_DOCKER_COMPOSE_SERVICE=pages" | ||
deploy/README.md+8−0
| @@ -834,9 +834,17 @@ just logs serve 'select(.message == "outgoing" and .level != "DEBUG")' # calls | ||
just logs serve 'select(.message | startswith("summary"))' | ||
just logs serve 'select(.trace_id == "4bf92f3577b34da6a3ce929d0e0e4736")' # one request, and the pages' calls for it | ||
just logs run --follow 'select(.message | startswith("run"))' | ||
just logs runner --since 1h 'select(.message == "batch started")' # the runner host's, which lands the queue | ||
just logs deploys # the deploy steps, with times | ||
``` | ||
| ||
`run` is a runner on this host. `runner` reads the runner host's | ||
(deploy/runner-host) instead, at `KNOTLESS_RUNNER_HOST` | ||
(runner.knotless.dev unset), by its container's tag, as that host's | ||
lines name no compose project. `KNOTLESS_RUNNER_ENV=deploy/ci.env just | ||
logs runner` reads another runner, such as the trusted one, from its | ||
own settings, as its deploy does. | ||
| ||
Or on the host itself, with journalctl, by the service's field; `-o cat` | ||
gives each line as it was written: | ||
| ||