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


##########
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);
+    }
+
+    public void removeLeaderMetrics() {
+        metrics.removeMetric(numObserversMetricName);
+        metrics.removeMetric(uncommittedVoterChangeMetricName);
+    }

Review Comment:
   Yes, now that we aren't directly reading from LeaderState fields, the local 
`KafkaRaftMetrics` values need to be reset when leadership is lost.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to