kevin-wu24 commented on code in PR #18304: URL: https://github.com/apache/kafka/pull/18304#discussion_r1903288983
########## 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); + } + @Override public void close() { Review Comment: Calls to `removeMetric` only do something when the metric is actually present in the metrics map, so any metrics that would be added in `initialize` using the `QuorumState` will pass through during `close` in this scenario. -- 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