-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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 'record-native-stats' option to jcache configuration. #460
Conversation
When true, this enables stats collection (Caffeine.recordStats() on the underlying caches. These caches can then be registered with micrometer and, imo, are more useful than the Jcache metrics.
Thanks! How would you register it into Micrometer, use A new option should be described and defaulted in reference.conf. There is a section for monitoring, which right now enables JCache's JMX beans. Should we skip the extra flag and enable native stats when that is set? Or maybe move your flag there as caffeine/jcache/src/main/resources/reference.conf Lines 49 to 56 in fe0131b
Thanks for the reminder of CLAhub disappearing. It is not important, but I should find an alternative. It's too bad how it quietly died since so I can't migrate the signatures, which kind of defeated the purpose... |
Having In regards to how I'm registering, yes, I'm using unwrap: CachingProvider provider = Caching.getCachingProvider(CaffeineCachingProvider.class.getName());
CacheManager cacheManager = provider.getCacheManager();
cacheManager.getCacheNames().forEach(name -> {
CaffeineCacheMetrics.monitor(meterRegistry, cacheManager.getCache(name).unwrap(Cache.class), name);
}); |
A quirk with the jcache adapter is that it predates the native variable expiration support. To match the spec team's providers, which used lazy expiration by relying on a size constraint, the jcache adapter adds a wrapper and manually validates the expiration. This means your stats will be a little off. I'd like to migrate to the native expiration and remove the lazy wrapper. This wasn't done yet because it appeared that it would cause backwards incompatibility with the existing configurations, so deferred until a major release. It may be possible with a fresh look, as I forget the details. The I'd propose we add the following option,
wdyt? |
You are right of course about it being per-cache. Not sure where I got that in my head. In regards to allowing the configuration of the What I think might be useful is to receive a notification when a Cache is created or even when being built. Something like:
Then one could customize (break ;)) things in preCreate. For example, one could enable stats there. In postCreate we could register it with the micrometer's CaffeineCacheMetrics. We also might just be making this over-complicated. The unwrap is not that ugly for me at least. |
Oh you're right, I forgot that the name is needed and wouldn't be supplied without a new interface. In theory I like the idea of the lifecycle listener, except that modifying the builder could cause various breakages. For example the builder rejects if a setting is made twice (like Your original proposal seems the best then, with a minor rename to I promised the Quarkus team a release over the weekend for them (added a jandex index for their graal AOT). If you don't get a chance to update this PR, I'll take it over and merge it with those minor tweaks. Thanks! 😄 |
to reference.conf.
Changed the name and moved it under monitoring. Feel free to change it more if you need/want. Thanks. |
Thanks! I tweaked it slightly to mirror other JCache idioms and will release today or tomorrow. |
When true, this enables stats collection via Caffeine.recordStats() on the underlying cache. The statistics can be accessed by using JCache's unwrap method, thereby registering into another metrics system (e.g. micrometer).
Released in 2.8.6 |
When true, this enables stats collection (Caffeine.recordStats() on
the underlying caches. These caches can then be registered with
micrometer and, imo, are more useful than the Jcache metrics.
PS: The CLA link in contributing.md is broken.