spring-boot icon indicating copy to clipboard operation
spring-boot copied to clipboard

Enable Cassandra Driver Metrics Via Properties

Open michaelmcfadyensky opened this issue 4 years ago • 2 comments

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.

michaelmcfadyensky avatar Dec 06 '21 14:12 michaelmcfadyensky

The background to this is some discussion on Gitter last month: https://gitter.im/spring-projects/spring-boot?at=61929146cd4972068baa8635

wilkinsona avatar Dec 06 '21 15:12 wilkinsona

The Micrometer-based implementation of Cassandra's MetricsFactory interface is in a separate module. We could provide auto-configuration in spring-boot-cassandra that auto-configures Cassandra's metrics when java-driver-metrics-micrometer is on the classpath. This would remove the need for an enabled property, although we may want some other properties for the various settings.

wilkinsona avatar Dec 10 '25 10:12 wilkinsona