From 0f5f95d86b738f2ddf2108e4f5f38e8b2c0fb3a0 Mon Sep 17 00:00:00 2001 From: Christofer Dutz Date: Sat, 23 Sep 2023 10:06:24 +0200 Subject: [PATCH] Fix: Updated dropwizard3 to a version with the separated jmx module. (#918) --- pom.xml | 10 ++-- ratis-assembly/pom.xml | 2 +- ratis-client/pom.xml | 2 +- ratis-common/pom.xml | 2 +- .../org/apache/ratis/util/StringUtils.java | 5 +- ratis-docs/pom.xml | 2 +- ratis-examples/pom.xml | 2 +- ratis-experiments/pom.xml | 2 +- ratis-grpc/pom.xml | 2 +- ratis-metrics/pom.xml | 13 ++--- .../ratis/metrics/MetricsReporting.java | 8 +-- .../ratis/metrics/RatisMetricRegistry.java | 2 +- .../ratis/metrics/RatisObjectNameFactory.java | 50 +++++++++++++++++++ .../metrics/impl/RatisMetricRegistryImpl.java | 2 +- ratis-netty/pom.xml | 2 +- ratis-proto/pom.xml | 2 +- ratis-replicated-map/pom.xml | 2 +- ratis-resource-bundle/pom.xml | 3 +- .../main/resources/supplemental-models.xml | 14 ------ ratis-server-api/pom.xml | 2 +- ratis-server/pom.xml | 2 +- .../metrics/TestLeaderElectionMetrics.java | 18 ++++--- ratis-shell/pom.xml | 2 +- ratis-test/pom.xml | 2 +- ratis-tools/pom.xml | 2 +- 25 files changed, 96 insertions(+), 59 deletions(-) create mode 100644 ratis-metrics/src/main/java/org/apache/ratis/metrics/RatisObjectNameFactory.java diff --git a/pom.xml b/pom.xml index 21b9043ea2..0ebb44cc5b 100644 --- a/pom.xml +++ b/pom.xml @@ -24,7 +24,7 @@ ratis org.apache.ratis - 2.5.2-a4398bf-SNAPSHOT + 2.5.2-c97b814-SNAPSHOT Apache Ratis pom @@ -182,7 +182,7 @@ 3.3.0 3.1.0 1.6.1 - 4.1 + 2.2.0 0.6.1 1.0 @@ -219,7 +219,7 @@ 4 - 3.2.5 + 4.2.9 2.0.7 @@ -414,13 +414,13 @@ io.dropwizard.metrics - metrics-jvm + metrics-jmx ${dropwizard.version} io.dropwizard.metrics - metrics-ganglia + metrics-jvm ${dropwizard.version} diff --git a/ratis-assembly/pom.xml b/ratis-assembly/pom.xml index ebfb944a6c..4b4881f2b3 100644 --- a/ratis-assembly/pom.xml +++ b/ratis-assembly/pom.xml @@ -17,7 +17,7 @@ ratis org.apache.ratis - 2.5.2-a4398bf-SNAPSHOT + 2.5.2-c97b814-SNAPSHOT ratis-assembly diff --git a/ratis-client/pom.xml b/ratis-client/pom.xml index 81dcdd0baf..fcd477588e 100644 --- a/ratis-client/pom.xml +++ b/ratis-client/pom.xml @@ -17,7 +17,7 @@ ratis org.apache.ratis - 2.5.2-a4398bf-SNAPSHOT + 2.5.2-c97b814-SNAPSHOT ratis-client diff --git a/ratis-common/pom.xml b/ratis-common/pom.xml index 21cfea468c..2616721b2a 100644 --- a/ratis-common/pom.xml +++ b/ratis-common/pom.xml @@ -17,7 +17,7 @@ ratis org.apache.ratis - 2.5.2-a4398bf-SNAPSHOT + 2.5.2-c97b814-SNAPSHOT ratis-common diff --git a/ratis-common/src/main/java/org/apache/ratis/util/StringUtils.java b/ratis-common/src/main/java/org/apache/ratis/util/StringUtils.java index 68c76ba999..96719ea743 100644 --- a/ratis-common/src/main/java/org/apache/ratis/util/StringUtils.java +++ b/ratis-common/src/main/java/org/apache/ratis/util/StringUtils.java @@ -24,6 +24,7 @@ import java.io.PrintWriter; import java.io.StringWriter; +import java.nio.Buffer; import java.nio.ByteBuffer; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; @@ -113,7 +114,9 @@ public static String bytes2HexString(ByteBuffer bytes) { for(; bytes.remaining() > 0; ) { s.append(format("%02x", bytes.get())); } - bytes.flip(); + // This cast avoids compatability issues with Java 8 + // In Java 8 ByteBuffer doesn't have a "flip()" method. + ((Buffer) bytes).flip(); return s.toString(); } diff --git a/ratis-docs/pom.xml b/ratis-docs/pom.xml index e8c15088c8..7d6300510c 100644 --- a/ratis-docs/pom.xml +++ b/ratis-docs/pom.xml @@ -20,7 +20,7 @@ https://maven.apache.org/xsd/maven-4.0.0.xsd"> ratis org.apache.ratis - 2.5.2-a4398bf-SNAPSHOT + 2.5.2-c97b814-SNAPSHOT ratis-docs diff --git a/ratis-examples/pom.xml b/ratis-examples/pom.xml index 856f9ab406..b072d94423 100644 --- a/ratis-examples/pom.xml +++ b/ratis-examples/pom.xml @@ -17,7 +17,7 @@ ratis org.apache.ratis - 2.5.2-a4398bf-SNAPSHOT + 2.5.2-c97b814-SNAPSHOT ratis-examples diff --git a/ratis-experiments/pom.xml b/ratis-experiments/pom.xml index fcc3d9f3be..ceef95e4fc 100644 --- a/ratis-experiments/pom.xml +++ b/ratis-experiments/pom.xml @@ -17,7 +17,7 @@ ratis org.apache.ratis - 2.5.2-a4398bf-SNAPSHOT + 2.5.2-c97b814-SNAPSHOT ratis-experiments diff --git a/ratis-grpc/pom.xml b/ratis-grpc/pom.xml index 37c323f8f9..82cd5e0574 100644 --- a/ratis-grpc/pom.xml +++ b/ratis-grpc/pom.xml @@ -17,7 +17,7 @@ ratis org.apache.ratis - 2.5.2-a4398bf-SNAPSHOT + 2.5.2-c97b814-SNAPSHOT ratis-grpc diff --git a/ratis-metrics/pom.xml b/ratis-metrics/pom.xml index 134162cb99..2d84c1181d 100644 --- a/ratis-metrics/pom.xml +++ b/ratis-metrics/pom.xml @@ -18,7 +18,7 @@ ratis org.apache.ratis - 2.5.2-a4398bf-SNAPSHOT + 2.5.2-c97b814-SNAPSHOT ratis-metrics @@ -62,18 +62,11 @@ io.dropwizard.metrics - metrics-jvm - true + metrics-jmx io.dropwizard.metrics - metrics-ganglia - - - org.acplt - oncrpc - - + metrics-jvm true diff --git a/ratis-metrics/src/main/java/org/apache/ratis/metrics/MetricsReporting.java b/ratis-metrics/src/main/java/org/apache/ratis/metrics/MetricsReporting.java index e45cefa963..42b3f27309 100644 --- a/ratis-metrics/src/main/java/org/apache/ratis/metrics/MetricsReporting.java +++ b/ratis-metrics/src/main/java/org/apache/ratis/metrics/MetricsReporting.java @@ -21,8 +21,8 @@ import java.util.function.Consumer; import com.codahale.metrics.ConsoleReporter; -import com.codahale.metrics.JmxReporter; -import com.codahale.metrics.JmxReporter.Builder; +import com.codahale.metrics.jmx.JmxReporter; +import com.codahale.metrics.jmx.JmxReporter.Builder; import org.apache.ratis.util.TimeDuration; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -53,9 +53,9 @@ public static Consumer stopConsoleReporter() { public static Consumer jmxReporter() { return registry -> { - Builder builder = - JmxReporter.forRegistry(registry.getDropWizardMetricRegistry()); + Builder builder = JmxReporter.forRegistry(registry.getDropWizardMetricRegistry()); builder.inDomain(registry.getMetricRegistryInfo().getApplicationName()); + builder.createsObjectNamesWith(new RatisObjectNameFactory()); JmxReporter reporter = builder.build(); reporter.start(); diff --git a/ratis-metrics/src/main/java/org/apache/ratis/metrics/RatisMetricRegistry.java b/ratis-metrics/src/main/java/org/apache/ratis/metrics/RatisMetricRegistry.java index 03f419c562..d4ee1738d4 100644 --- a/ratis-metrics/src/main/java/org/apache/ratis/metrics/RatisMetricRegistry.java +++ b/ratis-metrics/src/main/java/org/apache/ratis/metrics/RatisMetricRegistry.java @@ -23,13 +23,13 @@ import com.codahale.metrics.Counter; import com.codahale.metrics.Gauge; import com.codahale.metrics.Histogram; -import com.codahale.metrics.JmxReporter; import com.codahale.metrics.Meter; import com.codahale.metrics.Metric; import com.codahale.metrics.MetricFilter; import com.codahale.metrics.MetricRegistry; import com.codahale.metrics.MetricSet; import com.codahale.metrics.Timer; +import com.codahale.metrics.jmx.JmxReporter; import org.apache.ratis.thirdparty.com.google.common.annotations.VisibleForTesting; public interface RatisMetricRegistry { diff --git a/ratis-metrics/src/main/java/org/apache/ratis/metrics/RatisObjectNameFactory.java b/ratis-metrics/src/main/java/org/apache/ratis/metrics/RatisObjectNameFactory.java new file mode 100644 index 0000000000..636a60e072 --- /dev/null +++ b/ratis-metrics/src/main/java/org/apache/ratis/metrics/RatisObjectNameFactory.java @@ -0,0 +1,50 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ratis.metrics; + +import com.codahale.metrics.jmx.JmxReporter; +import com.codahale.metrics.jmx.ObjectNameFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.management.MalformedObjectNameException; +import javax.management.ObjectName; + +public class RatisObjectNameFactory implements ObjectNameFactory { + + private static final Logger LOGGER = LoggerFactory.getLogger(JmxReporter.class); + + @Override + public ObjectName createName(String type, String domain, String name) { + try { + ObjectName objectName = new ObjectName(domain, "name", name); + if (objectName.isPattern()) { + objectName = new ObjectName(domain, "name", ObjectName.quote(name)); + } + return objectName; + } catch (MalformedObjectNameException e) { + try { + return new ObjectName(domain, "name", ObjectName.quote(name)); + } catch (MalformedObjectNameException e1) { + LOGGER.warn("Unable to register {} {}", type, name, e1); + throw new RuntimeException(e1); + } + } + } +} \ No newline at end of file diff --git a/ratis-metrics/src/main/java/org/apache/ratis/metrics/impl/RatisMetricRegistryImpl.java b/ratis-metrics/src/main/java/org/apache/ratis/metrics/impl/RatisMetricRegistryImpl.java index 952ab97b0e..911469ff81 100644 --- a/ratis-metrics/src/main/java/org/apache/ratis/metrics/impl/RatisMetricRegistryImpl.java +++ b/ratis-metrics/src/main/java/org/apache/ratis/metrics/impl/RatisMetricRegistryImpl.java @@ -25,7 +25,6 @@ import com.codahale.metrics.Counter; import com.codahale.metrics.Gauge; import com.codahale.metrics.Histogram; -import com.codahale.metrics.JmxReporter; import com.codahale.metrics.Meter; import com.codahale.metrics.Metric; import com.codahale.metrics.MetricFilter; @@ -33,6 +32,7 @@ import com.codahale.metrics.MetricRegistry.MetricSupplier; import com.codahale.metrics.MetricSet; import com.codahale.metrics.Timer; +import com.codahale.metrics.jmx.JmxReporter; import org.apache.ratis.metrics.MetricRegistryInfo; import org.apache.ratis.metrics.RatisMetricRegistry; import org.apache.ratis.thirdparty.com.google.common.annotations.VisibleForTesting; diff --git a/ratis-netty/pom.xml b/ratis-netty/pom.xml index ceac8fc775..e3c1a70342 100644 --- a/ratis-netty/pom.xml +++ b/ratis-netty/pom.xml @@ -17,7 +17,7 @@ ratis org.apache.ratis - 2.5.2-a4398bf-SNAPSHOT + 2.5.2-c97b814-SNAPSHOT ratis-netty diff --git a/ratis-proto/pom.xml b/ratis-proto/pom.xml index baa164e713..9c059064ee 100644 --- a/ratis-proto/pom.xml +++ b/ratis-proto/pom.xml @@ -17,7 +17,7 @@ ratis org.apache.ratis - 2.5.2-a4398bf-SNAPSHOT + 2.5.2-c97b814-SNAPSHOT ratis-proto diff --git a/ratis-replicated-map/pom.xml b/ratis-replicated-map/pom.xml index ce9b360497..053c1187c8 100644 --- a/ratis-replicated-map/pom.xml +++ b/ratis-replicated-map/pom.xml @@ -17,7 +17,7 @@ ratis org.apache.ratis - 2.5.2-a4398bf-SNAPSHOT + 2.5.2-c97b814-SNAPSHOT ratis-replicated-map diff --git a/ratis-resource-bundle/pom.xml b/ratis-resource-bundle/pom.xml index 46121ce766..78586883e5 100644 --- a/ratis-resource-bundle/pom.xml +++ b/ratis-resource-bundle/pom.xml @@ -23,8 +23,7 @@ ratis org.apache.ratis - 2.5.2-a4398bf-SNAPSHOT - .. + 2.5.2-c97b814-SNAPSHOT ratis-resource-bundle diff --git a/ratis-resource-bundle/src/main/resources/supplemental-models.xml b/ratis-resource-bundle/src/main/resources/supplemental-models.xml index 587ca50701..ad41dd25a8 100644 --- a/ratis-resource-bundle/src/main/resources/supplemental-models.xml +++ b/ratis-resource-bundle/src/main/resources/supplemental-models.xml @@ -50,20 +50,6 @@ under the License. - - - io.dropwizard.metrics - metrics-ganglia - - - - Apache License, Version 2.0 - http://www.apache.org/licenses/LICENSE-2.0.txt - repo - - - - io.dropwizard.metrics diff --git a/ratis-server-api/pom.xml b/ratis-server-api/pom.xml index 9e3762bab8..5a2f33c684 100644 --- a/ratis-server-api/pom.xml +++ b/ratis-server-api/pom.xml @@ -17,7 +17,7 @@ ratis org.apache.ratis - 2.5.2-a4398bf-SNAPSHOT + 2.5.2-c97b814-SNAPSHOT ratis-server-api diff --git a/ratis-server/pom.xml b/ratis-server/pom.xml index 1f4def7eb1..e88a48b8db 100644 --- a/ratis-server/pom.xml +++ b/ratis-server/pom.xml @@ -17,7 +17,7 @@ ratis org.apache.ratis - 2.5.2-a4398bf-SNAPSHOT + 2.5.2-c97b814-SNAPSHOT ratis-server diff --git a/ratis-server/src/test/java/org/apache/ratis/server/metrics/TestLeaderElectionMetrics.java b/ratis-server/src/test/java/org/apache/ratis/server/metrics/TestLeaderElectionMetrics.java index 1a6129e150..de77ac72e3 100644 --- a/ratis-server/src/test/java/org/apache/ratis/server/metrics/TestLeaderElectionMetrics.java +++ b/ratis-server/src/test/java/org/apache/ratis/server/metrics/TestLeaderElectionMetrics.java @@ -23,6 +23,8 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; +import com.codahale.metrics.Gauge; +import org.apache.ratis.BaseTest; import org.apache.ratis.metrics.RatisMetricRegistry; import org.apache.ratis.protocol.RaftGroupId; import org.apache.ratis.protocol.RaftGroupMemberId; @@ -30,10 +32,12 @@ import org.junit.BeforeClass; import org.junit.Test; +import java.util.SortedMap; + /** * Test for LeaderElectionMetrics. */ -public class TestLeaderElectionMetrics { +public class TestLeaderElectionMetrics extends BaseTest { private static LeaderElectionMetrics leaderElectionMetrics; private static RatisMetricRegistry ratisMetricRegistry; @@ -48,15 +52,17 @@ public static void setUp() { } @Test - public void testOnLeaderElectionCompletion() throws Exception { + public void testOnLeaderElectionCompletion() { leaderElectionMetrics.onNewLeaderElectionCompletion(); - Long leaderElectionLatency = (Long) ratisMetricRegistry.getGauges((s, metric) -> - s.contains(LAST_LEADER_ELECTION_ELAPSED_TIME)).values().iterator().next().getValue(); - assertTrue(leaderElectionLatency >= 0L); + final SortedMap gauges = ratisMetricRegistry.getGauges( + (s, metric) -> s.contains(LAST_LEADER_ELECTION_ELAPSED_TIME)); + LOG.info("{} gauges: {}", LAST_LEADER_ELECTION_ELAPSED_TIME, gauges); + final Long leaderElectionLatency = (Long)gauges.values().iterator().next().getValue(); + assertTrue("leaderElectionLatency = " + leaderElectionLatency, leaderElectionLatency > 0L); } @Test - public void testOnLeaderElectionTimeout() throws Exception { + public void testOnLeaderElectionTimeout() { long numLeaderElectionTimeouts = ratisMetricRegistry.counter( LEADER_ELECTION_TIMEOUT_COUNT_METRIC).getCount(); assertTrue(numLeaderElectionTimeouts == 0); diff --git a/ratis-shell/pom.xml b/ratis-shell/pom.xml index 85b1f410a6..929b815a67 100644 --- a/ratis-shell/pom.xml +++ b/ratis-shell/pom.xml @@ -17,7 +17,7 @@ ratis org.apache.ratis - 2.5.2-a4398bf-SNAPSHOT + 2.5.2-c97b814-SNAPSHOT ratis-shell diff --git a/ratis-test/pom.xml b/ratis-test/pom.xml index 0e2c38c114..6291980f2c 100644 --- a/ratis-test/pom.xml +++ b/ratis-test/pom.xml @@ -17,7 +17,7 @@ ratis org.apache.ratis - 2.5.2-a4398bf-SNAPSHOT + 2.5.2-c97b814-SNAPSHOT ratis-test diff --git a/ratis-tools/pom.xml b/ratis-tools/pom.xml index 5622c4a31f..37281543a9 100644 --- a/ratis-tools/pom.xml +++ b/ratis-tools/pom.xml @@ -17,7 +17,7 @@ ratis org.apache.ratis - 2.5.2-a4398bf-SNAPSHOT + 2.5.2-c97b814-SNAPSHOT ratis-tools