After upgrading Spring Boot (and friends) to 2.1.0 I suddenly lost my Hikari metrics.
It seems to be related to HikariDataSourceMetricsConfiguration, and the fact that it doesn't work with dynamic proxies. When trying to get rid of the dynamic proxy, which I'm not creating or using myself, I found that it is somehow being created by spring-cloud-starter-consul-all and if I remove that dependency, I get my clean HikariDataSource that I initially created, back.
Versions
spring-boot (+data-jpa, webflux, actuator) 2.1.0
spring-cloud-starter-consul-all 2.1.0.M1 (tested with M2 as well)
hikari 3.2.0
micrometer 1.1.0
For the time being the following workaround does the trick, but it would be nice to be able to avoid having this piece of code
@Inject
fun instrumentHikari(dataSources: Set<DataSource>, registry: MeterRegistry) {
dataSources.forEach {
getTargetObject(it, HikariDataSource::class.java).metricsTrackerFactory = MicrometerMetricsTrackerFactory(registry)
}
}
@Suppress("UNCHECKED_CAST")
fun <T> getTargetObject(proxy: Any, targetClass: Class<T>): T =
if (AopUtils.isJdkDynamicProxy(proxy))
(proxy as Advised).targetSource.target as T
else
@sganslandt can you please remove your workaround and try with Spring Boot 2.1.1.BUILD-SNAPSHOT? I believe this is already fixed as part of #15227
That did not make a difference unfortunately. The code in HikariDataSourceMetricsConfiguration is the same (checking instanceof), HikariDataSource is still a class and the bean is still wrapped in a dynamic proxy. Am I missing a version upgrade of something? Where was the fix supposed to have been made?
@sganslandt good catch, I've reopened #15227 and polished the initial fix. When #2210 completes, you'll get a new snapshot with it so please give that a try and let us know if that works for you now.
馃挜 Works! In my project at least : )
Thanks a lot for the quick feedback and will eagerly await the upgrade once 2.1.1 reaches RELEASE.
Sweet, thanks for letting us know!
Duplicate of #15227
Most helpful comment
馃挜 Works! In my project at least : )
Thanks a lot for the quick feedback and will eagerly await the upgrade once 2.1.1 reaches RELEASE.