Files
Scrobbler/src/scrobbler/federation/metrics.py
T
mattandClaude Opus 5.5 142dc13fea
CI / validate-monitoring (push) Successful in 8s
CI / lint (push) Successful in 9s
CI / test (push) Successful in 1m57s
CI / images (push) Skipped
CI / assets (push) Skipped
CI / python-package (push) Skipped
CI / notify (push) Successful in 5s
Deliver outgoing activities with retries (phase 2, step 5)
The federation.deliver worker task sends queued activities:
- signed POSTs as the user, draft-cavage first and RFC 9421 after a
  401 (double-knocking), several at once (FEDERATION_DELIVERY_
  CONCURRENCY), up to 50 per pass
- 2xx delivered; 410 removes whoever that inbox belongs to as a
  follower and marks them gone; other 4xx (except 401/408/429) are
  abandoned; everything else retries at 1m, 5m, 30m, 2h, 6h, then
  every 12h, abandoned after 2 days
- claiming leases a delivery (pushes its next attempt forward), so a
  crashed worker's sends become due again on their own; claiming
  skips the eager join Postgres can't lock through
- metrics: deliveries by result, delivery time, outgoing signatures,
  queue depths and follower totals (gauges set every 30s)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MK52BGoJbPhZ1vSFuKcGUW
2026-09-25 21:36:05 +01:00

54 lines
1.7 KiB
Python

"""Federation's own metrics (the core's HTTP metrics already cover rate/latency)."""
from prometheus_client import Counter, Gauge, Histogram
lookups_total = Counter(
"scrobbler_federation_lookups_total",
"Fediverse lookups answered: WebFinger, actor, NodeInfo, profile",
["kind", "result"],
)
sharing_changes_total = Counter(
"scrobbler_federation_sharing_changes_total",
"Users switching fediverse sharing on or off",
["change"],
)
inbox_requests_total = Counter(
"scrobbler_federation_inbox_requests_total",
"Deliveries received at an inbox (not yet processed: phase 2)",
["inbox"],
)
inbox_activities_total = Counter(
"scrobbler_federation_inbox_activities_total",
"Activities received: queued, duplicate, blocked or invalid at intake; then processed, "
"rejected or failed",
["type", "result"],
)
signatures_total = Counter(
"scrobbler_federation_signatures_total",
"HTTP signature checks (in) and signing (out), by scheme and result",
["direction", "scheme", "result"],
)
deliveries_total = Counter(
"scrobbler_federation_deliveries_total",
"Outgoing deliveries: delivered, retry, abandoned (gave up or refused) or gone (410)",
["result"],
)
delivery_seconds = Histogram(
"scrobbler_federation_delivery_seconds",
"Time to deliver one activity to one inbox",
buckets=(0.05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10, 20),
)
queue = Gauge(
"scrobbler_federation_queue",
"Inbox items and deliveries by status (set by the worker)",
["queue", "status"],
multiprocess_mode="max",
)
followers = Gauge(
"scrobbler_federation_followers",
"Followers across all users, by state (set by the worker)",
["state"],
multiprocess_mode="max",
)