Dynamic caches not appearing in actuator endpoint
tomasAlabes opened this issue · 3 comments
Hi, first thank you for your work in this library, it makes working with memcached and spring much easier.
I was trying to look at the prometheus metrics exposed by the MemcachedCacheMetrics
class, and it seems that because CacheMetricsRegistrarConfiguration
is registering the cacheManager for the metrics on @PostConstruct
, then cacheManager.getCacheNames()
is empty and no caches are registered. The caches that are then created are not registered and no metrics are shown: link to source.
I workarounded it by registering each cache after every getCache()
, something like this
class MyMemcachedCacheManager(
private val memcachedCacheManager: MemcachedCacheManager,
private val cacheMetricsRegistrar: CacheMetricsRegistrar // bean exposed by `CacheMetricsRegistrarConfiguration`
): CacheManager {
override fun getCache(name: String): Cache? {
val cache = memcachedCacheManager.getCache(name)
cacheMetricsRegistrar.bindCacheToRegistry(cache)
return cache
}
override fun getCacheNames(): MutableCollection<String> = memcachedCacheManager.cacheNames
}
I don't know if this would be the fix or if I'm missing something, but it'd guess all the other official spring caches implementations don't have this issue.
Also, in the doc is mentioned that 60s is the default expiration, but it seems to be 0.
Using version 2.1.2
.
Thank you for reporting this. We'll take a look as soon as possible in order to remedy the cache names registration with the metrics registry.
For the default cache expiration, since version 2.x.x the cache would never expire i.e. if TTL (expiration) has not been specified, as stated in the README & Java docs.
Thanks for the response, I guess I misread the docs
We've added support for specifying the list of caches for which metrics will be collected (memcached.cache.metrics-cache-names
). At this moment dynamically adding the cache to metrics is not supported, instead the list should be specified. Resolved in #119
Thanks again for reporting this.