Skip to content

KAFKA-19406: Remove BrokerTopicStats#removeOldFollowerMetrics #19962

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions core/src/main/scala/kafka/server/ReplicaManager.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2201,9 +2201,7 @@ class ReplicaManager(val config: KafkaConfig,
private def updateLeaderAndFollowerMetrics(newFollowerTopics: Set[String]): Unit = {
val leaderTopicSet = leaderPartitionsIterator.map(_.topic).toSet
newFollowerTopics.diff(leaderTopicSet).foreach(brokerTopicStats.removeOldLeaderMetrics)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removeOldLeaderMetrics tries to remove REPLICATION_BYTES_OUT_PER_SEC and REASSIGNMENT_BYTES_OUT_PER_SEC which apply across all topics too. Could you please remove them?


// remove metrics for brokers which are not followers of a topic
leaderTopicSet.diff(newFollowerTopics).foreach(brokerTopicStats.removeOldFollowerMetrics)
// Currently, there are no follower metrics that need to be updated.
}

protected[server] def maybeAddLogDirFetchers(partitions: Set[Partition],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3603,7 +3603,6 @@ class ReplicaManagerTest {

// verify that broker 1 did remove its metrics when no longer being the leader of partition 1
verify(mockTopicStats1).removeOldLeaderMetrics(topic)
verify(mockTopicStats1).removeOldFollowerMetrics(topic)
}

private def prepareDifferentReplicaManagers(brokerTopicStats1: BrokerTopicStats,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,6 @@ public void removeOldLeaderMetrics(String topic) {
topicMetrics.closeMetric(BrokerTopicMetrics.FAILED_PRODUCE_REQUESTS_PER_SEC);
topicMetrics.closeMetric(BrokerTopicMetrics.TOTAL_PRODUCE_REQUESTS_PER_SEC);
topicMetrics.closeMetric(BrokerTopicMetrics.PRODUCE_MESSAGE_CONVERSIONS_PER_SEC);
topicMetrics.closeMetric(BrokerTopicMetrics.REPLICATION_BYTES_OUT_PER_SEC);
topicMetrics.closeMetric(BrokerTopicMetrics.REASSIGNMENT_BYTES_OUT_PER_SEC);
topicMetrics.closeMetric(RemoteStorageMetrics.REMOTE_COPY_BYTES_PER_SEC_METRIC.getName());
topicMetrics.closeMetric(RemoteStorageMetrics.REMOTE_FETCH_BYTES_PER_SEC_METRIC.getName());
topicMetrics.closeMetric(RemoteStorageMetrics.REMOTE_FETCH_REQUESTS_PER_SEC_METRIC.getName());
Expand All @@ -99,15 +97,6 @@ public void removeOldLeaderMetrics(String topic) {
}
}

// This method only removes metrics only used for follower
public void removeOldFollowerMetrics(String topic) {
BrokerTopicMetrics topicMetrics = topicStats(topic);
if (topicMetrics != null) {
topicMetrics.closeMetric(BrokerTopicMetrics.REPLICATION_BYTES_IN_PER_SEC);
topicMetrics.closeMetric(BrokerTopicMetrics.REASSIGNMENT_BYTES_IN_PER_SEC);
}
}

public void removeMetrics(String topic) {
BrokerTopicMetrics metrics = stats.remove(topic);
if (metrics != null) {
Expand Down