After migration to Spring Boot 2.0 (currently using 2.2.4), the prometheus actuator (therefore metronome) is not outputting datasource/pool connections metrics anymore. This is due the fact that I am using a multitenancy setup by means of an AbstractRoutingDatasource. Previously, info on connections appeared with the same setup.

The /actuator/metrics endpoint shows following metrics when I don't use the AbstractRouting: jdbc.connections.{min,max} hikaricp.connections.{idle,pending,active,creation,max,min,usage,timeout,aquire}

So I guess there must be a way to adapt DataSourcePoolMetadataProvider so it calls AbstractDataSource.determineTargetDataSource() and inferrs the metadata provider

Otherwise, any simple customization hack suggestion is welcomed

Comment From: wilkinsona

Thanks for the report.

Unless my memory is failing me, there was no Prometheus support in Spring Boot 1.5 so it's not clear what you were using prior to upgrading to Spring Boot 2.x. Perhaps you were using Micrometer's Spring Boot 1.5 support?

So I guess there must be a way to adapt DataSourcePoolMetadataProvider so it calls AbstractDataSource.determineTargetDataSource() and infers the metadata provider

determineTargetDataSource() relies on the lookup-key having been set and I don't think we can be sure that this will be the case when metrics are being retrieved.

To allow us to understand how things worked for you with Spring Boot 1.5 and, therefore, to be able to suggest how you can get things working with Spring Boot 2, I think we need some more information about your setup. Can you please provide a minimal sample that works with Spring Boot 1.5 but does not work when upgraded to Spring Boot 2? You can share it with us by pushing it to a separate repository on GitHub or by zipping it up and attaching it to this issue.

Comment From: nightswimmings

Thanks Andy, as always! I cannot share the code and honestly I am not sure I will find spare time to recreate such a complex scenario in my spare time, but I will try this weekend. Yes it was possible to export as prometheus in boot 1.5, https://www.ru-rocker.com/2018/03/17/setup-micrometer-prometheus-spring-boot-1-5/.

Comment From: wilkinsona

Let us know how you get on. Unfortunately, without knowing how you had things working with Spring Boot 1.5, we won't be able to offer much help with Spring Boot 2.

As far as I can tell, Micrometer didn't do anything special for AbstractRoutingDataSource. It relied upon the DataSourcePoolMetadataProviders from Spring Boot which didn't have any special treatment for AbstractRoutingDataSource either.

You could perhaps create your own DataSourcePoolMetrics beans, one for each DataSource which you have configured your AbstractRoutingDataSource to use.

Comment From: nightswimmings

That's the only practical solution, I concluded as well. Thanks!

Comment From: wilkinsona

I've opened https://github.com/spring-projects/spring-framework/issues/25544 to explore the possibility of Framework provide accessors for an AbstractRoutingDataSource's resolved targets.

Comment From: wilkinsona

spring-projects/spring-framework#25544 has been fixed. I've opened #22823 and #22824 to provide metrics and health respectively for a routing datasource's resolved targets.