Skip to content

feat: optional UDS listener + health endpoints for Kubernetes deployment - #62

Merged
tlongwell-block merged 1 commit into
mainfrom
cake-deployment
Mar 14, 2026
Merged

feat: optional UDS listener + health endpoints for Kubernetes deployment#62
tlongwell-block merged 1 commit into
mainfrom
cake-deployment

Conversation

@tlongwell-block

Copy link
Copy Markdown
Collaborator

Summary

Adds two opt-in features for deploying sprout-relay on Kubernetes with an Istio service mesh:

  1. Optional Unix Domain Socket listener — set SPROUT_UDS_PATH to bind a UDS alongside TCP. Useful when a service mesh sidecar (e.g. Istio/Envoy) delivers traffic via a Unix socket while Kubernetes health probes need TCP.

  2. Health endpoints/_liveness (always 200) and /_readiness (checks MySQL + Redis connectivity with a 2s timeout).

Changes

File What
sprout-db/src/lib.rs Add Db::ping()SELECT 1 health check
sprout-relay/src/config.rs Add uds_path: Option<String> from SPROUT_UDS_PATH env var
sprout-relay/src/main.rs serve_dual() — TCP always + optional UDS via tokio::select!, #[cfg(unix)] gated
sprout-relay/src/router.rs /_liveness, /_readiness routes; ConnectInfo read from extensions (works on both TCP and UDS)
sprout-relay/src/state.rs Add redis_pool field for readiness probe

Design decisions

  • Zero behavior change when SPROUT_UDS_PATH is unset — existing deployments are unaffected
  • UDS code gated with #[cfg(unix)] — compiles cleanly on all platforms; non-unix logs a warning if the env var is set
  • Readiness checks run concurrently via tokio::join! with a single 2s outer timeout (not sequential)
  • Safe UDS cleanup — only removes existing socket files on startup; errors if the path exists but is not a socket
  • No new dependencies — uses existing deadpool-redis and tokio features
  • /health endpoint preserved for backward compatibility

Testing

  • cargo fmt
  • cargo clippy --all-targets --all-features -D warnings
  • cargo test -p sprout-relay — 88/88 ✅
  • cargo test -p sprout-db — 54/54 ✅

- Add SPROUT_UDS_PATH env var for optional Unix Domain Socket binding
- Dual-bind TCP + UDS via tokio::select! (gated with #[cfg(unix)])
- Add /_liveness (always 200) and /_readiness (checks MySQL + Redis)
- Concurrent readiness checks with 2s global timeout
- Safe UDS cleanup (only removes socket files, not arbitrary paths)
- Add Db::ping() method for readiness health checks
- Add redis_pool to AppState for readiness probe
- Zero behavior change when SPROUT_UDS_PATH is unset
@tlongwell-block
tlongwell-block merged commit 1f7d56e into main Mar 14, 2026
8 checks passed
@tlongwell-block
tlongwell-block deleted the cake-deployment branch March 14, 2026 11:59
tlongwell-block added a commit that referenced this pull request Mar 14, 2026
* origin/main:
  feat: optional UDS listener + health endpoints for Kubernetes deployment (#62)

# Conflicts:
#	crates/sprout-relay/src/config.rs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant