feat(pds): Prometheus metrics + structured logging for rsky-pds - #249
Open
afbase wants to merge 1 commit into
Open
feat(pds): Prometheus metrics + structured logging for rsky-pds#249afbase wants to merge 1 commit into
afbase wants to merge 1 commit into
Conversation
rsky-pds previously had no telemetry: main.rs used a bare FmtSubscriber::new() with no EnvFilter, and there was no /metrics endpoint. This brings it to parity with rsky-relay's existing metrics/logging pattern in the same workspace, standardizing on the `metrics` + `metrics-exporter-prometheus` facade (rsky-wintermute and rsky-video use the `prometheus` crate directly; we don't add a third facade to the workspace). - src/metrics.rs: idempotent describe()/install_recorder() (OnceLock- guarded, so repeated build_rocket() calls in tests share one recorder), a Rocket XrpcMetrics fairing that records XRPC request count + latency labelled by lexicon method and HTTP status, plus record_* helpers for auth (login success/failure, service-auth token issuance), repo write throughput (create/update/delete), blob upload count/bytes, and a firehose subscriber gauge tracked via an RAII guard so every subscribeRepos exit path decrements it. - GET /metrics renders the Prometheus exposition text through a normal Rocket route (rsky-relay binds a second TCP listener via with_http_listener; Rocket already owns a listener here). - main.rs: tracing_subscriber::registry() + EnvFilter + fmt layer, replacing the bare FmtSubscriber (matches rsky-relay's layered registry shape). - Instrumented create_session, get_service_auth, upload_blob, create_record/put_record/delete_record/apply_writes, and subscribe_repos with the corresponding record_* calls. - Cargo.toml: added metrics = "0.24" and metrics-exporter-prometheus "0.17" (default-features off), matching rsky-relay's/tranquil-pds's already-resolved versions; tracing-subscriber gained the "env-filter" feature. - Tests: unit tests in metrics.rs (idempotent describe/install, per-metric increment/observe assertions) plus tests/metrics_tests.rs exercising a real Rocket instance (GET /metrics returns valid Prometheus text; a real XRPC request and a failed login show up with the right method/status/outcome labels). Out of scope: OpenTelemetry/distributed tracing (tracing-opentelemetry over existing spans) -- left as a follow-on, per task instructions. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
FmtSubscriber::new(), no/metricsendpoint, nothing to scrape.metrics+metrics-exporter-prometheuscrates, reusing exactly the patternrsky-relayalready established in this workspace (no new/third metrics facade introduced).pds_xrpc_requests_total{method,status},pds_xrpc_request_duration_seconds{method,status},pds_auth_login_total{outcome},pds_auth_service_tokens_issued_total,pds_repo_writes_total{op},pds_blob_uploads_total/pds_blob_upload_bytes_total,pds_firehose_subscribers(gauge, RAII-guarded across every exit path).tracing_subscriber::registry()+EnvFilter.prometheus/client_golang) and tranquil-pds, which independently already uses the identicalmetrics+metrics-exporter-prometheuscombination — validating this as the right shared convention for the workspace.Test plan
cargo build -p rsky-pdscargo test -p rsky-pds— 310 lib tests + integration suites incl. newtests/metrics_tests.rs(real Rocket instance, checks/metricsoutput and label correctness), all passingcargo fmt -p rsky-pds/cargo clippy -p rsky-pds --all-targetscleangit diff --stat -- rsky-relay/shows zero changes there)🤖 Generated with Claude Code