-
Notifications
You must be signed in to change notification settings - Fork 40.7k
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 redis-sentinel in spring.redis.url (Lettuce only) #27373
base: main
Are you sure you want to change the base?
Conversation
* | ||
* @author Chris Bono | ||
*/ | ||
class RedisAutoConfigurationLettuceUrlTests { |
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 chose to break these out into their own test as the existing test was already pretty unwieldy and adding this in would not help. If this is an issue we can of course consolidate back in.
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.
There isn't a relationship between the main test and the jedis related one. If you want to break things down, why not LettuceConnectionConfigurationTests
?
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 guess naming this new one containing the words "AutoConfiguration" and "Lettuce" may make it seem like this new test is the one that tests the Lettuce variant of auto-config when really the main test RedisAutoConfigurationTests
does that.
Naming this new test as you recommend is a bit clearer and may produce less confusion. I will adjust.
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.
Ok after going back into the code I think the current name makes sense. Let me summarize my thinking and you can tell me if I am off of what you are thinking about this @snicoll.
Before my changes:
RedisAutoConfiguration
:
- tests focused on provider agnostic auto-config features (albeit w/ Lettuce being the default provider).
- handles the URL configured cases (with default provider)
RedisAutoConfigurationJedisTests
:
- tests when Jedis is used as the provider
- not as exhaustive as the main
RedisAutoConfiguration
test and only focuses on URL configured cases and other Jedis specifics.
At this point the URL configured cases are handled for both providers from the 2 above tests.
My changes:
Rather than put the new Lettuce specific URL configured cases in RedisAutoConfiguration
I split it out into its own Lettuce URL auto-config test and removed any URL configured cases from the main test.
Up to this point the LettuceConnectionConfiguration
and JedisConnectionConfiguration
are tested implicitly via the RedisAutoConfiguration*Tests. I think naming this Lettuce URL test LettuceConnectionConfigurationTests
will leave contributors wondering where the Jedis version is and also it would not be testing all of the LettuceConnectionConfiguration. Therefore I think leaving it named as RedisAutoConfigurationLettuceUrlTests
makes sense.
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.
Thanks for the PR. I don't think the "Alt Schemes" are really a problem if we expand the scope of the PR a bit. Support for RedisURI
should cover our bases pretty well.
As for the validation, I don't know if failing is really an option. We do something like this in Mongo (MongoPropertiesClientSettingsBuilderCustomizer
) though. I've flagged for team attention to get more feedback.
* | ||
* @author Chris Bono | ||
*/ | ||
class RedisAutoConfigurationLettuceUrlTests { |
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.
There isn't a relationship between the main test and the jedis related one. If you want to break things down, why not LettuceConnectionConfigurationTests
?
Sounds good. I will probably add some more tests to cover the alt-schemes a bit.
Sounds good. I will see what you all come back w/ and adjust (or not) accordingly. |
I’m in two minds. On the one hand, given that we don’t have good support for clearing a property’s value, I think it’s safer not to perform the validation. You may have a profile where you’re setting the URL and want the sentinel nodes that are configured elsewhere to be ignored. On the other hand, silently ignoring some configuration may be confusing. For consistently with (most of) the rest of Boot, I think I’m leaning towards not performing any validation. |
Another option would be to log a warning rather than fail. One one hand, this could be helpful to a user when debugging a connection issue. On the other hand, a warn log may not be noticed and that is code we have to add/maintain. I will proceed as-is w/o validation. It can always be added later. |
@wilkinsona @snicoll |
@@ -41,6 +41,41 @@ The following listing shows an example of such a bean: | |||
include::{docs-java}/features/nosql/redis/connecting/MyBean.java[] | |||
---- | |||
|
|||
You can set the configprop:spring.data.redis.url[] property to change the URL and configure |
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.
@Buzzardo would you happen to be available for some of your famously fussy feedback 😺 ?
ℹ️ I based this on the MongoDB URL in the section directly below it.
|
||
The url property supports the `redis` and `rediss` schemes as well as the following additional schemes when using Lettuce: | ||
|
||
* `redis+ssl` |
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.
The list of schemes we support is only limited by what the Lettuce RedisURI. I was hesitant to link to that detail here though and instead list out the schemes directly.
@@ -82,6 +85,11 @@ LettuceConnectionFactory redisConnectionFactory( | |||
} | |||
|
|||
private LettuceConnectionFactory createLettuceConnectionFactory(LettuceClientConfiguration clientConfiguration) { | |||
if (StringUtils.hasText(this.getProperties().getUrl())) { |
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.
if (StringUtils.hasText(getProperties().getUrl())) {
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.
Checkstyle
nor format
seem to mind but it is not needed and inconsistent w/ the rest of the getProperties
invocations in here.
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 am not sure about this one. The behavior is that we're checking for specific properties for .cluster
or .sentinel
and configure that if present. This reverse the trend if an URI is set, only for Lettuce.
This makes it quite hard to resonate about. Also, any of those properties are ignored and fully replaced by the URI, which sounds like quite a big change.
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.
This reverse the trend if an URI is set, only for Lettuce.
True. Now the order they get connection config is:
- Jedis:
sentinel
->cluster
->standalone (which then uses uri)
- Lettuce:
url
->sentinel
->cluster
->standalone (which then uses uri)
This does create divergence between the 2 providers. Is the difference between the 2 providers the main concern, or the change in Lettuce connection config behavior?
Also, any of those properties are ignored and fully replaced by the URI, which sounds like quite a big change
Yeh this is why I was initially thinking about adding similar validation to MongoPropertiesClientSettingsBuilderCustomizer - which would force the consumer to use either the url or the direct props.
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.
Is the difference between the 2 providers the main concern, or the change in Lettuce connection config behavior?
Both.
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 could adjust the proposal to respect the previous order of sentinel -> cluster -> standalone (which then uses uri)
for Lettuce.
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.
@snicoll I went ahead pushed commit that respects the existing order and only deviates when the users specifies a url that has the new schemes. We are guaranteed existing clients do not use any schemes other than "redis" or "rediss" because we enforce that in RedisConnectionConfiguration base class.
This would be a compromise that allows the new schemes (below) to be taken advantage of:
- redis-sentinel
- rediss-sentinel
- redis+ssl
- redis+tls
- redis-socket
- redis+socket
Thoughts?
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 am not so sure we should be doing this. It's quite impactful and I don't know how we could conciliate the current arrangement while supporting this as an addition. Flagging for team attention again.
@@ -82,6 +85,11 @@ LettuceConnectionFactory redisConnectionFactory( | |||
} | |||
|
|||
private LettuceConnectionFactory createLettuceConnectionFactory(LettuceClientConfiguration clientConfiguration) { | |||
if (StringUtils.hasText(this.getProperties().getUrl())) { |
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 am not sure about this one. The behavior is that we're checking for specific properties for .cluster
or .sentinel
and configure that if present. This reverse the trend if an URI is set, only for Lettuce.
This makes it quite hard to resonate about. Also, any of those properties are ignored and fully replaced by the URI, which sounds like quite a big change.
…hen using Lettuce. Fixes gh-21920
…standard standalone scheme OR redis-sentinel scheme
…ocketConfiguration. Also updated test.
Looks like this one got bumped out of 2.6.x. I went ahead and updated w/ the changes I have in order to at least get a clean test run. I am happy to adjust the proposal once the team decides on a direction for the url wrt to Jedis/Redis. Just ping me when that time comes and I will hop back on this. |
7aa1646
to
5b11628
Compare
Adds support for setting the following
spring.redis.uri
when Lettuce is used:redis-sentnel
rediss-sentinel
redis-socket
redis-socket://
(#22273)Alt Schemes
ℹ️ : Because the RedisURI is being used to parse the url string, other url schemes are actually supported - namely:
redis+ssl
redis+tls
redis+socket
Should we block user's from using these alt schemes? It seems that if we don't block, we at least don't advertise the ability to use these alt schemes. @wilkinsona @snicoll wdyt?
Config Validation
I was tempted to add a validateConfiguration` that asserted that if the url was used, only the relevant other props could be used. This would of course, potentially break existing users (both Lettuce and Jedis). Just wanted to get your opinions here as well.
TODO