You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by "gaurav-narula (via GitHub)" <gi...@apache.org> on 2024/07/27 13:28:47 UTC

[PR] KAFKA-8366: Avoid false positives on offline partition count [kafka]

gaurav-narula opened a new pull request, #16704:
URL: https://github.com/apache/kafka/pull/16704

   In Zookeeper mode, the controller maintains an in-memory state of `topicsWithDeletionStarted` to decide if `OfflinePartitionsCount` metric must be incremented/decremented for a TopicPartition on its state transition.
   
   This in-memory state is however not maintained when a controller election happens in the midst of a topic deletion leading to false positives on the `OfflinePartitionsCount` metric.
   
   This change modifies `TopicDeletionManager::init` to populate `ControllerContext.topicsWithDeletionStarted` with `topicsIneligibleForDeletion` so that the new controller doesn't emit false positive metric.


-- 
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


Re: [PR] KAFKA-8366: Avoid false positives on offline partition count [kafka]

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


##########
core/src/test/scala/integration/kafka/controller/OfflinePartitionsFromDeletedTopicTest.scala:
##########
@@ -0,0 +1,123 @@
+/*
+ * 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 integration.kafka.controller
+
+import com.yammer.metrics.core.Gauge
+import kafka.api.IntegrationTestHarness
+import kafka.server.IntegrationTestUtils
+import kafka.utils.TestUtils
+import kafka.zk.KafkaZkClient
+import org.apache.kafka.clients.admin.Admin
+import org.apache.kafka.clients.producer.{KafkaProducer, ProducerRecord}
+import org.apache.kafka.common.serialization.StringSerializer
+import org.apache.kafka.server.metrics.KafkaYammerMetrics
+import org.junit.jupiter.api.Assertions.{assertEquals, assertNotEquals}
+import org.junit.jupiter.api.{BeforeEach, Test, TestInfo}
+import org.slf4j.{Logger, LoggerFactory}
+
+import java.time.Duration
+import java.util.concurrent.TimeUnit
+import scala.jdk.CollectionConverters._
+
+
+class OfflinePartitionsFromDeletedTopicTest extends IntegrationTestHarness {

Review Comment:
   > I believe if there is no active consumers you shouldn't have offset topic.
   
   yep, the new test infra (`ClusterTestExtensions`) does NOT create the `__consumer_offsets` in setup phase. By contrast, the zk infra does, and that is why there is a flag `createOffsetsTopic`.
   
   https://github.com/apache/kafka/blob/96816a3ed74857cc7631174b2c189ed8b1d9807c/core/src/test/scala/integration/kafka/api/IntegrationTestHarness.scala#L159
   
   



-- 
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


Re: [PR] KAFKA-8366: Avoid false positives on offline partition count [kafka]

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


##########
core/src/test/scala/integration/kafka/controller/OfflinePartitionsFromDeletedTopicTest.scala:
##########
@@ -0,0 +1,123 @@
+/*
+ * 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 integration.kafka.controller
+
+import com.yammer.metrics.core.Gauge
+import kafka.api.IntegrationTestHarness
+import kafka.server.IntegrationTestUtils
+import kafka.utils.TestUtils
+import kafka.zk.KafkaZkClient
+import org.apache.kafka.clients.admin.Admin
+import org.apache.kafka.clients.producer.{KafkaProducer, ProducerRecord}
+import org.apache.kafka.common.serialization.StringSerializer
+import org.apache.kafka.server.metrics.KafkaYammerMetrics
+import org.junit.jupiter.api.Assertions.{assertEquals, assertNotEquals}
+import org.junit.jupiter.api.{BeforeEach, Test, TestInfo}
+import org.slf4j.{Logger, LoggerFactory}
+
+import java.time.Duration
+import java.util.concurrent.TimeUnit
+import scala.jdk.CollectionConverters._
+
+
+class OfflinePartitionsFromDeletedTopicTest extends IntegrationTestHarness {

Review Comment:
   https://issues.apache.org/jira/browse/KAFKA-17284



-- 
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


Re: [PR] KAFKA-8366: Avoid false positives on offline partition count [kafka]

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


##########
core/src/test/scala/integration/kafka/controller/OfflinePartitionsFromDeletedTopicTest.scala:
##########
@@ -0,0 +1,123 @@
+/*
+ * 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 integration.kafka.controller
+
+import com.yammer.metrics.core.Gauge
+import kafka.api.IntegrationTestHarness
+import kafka.server.IntegrationTestUtils
+import kafka.utils.TestUtils
+import kafka.zk.KafkaZkClient
+import org.apache.kafka.clients.admin.Admin
+import org.apache.kafka.clients.producer.{KafkaProducer, ProducerRecord}
+import org.apache.kafka.common.serialization.StringSerializer
+import org.apache.kafka.server.metrics.KafkaYammerMetrics
+import org.junit.jupiter.api.Assertions.{assertEquals, assertNotEquals}
+import org.junit.jupiter.api.{BeforeEach, Test, TestInfo}
+import org.slf4j.{Logger, LoggerFactory}
+
+import java.time.Duration
+import java.util.concurrent.TimeUnit
+import scala.jdk.CollectionConverters._
+
+
+class OfflinePartitionsFromDeletedTopicTest extends IntegrationTestHarness {

Review Comment:
   > I'm happy to use the new harness but I think we'd need a way to disable auto consumer-offset topic creation in it somehow.
   
   I believe if there is no active consumers you shouldn't have offset topic. 



-- 
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


Re: [PR] KAFKA-8366: Avoid false positives on offline partition count [kafka]

Posted by "cmccabe (via GitHub)" <gi...@apache.org>.
cmccabe commented on PR #16704:
URL: https://github.com/apache/kafka/pull/16704#issuecomment-2278818713

   I'm sorry, but I don't think we should do this in 3.9.
   
   The offline partitions metric is at least a decade old, and has always worked this way in ZK mode. Changing the behavior at this point would require a KIP. And probably even then, we'd want to create a new metric rather than changing the behavior of the old one. Topics in "deleting" state really do represent a lack of availability in some sense, since their names cannot be used until the deleting state is cleared (probably manually, by starting stopped brokers.) So some administrators may be relying on the current behavior of this metric to detect that and realize they need to do something about it.
   
   Deleting state doesn't exist in 4.0 / KRaft, so if you agree, we can just close this JIRA with fix version 4.0.


-- 
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


Re: [PR] KAFKA-8366: Avoid false positives on offline partition count [kafka]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #16704:
URL: https://github.com/apache/kafka/pull/16704#issuecomment-2572216821

   This PR is being marked as stale since it has not had any activity in 90 days. If you
   would like to keep this PR alive, please leave a comment asking for a review. If the PR has 
   merge conflicts, update it with the latest from the base branch.
   <p>
   If you are having difficulty finding a reviewer, please reach out on the 
   [mailing list](https://kafka.apache.org/contact).
   <p>
   If this PR is no longer valid or desired, please feel free to close it. If no activity
   occurs in the next 30 days, it will be automatically closed.


-- 
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


Re: [PR] KAFKA-8366: Avoid false positives on offline partition count [kafka]

Posted by "gaurav-narula (via GitHub)" <gi...@apache.org>.
gaurav-narula commented on PR #16704:
URL: https://github.com/apache/kafka/pull/16704#issuecomment-2254150793

   CC: @soarez @hachikuji 


-- 
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


Re: [PR] KAFKA-8366: Avoid false positives on offline partition count [kafka]

Posted by "gaurav-narula (via GitHub)" <gi...@apache.org>.
gaurav-narula commented on code in PR #16704:
URL: https://github.com/apache/kafka/pull/16704#discussion_r1705699187


##########
core/src/main/scala/kafka/controller/KafkaController.scala:
##########
@@ -111,7 +111,11 @@ class KafkaController(val config: KafkaConfig,
                       tokenManager: DelegationTokenManager,
                       brokerFeatures: BrokerFeatures,
                       featureCache: ZkFinalizedFeatureCache,
-                      threadNamePrefix: Option[String] = None)
+                      threadNamePrefix: Option[String] = None,
+                      // KafkaYammerMetrics uses a static singleton that is shared across the JVM
+                      // Therefore, these are populated in tests with brokerId to disambiguate between metrics for
+                      // different nodes

Review Comment:
   It's true that there can be only a single active controller, but each node within the test harness registers the controller metrics during [KafkaServer::startup](https://github.com/apache/kafka/blob/3ddd8d0a0ec02eab8d9083d341ece14961fc0d1c/core/src/main/scala/kafka/server/KafkaServer.scala#L417).
   
   The same metrics are also removed on [KafkaServer::shutdown](https://github.com/apache/kafka/blob/3ddd8d0a0ec02eab8d9083d341ece14961fc0d1c/core/src/main/scala/kafka/server/KafkaServer.scala#L1041).
   
   Since the metrics are registered using `KafkaYammerMetrics` which uses a static variable behind the scenes, shutting down a broker during the test leads to removal of controller metrics. The disambiguation is therefore required so that "controller-metrics" are removed only for the broker that's being shut down.
   
   This isn't an issue in real-world scenarios because we don't run multiple brokers within the same JVM.



-- 
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


Re: [PR] KAFKA-8366: Avoid false positives on offline partition count [kafka]

Posted by "gaurav-narula (via GitHub)" <gi...@apache.org>.
gaurav-narula commented on code in PR #16704:
URL: https://github.com/apache/kafka/pull/16704#discussion_r1706770283


##########
core/src/test/scala/integration/kafka/controller/OfflinePartitionsFromDeletedTopicTest.scala:
##########
@@ -0,0 +1,123 @@
+/*
+ * 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 integration.kafka.controller
+
+import com.yammer.metrics.core.Gauge
+import kafka.api.IntegrationTestHarness
+import kafka.server.IntegrationTestUtils
+import kafka.utils.TestUtils
+import kafka.zk.KafkaZkClient
+import org.apache.kafka.clients.admin.Admin
+import org.apache.kafka.clients.producer.{KafkaProducer, ProducerRecord}
+import org.apache.kafka.common.serialization.StringSerializer
+import org.apache.kafka.server.metrics.KafkaYammerMetrics
+import org.junit.jupiter.api.Assertions.{assertEquals, assertNotEquals}
+import org.junit.jupiter.api.{BeforeEach, Test, TestInfo}
+import org.slf4j.{Logger, LoggerFactory}
+
+import java.time.Duration
+import java.util.concurrent.TimeUnit
+import scala.jdk.CollectionConverters._
+
+
+class OfflinePartitionsFromDeletedTopicTest extends IntegrationTestHarness {

Review Comment:
   > I believe if there is no active consumers you shouldn't have offset topic.
   
   I thought so too but the IntegrationTestHarness auto creates the consumer-offset topic by default. Refer https://github.com/apache/kafka/blob/96816a3ed74857cc7631174b2c189ed8b1d9807c/core/src/test/scala/integration/kafka/api/IntegrationTestHarness.scala#L121
   
   I'll try to follow Igor's suggestion and see if we can test this within `TopicDeletionManagerTest` instead to avoid the complexity.



-- 
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


Re: [PR] KAFKA-8366: Avoid false positives on offline partition count [kafka]

Posted by "gaurav-narula (via GitHub)" <gi...@apache.org>.
gaurav-narula commented on PR #16704:
URL: https://github.com/apache/kafka/pull/16704#issuecomment-2271001217

   @cmccabe can we consider this for backporting to 3.9 please given it's a long standing bug in ZK mode?


-- 
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


Re: [PR] KAFKA-8366: Avoid false positives on offline partition count [kafka]

Posted by "gaurav-narula (via GitHub)" <gi...@apache.org>.
gaurav-narula commented on code in PR #16704:
URL: https://github.com/apache/kafka/pull/16704#discussion_r1706801512


##########
core/src/test/scala/integration/kafka/controller/OfflinePartitionsFromDeletedTopicTest.scala:
##########
@@ -0,0 +1,123 @@
+/*
+ * 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 integration.kafka.controller
+
+import com.yammer.metrics.core.Gauge
+import kafka.api.IntegrationTestHarness
+import kafka.server.IntegrationTestUtils
+import kafka.utils.TestUtils
+import kafka.zk.KafkaZkClient
+import org.apache.kafka.clients.admin.Admin
+import org.apache.kafka.clients.producer.{KafkaProducer, ProducerRecord}
+import org.apache.kafka.common.serialization.StringSerializer
+import org.apache.kafka.server.metrics.KafkaYammerMetrics
+import org.junit.jupiter.api.Assertions.{assertEquals, assertNotEquals}
+import org.junit.jupiter.api.{BeforeEach, Test, TestInfo}
+import org.slf4j.{Logger, LoggerFactory}
+
+import java.time.Duration
+import java.util.concurrent.TimeUnit
+import scala.jdk.CollectionConverters._
+
+
+class OfflinePartitionsFromDeletedTopicTest extends IntegrationTestHarness {

Review Comment:
   > yep, the new test infra (ClusterTestExtensions) does NOT create the __consumer_offsets in setup phase
   
   @chia7712 I suppose that only applies to non `Type.ZK` tests? I reckon `ClusterTestExtensions` for `Type.ZK` uses `ZkClusterInvocationContext`? Wouldn't that use `ClusterConfigurableIntegrationHarness` which extends `IntegrationTestHarness` and auto create offsets topic as a result?
   
   https://github.com/apache/kafka/blob/c2f53a97608683405897c3dcb3bd25a03ceb7dba/core/src/test/java/kafka/test/junit/ZkClusterInvocationContext.java#L275
   



-- 
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


Re: [PR] KAFKA-8366: Avoid false positives on offline partition count [kafka]

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


##########
core/src/test/scala/unit/kafka/metrics/MetricsTest.scala:
##########
@@ -120,8 +120,15 @@ class MetricsTest extends KafkaServerTestHarness with Logging {
   @ValueSource(strings = Array("zk", "kraft"))
   def testJMXFilter(quorum: String): Unit = {
     // Check if cluster id metrics is not exposed in JMX
-    assertTrue(ManagementFactory.getPlatformMBeanServer
-                 .isRegistered(new ObjectName("kafka.controller:type=KafkaController,name=ActiveControllerCount")))
+    if (quorum == "zk") {
+      assertTrue(ManagementFactory.getPlatformMBeanServer
+        .isRegistered(new ObjectName("kafka.controller:type=KafkaController,name=ActiveControllerCount,brokerId=0")))
+      assertTrue(ManagementFactory.getPlatformMBeanServer
+        .isRegistered(new ObjectName("kafka.controller:type=KafkaController,name=ActiveControllerCount,brokerId=1")))
+    } else {
+      assertTrue(ManagementFactory.getPlatformMBeanServer
+        .isRegistered(new ObjectName("kafka.controller:type=KafkaController,name=ActiveControllerCount")))
+    }

Review Comment:
   Noting that all the changes in this file are unrelated to the bug, just collateral from introducing controller metric tags via the KafkaServer in TestUtils.



##########
core/src/test/scala/unit/kafka/controller/KafkaControllerTest.scala:
##########
@@ -51,19 +54,20 @@ class KafkaControllerTest {
         initialBrokerEpoch = 0,
         tokenManager = mock(classOf[DelegationTokenManager]),
         brokerFeatures = mock(classOf[BrokerFeatures]),
-        featureCache = mock(classOf[ZkMetadataCache])
+        featureCache = mock(classOf[ZkMetadataCache]),
+        metricTags = metricTags
       )
 
       // shutdown kafkaController so that metrics are removed
       kafkaController.shutdown()
 
       val mockMetricsGroup = mockMetricsGroupCtor.constructed.get(0)
       val numMetricsRegistered = KafkaController.MetricNames.size
-      verify(mockMetricsGroup, times(numMetricsRegistered)).newGauge(anyString(), any())
-      KafkaController.MetricNames.foreach(metricName => verify(mockMetricsGroup).newGauge(ArgumentMatchers.eq(metricName), any()))
+      verify(mockMetricsGroup, times(numMetricsRegistered)).newGauge(anyString(), any(), ArgumentMatchers.eq(metricTags.asJava))
+      KafkaController.MetricNames.foreach(metricName => verify(mockMetricsGroup).newGauge(ArgumentMatchers.eq(metricName), any(), ArgumentMatchers.eq(metricTags.asJava)))
       // verify that each metric is removed
-      verify(mockMetricsGroup, times(numMetricsRegistered)).removeMetric(anyString())
-      KafkaController.MetricNames.foreach(verify(mockMetricsGroup).removeMetric(_))
+      verify(mockMetricsGroup, times(numMetricsRegistered)).removeMetric(anyString(), ArgumentMatchers.eq(metricTags.asJava))
+      KafkaController.MetricNames.foreach { name => verify(mockMetricsGroup).removeMetric(ArgumentMatchers.eq(name), ArgumentMatchers.eq(metricTags.asJava)) }

Review Comment:
   Noting the same here, these changes simply deal with the implications of introducing metric tags to the KafkaController.



##########
core/src/main/scala/kafka/controller/KafkaController.scala:
##########
@@ -539,7 +543,7 @@ class KafkaController(val config: KafkaConfig,
   }
 
   private def removeMetrics(): Unit = {
-    KafkaController.MetricNames.foreach(metricsGroup.removeMetric)
+    KafkaController.MetricNames.foreach(metricsGroup.removeMetric(_, metricTags.asJava))

Review Comment:
   Same here, tags default to an empty map in `metricsGroup.removeMetric(String)`.



##########
core/src/main/scala/kafka/controller/KafkaController.scala:
##########
@@ -175,20 +179,20 @@ class KafkaController(val config: KafkaConfig,
   /* single-thread scheduler to clean expired tokens */
   private val tokenCleanScheduler = new KafkaScheduler(1, true, "delegation-token-cleaner")
 
