You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by "cmccabe (via GitHub)" <gi...@apache.org> on 2023/03/22 21:16:10 UTC

[GitHub] [kafka] cmccabe opened a new pull request, #13438: KAFKA-14835: Create ControllerServerMetricsPublisher

cmccabe opened a new pull request, #13438:
URL: https://github.com/apache/kafka/pull/13438

   Separate out KRaft controller metrics into two groups: metrics directly managed by the QuorumController, and metrics handled by an external publisher. This separation of concerns makes the code easier to reason about, by clarifying what metrics can be changed where.
   
   The external publisher, ControllerServerMetricsPublisher, handles all metrics which are related to the content of metadata. For example, metrics about number of topics or number of partitions, etc. etc. It fits into the MetadataLoader metadata publishing framework as another publisher.  Since ControllerServerMetricsPublisher operates off of a MetadataImage, we don't have to create (essentially) another copy of the metadata in memory, as ControllerMetricsManager. This reduces memory consumption. Another benefit of operating off of the MetadataImage is that we don't have to have special handling for each record type, like we do now in ControllerMetricsManager.
   


-- 
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-unsubscribe@kafka.apache.org

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


[GitHub] [kafka] cmccabe commented on a diff in pull request #13438: KAFKA-14835: Create ControllerServerMetricsPublisher

Posted by "cmccabe (via GitHub)" <gi...@apache.org>.
cmccabe commented on code in PR #13438:
URL: https://github.com/apache/kafka/pull/13438#discussion_r1146902273


