-
Notifications
You must be signed in to change notification settings - Fork 41.1k
Adapt to Spring Session Data Redis switching to an unindexed repository by default #30673
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
Comments
This commit temporarily disables the Redis Session smoke test, as it relies on the Session Actuator endpoint being present. Since spring-projects/spring-session#1711, the default session repository contributed is not of type `FindByIndexNameSessionRepository` and thus cannot support the Session endpoint use case. Until gh-30673 is resolved, this test is disabled. See gh-30673
This change also broke a smoke test - the session actuator endpoint relies on the indexed variant of the repository. The new default doesn't allow that and the session endpoint is not auto-configured. This test has been ignored with 21eab01, until a decision is made here. |
We're not going to add a property to switch the implementations. If users want the indexed version then they'll need to configure it themselves. |
@vpavic with
Lines 51 to 69 in 7f8e2d8
We could provide a simple Endpoint variant with |
Adding that users may opt in to using a I don't have background on |
I've reinstated the smoke test in 061d86e. The app under test was using |
Was anything decided about how to handle |
We've changed our minds on this one and decided that we'd like to add a property to control |
Sorry for failing to address the mentions earlier, I missed this in a pile of unresolved notifications. I'm not involved in Spring Session maintenance for some time now, so I might be out of the loop a bit - it caught me by surprise a bit to see this already impacting Spring Boot since I don't recall getting any notifications from spring-projects/spring-session#1711 and I see the issue is still open (update: I see the milestone issue was assigned to is closed so this must be an omission).
@bclozel Irregardless of this issue, I quite like your proposal as it increases the usability of sessions endpoint. Admins might obtain the session ids by some other means (not involving Spring Session provided listing) so fetching session details and terminating the session are still valid and quite useful features. If you'd like to go in that direction, I can provide the PR.
@wilkinsona I'd suggest not to go into that direction, at least not yet. I'm not a fan of Note that when I opened spring-projects/spring-session#1711, the idea was that configuration support would be refined in a way that it's easier for users to use a non-default |
Thanks for the input, @vpavic. We discussed the option to provide Regarding |
The new Redis Note that not tying sessions endpoint on presence of indexed repository also opens up the ability to provide the endpoint in its basic form for the reactive stack, where there are no indexed repositories yet (see #10827). |
I'd avoid adding this property since we are leaning against doing this and it is very simple for a user to expose the indexed version as a Bean already. In the long term it may be good to collaborate with the Data team to see if there is a better way to support looking up by attributes. |
Thanks, Rob.
Does this mean that you're considering reverting the introduction of the attribute? FWIW, I think it's important that users can restore the old behavior easily if they wish to do so. By easily, I mean something that's a single property or a minimal amount of code.
If they define the bean themselves, the |
Sorry this was not very clear. What I meant is that, I'd avoid adding the property to Boot because we are wanting to steer users toward the non-indexed versions due to the overhead problems. We will need to revisit how to implement indexing in a way that scales better in a future release.
Can you help me understand what specific properties not-being available would make it too complex? |
IMO, changing the default already does that.
Until that's happened, I think it's important that users who need indexing and are happy with the trade-offs that it entails can easily re-enable it.
Focusing on Redis, when a user defines their own
While these attributes are configurable via attributes on In other words, a user who is using Redis with indexing and configuring the session timeout can do this today:
If we add a property to switch indexing back on, they can do this:
If we don't add the property, they'll have to do something like this: @Configuration(proxyBeanMethods = false)
@EnableConfigurationProperties(MyRedisSessionProperties.class)
public class SessionRedisConfiguration extends RedisIndexedHttpSessionConfiguration {
@Autowired
void customize(MyRedisSessionProperties properties) {
setMaxInactiveIntervalInSeconds((int) properties.getMaxInactiveInterval().getSeconds());
}
@ConfigurationProperties("my.redis.session")
static class MyRedisSessionProperties {
private Duration maxInactiveInterval;
public Duration getMaxInactiveInterval() {
return this.maxInactiveInterval;
}
public void setMaxInactiveInterval(Duration maxInactiveInterval) {
this.maxInactiveInterval = maxInactiveInterval;
}
}
} |
I don't think many applications are actually needing externalized configuration for theses properties. If they do, I don't view this as a large amount of code. Users can reuse Spring Boot's @Configuration
public class SessionConfig extends RedisIndexedHttpSessionConfiguration {
@Autowired
public void customize(SessionProperties sessionProperties, RedisSessionProperties redisSessionProperties, ServerProperties serverProperties) {
Duration timeout = sessionProperties.determineTimeout(() -> {
return serverProperties.getServlet().getSession().getTimeout();
});
if (timeout != null) {
this.setMaxInactiveIntervalInSeconds((int)timeout.getSeconds());
}
this.setRedisNamespace(redisSessionProperties.getNamespace());
this.setFlushMode(redisSessionProperties.getFlushMode());
this.setSaveMode(redisSessionProperties.getSaveMode());
this.setCleanupCron(redisSessionProperties.getCleanupCron());
}
} If Spring Boot exposed Ultimately, I think it is up to the Boot team to decide if this is too much work but I think this is a limited amount of work for a user that is moving to a major release. Additionally, our users expect to configure a Bean when they decide to go outside of the recommendations (i.e. using the index repository that is not scaling). |
They shouldn't do that. We document that the getters and setters are not public API:
This is important in allowing us to evolve configuration properties to add features and fix bugs. For example, we've had to change
Viewed in isolation, this may be a small amount of work. However, small amounts of work quickly add up to a significant amount of work that impedes adoption. We're already requiring users to move to Jakarta EE 9 which is a pretty big ask and one that we can't do much about. Given this, it's our opinion that we should do all we can to minimise the upgrade effort in other areas where we do have some control. I think this is one such area. I'll flag this for discussion at a future team meeting to see if we are in agreement. |
@rwinch and I discussed this today, and concluded that We also plan to review and potentially restructure some of the existing Spring Session configuration infrastructure, which shouldn't (at least too much) impact Spring Boot's auto-configuration support. I'll start looking into these changes next week and will share the progress here. When things are done on Spring Session side, I can also help with adopting Spring Boot to these changes. |
Thanks, @vpavic. While you're doing that, can you please keep in mind that, from Spring Boot's perspective, it's important that it's as straightforward as possible for a user to switch back to the current behaviour where an indexed repository is used. |
Sure. Being able to go back to previous defaults with least amount of friction for users is among goals for this, regardless of the way they configure Spring Session (meaning, Session's own configuration support or Boot's auto-configuration). |
To provide some updates here on the direction Spring Session will likely go in. On top of the existing For Spring Boot side of things, I'd suggest introducing a configuration property like I've sketched something along those lines in |
Thanks @vpavic - this looks like the right approach from our perspective. Would you like to turn that into pull request? |
Sure, that was the plan anyway for that branch - I was just waiting for some initial feedback from the team. |
With Spring Session moving to RedisSessionRepository as the preferred session repository, Spring Boot auto-configuration should make it possible to easily switch back to the previous default (RedisIndexedSessionRepository). This commit introduces spring.session.redis.repository configuration property that allow selecting the desired Redis-backed session repository implementation. Closes spring-projectsgh-30673
Closing in favor of #32205 |
With Spring Session moving to RedisSessionRepository as the preferred session repository, Spring Boot auto-configuration should make it possible to easily switch back to the previous default (RedisIndexedSessionRepository). This commit introduces spring.session.redis.repository configuration property that allow selecting the desired Redis-backed session repository implementation. Closes spring-projectsgh-30673
See spring-projects/spring-session#1711 for background.
Spring Session's Redis module has switched to a simpler default repository implementation. This broke Boot's build as the simpler repository does not require a cleanup cron. 4a401bf has adapted to the breaking change but means that Boot's still using an indexed repository by default.
We should probably align our default with Spring Session's and use the simpler, more performant repository by default. To do so, we'll need to do something with the
spring.session.redis.cleanup-cron
as it only applies to the indexed repository. We may also want to provide a configuration property to control the type of repository that's used, making it easy for users to switch back to the indexed repository if they wish to do so./cc @eleftherias @vpavic
The text was updated successfully, but these errors were encountered: