Monitoring
This page covers health probes, Prometheus metrics, Watch client supervision, graceful shutdown, and primary switchover boundaries for the single-primary tenant gateway. When pgetcd backs Kubernetes, PostgreSQL and the gateway must be able to start without depending on that Kubernetes API server.
Diagnostics endpoints
The diagnostics listener (diagnostics_listen, port 2381 in examples) requires the same mutual TLS client certificate (spiffe://pgetcd/tenant/<tenant>) as the gRPC listener. All endpoints accept GET only and disable HTTP response caching.
| Endpoint | Response |
|---|---|
/livez | ok (HTTP 200) if the gateway process is alive and serving |
/readyz, /health | {"health":true} (HTTP 200) when ready, or {"health":false} (HTTP 503) when not ready |
/version | Product version (0.1.0), advertised etcd version (3.6.0), SQL ABI (1), and resource profiles |
/metrics | Prometheus text exposition format with fixed metric names and no client-controlled labels |
Query readiness with curl:
/livez checks only that the gateway HTTP handler responds. /readyz and /health also verify request admission, primary database connectivity, persistent identity, and Lease background worker readiness inside a fresh certified transaction that must complete its synchronous COMMIT within 1 second.
Since v0.1.0-rc2 (commit 81691bc), etcdctl endpoint health reports healthy, and the readiness check uses a reserved slot, so client load that fills pool_size does not withdraw readiness. The gateway logs tenant readiness withdrawn: <reason> and tenant readiness granted on each change; alert on the withdrawn line. In v0.1.0-rc1, endpoint health failed and the readiness check shared the client slots.
Prometheus metrics
All exported metrics on /metrics are gauges with no tenant keys, values, or credentials:
| Metric | Meaning |
|---|---|
pgetcd_ready | Runtime readiness flag (1 when ready, 0 when withdrawn) |
pgetcd_publication_inflight | Active requests currently holding a publication slot |
pgetcd_publication_capacity | Configured publication slot capacity (pool_size) |
pgetcd_pool_connections, pgetcd_pool_idle_connections | Total and idle connections in the PostgreSQL pool |
pgetcd_watch_streams | Currently admitted gRPC Watch streams |
pgetcd_watch_senders, pgetcd_watch_receivers | Active Watch sender and receiver goroutines |
pgetcd_watch_tail_inflight | In-flight _tail_v2 polling transactions |
pgetcd_watch_serialized_reserved_bytes | Reserved serialized Watch buffer bytes against watch_max_tenant_bytes |
What to watch and alert on:
pgetcd_ready == 0: Alert immediately. Inspectdiag.statusin PostgreSQL (not_ready_reasons) or check whetherpgetcd_publication_inflightreachedpgetcd_publication_capacity.pgetcd_publication_inflightapproachingpgetcd_publication_capacity: Indicates slow SQL, lock contention onetcd.meta, orCOMMITwaiting on synchronous standby replication. A slot remains occupied until itsCOMMITfinishes.pgetcd_watch_serialized_reserved_bytesapproachingwatch_max_tenant_bytes: Indicates slow Watch consumers or high write volume; streams that exceed their buffer or tenant quota receiveResourceExhausted.
Watch client supervision
- Watch consumers should persist a resume revision only after processing all events in a complete revision.
- A Watch
Createresponse confirms stream registration, not event progress. - If a Watch stream breaks with
Unavailable, reconnect starting atlast_processed_revision + 1. - If the requested revision has been logically compacted (
CompactRevision > 0), read a freshRangesnapshot and open a new Watch atheader.revision + 1(see Use etcdctl).
Graceful shutdown
On SIGINT or SIGTERM, the gateway withdraws readiness, stops admitting new requests, closes Watch streams, and waits up to a shared 10-second deadline for in-flight publication transactions and gRPC transports to drain. When the 10-second deadline expires, it stops the gRPC and HTTP servers forcibly.
In-flight COMMIT calls hold their publication slots until they return. A completed gateway shutdown timeout does not prove that every PostgreSQL backend transaction rolled back; the gateway suppresses responses for any unresolved COMMIT and never replays it.
Primary switchover, backup, and restore
All KV rows, event history, revision manifests, history anchors, Leases, and publication barriers live in PostgreSQL tables under schema etcd.
- Manual primary switchover: To preserve all acknowledged writes across a primary failure, PostgreSQL must run with
synchronous_commit = onand a synchronous standby. After promoting the synchronous standby, pointPGETCD_DSNat the new primary and restartpgetcd. In thev0.1.0-rc2switchover smoke test (commit81691bc, 2026-11-08), restarting the gateways after promotion took1.03 sand kept all52/52acknowledged writes. This checks the procedure only; it does not provide fencing. - Database restore: Startup and periodic metadata checks verify
database_name,database_oid,cluster_id,member_id, andrestore_generation. Keep a restored database isolated until you verify these identities. Automated failover fencing and offline PITR protocol recovery (pgetcd-restore) are post-MVP roadmap items (see HA roadmap and Offline protocol recovery).
