Skip to content

Monitoring

Diagnostics endpoints, metrics and what to alert on.

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.

EndpointResponse
/livezok (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
/versionProduct version (0.1.0), advertised etcd version (3.6.0), SQL ABI (1), and resource profiles
/metricsPrometheus text exposition format with fixed metric names and no client-controlled labels

Query readiness with curl:

curl --cacert /path/to/server-ca.crt \
  --cert /path/to/tenant-client.crt \
  --key /path/to/tenant-client.key \
  https://127.0.0.1:2381/readyz

/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.

Warning

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:

MetricMeaning
pgetcd_readyRuntime readiness flag (1 when ready, 0 when withdrawn)
pgetcd_publication_inflightActive requests currently holding a publication slot
pgetcd_publication_capacityConfigured publication slot capacity (pool_size)
pgetcd_pool_connections, pgetcd_pool_idle_connectionsTotal and idle connections in the PostgreSQL pool
pgetcd_watch_streamsCurrently admitted gRPC Watch streams
pgetcd_watch_senders, pgetcd_watch_receiversActive Watch sender and receiver goroutines
pgetcd_watch_tail_inflightIn-flight _tail_v2 polling transactions
pgetcd_watch_serialized_reserved_bytesReserved serialized Watch buffer bytes against watch_max_tenant_bytes

What to watch and alert on:

  • pgetcd_ready == 0: Alert immediately. Inspect diag.status in PostgreSQL (not_ready_reasons) or check whether pgetcd_publication_inflight reached pgetcd_publication_capacity.
  • pgetcd_publication_inflight approaching pgetcd_publication_capacity: Indicates slow SQL, lock contention on etcd.meta, or COMMIT waiting on synchronous standby replication. A slot remains occupied until its COMMIT finishes.
  • pgetcd_watch_serialized_reserved_bytes approaching watch_max_tenant_bytes: Indicates slow Watch consumers or high write volume; streams that exceed their buffer or tenant quota receive ResourceExhausted.

Watch client supervision

  • Watch consumers should persist a resume revision only after processing all events in a complete revision.
  • A Watch Create response confirms stream registration, not event progress.
  • If a Watch stream breaks with Unavailable, reconnect starting at last_processed_revision + 1.
  • If the requested revision has been logically compacted (CompactRevision > 0), read a fresh Range snapshot and open a new Watch at header.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 = on and a synchronous standby. After promoting the synchronous standby, point PGETCD_DSN at the new primary and restart pgetcd. In the v0.1.0-rc2 switchover smoke test (commit 81691bc, 2026-11-08), restarting the gateways after promotion took 1.03 s and kept all 52/52 acknowledged 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, and restore_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).
Scan to open this page
https://mimus.pgsty.com/docs/etcd/operations/monitoring/