use of org.apache.ratis.metrics.RatisMetricRegistry in project incubator-ratis by apache.
the class RaftSnapshotBaseTest method getTakeSnapshotTimer.
private static Timer getTakeSnapshotTimer(RaftServer.Division leader) {
MetricRegistryInfo info = new MetricRegistryInfo(leader.getMemberId().toString(), RATIS_APPLICATION_NAME_METRICS, RATIS_STATEMACHINE_METRICS, RATIS_STATEMACHINE_METRICS_DESC);
Optional<RatisMetricRegistry> opt = MetricRegistries.global().get(info);
Assert.assertTrue(opt.isPresent());
RatisMetricRegistry metricRegistry = opt.get();
Assert.assertNotNull(metricRegistry);
return metricRegistry.timer(STATEMACHINE_TAKE_SNAPSHOT_TIMER);
}
use of org.apache.ratis.metrics.RatisMetricRegistry in project incubator-ratis by apache.
the class TestRaftSnapshotWithGrpc method verifyInstallSnapshotMetric.
@Override
protected void verifyInstallSnapshotMetric(RaftServer.Division leader) {
MetricRegistryInfo info = new MetricRegistryInfo(leader.getMemberId().toString(), "ratis_grpc", "log_appender", "Metrics for Ratis Grpc Log Appender");
Optional<RatisMetricRegistry> metricRegistry = MetricRegistries.global().get(info);
Assert.assertTrue(metricRegistry.isPresent());
Counter installSnapshotCounter = metricRegistry.get().counter("num_install_snapshot");
Assert.assertNotNull(installSnapshotCounter);
Assert.assertTrue(installSnapshotCounter.getCount() >= 1);
}
use of org.apache.ratis.metrics.RatisMetricRegistry in project incubator-ratis by apache.
the class LeaderElectionTests method testLeaderElectionMetrics.
@Test
public void testLeaderElectionMetrics() throws IOException, InterruptedException {
Timestamp timestamp = Timestamp.currentTime();
final MiniRaftCluster cluster = newCluster(3);
cluster.start();
final RaftServer.Division leaderServer = waitForLeader(cluster);
final RatisMetricRegistry ratisMetricRegistry = LeaderElectionMetrics.getMetricRegistryForLeaderElection(leaderServer.getMemberId());
// Verify each metric individually.
long numLeaderElections = ratisMetricRegistry.counter(LEADER_ELECTION_COUNT_METRIC).getCount();
assertTrue(numLeaderElections > 0);
long numLeaderElectionTimeout = ratisMetricRegistry.counter(LEADER_ELECTION_TIMEOUT_COUNT_METRIC).getCount();
assertTrue(numLeaderElectionTimeout > 0);
Timer timer = ratisMetricRegistry.timer(LEADER_ELECTION_TIME_TAKEN);
double meanTimeNs = timer.getSnapshot().getMean();
long elapsedNs = timestamp.elapsedTime().toLong(TimeUnit.NANOSECONDS);
assertTrue(timer.getCount() > 0 && meanTimeNs < elapsedNs);
Long leaderElectionLatency = (Long) ratisMetricRegistry.getGauges((s, metric) -> s.contains(LAST_LEADER_ELECTION_ELAPSED_TIME)).values().iterator().next().getValue();
assertTrue(leaderElectionLatency > 0L);
}
Aggregations