caelum0x ee5070acb8 feat(railyard): nightly Relay and Rago shadow-metering reconciliation (RY-RG1)
tools/reconcile-relay-rago compares relay_cost_events with Rago relay_llm_usage
events for one UTC day, event by event: missing (dropped), dead-letter, amount
mismatch, duplicate across orgs, orphan and overdue pending. Drift over 0.5%,
any dead-letter or any duplicate pages the railyard ntfy topic; smaller findings
are reported at default priority. ry_rago_drift_ratio and per-key and per-org
figures go to VictoriaMetrics; a JSON report is kept per day. Both databases are
read in READ ONLY transactions, so no charge of record changes.

Includes systemd service and timer (04:20 UTC), installer, env sample, the
emitter flip checklist per lane, and 12 offline tests (fake psql, local ntfy and
VictoriaMetrics).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-29 02:09:50 +03:00

31 lines
1.3 KiB
Bash
Executable File

#!/usr/bin/env bash
# install.sh: install the nightly Relay and Rago reconciliation on box 2 (RY-RG1).
# sudo ./install.sh # units + env sample, enable the timer
# sudo ./install.sh run # one run now for yesterday, then show the log
# The code runs from this checkout (RAILYARD_SRC, default /srv/src/railyard).
set -euo pipefail
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
SRC="${RAILYARD_SRC:-/srv/src/railyard}"
UNIT_DIR="${UNIT_DIR:-/etc/systemd/system}"
ETC="${PRODUCTS_ETC:-/etc/products}"
[[ $EUID -eq 0 ]] || { echo "run as root" >&2; exit 1; }
command -v python3 >/dev/null || { echo "python3 is required" >&2; exit 1; }
case "${1:-install}" in
install)
for unit in reconcile-relay-rago.service reconcile-relay-rago.timer; do
sed "s#/srv/src/railyard#$SRC#g" "$HERE/systemd/$unit" >"$UNIT_DIR/$unit"
chmod 644 "$UNIT_DIR/$unit"
done
[[ -f "$ETC/reconcile-relay-rago.env" ]] || install -m 640 "$HERE/reconcile.env.sample" "$ETC/reconcile-relay-rago.env"
systemctl daemon-reload
systemctl enable --now reconcile-relay-rago.timer
systemctl list-timers reconcile-relay-rago.timer --no-pager
;;
run)
systemctl start reconcile-relay-rago.service
journalctl -u reconcile-relay-rago.service -n 20 --no-pager
;;
*) sed -n '2,5p' "${BASH_SOURCE[0]}" | sed 's/^# \{0,1\}//'; exit 2 ;;
esac