cmccabe commented on code in PR #19586: URL: https://github.com/apache/kafka/pull/19586#discussion_r2082446845
########## metadata/src/main/java/org/apache/kafka/controller/metrics/QuorumControllerMetrics.java: ########## @@ -148,6 +159,41 @@ public Long value() { })); } + public void addTimeSinceLastHeartbeatMetric(int brokerId) { + brokerContactTimesMs.put(brokerId, new AtomicLong(time.milliseconds())); + registry.ifPresent(r -> r.newGauge( + getBrokerIdTagMetricName( + "KafkaController", + TIME_SINCE_LAST_HEARTBEAT_RECEIVED_METRIC_NAME, + brokerId + ), + new Gauge<Integer>() { + @Override + public Integer value() { + return timeSinceLastHeartbeatMs(brokerId); + } + } + )); + } + + public void removeTimeSinceLastHeartbeatMetric(int brokerId) { + brokerContactTimesMs.remove(brokerId); + registry.ifPresent(r -> r.removeMetric( Review Comment: we need to remove the metric first to avoid having a race condition here, right? since otherwise it could be locklessly accessed after being removed from `brokerContactTimesMs` but before the metric is unregistered. -- 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