-
Notifications
You must be signed in to change notification settings - Fork 31
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
Cache Metrics Broken on JDK > 11 #605
Comments
does it work if you add |
I was able to reproduce this issue with micronaut 4.0.0 |
do you have a sample application @Richardson-e ? |
fyi, in JCache you have to enable stats as part of the cache configuration. For Caffeine, if using the config file, caffeine.jcache.default.monitoring.statistics = true where Since JCache requires JMX (management = true) you can enable and verify in jconsole separately from other reporters. |
https://github.com/Richardson-e/hello-world-caffeine-cache I'll take a look at explicitly enabling stats for jcache as part of the cache config. |
@Richardson-e assigning this to @guillermocalvo who has more availability |
So I've been looking into this issue and I believe cache metrics are working as expected, as far as Micronaut layer is concerned. It just so happens that Caffeine collects "performance statistics", which are not exactly the same as "usage statistics". Here's what cache statistics look like for Caffeine: On the one hand, there's simply no cache_puts recorded by Caffeine. On the other hand, Caffeine doesn't keep track of manually removed cache entries, which means that cache_evictions will not be altered as a result of invoking methods annotated with On the bright side though, Caffeine does report metrics for cache hits and cache misses. Which means that cache_gets will be incremented over time, as In summary,
Here's a sample application that collects cache metrics and exposes them through After playing around with it for a while,
@broadcom-tony Please note that in order to activate metrics for a specific cache, we need to explicitly set config property @sdelamo @Richardson-e I think it's safe to say that Micronaut is doing what it possibly can to retrieve and expose Caffeine metrics. Any thoughts before I close this ticket? |
@guillermocalvo Thanks for the in-depth description and investigation. I just looked in to |
The cache primarily tries to capture statistics that users couldn't easily obtain themselves, like the hit rate and number of evictions, and anything else of interest can be added by the user. The usage is meant to be a hidden implementation detail of the class, like one would use ConcurrentHashMap, so the caller might wrap it for the outside world. Is there any reason to not enrich the native stats by adding to the provider's DefaultSyncCache.put? A reason for this approach is that the more flexible of an api that is provided, the more ambiguous it is to map into statistics. The Map interface's |
Expected Behavior
All caching metrics should work cache_size, cache_puts, hits, etc.
Actual Behaviour
cache_size metrics work but cache_puts, hits, etc do not increment. This issue describes the behavior:
#94
I believe the issue is that
javax
was pulled out of the JDK in version 11 and greater however theJCacheMetricsBinder.java
and potentially other places @requirejavax.cache.CacheManager
to load their bean.See:
https://github.com/micronaut-projects/micronaut-cache/blob/master/cache-core/src/main/java/io/micronaut/cache/jcache/metrics/JCacheMetricsBinder.java#L42
Steps To Reproduce
No response
Environment Information
`
id "io.micronaut.minimal.application" version "3.7.8"
micronaut {
version = "3.9.1"
}
implementation "io.micronaut.micrometer:micronaut-micrometer-core"
implementation "io.micronaut.micrometer:micronaut-micrometer-registry-prometheus"
implementation "io.micronaut.cache:micronaut-cache-core"
implementation "io.micronaut.cache:micronaut-cache-caffeine"
Example Application
No response
Version
3.9.1
The text was updated successfully, but these errors were encountered: