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

Add support for client name configuration #71

Merged
merged 1 commit into from
Dec 18, 2023
Merged

Add support for client name configuration #71

merged 1 commit into from
Dec 18, 2023

Conversation

ikolomi
Copy link

@ikolomi ikolomi commented Dec 10, 2023

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.

Copy link

@shachlanAmazon shachlanAmazon left a comment

Choose a reason for hiding this comment

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

round

redis/src/aio/mod.rs Outdated Show resolved Hide resolved
redis/src/aio/mod.rs Show resolved Hide resolved
redis/src/aio/mod.rs Outdated Show resolved Hide resolved
redis/src/connection.rs Show resolved Hide resolved
redis/tests/support/mod.rs Show resolved Hide resolved
redis/tests/support/mod.rs Outdated Show resolved Hide resolved
redis/tests/test_basic.rs Outdated Show resolved Hide resolved
redis/tests/test_basic.rs Show resolved Hide resolved
let this_attr: Vec<&str> = i.split('=').collect();
if this_attr[0] == "name" {
assert!(
this_attr[1] == CLIENT_NAME,

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.

Choose a reason for hiding this comment

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

Copy link
Author

@ikolomi ikolomi Dec 11, 2023

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.

Copy link
Author

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?

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();

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?

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

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.

Copy link
Author

@ikolomi ikolomi Dec 18, 2023

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)

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 Show resolved Hide resolved
@@ -212,6 +222,13 @@ impl ClusterClientBuilder {
)));
}

if client_name.is_some() && node.redis.client_name != *client_name {

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/support/cluster.rs Show resolved Hide resolved
for attr in client_attrs.iter() {
let this_attr: Vec<&str> = attr.split('=').collect();
if this_attr[0] == "name" {
assert!(

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.

for attr in client_attrs.iter() {
let this_attr: Vec<&str> = attr.split('=').collect();
if this_attr[0] == "name" {
assert!(

Choose a reason for hiding this comment

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

same

.await
.unwrap();

let client_attrs: Vec<&str> = client_info.split(' ').collect();

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();

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/Cargo.toml Show resolved Hide resolved
@@ -191,6 +194,13 @@ impl ClusterClientBuilder {
};
}

let client_name = if cluster_params.client_name.is_none() {

Choose a reason for hiding this comment

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

remove, as discussed

@@ -212,6 +222,13 @@ impl ClusterClientBuilder {
)));
}

if client_name.is_some() && node.redis.client_name != *client_name {

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?

@@ -221,6 +238,12 @@ impl ClusterClientBuilder {
})
}

/// Sets password for the new ClusterClient.

Choose a reason for hiding this comment

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

fix comment

Copy link

@shachlanAmazon shachlanAmazon left a 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!(

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!(

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!(

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!(

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.
Copy link

@barshaul barshaul left a 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 🕺🕺

@ikolomi ikolomi merged commit 896fce1 into amazon-contributing:main Dec 18, 2023
10 checks passed
@ikolomi ikolomi deleted the add_clientname_support branch December 18, 2023 19:14
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.

3 participants