Files
ziadarafat 0502804032 observability: metrics, dashboard and morning check for the debrid pipeline
The rdtc incident was reconstructed from SQLite by hand because nothing was
watching. Now three layers exist:

* rdtc-async-add serves /metrics (adds accepted/deduped/delivered/failed,
  retries, delivery histogram); two tests pin the counters.
* tools/debrid-metrics merges that with rdtc's queue health (pending rows with
  no provider id, torrents stuck at 0%, oldest pending age) and nginx's
  add-request log (latency histogram, 499/504 counts) into one node_exporter
  textfile every 15s. The access log is parsed incrementally with an inode and
  offset state file, so restarts do not double-count or lose lines.
* tools/rtdc-health/check.sh answers 'did it work overnight' from Prometheus,
  the rdtc database and logs, and Radarr's log, and exits non-zero on failure.

Also fixes the reason the incident was invisible: rdtc logged nothing because
General:LogLevel was 4 (Error) and DownloadClient:LogLevel 5 (Fatal). Both are
now Information/Debug, journald is persistent with a 2G cap, and the rdtc API
vhost writes a dedicated access log with $request_time.

Grafana dashboard debrid-pipeline (13 panels) is provisioned on xatu and live.
2026-11-25 17:16:14 -07:00
..

rdtc-async-add

A small reverse proxy that sits between *arr and rdt-client and removes one failure mode: rdtc answers POST /api/v2/torrents/add only after the debrid provider call returns. When TorBox is slow — or when its slots are all taken by stalled torrents — that request can take minutes. *arr's download-client timeout is hardcoded at about 100 s, so it reports Failed to connect to qBittorrent, blocklists the release, and grabs the next one. The result is several copies of the same film queued for download.

This proxy accepts the add, answers 200 Ok. immediately, and delivers it to rdtc in the background with retries. Every other request is passed through untouched, so *arr still sees a normal qBittorrent API.

Behaviour

Request Behaviour
POST /api/v2/torrents/add body buffered, answered 200 "Ok." at once, delivered in the background
identical add inside -dedupe-window answered 200 "Ok.", not delivered twice
add body over -max-body 413, never forwarded
everything else proxied synchronously, status and body unchanged

Delivery retries up to -retries times with a backoff of attempt × -retry-delay. A failed delivery is logged and dropped; it is never reported to *arr, because reporting it is exactly what triggers the duplicate grabs.

Deployment (yveltal)

CGO_ENABLED=0 go build -trimpath -ldflags="-s -w" -o rdtc-async-add .
scp rdtc-async-add yveltal:~/.local/bin/
scp rdtc-async-add.service yveltal:~/.config/systemd/user/
ssh yveltal 'systemctl --user daemon-reload && systemctl --user enable --now rdtc-async-add'

nginx's private API vhost (/etc/nginx/conf.d/rdtc-private-api.conf, the :6501 listener that *arr uses) must point at the proxy, not at rdtc:

proxy_pass http://127.0.0.1:6502;   # was 6500

The browser UI vhost still talks to :6500 directly — only *arr's path goes through the proxy.

Metrics

GET /metrics (on the same loopback listener, so Prometheus reaches it only through node_exporter's textfile collector) exposes debrid_shim_adds_accepted_total, debrid_shim_adds_deduped_total, debrid_shim_adds_delivered_total, debrid_shim_adds_failed_total, debrid_shim_adds_rejected_total, debrid_shim_delivery_retries_total and the debrid_shim_delivery_seconds histogram.

tools/debrid-metrics/ collects those, plus rdtc's queue depth and nginx's add latency, into /var/lib/node_exporter/textfile/debrid.prom every 15s. The Grafana dashboard is debrid-pipeline (provisioned from /etc/monitoring/grafana/dashboards/debrid-pipeline.json on xatu).

Flags

Flag Default Meaning
-listen 127.0.0.1:6502 listen address
-upstream http://127.0.0.1:6500 rdtc base URL
-retries 3 delivery attempts
-retry-delay 10s base backoff
-dedupe-window 60s identical-add suppression window
-max-body 64MiB largest add body buffered

Logs go to stdout (journald): add accepted, add delivered, add delivery … failed, add delivery … given up, add: duplicate suppressed.

Tests

go test ./...        # 9 tests, no third-party dependencies

The tests pin the behaviour that matters: the add answers in <250 ms while the upstream takes seconds; the body, query string and Content-Type (including multipart boundaries) survive byte for byte; an upstream 500 still yields 200 to *arr; non-add requests keep the upstream status; identical adds collapse; the window expires; oversized bodies are refused.

-race needs cgo, so it is not run by default on the Steam Deck, which has no gcc.