-
Notifications
You must be signed in to change notification settings - Fork 1
feat: add optional REDIS_KEY_PREFIX for multi-app deployments, enable GCP Memorystore Valkey #19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
Add PrefixedRedis wrapper to support key prefixing in shared Redis instances (e.g., GCP Memorystore). When REDIS_KEY_PREFIX is set, all Redis keys are prefixed with the specified value. - Create api/src/redis.rs with PrefixedRedis wrapper - Update cluster-hashring to use start_with_prefix() - Update OAuth polling to use prefixed keys - Document REDIS_KEY_PREFIX in CLAUDE.md
2e76310 to
84addd2
Compare
- Add ValkeyConnectionFactory with GCP IAM token support - Tokens cached and auto-refreshed 5 minutes before expiry - Coordinator heartbeat monitors token TTL for connection refresh - PrefixedRedis supports factory-based connection refresh - New USE_VALKEY_IAM env var (default: false) - Backward compatible with standard Redis when IAM disabled
- Prevent token exposure in logs by not logging URLs with credentials - Add auto-refresh on auth errors in PrefixedRedis (handles token expiry) - Preserve URL scheme/path/query when injecting IAM credentials - Replace expect() panic with proper error handling - Add retry with exponential backoff for token fetch (3 attempts) - Deduplicate TOKEN_REFRESH_BUFFER_SECS constant
- Use redis ErrorKind::AuthenticationFailed instead of string matching - Add jitter to token fetch retry to prevent thundering herd
- Expand is_auth_error() to catch NOAUTH, WRONGPASS, and other auth patterns from expired IAM tokens (not just AuthenticationFailed) - Add warning log when token TTL conversion fails in valkey_auth - Add unit tests for auth error detection patterns - Add integration tests for PrefixedRedis (requires local Redis)
- Add Debug impl for ValkeyConnectionFactory (redacts sensitive fields) - Add Debug impl for PrefixedRedis (redacts connection) - Document magic values with named constants (retry params) - Improve doc comments: shorter first sentences, add # Errors sections - Add Send+Sync compile-time assertions for async types - Improve auth error detection using e.code() for NOAUTH/WRONGPASS - Keep string matching as fallback for robustness - Fix refresh_connection: return () instead of Result since errors are logged
dcadenas
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good! I added some nit picks on rust guidelines stuff, merge whenever if it looks good to you
Summary
PrefixedRediswrapper to support key prefixing in shared Redis instances (e.g., GCP Memorystore)AUTH_MODE_IAMREDIS_KEY_PREFIXis set, all Redis keys are prefixed with the specified valueUSE_VALKEY_IAM=true, uses GCP Workload Identity for authenticationChanges
Redis Key Prefix (original)
api/src/redis.rs- NewPrefixedRediswrapper withsetex,get,delmethodskeycast/src/main.rs- ReadREDIS_KEY_PREFIXenv var and pass to both componentsValkey IAM Authentication (new)
cluster-hashring/src/valkey_auth.rs- NEW:ValkeyConnectionFactorywith GCP IAM token supportcluster-hashring/src/coordinator.rs- Addstart_with_config()with IAM param, token refresh in heartbeatcluster-hashring/src/registry.rs- Addregister_with_factory()andrefresh_connection()api/src/redis.rs- Addnew_with_factory()for factory-based connection refreshkeycast/src/main.rs- ReadUSE_VALKEY_IAMenv var, share factory between coordinator and APIEnvironment Variables
REDIS_URLREDIS_KEY_PREFIXUSE_VALKEY_IAMfalseToken Refresh Strategy
Test plan
cargo buildcargo testin cluster-hashring crateUSE_VALKEY_IAM=falseagainst local RedisUSE_VALKEY_IAM=true, verify: