I am using multiple cache managers in my application - a RedisCacheManager and a JCacheCacheManager backed by EHCache.

I have found that an incompatibility with meter types registered by RedisCacheMetrics and by micrometer's JCacheMetrics causes a ClassCastException to occur when calling my application's Prometheus scrape endpoint.

It looks like RedisCacheMetrics registers a counter for "cache.removals" whereas JCacheMetrics registers a gauge:

https://github.com/spring-projects/spring-boot/blob/main/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/cache/RedisCacheMetrics.java#L71

https://github.com/micrometer-metrics/micrometer/blob/main/micrometer-core/src/main/java/io/micrometer/core/instrument/binder/cache/JCacheMetrics.java#L131

Comment From: wilkinsona

My understanding is that the number of removals cannot decrease. If that is correct, a counter is the more appropriate type for the meter and this would, ideally, be fixed in Micrometer. That said, I'm not sure how easy it is to change the type of a meter in a backwards-compatible manner. Can you please advise here @jonatan-ivanov and @shakuzen?

Comment From: shakuzen

causes a ClassCastException to occur when calling my application's Prometheus scrape endpoint.

@PaddyDrury Could you provide a stack trace for that? That would be a much more impactful failure than we expected from this.

We are aware of this inconsistency, and if we had a new major version, it would be corrected without hesitation. As Andy alludes to, it is the concern for backward compatibility that has caused us to leave things in this inconsistent state. If this is causing scraping to fail, though, that would increase the urgency to change something.