gavlyukovskiy/spring-boot-data-source-decorator

flexy-pool-sample project is broken?

Closed this issue · 3 comments

When I debug SampleController.java I see the datasource is of type HikariDataSource (not FlexyPoolDataSource), and in JConsole I see an MBean For HikariDataSource and nothing for FlexyPoolDataSource.

I noticed in the README.md,

NOTE: To use FlexyPool you must add PoolAdapter for your particular connection pool.

but this sample project doesn't seem to do so.

Hi, thanks for reporting this, looks like I missed pool adapter for flexy-pool samples.

Thanks, it's working now.

One more question.
When my project has dependencies spring boot 2.0.0, flexy-hikaricp 2.0.0, flexy-pool-spring-boot-starter 1.4.0, and micrometer-registry-prometheus,
I get some great datasource metrics by hitting the /actuator/prometheus endpoint.

Is there an easy way to configure things to get the same metrics when replacing versions of dependencies with:
spring boot 1.5.9, flexy-hikaricp 1.3.0, flexy-pool-spring-boot-starter 1.3.2
(and adding additional dependency on micrometer-spring-legacy)
?

Right now, I'm only getting the very basic default datasource metrics, that are there even without using flexypool or flexy-pool-spring-boot-starter:

dataSource_connections_min, dataSource_connections_max, dataSource_connections_active

In both cases I've configured

@Configuration
public class MetricsConfig
    @Bean
    public MetricsFactory metricsFactory(){
        return MetricsFactoryResolver.INSTANCE.resolve();
    }
}

and set property decorator.datasource.metrics.enabled=true

Hi, metrics that my library provides are working only with p6spy or datasource-proxy. You can combine one of it with flexy-pool, but since you're using hikaricp it's better to use metrics from the pool itself.
In spring boot 2 they are auto-configured by default, in spring-boot 1.5 you can use custom decorator to set MeterRegistry to the HikariDataSource.

I was able to do it with flexy-pool sample by adding dependencies

compile("org.springframework.boot:spring-boot-actuator:1.5.9.RELEASE")
compile("com.zaxxer:HikariCP:2.7.8")
compile("io.micrometer:micrometer-core:1.0.2")
compile("io.micrometer:micrometer-spring-legacy:1.0.2")
compile("io.micrometer:micrometer-registry-prometheus:1.0.2")

and this bean into configuration (order 0 is needed for decorator to run before flexy pool decorator with order 10)

@Bean
public DataSourceDecorator metricsRegistryDecorator(MeterRegistry meterRegistry) {
    return new HikariMetricsDataSourceDecorator(meterRegistry);
}

@Order(0)
private static class HikariMetricsDataSourceDecorator implements DataSourceDecorator {
    private final MeterRegistry meterRegistry;

    public HikariMetricsDataSourceDecorator(MeterRegistry meterRegistry) {
        this.meterRegistry = meterRegistry;
    }

    @Override
    public DataSource decorate(String beanName, DataSource dataSource) {
        if (dataSource instanceof HikariDataSource) {
            ((HikariDataSource) dataSource).setMetricRegistry(meterRegistry);
        }
        return dataSource;
    }
}