Caffeine cache_puts_total counter is always zero
Hi!
Please take a look into issue. Total put counter is constantly zero, other counters are alive.
prometheus-metrics-instrumentation-caffeine 1.3.8 caffeine 3.2.0
Please include steps to reproduce and the metric name that you'd expect.
Hi! Thank you for response
I have a Boot 3.5 project with a configuration class
@Slf4j
@Configuration
public class CaffeineConfig {
@Value("${lsl.CACHE_DURATION:15}")
private int cacheDuration;
@Value("${lsl.MAX_CACHE_SIZE:1000}")
private int maxCacheSize;
@Bean
public Cache<String, Tpe> tCache() {
return Caffeine.newBuilder()
.recordStats()
.expireAfterWrite(cacheDuration, TimeUnit.SECONDS)
.initialCapacity(100)
.maximumSize(maxCacheSize)
.build();
}
@Bean
public CaffeineCacheMetrics<String, Tpe, Cache<String, Tpe>> caffeineCacheMetrics(
Cache<String, Tpe> tCache) {
return new CaffeineCacheMetrics<>(tCache, "tCache", null);
}
}
after, I`m autowire beans in service
@Autowired
Cache<String, Tpe> tCache;
.....
Tpe t = tCache.getIfPresent(key);
tCache.put(key, t);
but after a while stats are
/actuator/prometheus
# HELP cache_eviction_weight_total The sum of weights of evicted entries. This total does not include manual invalidations.
# TYPE cache_eviction_weight_total counter
cache_eviction_weight_total{cache="tCache"} 19327.0
# HELP cache_evictions_total The number of times the cache was evicted.
# TYPE cache_evictions_total counter
cache_evictions_total{cache="tCache"} 19327.0
# HELP cache_gets_total The number of times cache lookup methods have returned a cached (hit) or uncached (newly loaded or null) value (miss).
# TYPE cache_gets_total counter
cache_gets_total{cache="tCache",result="hit"} 12655.0
cache_gets_total{cache="tCache",result="miss"} 19329.0
# HELP cache_puts_total The number of entries added to the cache
# TYPE cache_puts_total counter
cache_puts_total{cache="tCache"} 0.0
# HELP cache_size The number of entries in this cache. This may be an approximation, depending on the type of cache.
# TYPE cache_size gauge
cache_size{cache="tCache"} 2.0
as you can see cache_puts_total is zero
heads up: it will take some time until I can look into the issue - help is very welcome 😄
Hey,
CaffeineCacheMetrics is not the collector in prometheus-metrics-instrumentation-caffeine, but coming from micrometer.
The one provided by prometheus-metrics-instrumentation-caffeine is CacheMetricsCollector. The counters are also prefixed with caffeine_
Hey @KazzmanK, as @pheyken points out, it doesn't look like you are using prometheus for your caffeine metrics, so you might want to open an issue with micrometer instead.