kevin-wu24 commented on code in PR #18304:
URL: https://github.com/apache/kafka/pull/18304#discussion_r1903289284


##########
raft/src/main/java/org/apache/kafka/raft/internals/KafkaRaftMetrics.java:
##########
@@ -208,13 +230,35 @@ public void updateElectionStartMs(long currentTimeMs) {
         electionStartMs = OptionalLong.of(currentTimeMs);
     }
 
+    public void updateNumVoters(int numVoters) {
+        this.numVoters = numVoters;
+    }
+
+    public void updateNumObservers(int numObservers) {
+        this.numObservers = numObservers;
+    }
+
+    public void updateUncommittedVoterChange(int uncommittedVoterChange) {
+        this.uncommittedVoterChange = uncommittedVoterChange;
+    }
+
     public void maybeUpdateElectionLatency(long currentTimeMs) {
         if (electionStartMs.isPresent()) {
             electionTimeSensor.record(currentTimeMs - 
electionStartMs.getAsLong(), currentTimeMs);
             electionStartMs = OptionalLong.empty();
         }
     }
 
+    public void addLeaderMetrics() {
+        metrics.addMetric(numObserversMetricName, (Gauge<Integer>) (config, 
now) -> numObservers);
+        metrics.addMetric(uncommittedVoterChangeMetricName, (Gauge<Integer>) 
(config, now) -> uncommittedVoterChange);

Review Comment:
   Maybe not necessary but LMK what you think. If I don't include the cast, the 
second parameter for `addMetric` defaults to `Measurable`, meaning our volatile 
field serving as the metric value is up-casted to `double` when it doesn't need 
to be. The metrics introduced in this KIP would always have values of natural 
numbers ~(maybe `Gauge<Long>` actually most appropriate)~.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: jira-unsubscr...@kafka.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to