From 64b0bdc88d614b9dca2f28801783daf471593010 Mon Sep 17 00:00:00 2001 From: Tsz-Wo Nicholas Sze Date: Wed, 31 Aug 2022 07:10:27 -0700 Subject: [PATCH] RATIS-1692. Remove the use of the thirdparty Counter. --- .../ratis/grpc/metrics/GrpcServerMetrics.java | 64 ++++++++++--- .../grpc/server/TestGrpcServerMetrics.java | 6 +- .../org/apache/ratis/metrics/LongCounter.java | 34 +++++++ .../ratis/metrics/RatisMetricRegistry.java | 5 +- .../metrics/impl/RatisMetricRegistryImpl.java | 28 ++++-- .../server/metrics/RaftServerMetricsImpl.java | 89 +++++++++++++------ .../impl/TestRatisServerMetricsBase.java | 5 +- .../statemachine/RaftSnapshotBaseTest.java | 7 +- .../ratis/grpc/TestRaftServerWithGrpc.java | 9 +- .../ratis/grpc/TestRaftSnapshotWithGrpc.java | 5 +- 10 files changed, 187 insertions(+), 65 deletions(-) create mode 100644 ratis-metrics/src/main/java/org/apache/ratis/metrics/LongCounter.java diff --git a/ratis-grpc/src/main/java/org/apache/ratis/grpc/metrics/GrpcServerMetrics.java b/ratis-grpc/src/main/java/org/apache/ratis/grpc/metrics/GrpcServerMetrics.java index dcc2d309f4..df55514f93 100644 --- a/ratis-grpc/src/main/java/org/apache/ratis/grpc/metrics/GrpcServerMetrics.java +++ b/ratis-grpc/src/main/java/org/apache/ratis/grpc/metrics/GrpcServerMetrics.java @@ -17,12 +17,16 @@ */ package org.apache.ratis.grpc.metrics; +import org.apache.ratis.metrics.LongCounter; import org.apache.ratis.metrics.MetricRegistryInfo; import org.apache.ratis.metrics.RatisMetricRegistry; import org.apache.ratis.metrics.RatisMetrics; import org.apache.ratis.thirdparty.com.codahale.metrics.Timer; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import java.util.function.Function; import java.util.function.Supplier; public class GrpcServerMetrics extends RatisMetrics { @@ -44,11 +48,27 @@ public class GrpcServerMetrics extends RatisMetrics { = "%s_pending_log_requests_count"; public static final String RATIS_GRPC_METRICS_REQUEST_RETRY_COUNT = "num_retries"; - public static final String RATIS_GRPC_METRICS_REQUESTS_TOTAL = "num_requests"; + public static final String RATIS_GRPC_METRICS_REQUESTS_COUNT = "num_requests"; public static final String RATIS_GRPC_INSTALL_SNAPSHOT_COUNT = "num_install_snapshot"; + private final LongCounter requestRetry; + private final LongCounter requestInstallSnapshot; + + private final Function requestCreate; + + private final Map> requestSuccess = new ConcurrentHashMap<>(); + private final Map> requestTimeout = new ConcurrentHashMap<>(); + + private final Map requestNotLeader = new ConcurrentHashMap<>(); + private final Map requestInconsistency = new ConcurrentHashMap<>(); + public GrpcServerMetrics(String serverId) { registry = getMetricRegistryForGrpcServer(serverId); + + requestRetry = registry.counter(RATIS_GRPC_METRICS_REQUEST_RETRY_COUNT); + requestInstallSnapshot = registry.counter(RATIS_GRPC_INSTALL_SNAPSHOT_COUNT); + + requestCreate = newHeartbeatCounter(RATIS_GRPC_METRICS_REQUESTS_COUNT); } private RatisMetricRegistry getMetricRegistryForGrpcServer(String serverId) { @@ -64,29 +84,45 @@ public Timer getGrpcLogAppenderLatencyTimer(String follower, } public void onRequestRetry() { - registry.counter(RATIS_GRPC_METRICS_REQUEST_RETRY_COUNT).inc(); + requestRetry.inc(); } public void onRequestCreate(boolean isHeartbeat) { - registry.counter(RATIS_GRPC_METRICS_REQUESTS_TOTAL + getHeartbeatSuffix(isHeartbeat)).inc(); + requestCreate.apply(isHeartbeat).inc(); + } + + private Function newRequestSuccess(String follower) { + final String prefix = String.format(RATIS_GRPC_METRICS_LOG_APPENDER_SUCCESS, follower); + return newHeartbeatCounter(prefix); } - public void onRequestSuccess(String follower, boolean isHearbeat) { - registry.counter(String.format(RATIS_GRPC_METRICS_LOG_APPENDER_SUCCESS + getHeartbeatSuffix(isHearbeat), - follower)).inc(); + public void onRequestSuccess(String follower, boolean isHeartbeat) { + requestSuccess.computeIfAbsent(follower, this::newRequestSuccess).apply(isHeartbeat).inc(); + } + + private LongCounter newRequestNotLeader(String follower) { + return registry.counter(String.format(RATIS_GRPC_METRICS_LOG_APPENDER_NOT_LEADER, follower)); } public void onRequestNotLeader(String follower) { - registry.counter(String.format(RATIS_GRPC_METRICS_LOG_APPENDER_NOT_LEADER, follower)).inc(); + requestNotLeader.computeIfAbsent(follower, this::newRequestNotLeader).inc(); + } + + private LongCounter newRequestInconsistency(String follower) { + return registry.counter(String.format(RATIS_GRPC_METRICS_LOG_APPENDER_INCONSISTENCY, follower)); } public void onRequestInconsistency(String follower) { - registry.counter(String.format(RATIS_GRPC_METRICS_LOG_APPENDER_INCONSISTENCY, follower)).inc(); + requestInconsistency.computeIfAbsent(follower, this::newRequestInconsistency).inc(); + } + + private Function newRequestTimeout(String follower) { + final String prefix = String.format(RATIS_GRPC_METRICS_LOG_APPENDER_TIMEOUT, follower); + return newHeartbeatCounter(prefix); } public void onRequestTimeout(String follower, boolean isHeartbeat) { - registry.counter(String.format(RATIS_GRPC_METRICS_LOG_APPENDER_TIMEOUT + getHeartbeatSuffix(isHeartbeat), - follower)).inc(); + requestTimeout.computeIfAbsent(follower, this::newRequestTimeout).apply(isHeartbeat).inc(); } public void addPendingRequestsCount(String follower, Supplier pendinglogQueueSize) { @@ -94,7 +130,13 @@ public void addPendingRequestsCount(String follower, Supplier pendinglo } public void onInstallSnapshot() { - registry.counter(RATIS_GRPC_INSTALL_SNAPSHOT_COUNT).inc(); + requestInstallSnapshot.inc(); + } + + private Function newHeartbeatCounter(String prefix) { + final LongCounter trueCounter = registry.counter(prefix + getHeartbeatSuffix(true)); + final LongCounter falseCounter = registry.counter(prefix + getHeartbeatSuffix(false)); + return b -> b? trueCounter : falseCounter; } public static String getHeartbeatSuffix(boolean heartbeat) { diff --git a/ratis-grpc/src/test/java/org/apache/ratis/grpc/server/TestGrpcServerMetrics.java b/ratis-grpc/src/test/java/org/apache/ratis/grpc/server/TestGrpcServerMetrics.java index 7cd10bc5d5..dad04e32e7 100644 --- a/ratis-grpc/src/test/java/org/apache/ratis/grpc/server/TestGrpcServerMetrics.java +++ b/ratis-grpc/src/test/java/org/apache/ratis/grpc/server/TestGrpcServerMetrics.java @@ -23,7 +23,7 @@ import static org.apache.ratis.grpc.metrics.GrpcServerMetrics.RATIS_GRPC_METRICS_LOG_APPENDER_PENDING_COUNT; import static org.apache.ratis.grpc.metrics.GrpcServerMetrics.RATIS_GRPC_METRICS_LOG_APPENDER_SUCCESS; import static org.apache.ratis.grpc.metrics.GrpcServerMetrics.RATIS_GRPC_METRICS_LOG_APPENDER_TIMEOUT; -import static org.apache.ratis.grpc.metrics.GrpcServerMetrics.RATIS_GRPC_METRICS_REQUESTS_TOTAL; +import static org.apache.ratis.grpc.metrics.GrpcServerMetrics.RATIS_GRPC_METRICS_REQUESTS_COUNT; import static org.apache.ratis.grpc.metrics.GrpcServerMetrics.RATIS_GRPC_METRICS_REQUEST_RETRY_COUNT; import static org.mockito.Mockito.when; @@ -88,11 +88,11 @@ public void testGrpcLogAppenderLatencyTimer() throws Exception { public void testGrpcLogRequestTotal() { for (boolean heartbeat : new boolean[] { true, false }) { long reqTotal = ratisMetricRegistry.counter( - RATIS_GRPC_METRICS_REQUESTS_TOTAL + GrpcServerMetrics + RATIS_GRPC_METRICS_REQUESTS_COUNT + GrpcServerMetrics .getHeartbeatSuffix(heartbeat)).getCount(); grpcServerMetrics.onRequestCreate(heartbeat); Assert.assertEquals(reqTotal + 1, ratisMetricRegistry.counter( - RATIS_GRPC_METRICS_REQUESTS_TOTAL + GrpcServerMetrics + RATIS_GRPC_METRICS_REQUESTS_COUNT + GrpcServerMetrics .getHeartbeatSuffix(heartbeat)).getCount()); } } diff --git a/ratis-metrics/src/main/java/org/apache/ratis/metrics/LongCounter.java b/ratis-metrics/src/main/java/org/apache/ratis/metrics/LongCounter.java new file mode 100644 index 0000000000..b69b64a4eb --- /dev/null +++ b/ratis-metrics/src/main/java/org/apache/ratis/metrics/LongCounter.java @@ -0,0 +1,34 @@ +/* + * 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; + +public interface LongCounter { + default void inc() { + inc(1L); + } + + void inc(long n); + + default void dec() { + dec(1L); + } + + void dec(long n); + + long getCount(); +} 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 2d0887e340..fc29f45a90 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 @@ -18,7 +18,6 @@ package org.apache.ratis.metrics; import org.apache.ratis.thirdparty.com.codahale.metrics.ConsoleReporter; -import org.apache.ratis.thirdparty.com.codahale.metrics.Counter; import org.apache.ratis.thirdparty.com.codahale.metrics.Histogram; import org.apache.ratis.thirdparty.com.codahale.metrics.Meter; import org.apache.ratis.thirdparty.com.codahale.metrics.Metric; @@ -33,7 +32,7 @@ public interface RatisMetricRegistry { Timer timer(String name); - Counter counter(String name); + LongCounter counter(String name); boolean remove(String name); @@ -41,8 +40,6 @@ public interface RatisMetricRegistry { Timer timer(String name, MetricRegistry.MetricSupplier supplier); - Counter counter(String name, MetricRegistry.MetricSupplier supplier); - Histogram histogram(String name); Meter meter(String name); 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 9b780d5976..e77aa7b4c6 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 @@ -17,6 +17,7 @@ */ package org.apache.ratis.metrics.impl; +import org.apache.ratis.metrics.LongCounter; import org.apache.ratis.metrics.MetricRegistryInfo; import org.apache.ratis.metrics.RatisMetricRegistry; import org.apache.ratis.thirdparty.com.codahale.metrics.ConsoleReporter; @@ -57,9 +58,28 @@ public Timer timer(String name) { return metricRegistry.timer(getMetricName(name)); } + static LongCounter toLongCounter(Counter c) { + return new LongCounter() { + @Override + public void inc(long n) { + c.inc(n); + } + + @Override + public void dec(long n) { + c.dec(n); + } + + @Override + public long getCount() { + return c.getCount(); + } + }; + } + @Override - public Counter counter(String name) { - return metricRegistry.counter(getMetricName(name)); + public LongCounter counter(String name) { + return toLongCounter(metricRegistry.counter(getMetricName(name))); } @Override @@ -84,10 +104,6 @@ public SortedMap getGauges(MetricFilter filter) { return metricRegistry.getGauges(filter); } - @Override public Counter counter(String name, MetricRegistry.MetricSupplier supplier) { - return metricRegistry.counter(getMetricName(name), supplier); - } - @Override public Histogram histogram(String name) { return metricRegistry.histogram(getMetricName(name)); } diff --git a/ratis-server/src/main/java/org/apache/ratis/server/metrics/RaftServerMetricsImpl.java b/ratis-server/src/main/java/org/apache/ratis/server/metrics/RaftServerMetricsImpl.java index 35e35c1cd0..f8476eb8c3 100644 --- a/ratis-server/src/main/java/org/apache/ratis/server/metrics/RaftServerMetricsImpl.java +++ b/ratis-server/src/main/java/org/apache/ratis/server/metrics/RaftServerMetricsImpl.java @@ -25,7 +25,7 @@ import java.util.function.Function; import java.util.function.Supplier; -import org.apache.ratis.thirdparty.com.codahale.metrics.Counter; +import org.apache.ratis.metrics.LongCounter; import org.apache.ratis.thirdparty.com.codahale.metrics.Timer; import org.apache.ratis.metrics.MetricRegistryInfo; @@ -54,9 +54,11 @@ public final class RaftServerMetricsImpl extends RatisMetrics implements RaftSer public static final String RAFT_CLIENT_STALE_READ_REQUEST = "clientStaleReadRequest"; public static final String RAFT_CLIENT_WRITE_REQUEST = "clientWriteRequest"; public static final String RAFT_CLIENT_WATCH_REQUEST = "clientWatch%sRequest"; + public static final String REQUEST_QUEUE_LIMIT_HIT_COUNTER = "numRequestQueueLimitHits"; - public static final String RESOURCE_LIMIT_HIT_COUNTER = "leaderNumResourceLimitHits"; public static final String REQUEST_BYTE_SIZE_LIMIT_HIT_COUNTER = "numRequestsByteSizeLimitHits"; + public static final String RESOURCE_LIMIT_HIT_COUNTER = "numResourceLimitHits"; + public static final String REQUEST_QUEUE_SIZE = "numPendingRequestInQueue"; public static final String REQUEST_MEGA_BYTE_SIZE = "numPendingRequestMegaByteSize"; public static final String RETRY_CACHE_ENTRY_COUNT_METRIC = "retryCacheEntryCount"; @@ -64,18 +66,26 @@ public final class RaftServerMetricsImpl extends RatisMetrics implements RaftSer public static final String RETRY_CACHE_HIT_RATE_METRIC = "retryCacheHitRate"; public static final String RETRY_CACHE_MISS_COUNT_METRIC = "retryCacheMissCount"; public static final String RETRY_CACHE_MISS_RATE_METRIC = "retryCacheMissRate"; - public static final String RATIS_SERVER_FAILED_CLIENT_STALE_READ_COUNT = - "numFailedClientStaleReadOnServer"; - public static final String RATIS_SERVER_FAILED_CLIENT_READ_COUNT = - "numFailedClientReadOnServer"; - public static final String RATIS_SERVER_FAILED_CLIENT_WRITE_COUNT = - "numFailedClientWriteOnServer"; - public static final String RATIS_SERVER_FAILED_CLIENT_WATCH_COUNT = - "numFailedClientWatchOnServer"; - public static final String RATIS_SERVER_FAILED_CLIENT_STREAM_COUNT = - "numFailedClientStreamOnServer"; + + public static final String RATIS_SERVER_FAILED_CLIENT_STALE_READ_COUNT = "numFailedClientStaleReadOnServer"; + public static final String RATIS_SERVER_FAILED_CLIENT_READ_COUNT = "numFailedClientReadOnServer"; + public static final String RATIS_SERVER_FAILED_CLIENT_WRITE_COUNT = "numFailedClientWriteOnServer"; + public static final String RATIS_SERVER_FAILED_CLIENT_WATCH_COUNT = "numFailedClientWatchOnServer"; + public static final String RATIS_SERVER_FAILED_CLIENT_STREAM_COUNT = "numFailedClientStreamOnServer"; public static final String RATIS_SERVER_INSTALL_SNAPSHOT_COUNT = "numInstallSnapshot"; + private final LongCounter numRequestQueueLimitHits; + private final LongCounter numRequestsByteSizeLimitHits; + private final LongCounter numResourceLimitHits; + + private final LongCounter numFailedClientStaleRead; + private final LongCounter numFailedClientRead; + private final LongCounter numFailedClientWrite; + private final LongCounter numFailedClientWatch; + private final LongCounter numFailedClientStream; + + private final LongCounter numInstallSnapshot; + /** Follower Id -> heartbeat elapsed */ private final Map followerLastHeartbeatElapsedTimeMap = new HashMap<>(); private final Supplier> commitInfoCache; @@ -106,10 +116,43 @@ public RaftServerMetricsImpl(RaftGroupMemberId serverId, Supplier retryCacheStatistics) { this.registry = getMetricRegistryForRaftServer(serverId.toString()); this.commitInfoCache = commitInfoCache; + + numRequestQueueLimitHits = registry.counter(REQUEST_QUEUE_LIMIT_HIT_COUNTER); + numRequestsByteSizeLimitHits = registry.counter(REQUEST_BYTE_SIZE_LIMIT_HIT_COUNTER); + numResourceLimitHits = registry.counter(RESOURCE_LIMIT_HIT_COUNTER); + + numFailedClientStaleRead = registry.counter(RATIS_SERVER_FAILED_CLIENT_STALE_READ_COUNT); + numFailedClientRead = registry.counter(RATIS_SERVER_FAILED_CLIENT_READ_COUNT); + numFailedClientWrite = registry.counter(RATIS_SERVER_FAILED_CLIENT_WRITE_COUNT); + numFailedClientWatch = registry.counter(RATIS_SERVER_FAILED_CLIENT_WATCH_COUNT); + numFailedClientStream = registry.counter(RATIS_SERVER_FAILED_CLIENT_STREAM_COUNT); + + numInstallSnapshot = registry.counter(RATIS_SERVER_INSTALL_SNAPSHOT_COUNT); + addPeerCommitIndexGauge(serverId.getPeerId()); addRetryCacheMetric(retryCacheStatistics); } + public LongCounter getNumRequestQueueLimitHits() { + return numRequestQueueLimitHits; + } + + public LongCounter getNumRequestsByteSizeLimitHits() { + return numRequestsByteSizeLimitHits; + } + + public LongCounter getNumResourceLimitHits() { + return numResourceLimitHits; + } + + public LongCounter getNumFailedClientStaleRead() { + return numFailedClientStaleRead; + } + + public LongCounter getNumInstallSnapshot() { + return numInstallSnapshot; + } + private RatisMetricRegistry getMetricRegistryForRaftServer(String serverId) { return create(new MetricRegistryInfo(serverId, RATIS_APPLICATION_NAME_METRICS, RATIS_SERVER_METRICS, @@ -171,10 +214,6 @@ public Timer getTimer(String timerName) { return registry.timer(timerName); } - public Counter getCounter(String counterName) { - return registry.counter(counterName); - } - public Timer getClientRequestTimer(Type request) { if (request.is(TypeCase.READ)) { return getTimer(RAFT_CLIENT_READ_REQUEST); @@ -190,7 +229,7 @@ public Timer getClientRequestTimer(Type request) { } public void onRequestQueueLimitHit() { - registry.counter(REQUEST_QUEUE_LIMIT_HIT_COUNTER).inc(); + numRequestQueueLimitHits.inc(); } public void addNumPendingRequestsGauge(Supplier queueSize) { @@ -210,31 +249,31 @@ public boolean removeNumPendingRequestsByteSize() { } public void onRequestByteSizeLimitHit() { - registry.counter(REQUEST_BYTE_SIZE_LIMIT_HIT_COUNTER).inc(); + numRequestsByteSizeLimitHits.inc(); } public void onResourceLimitHit() { - registry.counter(RESOURCE_LIMIT_HIT_COUNTER).inc(); + numResourceLimitHits.inc(); } void onFailedClientStaleRead() { - registry.counter(RATIS_SERVER_FAILED_CLIENT_STALE_READ_COUNT).inc(); + numFailedClientStaleRead.inc(); } void onFailedClientRead() { - registry.counter(RATIS_SERVER_FAILED_CLIENT_READ_COUNT).inc(); + numFailedClientRead.inc(); } void onFailedClientWatch() { - registry.counter(RATIS_SERVER_FAILED_CLIENT_WATCH_COUNT).inc(); + numFailedClientWatch.inc(); } void onFailedClientWrite() { - registry.counter(RATIS_SERVER_FAILED_CLIENT_WRITE_COUNT).inc(); + numFailedClientWrite.inc(); } void onFailedClientStream() { - registry.counter(RATIS_SERVER_FAILED_CLIENT_STREAM_COUNT).inc(); + numFailedClientStream.inc(); } public void incFailedRequestCount(Type type) { @@ -253,7 +292,7 @@ public void incFailedRequestCount(Type type) { @Override public void onSnapshotInstalled() { - registry.counter(RATIS_SERVER_INSTALL_SNAPSHOT_COUNT).inc(); + numInstallSnapshot.inc(); } public RatisMetricRegistry getRegistry() { diff --git a/ratis-server/src/test/java/org/apache/ratis/server/impl/TestRatisServerMetricsBase.java b/ratis-server/src/test/java/org/apache/ratis/server/impl/TestRatisServerMetricsBase.java index 3104f08990..88ada6a8fc 100644 --- a/ratis-server/src/test/java/org/apache/ratis/server/impl/TestRatisServerMetricsBase.java +++ b/ratis-server/src/test/java/org/apache/ratis/server/impl/TestRatisServerMetricsBase.java @@ -17,7 +17,6 @@ */ package org.apache.ratis.server.impl; -import static org.apache.ratis.server.metrics.RaftServerMetricsImpl.RATIS_SERVER_FAILED_CLIENT_STALE_READ_COUNT; import static org.junit.Assert.assertEquals; import java.io.IOException; @@ -67,8 +66,8 @@ void runTestClientFailedRequest(CLUSTER cluster) .setType(RaftClientRequest.staleReadRequestType(Long.MAX_VALUE)) .build(); final CompletableFuture f = leaderImpl.getRaftServer().submitClientRequestAsync(r); - Assert.assertTrue(!f.get().isSuccess()); + Assert.assertFalse(f.get().isSuccess()); assertEquals(1L, ((RaftServerMetricsImpl)leaderImpl.getRaftServerMetrics()) - .getCounter(RATIS_SERVER_FAILED_CLIENT_STALE_READ_COUNT).getCount()); + .getNumFailedClientStaleRead().getCount()); } } diff --git a/ratis-server/src/test/java/org/apache/ratis/statemachine/RaftSnapshotBaseTest.java b/ratis-server/src/test/java/org/apache/ratis/statemachine/RaftSnapshotBaseTest.java index d168b7e2f7..ce301124f6 100644 --- a/ratis-server/src/test/java/org/apache/ratis/statemachine/RaftSnapshotBaseTest.java +++ b/ratis-server/src/test/java/org/apache/ratis/statemachine/RaftSnapshotBaseTest.java @@ -20,11 +20,11 @@ import static org.apache.ratis.server.impl.StateMachineMetrics.RATIS_STATEMACHINE_METRICS; import static org.apache.ratis.server.impl.StateMachineMetrics.RATIS_STATEMACHINE_METRICS_DESC; import static org.apache.ratis.server.impl.StateMachineMetrics.STATEMACHINE_TAKE_SNAPSHOT_TIMER; -import static org.apache.ratis.server.metrics.RaftServerMetricsImpl.RATIS_SERVER_INSTALL_SNAPSHOT_COUNT; import static org.apache.ratis.metrics.RatisMetrics.RATIS_APPLICATION_NAME_METRICS; import org.apache.log4j.Level; import org.apache.ratis.BaseTest; +import org.apache.ratis.metrics.LongCounter; import org.apache.ratis.server.impl.MiniRaftCluster; import org.apache.ratis.RaftTestUtil; import org.apache.ratis.RaftTestUtil.SimpleMessage; @@ -61,7 +61,6 @@ import java.util.stream.Collectors; import java.util.stream.LongStream; -import org.apache.ratis.thirdparty.com.codahale.metrics.Counter; import org.apache.ratis.thirdparty.com.codahale.metrics.Timer; public abstract class RaftSnapshotBaseTest extends BaseTest { @@ -311,8 +310,8 @@ public void testInstallSnapshotDuringBootstrap() throws Exception { } protected void verifyInstallSnapshotMetric(RaftServer.Division leader) { - final Counter installSnapshotCounter = ((RaftServerMetricsImpl)leader.getRaftServerMetrics()) - .getCounter(RATIS_SERVER_INSTALL_SNAPSHOT_COUNT); + final LongCounter installSnapshotCounter = ((RaftServerMetricsImpl)leader.getRaftServerMetrics()) + .getNumInstallSnapshot(); Assert.assertNotNull(installSnapshotCounter); Assert.assertTrue(installSnapshotCounter.getCount() >= 1); } diff --git a/ratis-test/src/test/java/org/apache/ratis/grpc/TestRaftServerWithGrpc.java b/ratis-test/src/test/java/org/apache/ratis/grpc/TestRaftServerWithGrpc.java index d44e38b878..ccdd8474cd 100644 --- a/ratis-test/src/test/java/org/apache/ratis/grpc/TestRaftServerWithGrpc.java +++ b/ratis-test/src/test/java/org/apache/ratis/grpc/TestRaftServerWithGrpc.java @@ -21,9 +21,6 @@ import static org.apache.ratis.server.metrics.RaftServerMetricsImpl.RAFT_CLIENT_STALE_READ_REQUEST; import static org.apache.ratis.server.metrics.RaftServerMetricsImpl.RAFT_CLIENT_WATCH_REQUEST; import static org.apache.ratis.server.metrics.RaftServerMetricsImpl.RAFT_CLIENT_WRITE_REQUEST; -import static org.apache.ratis.server.metrics.RaftServerMetricsImpl.REQUEST_QUEUE_LIMIT_HIT_COUNTER; -import static org.apache.ratis.server.metrics.RaftServerMetricsImpl.REQUEST_BYTE_SIZE_LIMIT_HIT_COUNTER; -import static org.apache.ratis.server.metrics.RaftServerMetricsImpl.RESOURCE_LIMIT_HIT_COUNTER; import org.apache.ratis.server.storage.RaftStorage; import org.apache.log4j.Level; @@ -257,7 +254,7 @@ void testRequestMetrics(MiniRaftClusterWithGrpc cluster) throws Exception { // Because we have passed 11 requests, and the element queue size is 10. RaftTestUtil.waitFor(() -> getRaftServerMetrics(cluster.getLeader()) - .getCounter(REQUEST_QUEUE_LIMIT_HIT_COUNTER).getCount() == 1, 300, 5000); + .getNumRequestQueueLimitHits().getCount() == 1, 300, 5000); stateMachine.unblockFlushStateMachineData(); @@ -272,10 +269,10 @@ void testRequestMetrics(MiniRaftClusterWithGrpc cluster) throws Exception { clients.add(client); RaftTestUtil.waitFor(() -> getRaftServerMetrics(cluster.getLeader()) - .getCounter(REQUEST_BYTE_SIZE_LIMIT_HIT_COUNTER).getCount() == 1, 300, 5000); + .getNumRequestsByteSizeLimitHits().getCount() == 1, 300, 5000); Assert.assertEquals(2, getRaftServerMetrics(cluster.getLeader()) - .getCounter(RESOURCE_LIMIT_HIT_COUNTER).getCount()); + .getNumResourceLimitHits().getCount()); } finally { for (RaftClient client : clients) { client.close(); diff --git a/ratis-test/src/test/java/org/apache/ratis/grpc/TestRaftSnapshotWithGrpc.java b/ratis-test/src/test/java/org/apache/ratis/grpc/TestRaftSnapshotWithGrpc.java index 2c72df09f2..2d8524f26c 100644 --- a/ratis-test/src/test/java/org/apache/ratis/grpc/TestRaftSnapshotWithGrpc.java +++ b/ratis-test/src/test/java/org/apache/ratis/grpc/TestRaftSnapshotWithGrpc.java @@ -19,6 +19,7 @@ import java.util.Optional; +import org.apache.ratis.metrics.LongCounter; import org.apache.ratis.server.impl.MiniRaftCluster; import org.apache.ratis.metrics.MetricRegistries; import org.apache.ratis.metrics.MetricRegistryInfo; @@ -27,8 +28,6 @@ import org.apache.ratis.statemachine.RaftSnapshotBaseTest; import org.junit.Assert; -import org.apache.ratis.thirdparty.com.codahale.metrics.Counter; - public class TestRaftSnapshotWithGrpc extends RaftSnapshotBaseTest { @Override public MiniRaftCluster.Factory getFactory() { @@ -41,7 +40,7 @@ protected void verifyInstallSnapshotMetric(RaftServer.Division leader) { "ratis_grpc", "log_appender", "Metrics for Ratis Grpc Log Appender"); Optional metricRegistry = MetricRegistries.global().get(info); Assert.assertTrue(metricRegistry.isPresent()); - Counter installSnapshotCounter = metricRegistry.get().counter("num_install_snapshot"); + final LongCounter installSnapshotCounter = metricRegistry.get().counter("num_install_snapshot"); Assert.assertNotNull(installSnapshotCounter); Assert.assertTrue(installSnapshotCounter.getCount() >= 1); }