use of org.apache.ratis.metrics.RatisMetricRegistry in project incubator-ratis by apache.
the class MetricRegistriesImpl method create.
@Override
public RatisMetricRegistry create(MetricRegistryInfo info) {
return registries.put(info, () -> {
if (reporterRegistrations.isEmpty()) {
if (LOG.isDebugEnabled()) {
LOG.debug("First MetricRegistry has been created without registering reporters. " + "Hence registering JMX reporter by default.");
}
enableJmxReporter();
}
RatisMetricRegistry registry = factory.create(info);
reporterRegistrations.forEach(reg -> reg.accept(registry));
return registry;
});
}
use of org.apache.ratis.metrics.RatisMetricRegistry in project incubator-ratis by apache.
the class TestRaftServerSlownessDetection method testSlownessDetection.
@Test
public void testSlownessDetection() throws Exception {
RaftServer.Division leaderServer = RaftTestUtil.waitForLeader(cluster);
long slownessTimeout = RaftServerConfigKeys.Rpc.slownessTimeout(cluster.getProperties()).toIntExact(TimeUnit.MILLISECONDS);
RaftServer.Division failedFollower = cluster.getFollowers().get(0);
final RatisMetricRegistry ratisMetricRegistry = ((RaftServerMetricsImpl) leaderServer.getRaftServerMetrics()).getRegistry();
SortedMap<String, Gauge> heartbeatElapsedTimeGauges = ratisMetricRegistry.getGauges((s, metric) -> s.contains("lastHeartbeatElapsedTime"));
String followerId = failedFollower.getId().toString();
Gauge metric = heartbeatElapsedTimeGauges.entrySet().parallelStream().filter(e -> e.getKey().contains(followerId)).iterator().next().getValue();
long followerHeartBeatElapsedMetric = (long) metric.getValue();
// fail the node and wait for the callback to be triggered
cluster.killServer(failedFollower.getId());
Thread.sleep(slownessTimeout * 2);
long followerHeartBeatElapsedMetricNew = (long) metric.getValue();
Assert.assertTrue(followerHeartBeatElapsedMetricNew > followerHeartBeatElapsedMetric);
// Followers should not get any failed not notification
for (RaftServer.Division followerServer : cluster.getFollowers()) {
Assert.assertNull(SimpleStateMachine4Testing.get(followerServer).getSlownessInfo());
}
// the leader should get notification that the follower has failed now
RaftProtos.RoleInfoProto roleInfoProto = SimpleStateMachine4Testing.get(cluster.getLeader()).getSlownessInfo();
Assert.assertNotNull(roleInfoProto);
List<RaftProtos.ServerRpcProto> followers = roleInfoProto.getLeaderInfo().getFollowerInfoList();
// Assert that the node shutdown is lagging behind
for (RaftProtos.ServerRpcProto serverProto : followers) {
if (RaftPeerId.valueOf(serverProto.getId().getId()).equals(failedFollower.getId())) {
Assert.assertTrue(serverProto.getLastRpcElapsedTimeMs() > slownessTimeout);
}
}
}
use of org.apache.ratis.metrics.RatisMetricRegistry in project incubator-ratis by apache.
the class TestGrpcMessageMetrics method assertMessageCount.
static void assertMessageCount(RaftServer.Division server) {
String serverId = server.getId().toString();
GrpcService service = (GrpcService) RaftServerTestUtil.getServerRpc(server);
RatisMetricRegistry registry = service.getServerInterceptor().getMetrics().getRegistry();
String counter_prefix = serverId + "_" + "ratis.grpc.RaftServerProtocolService";
Assert.assertTrue(registry.counter(counter_prefix + "_" + "requestVote" + "_OK_completed_total").getCount() > 0);
}
use of org.apache.ratis.metrics.RatisMetricRegistry in project incubator-ratis by apache.
the class TestSegmentedRaftLog method testLoadLogSegments.
@Test
public void testLoadLogSegments() throws Exception {
// first generate log files
List<SegmentRange> ranges = prepareRanges(0, 5, 100, 0);
LogEntryProto[] entries = prepareLog(ranges);
// create RaftLog object and load log file
try (SegmentedRaftLog raftLog = newSegmentedRaftLog()) {
raftLog.open(RaftLog.INVALID_LOG_INDEX, null);
// check if log entries are loaded correctly
for (LogEntryProto e : entries) {
LogEntryProto entry = raftLog.get(e.getIndex());
Assert.assertEquals(e, entry);
}
final LogEntryHeader[] termIndices = raftLog.getEntries(0, 500);
LogEntryProto[] entriesFromLog = Arrays.stream(termIndices).map(ti -> {
try {
return raftLog.get(ti.getIndex());
} catch (IOException e) {
throw new RuntimeException(e);
}
}).toArray(LogEntryProto[]::new);
Assert.assertArrayEquals(entries, entriesFromLog);
Assert.assertEquals(entries[entries.length - 1], getLastEntry(raftLog));
final RatisMetricRegistry metricRegistryForLogWorker = RaftLogMetricsBase.getLogWorkerMetricRegistry(memberId);
Timer raftLogSegmentLoadLatencyTimer = metricRegistryForLogWorker.timer("segmentLoadLatency");
assertTrue(raftLogSegmentLoadLatencyTimer.getMeanRate() > 0);
Timer raftLogReadLatencyTimer = metricRegistryForLogWorker.timer("readEntryLatency");
assertTrue(raftLogReadLatencyTimer.getMeanRate() > 0);
}
}
use of org.apache.ratis.metrics.RatisMetricRegistry in project incubator-ratis by apache.
the class LogAppenderTests method testFollowerHeartbeatMetric.
@Test
public void testFollowerHeartbeatMetric() throws IOException, InterruptedException {
// Start a 3 node Ratis ring.
final MiniRaftCluster cluster = newCluster(3);
cluster.start();
final RaftServer.Division leaderServer = waitForLeader(cluster);
// Write 10 messages to leader.
try (RaftClient client = cluster.createClient(leaderServer.getId())) {
for (int i = 1; i <= 10; i++) {
client.io().send(new RaftTestUtil.SimpleMessage("Msg to make leader ready " + i));
}
} catch (IOException e) {
throw e;
}
final RatisMetricRegistry ratisMetricRegistry = ((RaftServerMetricsImpl) leaderServer.getRaftServerMetrics()).getRegistry();
// Get all last_heartbeat_elapsed_time metric gauges. Should be equal to number of followers.
SortedMap<String, Gauge> heartbeatElapsedTimeGauges = ratisMetricRegistry.getGauges((s, metric) -> s.contains("lastHeartbeatElapsedTime"));
assertTrue(heartbeatElapsedTimeGauges.size() == 2);
for (RaftServer.Division followerServer : cluster.getFollowers()) {
String followerId = followerServer.getId().toString();
Gauge metric = heartbeatElapsedTimeGauges.entrySet().parallelStream().filter(e -> e.getKey().contains(followerId)).iterator().next().getValue();
// Metric for this follower exists.
assertTrue(metric != null);
// Metric in nanos > 0.
assertTrue((long) metric.getValue() > 0);
// Try to get Heartbeat metrics for follower.
final RaftServerMetricsImpl followerMetrics = (RaftServerMetricsImpl) followerServer.getRaftServerMetrics();
// Metric should not exist. It only exists in leader.
assertTrue(followerMetrics.getRegistry().getGauges((s, m) -> s.contains("lastHeartbeatElapsedTime")).isEmpty());
for (boolean heartbeat : new boolean[] { true, false }) {
assertTrue(followerMetrics.getFollowerAppendEntryTimer(heartbeat).getMeanRate() > 0.0d);
assertTrue(followerMetrics.getFollowerAppendEntryTimer(heartbeat).getCount() > 0L);
}
}
}
Aggregations