Search in sources :

Example 1 with QuorumState

use of org.apache.kafka.raft.QuorumState in project kafka by apache.

the class KafkaRaftMetricsTest method shouldRecordPollIdleRatio.

@Test
public void shouldRecordPollIdleRatio() throws IOException {
    QuorumState state = buildQuorumState(Collections.singleton(localId));
    state.initialize(new OffsetAndEpoch(0L, 0));
    raftMetrics = new KafkaRaftMetrics(metrics, "raft", state);
    raftMetrics.updatePollStart(time.milliseconds());
    time.sleep(100L);
    raftMetrics.updatePollEnd(time.milliseconds());
    time.sleep(900L);
    raftMetrics.updatePollStart(time.milliseconds());
    assertEquals(0.1, getMetric(metrics, "poll-idle-ratio-avg").metricValue());
    time.sleep(100L);
    raftMetrics.updatePollEnd(time.milliseconds());
    time.sleep(100L);
    raftMetrics.updatePollStart(time.milliseconds());
    assertEquals(0.3, getMetric(metrics, "poll-idle-ratio-avg").metricValue());
}
Also used : OffsetAndEpoch(org.apache.kafka.raft.OffsetAndEpoch) QuorumState(org.apache.kafka.raft.QuorumState) Test(org.junit.jupiter.api.Test)

Example 2 with QuorumState

use of org.apache.kafka.raft.QuorumState in project kafka by apache.

the class KafkaRaftMetricsTest method shouldRecordNonVoterQuorumState.

@Test
public void shouldRecordNonVoterQuorumState() throws IOException {
    QuorumState state = buildQuorumState(Utils.mkSet(1, 2, 3));
    state.initialize(new OffsetAndEpoch(0L, 0));
    raftMetrics = new KafkaRaftMetrics(metrics, "raft", state);
    assertEquals("unattached", getMetric(metrics, "current-state").metricValue());
    assertEquals((double) -1L, getMetric(metrics, "current-leader").metricValue());
    assertEquals((double) -1L, getMetric(metrics, "current-vote").metricValue());
    assertEquals((double) 0, getMetric(metrics, "current-epoch").metricValue());
    assertEquals((double) -1L, getMetric(metrics, "high-watermark").metricValue());
    state.transitionToFollower(2, 1);
    assertEquals("follower", getMetric(metrics, "current-state").metricValue());
    assertEquals((double) 1, getMetric(metrics, "current-leader").metricValue());
    assertEquals((double) -1, getMetric(metrics, "current-vote").metricValue());
    assertEquals((double) 2, getMetric(metrics, "current-epoch").metricValue());
    assertEquals((double) -1L, getMetric(metrics, "high-watermark").metricValue());
    state.followerStateOrThrow().updateHighWatermark(OptionalLong.of(10L));
    assertEquals((double) 10L, getMetric(metrics, "high-watermark").metricValue());
    state.transitionToUnattached(4);
    assertEquals("unattached", getMetric(metrics, "current-state").metricValue());
    assertEquals((double) -1, getMetric(metrics, "current-leader").metricValue());
    assertEquals((double) -1, getMetric(metrics, "current-vote").metricValue());
    assertEquals((double) 4, getMetric(metrics, "current-epoch").metricValue());
    assertEquals((double) 10L, getMetric(metrics, "high-watermark").metricValue());
}
Also used : OffsetAndEpoch(org.apache.kafka.raft.OffsetAndEpoch) QuorumState(org.apache.kafka.raft.QuorumState) Test(org.junit.jupiter.api.Test)

Example 3 with QuorumState

use of org.apache.kafka.raft.QuorumState in project kafka by apache.

the class KafkaRaftMetricsTest method shouldRecordLatency.

