-
Notifications
You must be signed in to change notification settings - Fork 16
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
Add support for client name configuration #71
Add support for client name configuration #71
Conversation
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.
round
redis/tests/test_async.rs
Outdated
let this_attr: Vec<&str> = i.split('=').collect(); | ||
if this_attr[0] == "name" { | ||
assert!( | ||
this_attr[1] == CLIENT_NAME, |
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.
We are planning to have additional connection for each node ('management' connection). We can't be sure it's the first client connection we find.
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.
You can take an example from this test:
https://github.com/amazon-contributing/redis-rs/pull/56/files#diff-85259ca2185589cf8979102fc91c6ce1a9461aac8ed605472b9ad53c3324c400R1912
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.
it is not the first client, its the first that has the name set. During the test it is reasonable to require that no other client has set its name.
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.
Example for what please? What is the issue we are talking about?
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.
Summarizing our talk yesterday - the test will be changed to check the client ID and based on the it would check that its name is the one passed in the config
false, | ||
); | ||
let mut con = cluster.connection(); | ||
let client_info: String = redis::cmd("CLIENT").arg("INFO").query(&mut con).unwrap(); |
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.
i'm not sure if client info is being sent to all nodes, have you checked it?
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.
I think routing it to all nodes would cover the functionality of this feature in cluster better
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.
you can't route manually in sync cluster.
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.
We think that randomly checking a single node is good enough (since we cant route to all)
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.
but you can route to all in async cluster
redis/src/cluster_client.rs
Outdated
@@ -212,6 +222,13 @@ impl ClusterClientBuilder { | |||
))); | |||
} | |||
|
|||
if client_name.is_some() && node.redis.client_name != *client_name { |
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.
IMO we should return an error if node.redis.client_name
is set, regardless of client_name
it should be an error, because it might confuse users - they'll think that setting the client name on the initial nodes will affect the whole cluster, but it won't survive any change to the cluster. WDYT?
I see that the same mistake is made with the username and password, so this can be fixed in a separate PR.
redis/tests/test_async.rs
Outdated
for attr in client_attrs.iter() { | ||
let this_attr: Vec<&str> = attr.split('=').collect(); | ||
if this_attr[0] == "name" { | ||
assert!( |
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.
you can use assert_eq!
, it logs the different values so there's no need for the extra message.
redis/tests/test_basic.rs
Outdated
for attr in client_attrs.iter() { | ||
let this_attr: Vec<&str> = attr.split('=').collect(); | ||
if this_attr[0] == "name" { | ||
assert!( |
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.
same
redis/tests/test_async.rs
Outdated
.await | ||
.unwrap(); | ||
|
||
let client_attrs: Vec<&str> = client_info.split(' ').collect(); |
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.
you're using the same logic, at the very least move the splitting into attribute pairs to a separate function. If you really want to make it handy, have it return HashMap<String, String>
.
Also, there's no need for the collecting. for
statements work on iterators:
for (key, value) in client_info.split(' ').map(|line| attr.split('=').collect::<(&str, &str)>()) {
should be sufficient.
false, | ||
); | ||
let mut con = cluster.connection(); | ||
let client_info: String = redis::cmd("CLIENT").arg("INFO").query(&mut con).unwrap(); |
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.
you can't route manually in sync cluster.
redis/src/cluster_client.rs
Outdated
@@ -191,6 +194,13 @@ impl ClusterClientBuilder { | |||
}; | |||
} | |||
|
|||
let client_name = if cluster_params.client_name.is_none() { |
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.
remove, as discussed
redis/src/cluster_client.rs
Outdated
@@ -212,6 +222,13 @@ impl ClusterClientBuilder { | |||
))); | |||
} | |||
|
|||
if client_name.is_some() && node.redis.client_name != *client_name { |
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.
I think we said it should be if client_name != node.redis.client_name {
. rigtht?
redis/src/cluster_client.rs
Outdated
@@ -221,6 +238,12 @@ impl ClusterClientBuilder { | |||
}) | |||
} | |||
|
|||
/// Sets password for the new ClusterClient. |
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.
fix 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.
all comments are minor. approved.
|
||
let client_attrs = parse_client_info(&client_info); | ||
|
||
assert!( |
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.
minor: this is essentially contained in the next assert, IMO can be removed
|
||
let client_attrs = parse_client_info(&client_info); | ||
|
||
assert!( |
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.
same
|
||
let client_attrs = parse_client_info(&client_info); | ||
|
||
assert!( |
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.
same
|
||
let client_attrs = parse_client_info(&client_info); | ||
|
||
assert!( |
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.
same
…be used with 'CLIENT SETNAME' command during connection setup.
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.
Overall approved,
But I do think the async cluster test should route to all nodes. If it's not a lot of work adding that - please do 🕺🕺
Issue #, if available:
Part of valkey-io/valkey-glide#407
Description of changes:
Add optional client_name property to RedisConnectionInfo, which will be used with 'CLIENT SETNAME' command during connection setup.
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.