Search in sources :

Example 11 with RatisMetricRegistry

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);
}
Also used : RatisMetricRegistry(org.apache.ratis.metrics.RatisMetricRegistry) MetricRegistryInfo(org.apache.ratis.metrics.MetricRegistryInfo)

Example 12 with RatisMetricRegistry

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);
}
Also used : Counter(com.codahale.metrics.Counter) RatisMetricRegistry(org.apache.ratis.metrics.RatisMetricRegistry) MetricRegistryInfo(org.apache.ratis.metrics.MetricRegistryInfo)

Example 13 with RatisMetricRegistry

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);
}
Also used : LEADER_ELECTION_TIMEOUT_COUNT_METRIC(org.apache.ratis.server.metrics.LeaderElectionMetrics.LEADER_ELECTION_TIMEOUT_COUNT_METRIC) RaftGroupMemberId(org.apache.ratis.protocol.RaftGroupMemberId) TransferLeadershipException(org.apache.ratis.protocol.exceptions.TransferLeadershipException) CompletableFuture(java.util.concurrent.CompletableFuture) RaftGroupId(org.apache.ratis.protocol.RaftGroupId) Log4jUtils(org.apache.ratis.util.Log4jUtils) Level(org.apache.log4j.Level) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) Assert.fail(org.junit.Assert.fail) JavaUtils(org.apache.ratis.util.JavaUtils) RaftTestUtil.waitForLeader(org.apache.ratis.RaftTestUtil.waitForLeader) Timestamp(org.apache.ratis.util.Timestamp) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) RaftPeer(org.apache.ratis.protocol.RaftPeer) Assert.assertNotNull(org.junit.Assert.assertNotNull) RaftPeerId(org.apache.ratis.protocol.RaftPeerId) RaftServerConfigKeys(org.apache.ratis.server.RaftServerConfigKeys) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) IOException(java.io.IOException) Mockito.when(org.mockito.Mockito.when) BaseTest(org.apache.ratis.BaseTest) RatisMetricRegistry(org.apache.ratis.metrics.RatisMetricRegistry) RaftTestUtil(org.apache.ratis.RaftTestUtil) LeaderElectionMetrics(org.apache.ratis.server.metrics.LeaderElectionMetrics) TimeUnit(java.util.concurrent.TimeUnit) LEADER_ELECTION_TIME_TAKEN(org.apache.ratis.server.metrics.LeaderElectionMetrics.LEADER_ELECTION_TIME_TAKEN) List(java.util.List) LeaderSteppingDownException(org.apache.ratis.protocol.exceptions.LeaderSteppingDownException) LEADER_ELECTION_COUNT_METRIC(org.apache.ratis.server.metrics.LeaderElectionMetrics.LEADER_ELECTION_COUNT_METRIC) RaftClientReply(org.apache.ratis.protocol.RaftClientReply) RaftProperties(org.apache.ratis.conf.RaftProperties) DivisionInfo(org.apache.ratis.server.DivisionInfo) ExitUtils(org.apache.ratis.util.ExitUtils) LifeCycle(org.apache.ratis.util.LifeCycle) Optional(java.util.Optional) Timer(com.codahale.metrics.Timer) LAST_LEADER_ELECTION_ELAPSED_TIME(org.apache.ratis.server.metrics.LeaderElectionMetrics.LAST_LEADER_ELECTION_ELAPSED_TIME) RaftServer(org.apache.ratis.server.RaftServer) RaftClient(org.apache.ratis.client.RaftClient) Assert(org.junit.Assert) SegmentedRaftLogTestUtils(org.apache.ratis.server.raftlog.segmented.SegmentedRaftLogTestUtils) Assert.assertEquals(org.junit.Assert.assertEquals) TimeDuration(org.apache.ratis.util.TimeDuration) Mockito.mock(org.mockito.Mockito.mock) Timer(com.codahale.metrics.Timer) RaftServer(org.apache.ratis.server.RaftServer) Timestamp(org.apache.ratis.util.Timestamp) RatisMetricRegistry(org.apache.ratis.metrics.RatisMetricRegistry) Test(org.junit.Test) BaseTest(org.apache.ratis.BaseTest)

Aggregations

RatisMetricRegistry (org.apache.ratis.metrics.RatisMetricRegistry)13 Test (org.junit.Test)5 Timer (com.codahale.metrics.Timer)4 IOException (java.io.IOException)4 List (java.util.List)4 Level (org.apache.log4j.Level)4 RaftProperties (org.apache.ratis.conf.RaftProperties)4 RaftPeerId (org.apache.ratis.protocol.RaftPeerId)4 RaftServerConfigKeys (org.apache.ratis.server.RaftServerConfigKeys)4 Log4jUtils (org.apache.ratis.util.Log4jUtils)4 Gauge (com.codahale.metrics.Gauge)3 TimeUnit (java.util.concurrent.TimeUnit)3 RaftServer (org.apache.ratis.server.RaftServer)3 SimpleStateMachine4Testing (org.apache.ratis.statemachine.SimpleStateMachine4Testing)3 StateMachine (org.apache.ratis.statemachine.StateMachine)3 JavaUtils (org.apache.ratis.util.JavaUtils)3 Assert (org.junit.Assert)3 ArrayList (java.util.ArrayList)2 Arrays (java.util.Arrays)2 SortedMap (java.util.SortedMap)2