##########
metadata/src/main/java/org/apache/kafka/controller/metrics/ControllerMetricsChanges.java:
##########
@@ -0,0 +1,147 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.kafka.controller.metrics;
+
+import org.apache.kafka.image.TopicDelta;
+import org.apache.kafka.image.TopicImage;
+import org.apache.kafka.metadata.BrokerRegistration;
+import org.apache.kafka.metadata.PartitionRegistration;
+
+import java.util.Map.Entry;
+
+
+class ControllerMetricsChanges {
+    static int delta(boolean prev, boolean next) {

Review Comment:
   I added a JavaDoc



-- 
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-unsubscribe@kafka.apache.org

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


[GitHub] [kafka] cmccabe commented on a diff in pull request #13438: KAFKA-14835: Create ControllerServerMetricsPublisher

Posted by "cmccabe (via GitHub)" <gi...@apache.org>.
cmccabe commented on code in PR #13438:
URL: https://github.com/apache/kafka/pull/13438#discussion_r1146927689


##########
core/src/main/scala/kafka/server/ControllerServer.scala:
##########
@@ -104,13 +106,15 @@ class ControllerServer(
   val socketServerFirstBoundPortFuture = new CompletableFuture[Integer]()
   var createTopicPolicy: Option[CreateTopicPolicy] = None
   var alterConfigPolicy: Option[AlterConfigPolicy] = None
+  @volatile var quorumControllerMetrics: QuorumControllerMetrics = _
   var controller: Controller = _
   var quotaManagers: QuotaManagers = _
   var clientQuotaMetadataManager: ClientQuotaMetadataManager = _
   var controllerApis: ControllerApis = _
   var controllerApisHandlerPool: KafkaRequestHandlerPool = _
   var migrationSupport: Option[ControllerMigrationSupport] = None
   def kafkaYammerMetrics: KafkaYammerMetrics = KafkaYammerMetrics.INSTANCE
+  val metadataPublishers: util.List[MetadataPublisher] = new CopyOnWriteArrayList[MetadataPublisher]()

Review Comment:
   ok, I'll just use array list for now.



-- 
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-unsubscribe@kafka.apache.org

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


[GitHub] [kafka] mumrah commented on a diff in pull request #13438: KAFKA-14835: Create ControllerMetadataMetricsPublisher

Posted by "mumrah (via GitHub)" <gi...@apache.org>.
mumrah commented on code in PR #13438:
URL: https://github.com/apache/kafka/pull/13438#discussion_r1147915381


##########
core/src/main/scala/kafka/server/ControllerServer.scala:
##########
@@ -366,6 +376,8 @@ class ControllerServer(
       // Ensure that we're not the Raft leader prior to shutting down our socket server, for a
       // smoother transition.
       sharedServer.ensureNotRaftLeader()
+      metadataPublishers.forEach(p => sharedServer.loader.removeAndClosePublisher(p).get())

Review Comment:
   Do we have a JIRA for shutdown timeout? Seems like it could be useful



-- 
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-unsubscribe@kafka.apache.org

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


[GitHub] [kafka] cmccabe commented on a diff in pull request #13438: KAFKA-14835: Create ControllerServerMetricsPublisher

Posted by "cmccabe (via GitHub)" <gi...@apache.org>.
cmccabe commented on code in PR #13438:
URL: https://github.com/apache/kafka/pull/13438#discussion_r1146899679


##########
core/src/main/scala/kafka/server/ControllerServer.scala:
##########
@@ -366,6 +376,8 @@ class ControllerServer(
       // Ensure that we're not the Raft leader prior to shutting down our socket server, for a
       // smoother transition.
       sharedServer.ensureNotRaftLeader()
+      metadataPublishers.forEach(p => sharedServer.loader.removeAndClosePublisher(p).get())

Review Comment:
   I would like to do this eventually, but we don't have any shutdown timeout currently. We would have to add something like that in order to use it here.



-- 
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-unsubscribe@kafka.apache.org

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


[GitHub] [kafka] cmccabe merged pull request #13438: KAFKA-14835: Create ControllerMetadataMetricsPublisher

Posted by "cmccabe (via GitHub)" <gi...@apache.org>.
cmccabe merged PR #13438:
URL: https://github.com/apache/kafka/pull/13438


-- 
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-unsubscribe@kafka.apache.org

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


[GitHub] [kafka] cmccabe commented on a diff in pull request #13438: KAFKA-14835: Create ControllerServerMetricsPublisher

Posted by "cmccabe (via GitHub)" <gi...@apache.org>.
cmccabe commented on code in PR #13438:
URL: https://github.com/apache/kafka/pull/13438#discussion_r1146909450


##########
metadata/src/main/java/org/apache/kafka/controller/metrics/ControllerServerMetrics.java:
##########
@@ -0,0 +1,211 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.kafka.controller.metrics;
+
+import com.yammer.metrics.core.Gauge;
+import com.yammer.metrics.core.MetricName;
+import com.yammer.metrics.core.MetricsRegistry;
+import org.apache.kafka.server.metrics.KafkaYammerMetrics;
+
+import java.util.Arrays;
+import java.util.Optional;
+import java.util.concurrent.atomic.AtomicInteger;
+
+/**
+ * These are the metrics which are managed by the ControllerServer class. They generally pertain to
+ * aspects of the metadata, like how many topics or partitions we have.
+ * All of these except MetadataErrorCount are managed by ControllerServerMetricsPublisher.
+ *
+ * IMPORTANT: Metrics which are managed by the QuorumController class itself should go in
+ * @link{org.apache.kafka.controller.metrics.QuorumControllerMetrics}, not here.
+ */
+public final class ControllerServerMetrics implements AutoCloseable {
+    private final static MetricName FENCED_BROKER_COUNT = getMetricName(
+        "KafkaController", "FencedBrokerCount");
+    private final static MetricName ACTIVE_BROKER_COUNT = getMetricName(
+        "KafkaController", "ActiveBrokerCount");
+    private final static MetricName GLOBAL_TOPIC_COUNT = getMetricName(
+        "KafkaController", "GlobalTopicCount");
+    private final static MetricName GLOBAL_PARTITION_COUNT = getMetricName(
+        "KafkaController", "GlobalPartitionCount");
+    private final static MetricName OFFLINE_PARTITION_COUNT = getMetricName(
+        "KafkaController", "OfflinePartitionsCount");
+    private final static MetricName PREFERRED_REPLICA_IMBALANCE_COUNT = getMetricName(
+        "KafkaController", "PreferredReplicaImbalanceCount");
+    private final static MetricName METADATA_ERROR_COUNT = getMetricName(
+        "KafkaController", "MetadataErrorCount");
+
+    private final Optional<MetricsRegistry> registry;
+    private final AtomicInteger fencedBrokerCount = new AtomicInteger(0);
+    private final AtomicInteger activeBrokerCount = new AtomicInteger(0);
+    private final AtomicInteger globalTopicCount = new AtomicInteger(0);
+    private final AtomicInteger globalPartitionCount = new AtomicInteger();

Review Comment:
   Good point. I changed them all to just use `new AtomicInteger(0)` to be explicit. The no-argument form defaults to 0 too but better to avoid that bit of cleverness



-- 
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-unsubscribe@kafka.apache.org

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


[GitHub] [kafka] cmccabe commented on a diff in pull request #13438: KAFKA-14835: Create ControllerServerMetricsPublisher

Posted by "cmccabe (via GitHub)" <gi...@apache.org>.
cmccabe commented on code in PR #13438:
URL: https://github.com/apache/kafka/pull/13438#discussion_r1146908247


##########
metadata/src/main/java/org/apache/kafka/controller/metrics/ControllerServerMetricsPublisher.java:
##########
@@ -0,0 +1,156 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.kafka.controller.metrics;
+
+import org.apache.kafka.common.Uuid;
+import org.apache.kafka.image.MetadataDelta;
+import org.apache.kafka.image.MetadataImage;
+import org.apache.kafka.image.TopicDelta;
+import org.apache.kafka.image.TopicImage;
+import org.apache.kafka.image.loader.LoaderManifest;
+import org.apache.kafka.image.publisher.MetadataPublisher;
+import org.apache.kafka.metadata.BrokerRegistration;
+import org.apache.kafka.metadata.PartitionRegistration;
+import org.apache.kafka.server.fault.FaultHandler;
+
+import java.util.Map.Entry;
+import java.util.Optional;
+
+
+/**
+ * This publisher translates metadata updates sent by MetadataLoader into changes to controller
+ * metrics. Like all MetadataPublisher objects, it only receives notifications about events that
+ * have been persisted to the metadata log. So on the active controller, it will run slightly
+ * behind the latest in-memory state which has not yet been fully persisted to the log. This is
+ * reasonable for metrics, which don't need up-to-the-millisecond update latency.
+ *
+ * NOTE: the ZK controller has some special rules for calculating preferredReplicaImbalanceCount
+ * which we haven't implemented here. Specifically, the ZK controller considers reassigning
+ * partitions to always have their preferred leader, even if they don't.
+ * All other metrics should be the same, as far as is possible.
+ */
+public class ControllerServerMetricsPublisher implements MetadataPublisher {

Review Comment:
   Good idea. I renamed:
   
   ControllerServerMetrics -> ControllerMetadataMetrics
   ControllerServerMetricsPublisher -> ControllerMetadataMetricsPublisher
   
   and associated tests



-- 
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-unsubscribe@kafka.apache.org

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


[GitHub] [kafka] cmccabe commented on a diff in pull request #13438: KAFKA-14835: Create ControllerServerMetricsPublisher

Posted by "cmccabe (via GitHub)" <gi...@apache.org>.
cmccabe commented on code in PR #13438:
URL: https://github.com/apache/kafka/pull/13438#discussion_r1146914196


##########
metadata/src/main/java/org/apache/kafka/controller/metrics/ControllerServerMetrics.java:
##########
@@ -0,0 +1,211 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.kafka.controller.metrics;
+
+import com.yammer.metrics.core.Gauge;
+import com.yammer.metrics.core.MetricName;
+import com.yammer.metrics.core.MetricsRegistry;
+import org.apache.kafka.server.metrics.KafkaYammerMetrics;
+
+import java.util.Arrays;
+import java.util.Optional;
+import java.util.concurrent.atomic.AtomicInteger;
+
+/**
+ * These are the metrics which are managed by the ControllerServer class. They generally pertain to
+ * aspects of the metadata, like how many topics or partitions we have.
+ * All of these except MetadataErrorCount are managed by ControllerServerMetricsPublisher.
+ *
+ * IMPORTANT: Metrics which are managed by the QuorumController class itself should go in
+ * @link{org.apache.kafka.controller.metrics.QuorumControllerMetrics}, not here.
+ */
+public final class ControllerServerMetrics implements AutoCloseable {
+    private final static MetricName FENCED_BROKER_COUNT = getMetricName(
+        "KafkaController", "FencedBrokerCount");
+    private final static MetricName ACTIVE_BROKER_COUNT = getMetricName(
+        "KafkaController", "ActiveBrokerCount");
+    private final static MetricName GLOBAL_TOPIC_COUNT = getMetricName(
+        "KafkaController", "GlobalTopicCount");
+    private final static MetricName GLOBAL_PARTITION_COUNT = getMetricName(
+        "KafkaController", "GlobalPartitionCount");
+    private final static MetricName OFFLINE_PARTITION_COUNT = getMetricName(
+        "KafkaController", "OfflinePartitionsCount");
+    private final static MetricName PREFERRED_REPLICA_IMBALANCE_COUNT = getMetricName(
+        "KafkaController", "PreferredReplicaImbalanceCount");
+    private final static MetricName METADATA_ERROR_COUNT = getMetricName(
+        "KafkaController", "MetadataErrorCount");
+
+    private final Optional<MetricsRegistry> registry;
+    private final AtomicInteger fencedBrokerCount = new AtomicInteger(0);
+    private final AtomicInteger activeBrokerCount = new AtomicInteger(0);
+    private final AtomicInteger globalTopicCount = new AtomicInteger(0);
+    private final AtomicInteger globalPartitionCount = new AtomicInteger();
+    private final AtomicInteger offlinePartitionCount = new AtomicInteger();
+    private final AtomicInteger preferredReplicaImbalanceCount = new AtomicInteger();
+    private final AtomicInteger metadataErrorCount = new AtomicInteger(0);
+
+    /**
+     * Create a new ControllerServerMetrics object.
+     *
+     * @param registry  The metrics registry, or Optional.empty if this is a test and we don't have one.
+     */
+    public ControllerServerMetrics(Optional<MetricsRegistry> registry) {

Review Comment:
   Yeah. Looking at the previous code, I realized that `MockControllerMetrics` was implementing all the same stuff as `QuorumControllerMetrics` (atomic adds, atomic gets, etc.) So there was no point... just don't register with the registry if you don't care about the registry, and you can avoid the whole layer of abstraction.



-- 
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-unsubscribe@kafka.apache.org

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


[GitHub] [kafka] mumrah commented on a diff in pull request #13438: KAFKA-14835: Create ControllerServerMetricsPublisher

Posted by "mumrah (via GitHub)" <gi...@apache.org>.
mumrah commented on code in PR #13438:
URL: https://github.com/apache/kafka/pull/13438#discussion_r1146431114


##########
core/src/main/scala/kafka/server/ControllerServer.scala:
##########
@@ -366,6 +376,8 @@ class ControllerServer(
       // Ensure that we're not the Raft leader prior to shutting down our socket server, for a
       // smoother transition.
       sharedServer.ensureNotRaftLeader()
+      metadataPublishers.forEach(p => sharedServer.loader.removeAndClosePublisher(p).get())

Review Comment:
   Should we provide a timeout to `get()` to avoid indefinite blocking?



##########
core/src/main/scala/kafka/server/ControllerServer.scala:
##########
@@ -104,13 +106,15 @@ class ControllerServer(
   val socketServerFirstBoundPortFuture = new CompletableFuture[Integer]()
   var createTopicPolicy: Option[CreateTopicPolicy] = None
   var alterConfigPolicy: Option[AlterConfigPolicy] = None
+  @volatile var quorumControllerMetrics: QuorumControllerMetrics = _
   var controller: Controller = _
   var quotaManagers: QuotaManagers = _
   var clientQuotaMetadataManager: ClientQuotaMetadataManager = _
   var controllerApis: ControllerApis = _
   var controllerApisHandlerPool: KafkaRequestHandlerPool = _
   var migrationSupport: Option[ControllerMigrationSupport] = None
   def kafkaYammerMetrics: KafkaYammerMetrics = KafkaYammerMetrics.INSTANCE
+  val metadataPublishers: util.List[MetadataPublisher] = new CopyOnWriteArrayList[MetadataPublisher]()

Review Comment:
   Do we need a thread-safe collection here? It looks like we're just populating this list here and then passing it to the MetadataLoader.



##########
metadata/src/main/java/org/apache/kafka/controller/metrics/ControllerMetricsChanges.java:
##########
@@ -0,0 +1,147 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.kafka.controller.metrics;
+
+import org.apache.kafka.image.TopicDelta;
+import org.apache.kafka.image.TopicImage;
+import org.apache.kafka.metadata.BrokerRegistration;
+import org.apache.kafka.metadata.PartitionRegistration;
+
+import java.util.Map.Entry;
+
+
+class ControllerMetricsChanges {
+    static int delta(boolean prev, boolean next) {

Review Comment:
   Maybe add a Javadoc for this method? Also, "delta" is kind of vague. 



##########
metadata/src/main/java/org/apache/kafka/controller/metrics/ControllerMetricsChanges.java:
##########
@@ -0,0 +1,147 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.kafka.controller.metrics;
+
+import org.apache.kafka.image.TopicDelta;
+import org.apache.kafka.image.TopicImage;
+import org.apache.kafka.metadata.BrokerRegistration;
+import org.apache.kafka.metadata.PartitionRegistration;
+
+import java.util.Map.Entry;
+
+
+class ControllerMetricsChanges {
+    static int delta(boolean prev, boolean next) {
+        if (prev) {
+            return next ? 0 : -1;
+        } else {
+            return next ? 1 : 0;
+        }
+    }
+
+    private int fencedBrokersChange = 0;
+    private int activeBrokersChange = 0;
+    private int globalTopicsChange = 0;
+    private int globalPartitionsChange = 0;
+    private int offlinePartitionsChange = 0;
+    private int partitionsWithoutPreferredLeaderChange = 0;
+
+    public int fencedBrokersChange() {
+        return fencedBrokersChange;
+    }
+
+    public int activeBrokersChange() {
+        return activeBrokersChange;
+    }
+
+    public int globalTopicsChange() {
+        return globalTopicsChange;
+    }
+
+    public int globalPartitionsChange() {
+        return globalPartitionsChange;
+    }
+
+    public int offlinePartitionsChange() {
+        return offlinePartitionsChange;
+    }
+
+    public int partitionsWithoutPreferredLeaderChange() {
+        return partitionsWithoutPreferredLeaderChange;
+    }
+
+    void handleBrokerChange(BrokerRegistration prev, BrokerRegistration next) {
+        boolean wasFenced = false;
+        boolean wasActive = false;
+        if (prev != null) {
+            wasFenced = prev.fenced();
+            wasActive = !prev.fenced();
+        }
+        boolean isFenced = false;
+        boolean isActive = false;
+        if (next != null) {
+            isFenced = next.fenced();
+            isActive = !next.fenced();
+        }
+        fencedBrokersChange += delta(wasFenced, isFenced);
+        activeBrokersChange += delta(wasActive, isActive);
+    }
+
+    void handleDeletedTopic(TopicImage deletedTopic) {
+        deletedTopic.partitions().values().forEach(prev -> handlePartitionChange(prev, null));
+        globalTopicsChange--;
+    }
+
+    void handleTopicChange(TopicImage prev, TopicDelta topicDelta) {
+        if (prev == null) {
+            globalTopicsChange++;
+            for (PartitionRegistration nextPartition : topicDelta.partitionChanges().values()) {
+                handlePartitionChange(null, nextPartition);
+            }
+        } else {
+            for (Entry<Integer, PartitionRegistration> entry : topicDelta.partitionChanges().entrySet()) {
+                int partitionId = entry.getKey();
+                PartitionRegistration nextPartition = entry.getValue();
+                handlePartitionChange(prev.partitions().get(partitionId), nextPartition);
+            }
+        }
+    }
+
+    void handlePartitionChange(PartitionRegistration prev, PartitionRegistration next) {
+        boolean wasPresent = false;
+        boolean wasOffline = false;
+        boolean wasWithoutPreferredLeader = false;
+        if (prev != null) {
+            wasPresent = true;
+            wasOffline = !prev.hasLeader();
+            wasWithoutPreferredLeader = !prev.hasPreferredLeader();
+        }
+        boolean isPresent = false;
+        boolean isOffline = false;
+        boolean isWithoutPreferredLeader = false;
+        if (next != null) {
+            isPresent = true;
+            isOffline = !next.hasLeader();
+            isWithoutPreferredLeader = !next.hasPreferredLeader();
+        }
+        globalPartitionsChange += delta(wasPresent, isPresent);
+        offlinePartitionsChange += delta(wasOffline, isOffline);
+        partitionsWithoutPreferredLeaderChange += delta(wasWithoutPreferredLeader, isWithoutPreferredLeader);
+    }
+
+    void apply(ControllerServerMetrics metrics) {
+        if (fencedBrokersChange != 0) {
+            metrics.addToFencedBrokerCount(fencedBrokersChange);
+        }
+        if (activeBrokersChange != 0) {
+            metrics.addToActiveBrokerCount(activeBrokersChange);
+        }
+        if (globalTopicsChange != 0) {
+            metrics.addToGlobalTopicCount(globalTopicsChange);
+        }
+        if (globalPartitionsChange != 0) {
+            metrics.addToGlobalPartitionCount(globalPartitionsChange);
+        }
+        if (offlinePartitionsChange != 0) {
+            metrics.addToOfflinePartitionCount(offlinePartitionsChange);
+        }
+        if (partitionsWithoutPreferredLeaderChange != 0) {
+            metrics.addToPreferredReplicaImbalanceCount(partitionsWithoutPreferredLeaderChange);
+        }
+    }
+}

Review Comment:
   nit: newline



##########
metadata/src/main/java/org/apache/kafka/controller/metrics/ControllerServerMetricsPublisher.java:
##########
@@ -0,0 +1,156 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.kafka.controller.metrics;
+
+import org.apache.kafka.common.Uuid;
+import org.apache.kafka.image.MetadataDelta;
+import org.apache.kafka.image.MetadataImage;
+import org.apache.kafka.image.TopicDelta;
+import org.apache.kafka.image.TopicImage;
+import org.apache.kafka.image.loader.LoaderManifest;
+import org.apache.kafka.image.publisher.MetadataPublisher;
+import org.apache.kafka.metadata.BrokerRegistration;
+import org.apache.kafka.metadata.PartitionRegistration;
+import org.apache.kafka.server.fault.FaultHandler;
+
+import java.util.Map.Entry;
+import java.util.Optional;
+
+
+/**
+ * This publisher translates metadata updates sent by MetadataLoader into changes to controller
+ * metrics. Like all MetadataPublisher objects, it only receives notifications about events that
+ * have been persisted to the metadata log. So on the active controller, it will run slightly
+ * behind the latest in-memory state which has not yet been fully persisted to the log. This is
+ * reasonable for metrics, which don't need up-to-the-millisecond update latency.
+ *
+ * NOTE: the ZK controller has some special rules for calculating preferredReplicaImbalanceCount
+ * which we haven't implemented here. Specifically, the ZK controller considers reassigning
+ * partitions to always have their preferred leader, even if they don't.
+ * All other metrics should be the same, as far as is possible.
+ */
+public class ControllerServerMetricsPublisher implements MetadataPublisher {

Review Comment:
   I wonder if having Metadata in the class name would make it more clear that this is a metrics publisher for metadata-derived things



##########
metadata/src/main/java/org/apache/kafka/controller/metrics/ControllerMetricsChanges.java:
##########
@@ -0,0 +1,147 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.kafka.controller.metrics;
+
+import org.apache.kafka.image.TopicDelta;
+import org.apache.kafka.image.TopicImage;
+import org.apache.kafka.metadata.BrokerRegistration;
+import org.apache.kafka.metadata.PartitionRegistration;
+
+import java.util.Map.Entry;
+
+
+class ControllerMetricsChanges {

Review Comment:
   Short Javadoc would be helpful here



##########
metadata/src/main/java/org/apache/kafka/controller/metrics/ControllerServerMetrics.java:
##########
@@ -0,0 +1,211 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.kafka.controller.metrics;
+
+import com.yammer.metrics.core.Gauge;
+import com.yammer.metrics.core.MetricName;
+import com.yammer.metrics.core.MetricsRegistry;
+import org.apache.kafka.server.metrics.KafkaYammerMetrics;
+
+import java.util.Arrays;
+import java.util.Optional;
+import java.util.concurrent.atomic.AtomicInteger;
+
+/**
+ * These are the metrics which are managed by the ControllerServer class. They generally pertain to
+ * aspects of the metadata, like how many topics or partitions we have.
+ * All of these except MetadataErrorCount are managed by ControllerServerMetricsPublisher.
+ *
+ * IMPORTANT: Metrics which are managed by the QuorumController class itself should go in
+ * @link{org.apache.kafka.controller.metrics.QuorumControllerMetrics}, not here.
+ */
+public final class ControllerServerMetrics implements AutoCloseable {
+    private final static MetricName FENCED_BROKER_COUNT = getMetricName(
+        "KafkaController", "FencedBrokerCount");
+    private final static MetricName ACTIVE_BROKER_COUNT = getMetricName(
+        "KafkaController", "ActiveBrokerCount");
+    private final static MetricName GLOBAL_TOPIC_COUNT = getMetricName(
+        "KafkaController", "GlobalTopicCount");
+    private final static MetricName GLOBAL_PARTITION_COUNT = getMetricName(
+        "KafkaController", "GlobalPartitionCount");
+    private final static MetricName OFFLINE_PARTITION_COUNT = getMetricName(
+        "KafkaController", "OfflinePartitionsCount");
+    private final static MetricName PREFERRED_REPLICA_IMBALANCE_COUNT = getMetricName(
+        "KafkaController", "PreferredReplicaImbalanceCount");
+    private final static MetricName METADATA_ERROR_COUNT = getMetricName(
+        "KafkaController", "MetadataErrorCount");
+
+    private final Optional<MetricsRegistry> registry;
+    private final AtomicInteger fencedBrokerCount = new AtomicInteger(0);
+    private final AtomicInteger activeBrokerCount = new AtomicInteger(0);
+    private final AtomicInteger globalTopicCount = new AtomicInteger(0);
+    private final AtomicInteger globalPartitionCount = new AtomicInteger();
+    private final AtomicInteger offlinePartitionCount = new AtomicInteger();
+    private final AtomicInteger preferredReplicaImbalanceCount = new AtomicInteger();
+    private final AtomicInteger metadataErrorCount = new AtomicInteger(0);
+
+    /**
+     * Create a new ControllerServerMetrics object.
+     *
+     * @param registry  The metrics registry, or Optional.empty if this is a test and we don't have one.
+     */
+    public ControllerServerMetrics(Optional<MetricsRegistry> registry) {

Review Comment:
   I was sort of confused by this, but I think I get it. Since MetricsRegistry is not an interface, we can't easily stub it out for tests. So it's either something like this, or using a mocking library. 



##########
metadata/src/main/java/org/apache/kafka/controller/metrics/ControllerServerMetrics.java:
##########
@@ -0,0 +1,211 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.kafka.controller.metrics;
+
+import com.yammer.metrics.core.Gauge;
+import com.yammer.metrics.core.MetricName;
+import com.yammer.metrics.core.MetricsRegistry;
+import org.apache.kafka.server.metrics.KafkaYammerMetrics;
+
+import java.util.Arrays;
+import java.util.Optional;
+import java.util.concurrent.atomic.AtomicInteger;
+
+/**
+ * These are the metrics which are managed by the ControllerServer class. They generally pertain to
+ * aspects of the metadata, like how many topics or partitions we have.
+ * All of these except MetadataErrorCount are managed by ControllerServerMetricsPublisher.
+ *
+ * IMPORTANT: Metrics which are managed by the QuorumController class itself should go in
+ * @link{org.apache.kafka.controller.metrics.QuorumControllerMetrics}, not here.
+ */
+public final class ControllerServerMetrics implements AutoCloseable {
+    private final static MetricName FENCED_BROKER_COUNT = getMetricName(
+        "KafkaController", "FencedBrokerCount");
+    private final static MetricName ACTIVE_BROKER_COUNT = getMetricName(
+        "KafkaController", "ActiveBrokerCount");
+    private final static MetricName GLOBAL_TOPIC_COUNT = getMetricName(
+        "KafkaController", "GlobalTopicCount");
+    private final static MetricName GLOBAL_PARTITION_COUNT = getMetricName(
+        "KafkaController", "GlobalPartitionCount");
+    private final static MetricName OFFLINE_PARTITION_COUNT = getMetricName(
+        "KafkaController", "OfflinePartitionsCount");
+    private final static MetricName PREFERRED_REPLICA_IMBALANCE_COUNT = getMetricName(
+        "KafkaController", "PreferredReplicaImbalanceCount");
+    private final static MetricName METADATA_ERROR_COUNT = getMetricName(
+        "KafkaController", "MetadataErrorCount");
+
+    private final Optional<MetricsRegistry> registry;
+    private final AtomicInteger fencedBrokerCount = new AtomicInteger(0);
+    private final AtomicInteger activeBrokerCount = new AtomicInteger(0);
+    private final AtomicInteger globalTopicCount = new AtomicInteger(0);
+    private final AtomicInteger globalPartitionCount = new AtomicInteger();

Review Comment:
   Some are initialized with 0, others aren't. We should probably pick one and be consistent 



-- 
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-unsubscribe@kafka.apache.org

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


[GitHub] [kafka] mumrah commented on a diff in pull request #13438: KAFKA-14835: Create ControllerMetadataMetricsPublisher

Posted by "mumrah (via GitHub)" <gi...@apache.org>.
mumrah commented on code in PR #13438:
URL: https://github.com/apache/kafka/pull/13438#discussion_r1147915745


##########
metadata/src/main/java/org/apache/kafka/controller/metrics/ControllerMetadataMetrics.java:
##########
@@ -0,0 +1,211 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.kafka.controller.metrics;
+
+import com.yammer.metrics.core.Gauge;
+import com.yammer.metrics.core.MetricName;
+import com.yammer.metrics.core.MetricsRegistry;
+import org.apache.kafka.server.metrics.KafkaYammerMetrics;
+
+import java.util.Arrays;
+import java.util.Optional;
+import java.util.concurrent.atomic.AtomicInteger;
+
+/**
+ * These are the metrics which are managed by the ControllerServer class. They generally pertain to
+ * aspects of the metadata, like how many topics or partitions we have.
+ * All of these except MetadataErrorCount are managed by ControllerMetadataMetricsPublisher.
+ *
+ * IMPORTANT: Metrics which are managed by the QuorumController class itself should go in
+ * @link{org.apache.kafka.controller.metrics.QuorumControllerMetrics}, not here.
+ */
+public final class ControllerMetadataMetrics implements AutoCloseable {
+    private final static MetricName FENCED_BROKER_COUNT = getMetricName(
+        "KafkaController", "FencedBrokerCount");
+    private final static MetricName ACTIVE_BROKER_COUNT = getMetricName(
+        "KafkaController", "ActiveBrokerCount");
+    private final static MetricName GLOBAL_TOPIC_COUNT = getMetricName(
+        "KafkaController", "GlobalTopicCount");
+    private final static MetricName GLOBAL_PARTITION_COUNT = getMetricName(
+        "KafkaController", "GlobalPartitionCount");
+    private final static MetricName OFFLINE_PARTITION_COUNT = getMetricName(
+        "KafkaController", "OfflinePartitionsCount");
+    private final static MetricName PREFERRED_REPLICA_IMBALANCE_COUNT = getMetricName(
+        "KafkaController", "PreferredReplicaImbalanceCount");
+    private final static MetricName METADATA_ERROR_COUNT = getMetricName(
+        "KafkaController", "MetadataErrorCount");
+
+    private final Optional<MetricsRegistry> registry;
+    private final AtomicInteger fencedBrokerCount = new AtomicInteger(0);
+    private final AtomicInteger activeBrokerCount = new AtomicInteger(0);
+    private final AtomicInteger globalTopicCount = new AtomicInteger(0);
+    private final AtomicInteger globalPartitionCount = new AtomicInteger(0);
+    private final AtomicInteger offlinePartitionCount = new AtomicInteger(0);
+    private final AtomicInteger preferredReplicaImbalanceCount = new AtomicInteger(0);
+    private final AtomicInteger metadataErrorCount = new AtomicInteger(0);
+
+    /**
+     * Create a new ControllerMetadataMetrics object.
+     *
+     * @param registry  The metrics registry, or Optional.empty if this is a test and we don't have one.
+     */
+    public ControllerMetadataMetrics(Optional<MetricsRegistry> registry) {
+        this.registry = registry;
+        registry.ifPresent(r -> r.newGauge(FENCED_BROKER_COUNT, new Gauge<Integer>() {
+            @Override
+            public Integer value() {
+                return fencedBrokerCount();
+            }
+        }));
+        registry.ifPresent(r -> r.newGauge(ACTIVE_BROKER_COUNT, new Gauge<Integer>() {
+            @Override
+            public Integer value() {
+                return activeBrokerCount();
+            }
+        }));
+        registry.ifPresent(r -> r.newGauge(GLOBAL_TOPIC_COUNT, new Gauge<Integer>() {
+            @Override
+            public Integer value() {
+                return globalTopicCount();
+            }
+        }));
+        registry.ifPresent(r -> r.newGauge(GLOBAL_PARTITION_COUNT, new Gauge<Integer>() {
+            @Override
+            public Integer value() {
+                return globalPartitionCount();
+            }
+        }));
+        registry.ifPresent(r -> r.newGauge(OFFLINE_PARTITION_COUNT, new Gauge<Integer>() {
+            @Override
+            public Integer value() {
+                return offlinePartitionCount();
+            }
+        }));
+        registry.ifPresent(r -> r.newGauge(PREFERRED_REPLICA_IMBALANCE_COUNT, new Gauge<Integer>() {
+            @Override
+            public Integer value() {
+                return preferredReplicaImbalanceCount();
+            }
+        }));
+        registry.ifPresent(r -> r.newGauge(METADATA_ERROR_COUNT, new Gauge<Integer>() {
+            @Override
+            public Integer value() {
+                return metadataErrorCount();
+            }
+        }));
+    }
+
+    public void setFencedBrokerCount(int brokerCount) {
+        this.fencedBrokerCount.set(brokerCount);
+    }
+
+    public void addToFencedBrokerCount(int brokerCountDelta) {
+        this.fencedBrokerCount.addAndGet(brokerCountDelta);
+    }
+
+    public int fencedBrokerCount() {
+        return this.fencedBrokerCount.get();
+    }
+
+    public void setActiveBrokerCount(int brokerCount) {
+        this.activeBrokerCount.set(brokerCount);
+    }
+
+    public void addToActiveBrokerCount(int brokerCountDelta) {
+        this.activeBrokerCount.addAndGet(brokerCountDelta);
+    }
+
+    public int activeBrokerCount() {
+        return this.activeBrokerCount.get();
+    }
+
+    public void setGlobalTopicCount(int topicCount) {
+        this.globalTopicCount.set(topicCount);
+    }
+
+    public void addToGlobalTopicCount(int topicCountDelta) {
+        this.globalTopicCount.addAndGet(topicCountDelta);
+    }
+
+    public int globalTopicCount() {
+        return this.globalTopicCount.get();
+    }
+
+    public void setGlobalPartitionCount(int partitionCount) {
+        this.globalPartitionCount.set(partitionCount);
+    }
+
+    public void addToGlobalPartitionCount(int partitionCountDelta) {
+        this.globalPartitionCount.addAndGet(partitionCountDelta);
+    }
+
+    public int globalPartitionCount() {
+        return this.globalPartitionCount.get();
+    }
+
+    public void setOfflinePartitionCount(int offlinePartitions) {
+        this.offlinePartitionCount.set(offlinePartitions);
+    }
+
+    public void addToOfflinePartitionCount(int offlinePartitionsDelta) {
+        this.offlinePartitionCount.addAndGet(offlinePartitionsDelta);
+    }
+
+    public int offlinePartitionCount() {
+        return this.offlinePartitionCount.get();
+    }
+
+    public void setPreferredReplicaImbalanceCount(int replicaImbalances) {
+        this.preferredReplicaImbalanceCount.set(replicaImbalances);
+    }
+
+    public void addToPreferredReplicaImbalanceCount(int replicaImbalancesCount) {
+        this.preferredReplicaImbalanceCount.addAndGet(replicaImbalancesCount);
+    }
+
+    public int preferredReplicaImbalanceCount() {
+        return this.preferredReplicaImbalanceCount.get();
+    }
+
+    public void incrementMetadataErrorCount() {
+        this.metadataErrorCount.getAndIncrement();
+    }
+
+    public int metadataErrorCount() {
+        return this.metadataErrorCount.get();
+    }
+
+    @Override
+    public void close() {
+        registry.ifPresent(r -> {
+            Arrays.asList(
+                FENCED_BROKER_COUNT,
+                ACTIVE_BROKER_COUNT,
+                GLOBAL_TOPIC_COUNT,
+                GLOBAL_PARTITION_COUNT,
+                OFFLINE_PARTITION_COUNT,
+                PREFERRED_REPLICA_IMBALANCE_COUNT,
+                METADATA_ERROR_COUNT
+                ).forEach(r::removeMetric);

Review Comment:
   nit: indent



##########
metadata/src/main/java/org/apache/kafka/controller/metrics/ControllerMetadataMetricsPublisher.java:
##########
@@ -0,0 +1,156 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.kafka.controller.metrics;
+
+import org.apache.kafka.common.Uuid;
+import org.apache.kafka.image.MetadataDelta;
+import org.apache.kafka.image.MetadataImage;
+import org.apache.kafka.image.TopicDelta;
+import org.apache.kafka.image.TopicImage;
+import org.apache.kafka.image.loader.LoaderManifest;
+import org.apache.kafka.image.publisher.MetadataPublisher;
+import org.apache.kafka.metadata.BrokerRegistration;
+import org.apache.kafka.metadata.PartitionRegistration;
+import org.apache.kafka.server.fault.FaultHandler;
+
+import java.util.Map.Entry;
+import java.util.Optional;
+
+
+/**
+ * This publisher translates metadata updates sent by MetadataLoader into changes to controller
+ * metrics. Like all MetadataPublisher objects, it only receives notifications about events that
+ * have been persisted to the metadata log. So on the active controller, it will run slightly
+ * behind the latest in-memory state which has not yet been fully persisted to the log. This is
+ * reasonable for metrics, which don't need up-to-the-millisecond update latency.
+ *
+ * NOTE: the ZK controller has some special rules for calculating preferredReplicaImbalanceCount
+ * which we haven't implemented here. Specifically, the ZK controller considers reassigning
+ * partitions to always have their preferred leader, even if they don't.
+ * All other metrics should be the same, as far as is possible.
+ */
+public class ControllerMetadataMetricsPublisher implements MetadataPublisher {
+    private final ControllerMetadataMetrics metrics;
+    private final FaultHandler faultHandler;
+    private MetadataImage prevImage = MetadataImage.EMPTY;
+
+    public ControllerMetadataMetricsPublisher(
+        ControllerMetadataMetrics metrics,
+        FaultHandler faultHandler
+    ) {
+        this.metrics = metrics;
+        this.faultHandler = faultHandler;
+    }
+
+    @Override
+    public String name() {
+        return "ControllerMetadataMetricsPublisher";
+    }
+
+    @Override
+    public void onMetadataUpdate(
+            MetadataDelta delta,
+            MetadataImage newImage,
+            LoaderManifest manifest

Review Comment:
   nit: indent should be 4 here



-- 
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-unsubscribe@kafka.apache.org

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