Skip to content
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

fix: Change Redis.go to support explicitely connecting to a Redis Cluster with a single address for GCP compatibility #450

Merged
merged 5 commits into from
Jul 2, 2024

Conversation

Zurvarian
Copy link
Contributor

What type of PR is this?

Uncomment only one /kind <> line, hit enter to put that in a new line, and remove leading whitespace from that line:

/kind feat
/kind build
/kind chore
/kind ci
/kind docs
/kind style
/kind refactor
/kind perf
/kind test

/kind fix

What this PR does / Why we need it:
When testing Redis connection with GCP managed Redis Cluster we've seen that GCP expects clients to connect using a single discovery IP instead of the set of IPs that is expected by Go-Redis UniversalClient.

Which issue(s) this PR fixes:

Closes #449

Special notes for your reviewer:

@Zurvarian
Copy link
Contributor Author

/gcbrun

@Zurvarian
Copy link
Contributor Author

I still need to validate this works with Metastore - Redis Cluster in GCP to ensure it works well.

Copy link
Collaborator

@lorangf lorangf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change the way we determine if the redis server is in cluster mode on not based on an additional config variable.

@@ -29,6 +29,11 @@ type Redis struct {
c redis.UniversalClient
}

const (
redisClusterPrefix = "cluster/"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not like the implicit prefix hidden in the connection string.

I prefer if you provide two explicit New functions, one for creating a redis server and another for creating a redis cluster.

ConnMaxLifetime: cfg.MaxConnAge,
var c redis.UniversalClient

if isRedisClusterAddress(cfg.Address) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use a different config variable to indicate to the service whether or not the redis server is in cluster mode or not.

@Zurvarian Zurvarian changed the title fix: Change Redis.go to support explicitely connecting to a Redis Cluster with a single address (GCP Model) fix: Change Redis.go to support explicitely connecting to a Redis Cluster with a single address for GCP compatibility Jun 28, 2024
Copy link
Collaborator

@lorangf lorangf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good but I have a question regarding the discovery endpoint.


if cfg.RedisMode == RedisModeCluster {
o := &redis.ClusterOptions{
Addrs: parseRedisClusterMultiAddress(cfg.Address),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is this working with the Redis Cluster discovery endpoint? Is the discovery endpoint a list of IPs, or is it always one IP?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://cloud.google.com/memorystore/docs/cluster/cluster-node-specification#discovery_endpoint

TL;DR: The discovery endpoint guarantees a consistent IP for the entire lifecycle of the Redis Cluster, independently of the nodes going up or down. Once the client connects to the endpoint, the client starts receiving packets with the master and replica nodes it must create a connection with.

Copy link
Collaborator

@lorangf lorangf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small tweak.

Copy link
Collaborator

@lorangf lorangf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@lorangf lorangf merged commit f72b80a into googleforgames:main Jul 2, 2024
4 checks passed
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.

Open Saves cannot connect with GCP MemoryStore - Redis Cluster
2 participants