-  metricsGroup.newGauge(ZkMigrationStateMetricName, () => ZkMigrationState.ZK.value().intValue())
-  metricsGroup.newGauge(ActiveControllerCountMetricName, () => if (isActive) 1 else 0)
-  metricsGroup.newGauge(OfflinePartitionsCountMetricName, () => offlinePartitionCount)
-  metricsGroup.newGauge(PreferredReplicaImbalanceCountMetricName, () => preferredReplicaImbalanceCount)
-  metricsGroup.newGauge(ControllerStateMetricName, () => state.value)
-  metricsGroup.newGauge(GlobalTopicCountMetricName, () => globalTopicCount)
-  metricsGroup.newGauge(GlobalPartitionCountMetricName, () => globalPartitionCount)
-  metricsGroup.newGauge(TopicsToDeleteCountMetricName, () => topicsToDeleteCount)
-  metricsGroup.newGauge(ReplicasToDeleteCountMetricName, () => replicasToDeleteCount)
-  metricsGroup.newGauge(TopicsIneligibleToDeleteCountMetricName, () => ineligibleTopicsToDeleteCount)
-  metricsGroup.newGauge(ReplicasIneligibleToDeleteCountMetricName, () => ineligibleReplicasToDeleteCount)
-  metricsGroup.newGauge(ActiveBrokerCountMetricName, () => activeBrokerCount)
+  metricsGroup.newGauge(ZkMigrationStateMetricName, () => ZkMigrationState.ZK.value().intValue(), metricTags.asJava)
+  metricsGroup.newGauge(ActiveControllerCountMetricName, () => if (isActive) 1 else 0, metricTags.asJava)
+  metricsGroup.newGauge(OfflinePartitionsCountMetricName, () => offlinePartitionCount, metricTags.asJava)
+  metricsGroup.newGauge(PreferredReplicaImbalanceCountMetricName, () => preferredReplicaImbalanceCount, metricTags.asJava)
+  metricsGroup.newGauge(ControllerStateMetricName, () => state.value, metricTags.asJava)
+  metricsGroup.newGauge(GlobalTopicCountMetricName, () => globalTopicCount, metricTags.asJava)
+  metricsGroup.newGauge(GlobalPartitionCountMetricName, () => globalPartitionCount, metricTags.asJava)
+  metricsGroup.newGauge(TopicsToDeleteCountMetricName, () => topicsToDeleteCount, metricTags.asJava)
+  metricsGroup.newGauge(ReplicasToDeleteCountMetricName, () => replicasToDeleteCount, metricTags.asJava)
+  metricsGroup.newGauge(TopicsIneligibleToDeleteCountMetricName, () => ineligibleTopicsToDeleteCount, metricTags.asJava)
+  metricsGroup.newGauge(ReplicasIneligibleToDeleteCountMetricName, () => ineligibleReplicasToDeleteCount, metricTags.asJava)
+  metricsGroup.newGauge(ActiveBrokerCountMetricName, () => activeBrokerCount, metricTags.asJava)
   // FencedBrokerCount metric is always 0 in the ZK controller.