@Test
public void shouldRecordLatency() throws IOException {
    QuorumState state = buildQuorumState(Collections.singleton(localId));
    state.initialize(new OffsetAndEpoch(0L, 0));
    raftMetrics = new KafkaRaftMetrics(metrics, "raft", state);
    raftMetrics.updateElectionStartMs(time.milliseconds());
    time.sleep(1000L);
    raftMetrics.maybeUpdateElectionLatency(time.milliseconds());
    assertEquals((double) 1000, getMetric(metrics, "election-latency-avg").metricValue());
    assertEquals((double) 1000, getMetric(metrics, "election-latency-max").metricValue());
    raftMetrics.updateElectionStartMs(time.milliseconds());
    time.sleep(800L);
    raftMetrics.maybeUpdateElectionLatency(time.milliseconds());
    assertEquals((double) 900, getMetric(metrics, "election-latency-avg").metricValue());
    assertEquals((double) 1000, getMetric(metrics, "election-latency-max").metricValue());
    raftMetrics.updateCommitLatency(50, time.milliseconds());
    assertEquals(50.0, getMetric(metrics, "commit-latency-avg").metricValue());
    assertEquals(50.0, getMetric(metrics, "commit-latency-max").metricValue());
    raftMetrics.updateCommitLatency(60, time.milliseconds());
    assertEquals(55.0, getMetric(metrics, "commit-latency-avg").metricValue());
    assertEquals(60.0, getMetric(metrics, "commit-latency-max").metricValue());
}
Also used : OffsetAndEpoch(org.apache.kafka.raft.OffsetAndEpoch) QuorumState(org.apache.kafka.raft.QuorumState) Test(org.junit.jupiter.api.Test)

Example 4 with QuorumState

use of org.apache.kafka.raft.QuorumState in project kafka by apache.

the class KafkaRaftMetricsTest method shouldRecordRate.

@Test
public void shouldRecordRate() throws IOException {
    QuorumState state = buildQuorumState(Collections.singleton(localId));
    state.initialize(new OffsetAndEpoch(0L, 0));
    raftMetrics = new KafkaRaftMetrics(metrics, "raft", state);
    raftMetrics.updateAppendRecords(12);
    assertEquals(0.4, getMetric(metrics, "append-records-rate").metricValue());
    raftMetrics.updateAppendRecords(9);
    assertEquals(0.7, getMetric(metrics, "append-records-rate").metricValue());
    raftMetrics.updateFetchedRecords(24);
    assertEquals(0.8, getMetric(metrics, "fetch-records-rate").metricValue());
    raftMetrics.updateFetchedRecords(48);
    assertEquals(2.4, getMetric(metrics, "fetch-records-rate").metricValue());
}
Also used : OffsetAndEpoch(org.apache.kafka.raft.OffsetAndEpoch) QuorumState(org.apache.kafka.raft.QuorumState) Test(org.junit.jupiter.api.Test)

Example 5 with QuorumState

use of org.apache.kafka.raft.QuorumState in project kafka by apache.

the class KafkaRaftMetricsTest method shouldRecordNumUnknownVoterConnections.

@Test
public void shouldRecordNumUnknownVoterConnections() throws IOException {
    QuorumState state = buildQuorumState(Collections.singleton(localId));
    state.initialize(new OffsetAndEpoch(0L, 0));
    raftMetrics = new KafkaRaftMetrics(metrics, "raft", state);
    assertEquals((double) 0, getMetric(metrics, "number-unknown-voter-connections").metricValue());
    raftMetrics.updateNumUnknownVoterConnections(2);
    assertEquals((double) 2, getMetric(metrics, "number-unknown-voter-connections").metricValue());
}
Also used : OffsetAndEpoch(org.apache.kafka.raft.OffsetAndEpoch) QuorumState(org.apache.kafka.raft.QuorumState) Test(org.junit.jupiter.api.Test)

Aggregations

OffsetAndEpoch (org.apache.kafka.raft.OffsetAndEpoch)7 QuorumState (org.apache.kafka.raft.QuorumState)7 Test (org.junit.jupiter.api.Test)7 LogOffsetMetadata (org.apache.kafka.raft.LogOffsetMetadata)1