Current behaviour
To enable the cassandra 4.x driver metrics, you need to provide the configuration below, which includes the fully qualified class name of the MetricsFactory implementation within the cassandra driver and lists of the metric names to enable.
@Configuration
public static class CassandraMetricConfig {
@Bean
public DriverConfigLoaderBuilderCustomizer driverConfigLoaderBuilderCustomizer() {
return builder -> {
builder.withString(METRICS_FACTORY_CLASS, "com.datastax.oss.driver.internal.metrics.micrometer.MicrometerMetricsFactory");
builder.withStringList(METRICS_SESSION_ENABLED, List.of("connected-nodes", "cql-requests"));
builder.withStringList(METRICS_NODE_ENABLED, List.of("pool.open-connections", "pool.in-flight"));
};
}
}
Proposed Behaviour
Expose a property to enabled the cassandra 4.x metrics, which if enabled will autoconfigure a DriverConfigLoaderBuilderCustomizer which will set the metrics factory class property to micrometer ie.
spring.data.cassandra.metrics.enabled: true
Expose two other properties to allow a user to configure which metrics should be enabled
spring.data.cassandra.metrics:
session:
- cql-requests
- connected-nodes
node:
- pool.open-connections
- pool.in-flight
Justification
To me, this feels like a very common use case and with the current way of enabling will likely result in developers writing their own ConfigurationProperties classes to give them the ability to configure this via properties. Should we provide an out of the box solution to make this easier for developers to use? No code required, just properties.
NOTE More than happy for the proposed property names to be changed.
Comment From: wilkinsona
The background to this is some discussion on Gitter last month: https://gitter.im/spring-projects/spring-boot?at=61929146cd4972068baa8635