-  metricsGroup.newGauge(FencedBrokerCountMetricName, () => 0)
+  metricsGroup.newGauge(FencedBrokerCountMetricName, () => 0, metricTags.asJava)

Review Comment:
   This new `metricsTags.asJava` argument is always an empty map in non-test paths, which is also the default used by the method overload without the new argument. So this causes no effective changes the controller metrics.



##########
core/src/main/scala/kafka/controller/TopicDeletionManager.scala:
##########
@@ -97,6 +97,9 @@ class TopicDeletionManager(config: KafkaConfig,
 
     if (isDeleteTopicEnabled) {
       controllerContext.queueTopicDeletion(initialTopicsToBeDeleted)
+      // We must populate topicsWithDeletionStarted with topics ineligible for deletion because that Set is used
+      // to check if OfflinePartitionCount metric must be changed or not.

Review Comment:
   ```suggestion
         // in updatePartitionStateMetrics to gate changes to OfflinePartitionCount via isTopicDeletionInProgress.
   ```



##########
core/src/test/scala/integration/kafka/controller/OfflinePartitionsFromDeletedTopicTest.scala:
##########
@@ -0,0 +1,123 @@
+/*
+ * 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 integration.kafka.controller
+
+import com.yammer.metrics.core.Gauge
+import kafka.api.IntegrationTestHarness
+import kafka.server.IntegrationTestUtils
+import kafka.utils.TestUtils
+import kafka.zk.KafkaZkClient
+import org.apache.kafka.clients.admin.Admin
+import org.apache.kafka.clients.producer.{KafkaProducer, ProducerRecord}
+import org.apache.kafka.common.serialization.StringSerializer
+import org.apache.kafka.server.metrics.KafkaYammerMetrics
+import org.junit.jupiter.api.Assertions.{assertEquals, assertNotEquals}
+import org.junit.jupiter.api.{BeforeEach, Test, TestInfo}
+import org.slf4j.{Logger, LoggerFactory}
+
+import java.time.Duration
+import java.util.concurrent.TimeUnit
+import scala.jdk.CollectionConverters._
+
+
+class OfflinePartitionsFromDeletedTopicTest extends IntegrationTestHarness {

Review Comment:
   There's a new preferred approach to integration testing. See #16500. cc @chia7712 



##########
core/src/main/scala/kafka/controller/KafkaController.scala:
##########
@@ -111,7 +111,11 @@ class KafkaController(val config: KafkaConfig,
                       tokenManager: DelegationTokenManager,
                       brokerFeatures: BrokerFeatures,
                       featureCache: ZkFinalizedFeatureCache,
-                      threadNamePrefix: Option[String] = None)
+                      threadNamePrefix: Option[String] = None,
+                      // KafkaYammerMetrics uses a static singleton that is shared across the JVM
+                      // Therefore, these are populated in tests with brokerId to disambiguate between metrics for
+                      // different nodes

Review Comment:
   There may be some missing part of the explanation here. At any point there should only be a single active controller, so the need to disambiguate metrics isn't clear from this comment. 



-- 
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


Re: [PR] KAFKA-8366: Avoid false positives on offline partition count [kafka]

Posted by "gaurav-narula (via GitHub)" <gi...@apache.org>.
gaurav-narula commented on PR #16704:
URL: https://github.com/apache/kafka/pull/16704#issuecomment-2620300905

   Closing as this is not to be taken up as Kraft is the way forward.


-- 
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


Re: [PR] KAFKA-8366: Avoid false positives on offline partition count [kafka]

Posted by "gaurav-narula (via GitHub)" <gi...@apache.org>.
gaurav-narula commented on code in PR #16704:
URL: https://github.com/apache/kafka/pull/16704#discussion_r1705702084


##########
core/src/test/scala/integration/kafka/controller/OfflinePartitionsFromDeletedTopicTest.scala:
##########
@@ -0,0 +1,123 @@
+/*
+ * 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 integration.kafka.controller
+
+import com.yammer.metrics.core.Gauge
+import kafka.api.IntegrationTestHarness
+import kafka.server.IntegrationTestUtils
+import kafka.utils.TestUtils
+import kafka.zk.KafkaZkClient
+import org.apache.kafka.clients.admin.Admin
+import org.apache.kafka.clients.producer.{KafkaProducer, ProducerRecord}
+import org.apache.kafka.common.serialization.StringSerializer
+import org.apache.kafka.server.metrics.KafkaYammerMetrics
+import org.junit.jupiter.api.Assertions.{assertEquals, assertNotEquals}
+import org.junit.jupiter.api.{BeforeEach, Test, TestInfo}
+import org.slf4j.{Logger, LoggerFactory}
+
+import java.time.Duration
+import java.util.concurrent.TimeUnit
+import scala.jdk.CollectionConverters._
+
+
+class OfflinePartitionsFromDeletedTopicTest extends IntegrationTestHarness {

Review Comment:
   I'm happy to use the new harness but I think we'd need a way to disable auto consumer-offset topic creation in it somehow.



-- 
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


Re: [PR] KAFKA-8366: Avoid false positives on offline partition count [kafka]

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


##########
core/src/test/scala/integration/kafka/controller/OfflinePartitionsFromDeletedTopicTest.scala:
##########
@@ -0,0 +1,123 @@
+/*
+ * 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 integration.kafka.controller
+
+import com.yammer.metrics.core.Gauge
+import kafka.api.IntegrationTestHarness
+import kafka.server.IntegrationTestUtils
+import kafka.utils.TestUtils
+import kafka.zk.KafkaZkClient
+import org.apache.kafka.clients.admin.Admin
+import org.apache.kafka.clients.producer.{KafkaProducer, ProducerRecord}
+import org.apache.kafka.common.serialization.StringSerializer
+import org.apache.kafka.server.metrics.KafkaYammerMetrics
+import org.junit.jupiter.api.Assertions.{assertEquals, assertNotEquals}
+import org.junit.jupiter.api.{BeforeEach, Test, TestInfo}
+import org.slf4j.{Logger, LoggerFactory}
+
+import java.time.Duration
+import java.util.concurrent.TimeUnit
+import scala.jdk.CollectionConverters._
+
+
+class OfflinePartitionsFromDeletedTopicTest extends IntegrationTestHarness {

Review Comment:
   > I suppose that only applies to non Type.ZK tests?
   
   yes. Maybe we should disable that in order to make consistent behavior in new test infra. I will file another jira to address that (and check the possible side effect). I feel this PR can keep using `IntegrationTestHarness`, and then we can do a bit refactor as follow-up



-- 
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


Re: [PR] KAFKA-8366: Avoid false positives on offline partition count [kafka]

Posted by "gaurav-narula (via GitHub)" <gi...@apache.org>.
gaurav-narula closed pull request #16704: KAFKA-8366: Avoid false positives on offline partition count
URL: https://github.com/apache/kafka/pull/16704


-- 
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