Skip to content

Conversation

@joshiste
Copy link
Contributor

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

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Feb 25, 2018
@joshiste joshiste force-pushed the caches-endpoint branch 4 times, most recently from 67b1140 to 86e5b2a Compare February 25, 2018 19:30
@philwebb philwebb added type: enhancement A general enhancement priority: normal and removed status: waiting-for-triage An issue we've not yet triaged labels Feb 25, 2018
@philwebb philwebb added this to the 2.1.0 milestone Feb 25, 2018
@philwebb
Copy link
Member

Nice, thanks.

@snicoll
Copy link
Member

snicoll commented Feb 26, 2018

See #2625

Copy link
Member

@snicoll snicoll left a 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.
Copy link
Member

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",
Copy link
Member

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")
Copy link
Member

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() {
Copy link
Member

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,
Copy link
Member

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,
Copy link
Member

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 {
Copy link
Member

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.

@joshiste
Copy link
Contributor Author

@snicoll Thanks for your comments. I've copied some stuff from the liquibaseEndpoint hence the handling of multiple contexts.

@joshiste
Copy link
Contributor Author

joshiste commented Feb 26, 2018

I've renamed the endpoint to CachesEndpoint.
I've removed the handling of complex context structures.
I've removed the superfluous config metadata.

I didn't make the cacheManager a @Selector since having it as queryParam allows to delete all caches over all cacheManagers.

@wilkinsona wilkinsona changed the title Add cache actuator endpoint for listing an clearing caches Add cache actuator endpoint for listing and clearing caches Feb 26, 2018
cacheManager.getCacheNames().forEach(cn -> cacheManager.getCache(cn).clear());
}
else {
cacheManager.getCache(cacheName).clear();
Copy link
Contributor

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.

@ptahchiev
Copy link
Contributor

Maybe it's a good idea to add also a method for removing a single entry from the Cache region? Would be nice to also list all the entries in a given cache region, but the current spring cache API does not allow it (jcache does it allow it).

@philwebb philwebb modified the milestones: Icebox, Backlog Mar 28, 2018
@snicoll
Copy link
Member

snicoll commented Apr 9, 2018

@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).

@joshiste
Copy link
Contributor Author

Added null check and rebased to master

@snicoll snicoll added for: team-attention An issue we'd like other members of the team to review and removed for: team-attention An issue we'd like other members of the team to review labels Apr 17, 2018
@snicoll
Copy link
Member

snicoll commented Apr 18, 2018

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 CacheManager reference where the vast majority of apps only have one and I don't like the idea of using a bean name there either.

We've also discussed that the POST operation should just drop the cache with given names, with the ability to further qualify in case of conflicts (but, IMO, that's a corner case that shouldn't happen).

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.

@philwebb philwebb added the for: merge-with-amendments Needs some changes when we merge label Apr 18, 2018
@joshiste
Copy link
Contributor Author

joshiste commented Apr 18, 2018

I don't like the idea of using a bean name there either.

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?
The downside is: it would need a mvc extension for the endpoint and doesn't clarify the usage in case of using the MXBean

{
  "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 / it need's to be encoded in the link...

@snicoll
Copy link
Member

snicoll commented Apr 25, 2018

@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
@joshiste
Copy link
Contributor Author

I've modified the output of the read operation as you suggested.

@snicoll snicoll self-assigned this Apr 27, 2018
@snicoll snicoll removed the for: merge-with-amendments Needs some changes when we merge label Apr 30, 2018
@snicoll snicoll modified the milestones: Backlog, 2.1.0.M1 Apr 30, 2018
snicoll pushed a commit that referenced this pull request Apr 30, 2018
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
@snicoll snicoll closed this in fb8a5a9 Apr 30, 2018
snicoll added a commit that referenced this pull request Apr 30, 2018
* pr/12216:
  Polish "Add cache actuator endpoint"
  Add cache actuator endpoint
@snicoll
Copy link
Member

snicoll commented Apr 30, 2018

@joshiste thanks for the PR. While reviewing, I've reworked and significantly changed the initial proposal, see fb8a5a9 for more details.

@joshiste
Copy link
Contributor Author

Yay! Thanks for merging!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: enhancement A general enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Create a cache actuator endpoint.

5 participants