Skip to content

relay: wire pyrycode_relay_connected_{binaries,phones} gauges into registry events #61

@ilmoniemi

Description

@ilmoniemi

User Story

As a relay operator, I want pyrycode_relay_connected_binaries and pyrycode_relay_connected_phones gauges to track live connection counts in real time, so I can graph utilization and alert on unexpected drops from Prometheus instead of polling /healthz.

Context

/healthz (#10) reports current connection counts as a one-shot snapshot. Time-series visibility into connection lifecycle (joins, leaves, grace expiries) requires Prometheus gauges wired at the registry's mutation points.

This ticket wires the cheapest pair of metrics — connection counters — into the existing register / unregister / grace-expiry-eviction sites in internal/relay/registry.go. The gauges live on the metrics registry introduced by the scaffolding slice (#59); this ticket adds the gauge definitions and the Inc/Dec wiring.

The gauges are independent of the listener — once they're wired, they reflect live counts in the registry whether or not anyone is scraping. The listener slice (#60) is a separate sibling.

Acceptance Criteria

  • Two gauges defined and registered against the metrics registry from relay: adopt prometheus/client_golang and introduce metrics registry scaffolding #59 (not the global default registry):
    • pyrycode_relay_connected_binaries
    • pyrycode_relay_connected_phones
  • Gauges are incremented and decremented at the existing register, unregister, and grace-expiry-eviction sites in internal/relay/registry.go. The architect picks the exact shape (counters maintained inside the registry's lock vs. a pull-based prometheus.Collector over the existing Counts()).
  • Under concurrent register/unregister/grace-expiry sequences, gauge values match the registry's live count at all observation points (verified by -race test that races register/unregister/grace-expiry against periodic gauge reads).
  • Grace-expiry-eviction increments/decrements fire only on real evictions — stale-fire no-ops (per the pointer-identity guard pattern in docs/PROJECT-MEMORY.md) must not change the gauge.
  • make vet, make test -race, and make build clean.
  • docs/knowledge/codebase/<n>.md summary entry created; docs/knowledge/INDEX.md updated.

Technical Notes

Size Estimate

S

Split from #56. Depends on the scaffolding slice (#59, closed 2026-05-11).

Metadata

Metadata

Assignees

No one assigned

    Labels

    security-sensitiveTouches auth, crypto, or internet-exposed input pathssize:sSmall ticket: <100 lines production code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions