From 94798062ab6c2ae0e9a6f352b116120eaf58c681 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Wed, 10 Oct 2018 09:57:29 -0700 Subject: [PATCH] Configure Cassandra JMX Reporting Allow Cassandra JMX reporting to be configured via a property, and disable it by default since it won't work with Dropwizard metrics 4. Also update some of our own tests to explicitly disable it. Closes gh-14778 --- .../cassandra/CassandraAutoConfiguration.java | 2 ++ .../cassandra/CassandraProperties.java | 14 ++++++++++++++ ...andraDataAutoConfigurationIntegrationTests.java | 4 ++-- .../testcontainers/CassandraContainer.java | 2 +- 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cassandra/CassandraAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cassandra/CassandraAutoConfiguration.java index f725167545..9664fd883a 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cassandra/CassandraAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cassandra/CassandraAutoConfiguration.java @@ -83,6 +83,8 @@ public class CassandraAutoConfiguration { map.from(properties::getContactPoints) .as((list) -> StringUtils.toStringArray(list)) .to(builder::addContactPoints); + map.from(properties::isJmxReporting).whenFalse() + .toCall(builder::withoutJMXReporting); customize(builder); return builder.build(); } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cassandra/CassandraProperties.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cassandra/CassandraProperties.java index db3a1dd813..911c8c2c61 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cassandra/CassandraProperties.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cassandra/CassandraProperties.java @@ -132,6 +132,12 @@ public class CassandraProperties { */ private boolean ssl = false; + /** + * If JMX reporting should be enabled. Default to false as Cassandra JMX reporting is + * not compatible with Dropwizrd Metrics 4. + */ + private boolean jmxReporting = false; + /** * Pool configuration. */ @@ -272,6 +278,14 @@ public class CassandraProperties { this.ssl = ssl; } + public boolean isJmxReporting() { + return this.jmxReporting; + } + + public void setJmxReporting(boolean jmxReporting) { + this.jmxReporting = jmxReporting; + } + public String getSchemaAction() { return this.schemaAction; } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/cassandra/CassandraDataAutoConfigurationIntegrationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/cassandra/CassandraDataAutoConfigurationIntegrationTests.java index 8c9ccb499a..4ae1543fa4 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/cassandra/CassandraDataAutoConfigurationIntegrationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/cassandra/CassandraDataAutoConfigurationIntegrationTests.java @@ -95,8 +95,8 @@ public class CassandraDataAutoConfigurationIntegrationTests { } private void createTestKeyspaceIfNotExists() { - Cluster cluster = Cluster.builder().withPort(cassandra.getMappedPort()) - .addContactPoint("localhost").build(); + Cluster cluster = Cluster.builder().withoutJMXReporting() + .withPort(cassandra.getMappedPort()).addContactPoint("localhost").build(); try (Session session = cluster.connect()) { session.execute("CREATE KEYSPACE IF NOT EXISTS boot_test" + " WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 };"); diff --git a/spring-boot-project/spring-boot-tools/spring-boot-test-support/src/main/java/org/springframework/boot/testsupport/testcontainers/CassandraContainer.java b/spring-boot-project/spring-boot-tools/spring-boot-test-support/src/main/java/org/springframework/boot/testsupport/testcontainers/CassandraContainer.java index 6e8b63e84e..d0a26d3bd3 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-test-support/src/main/java/org/springframework/boot/testsupport/testcontainers/CassandraContainer.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-test-support/src/main/java/org/springframework/boot/testsupport/testcontainers/CassandraContainer.java @@ -67,7 +67,7 @@ public class CassandraContainer extends Container { private Callable checkConnection() { return () -> { - try (Cluster cluster = Cluster.builder() + try (Cluster cluster = Cluster.builder().withoutJMXReporting() .withPort(this.container.getMappedPort(CassandraContainer.PORT)) .addContactPoint("localhost").build()) { cluster.connect();