-
Notifications
You must be signed in to change notification settings - Fork 41.6k
Add cache actuator endpoint for listing and clearing caches #12216
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
Conversation
67b1140 to
86e5b2a
Compare
|
Nice, thanks. |
|
See #2625 |
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 think there are several areas that need discussion, see my comments.
| */ | ||
|
|
||
| /** | ||
| * Auto-configuration for actuator Cache concerns. |
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.
Not sure we need an upper case for cache.
| } | ||
| }, | ||
| { | ||
| "name": "endpoints.caches.enabled", |
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 don't need to write deprecation information for an endpoint that did not exist in 1.5
| * @author Johannes Edmeuer | ||
| * @since 2.0.0 | ||
| */ | ||
| @Endpoint(id = "caches") |
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 id should be cache IMO (if you feel strongly otherwise, you need to rename that class then).
| } | ||
|
|
||
| @ReadOperation | ||
| public ApplicationCacheManagerBeans cacheManagerBeans() { |
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.
cacheManagers sounds more sensible to me.
| } | ||
|
|
||
| @DeleteOperation | ||
| public void clearCaches(@Nullable String contextId, @Nullable String cacheManagerName, |
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 wonder if we need to bring the complexity of BeansEndpoint here. If you are working with an application, I don't see the use case of having two cache managers with the same name in different context.
As a user, having to specify the context is very annoying isn't it?
| } | ||
| } | ||
|
|
||
| private void clearCaches(ApplicationContext context, String cacheManagerName, |
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.
Naturally I would go with clearing a cache by name and just throw an exception if there are more than one CacheManager defining a cache with that name. Again, I don't think we should bring that complexity to the user for the very few that chose a complicated setup. The name of the cache manager could be used as a selector perhaps?
| * Description of an application's {@link CacheManager} beans, primarily intended for | ||
| * serialization to JSON. | ||
| */ | ||
| public static final class ApplicationCacheManagerBeans { |
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 have a feeling those names comes from the BeansEndpoint. I don't think this applies here.
|
@snicoll Thanks for your comments. I've copied some stuff from the liquibaseEndpoint hence the handling of multiple contexts. |
|
I've renamed the endpoint to I didn't make the cacheManager a |
aa4f990 to
c193834
Compare
| cacheManager.getCacheNames().forEach(cn -> cacheManager.getCache(cn).clear()); | ||
| } | ||
| else { | ||
| cacheManager.getCache(cacheName).clear(); |
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 believe a null-pointer check is necessary here.
|
Maybe it's a good idea to add also a method for removing a single entry from the |
|
@ptahchiev let's not expand the scope of this PR please. Listing the content of the cache is definitely not at the agenda. We can refine the support once that PR is merged (or you can submit one once this one is merged). |
c193834 to
cb9eb6c
Compare
|
Added null check and rebased to master |
|
We've discussed a few things and we'd like a different output format. We'd like to list the caches with a name, potentially adding a reference to the cache manager when they are two caches with the same name. I don't like the idea of adding the penalty of the We've also discussed that the I am not sure yet how to structure the read operation so we need to give it a bit more thought. We will use this PR as the base for this work. |
cb9eb6c to
59b3eae
Compare
If we need to qualify the caches in case of duplicates names in two CacheManagers, I guess there is nothing else left to distinct the caches How about rendering links for cache eviction into the response and just prefixing the cache name in case of ambiguity? {
"caches": [
{
"name": "manager-foo/ambiguousName",
"_links": {
"evict": "/actuator/caches/manager-foo/ambiguousName"
}
},
{
"name": "manager-bar/ambiguousName",
"_links": {
"evict": "/actuator/caches/manager-bar/ambiguousName"
}
},
{
"name": "uniqueName",
"_links": {
"evict": "/actuator/caches/manager-bar/uniqueName"
}
}
]
}... if the cache name contains a |
|
@joshiste what I had in mind was more an attribute that would qualify the cache {
"caches": [
{
"name": "ambiguousName",
"cacheManager": "manager-foo"
},
{
"name": "ambiguousName",
"cacheManager": "manager-bar"
},
{
"name": "uniqueName",
"cacheManager": "manager-foo"
}
]
}Those links are also not very welcome there (if we want to do this we should do this consistently and at the endpoint API level as those links are useless and irrelevant for JMX). |
This commits adds an actuator endpoint which lists the caches per context and cacheManager and provides a delete operation to clear the caches. As the statistics are exposed via the metrics endpoint they are not included closes spring-projects#2625
- rename to CachesEndpoint - remove handling of complex Contexts - remove unecessary config metadata
59b3eae to
253a65b
Compare
|
I've modified the output of the read operation as you suggested. |
This commits adds an actuator endpoint which lists the caches per context and cacheManager and provides a delete operation to clear the caches. As the statistics are exposed via the metrics endpoint they are not included See gh-12216
* pr/12216: Polish "Add cache actuator endpoint" Add cache actuator endpoint
|
Yay! Thanks for merging! |
This commits adds an actuator endpoint which lists the caches per
context and cacheManager and provides a delete operation to clear the
caches. As the statistics are exposed via the metrics endpoint they are
not included
closes #2625