You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by "tinaselenge (via GitHub)" <gi...@apache.org> on 2024/10/17 13:10:42 UTC

[PR] KIP-1073: Return fenced brokers in DescribeCluster response [kafka]

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

   *More detailed description of your change,
   if necessary. The PR title and PR message become
   the squashed commit message, so use a separate
   comment to ping reviewers.*
   
   *Summary of testing strategy (including rationale)
   for the feature or bug fix. Unit and/or integration
   tests are expected for any behaviour change and
   system tests should be considered for larger changes.*
   
   ### Committer Checklist (excluded from commit message)
   - [ ] Verify design and implementation 
   - [ ] Verify test coverage and CI build status
   - [ ] Verify documentation (including upgrade notes)
   


-- 
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] KIP-1073: Return fenced brokers in DescribeCluster response [kafka]

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


##########
core/src/main/scala/kafka/server/KafkaApis.scala:
##########
@@ -3611,12 +3611,17 @@ class KafkaApis(val requestChannel: RequestChannel,
       clusterId,
       () => {
         val brokers = new DescribeClusterResponseData.DescribeClusterBrokerCollection()
-        metadataCache.getAliveBrokerNodes(request.context.listenerName).foreach { node =>
+        val describeClusterRequest = request.body[DescribeClusterRequest]
+        metadataCache.getBrokerNodes(request.context.listenerName).foreach { node =>
+          if (node.isFenced && !describeClusterRequest.data().includeFencedBrokers()) {
+          } else {

Review Comment:
   I removed the else and swapped the condition around



-- 
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] KIP-1073: Return fenced brokers in DescribeCluster response [kafka]

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


##########
core/src/test/scala/integration/kafka/api/PlaintextAdminIntegrationTest.scala:
##########
@@ -615,6 +615,30 @@ class PlaintextAdminIntegrationTest extends BaseAdminIntegrationTest {
     assertEquals(brokerStrs.mkString(","), nodeStrs.mkString(","))
   }
 
+  @ParameterizedTest
+  @ValueSource(strings = Array("kraft"))
+  def testListNodesWithFencedBroker(quorum: String): Unit = {
+    client = createAdminClient
+    val fencedBrokerId = brokers.last.config.brokerId
+    killBroker(fencedBrokerId)
+    // It takes a few seconds for a broker to get fenced after being killed
+    // So we retry until only 2 of 3 brokers returned in the result or the max wait is reached
+    TestUtils.retry(20000) {

Review Comment:
   I think this is ok, because the fencing time should be around `broker.session.timeout.ms` (9 seconds) in the worst case.
   
   https://github.com/apache/kafka/blob/trunk/metadata/src/main/java/org/apache/kafka/controller/QuorumController.java#L1650-L1662
   
   One thing we can improve is the to kill the broker immediately:
   
   ```sh
   killBroker(fencedBrokerId, JDuration.ofMillis(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] KIP-1073: Return fenced brokers in DescribeCluster response [kafka]

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


##########
core/src/main/scala/kafka/server/metadata/ZkMetadataCache.scala:
##########
@@ -354,6 +354,10 @@ class ZkMetadataCache(
     metadataSnapshot.aliveBrokers.values.flatMap(_.getNode(listenerName))
   }
 
+  override def getBrokerNodes(listenerName: ListenerName): Iterable[Node] = {
+    getAliveBrokerNodes(listenerName)
+  }
+

Review Comment:
   It seems like until we remove ZKMetadataCache completely, this is needed in order to compile.



-- 
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] KIP-1073: Return fenced brokers in DescribeCluster response [kafka]

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


##########
clients/src/main/java/org/apache/kafka/clients/admin/KafkaAdminClient.java:
##########
@@ -2557,7 +2557,10 @@ boolean handleUnsupportedVersionException(final UnsupportedVersionException exce
                     return false;
                 }
 
-                if (exception.getMessage().contains("Including fenced broker endpoints is not supported with version")) {
+                // If unsupportedVersion exception was caused by the option to include fenced brokers (only supported for version 1+)
+                // then we should not fall back to the metadataRequest.
+                if (options.includeFencedBrokers()) {
+                    log.error("Including fenced broker endpoints is not supported with " + exception.getMessage());

Review Comment:
   I'm not sure the exception message when unsupportedVersionException thrown. You need to check again in integration test. The `Api DESCRIBE_CLUSTER with version 1` is from `mockClient`, not real `networkClient`. FYI.



-- 
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] KIP-1073: Return fenced brokers in DescribeCluster response [kafka]

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

   @tinaselenge , there are some tests failure. Could you help fix them? Thanks.


-- 
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] KIP-1073: Return fenced brokers in DescribeCluster response [kafka]

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


##########
core/src/main/scala/kafka/server/metadata/ZkMetadataCache.scala:
##########
@@ -354,6 +354,10 @@ class ZkMetadataCache(
     metadataSnapshot.aliveBrokers.values.flatMap(_.getNode(listenerName))
   }
 
+  override def getBrokerNodes(listenerName: ListenerName): Iterable[Node] = {
+    getAliveBrokerNodes(listenerName)
+  }
+

Review Comment:
   It seems like until we remove ZKMetadataCache completely, this is needed to in order to compile.



-- 
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] KIP-1073: Return fenced brokers in DescribeCluster response [kafka]

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


##########
clients/src/main/java/org/apache/kafka/clients/admin/KafkaAdminClient.java:
##########
@@ -2554,6 +2557,10 @@ boolean handleUnsupportedVersionException(final UnsupportedVersionException exce
                     return false;
                 }
 
+                if (exception.getMessage().contains("Including fenced broker endpoints is not supported with version")) {
+                    return false;
+                }
+
                 useMetadataRequest = true;
                 return true;

Review Comment:
   Thanks Luke for reviewing the PR. I'm not quite sure on this. We fallback to metadata request, if the broker does not support the new DescribeCluster API. In this case, DescribeCluster API is supported but the option to include fenced broker is not. So this is why we are checking the specific error message to differentiate the cause of UnsupportedVersion exception. 



-- 
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] KIP-1073: Return fenced brokers in DescribeCluster response [kafka]

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

   @fvaleri thank you so much for spotting that! This was because my change for DescribeClusterResponse.class was missed out from the commit accidentally. This issue also pointed out that the tests needed to be improved, which I did 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


Re: [PR] KIP-1073: Return fenced brokers in DescribeCluster response [kafka]

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

   thanks a lot @fvaleri!


-- 
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] KIP-1073: Return fenced brokers in DescribeCluster response [kafka]

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


##########
core/src/test/scala/integration/kafka/api/PlaintextAdminIntegrationTest.scala:
##########
@@ -615,6 +615,42 @@ class PlaintextAdminIntegrationTest extends BaseAdminIntegrationTest {
     assertEquals(brokerStrs.mkString(","), nodeStrs.mkString(","))
   }
 
+  @ParameterizedTest
+  @ValueSource(strings = Array("kraft"))
+  def testListNodesNotIncludingFencedBrokers(quorum: String): Unit = {
+    client = createAdminClient
+    val fencedBrokerId = brokers.last.config.brokerId
+    killBroker(fencedBrokerId)
+    Thread.sleep(10000) //sleep is needed to ensure the broker is fenced after the shutdown

Review Comment:
   This was my concern too but the broker takes a few seconds to get fenced after being killed and 10000ms seems to be sufficient, although I had planned to run this test several times in Jenkins to confirm it and adjust if needed. 
   
   I pushed another commit to merge these two test cases together, so that we only wait for a broker to get fenced once instead of twice. Also used TestUtils.retry to retry the request until we receive 2 of 3 brokers in the response or reach the max wait time. I set the max wait time to a larger value, in case it takes longer sometimes, but it shouldn't take more than 10s normally.



-- 
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] KIP-1073: Return fenced brokers in DescribeCluster response [kafka]

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


##########
core/src/main/scala/kafka/server/metadata/ZkMetadataCache.scala:
##########
@@ -354,6 +354,10 @@ class ZkMetadataCache(
     metadataSnapshot.aliveBrokers.values.flatMap(_.getNode(listenerName))
   }
 
+  override def getBrokerNodes(listenerName: ListenerName): Iterable[Node] = {
+    getAliveBrokerNodes(listenerName)
+  }
+

Review Comment:
   Fair enough.



-- 
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] KIP-1073: Return fenced brokers in DescribeCluster response [kafka]

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


##########
clients/src/main/java/org/apache/kafka/clients/admin/KafkaAdminClient.java:
##########
@@ -2557,7 +2557,10 @@ boolean handleUnsupportedVersionException(final UnsupportedVersionException exce
                     return false;
                 }
 
-                if (exception.getMessage().contains("Including fenced broker endpoints is not supported with version")) {
+                // If unsupportedVersion exception was caused by the option to include fenced brokers (only supported for version 1+)
+                // then we should not fall back to the metadataRequest.
+                if (options.includeFencedBrokers()) {
+                    log.error("Including fenced broker endpoints is not supported with " + exception.getMessage());

Review Comment:
   I think so.



-- 
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] KIP-1073: Return fenced brokers in DescribeCluster response [kafka]

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

   Thanks @showuon , I pushed a fix for the failed test. 


-- 
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] KIP-1073: Return fenced brokers in DescribeCluster response [kafka]

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


##########
clients/src/main/java/org/apache/kafka/clients/admin/KafkaAdminClient.java:
##########
@@ -2554,6 +2557,12 @@ boolean handleUnsupportedVersionException(final UnsupportedVersionException exce
                     return false;
                 }
 
+                // If unsupportedVersion exception was caused by the option to include fenced brokers (only supported for version 1+)

Review Comment:
   supported for version 2+?



##########
clients/src/main/java/org/apache/kafka/common/requests/DescribeClusterRequest.java:
##########
@@ -51,6 +52,13 @@ public String toString() {
     public DescribeClusterRequest(DescribeClusterRequestData data, short version) {
         super(ApiKeys.DESCRIBE_CLUSTER, version);
         this.data = data;
+        validateVersionForIncludingFencedBrokers(version, data.includeFencedBrokers());
+    }
+
+    private void validateVersionForIncludingFencedBrokers(short version, boolean includeFencedBrokers) {
+        if (version < 2 && includeFencedBrokers) {
+            throw new UnsupportedVersionException("Including fenced broker endpoints is not supported with version " + version);
+        }

Review Comment:
   Hmm... it's quite complicated to have a integration test to test with lower describeCluster version. I think it's fine sine we already have unit test to cover it. Thanks.



-- 
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] KIP-1073: Return fenced brokers in DescribeCluster response [kafka]

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


##########
clients/src/main/java/org/apache/kafka/common/requests/DescribeClusterRequest.java:
##########
@@ -51,6 +52,13 @@ public String toString() {
     public DescribeClusterRequest(DescribeClusterRequestData data, short version) {
         super(ApiKeys.DESCRIBE_CLUSTER, version);
         this.data = data;
+        validateVersionForIncludingFencedBrokers(version, data.includeFencedBrokers());
+    }
+
+    private void validateVersionForIncludingFencedBrokers(short version, boolean includeFencedBrokers) {
+        if (version < 2 && includeFencedBrokers) {
+            throw new UnsupportedVersionException("Including fenced broker endpoints is not supported with version " + version);
+        }

Review Comment:
   I agree, I think this will take quite a lot of refactoring to the testing framework. We have unit tests for the compatibility part and integration tests for the new option to include fenced brokers. 



-- 
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] KIP-1073: Return fenced brokers in DescribeCluster response [kafka]

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


##########
core/src/test/scala/integration/kafka/api/PlaintextAdminIntegrationTest.scala:
##########
@@ -615,6 +615,42 @@ class PlaintextAdminIntegrationTest extends BaseAdminIntegrationTest {
     assertEquals(brokerStrs.mkString(","), nodeStrs.mkString(","))
   }
 
+  @ParameterizedTest
+  @ValueSource(strings = Array("kraft"))
+  def testListNodesNotIncludingFencedBrokers(quorum: String): Unit = {
+    client = createAdminClient
+    val fencedBrokerId = brokers.last.config.brokerId
+    killBroker(fencedBrokerId)
+    Thread.sleep(10000) //sleep is needed to ensure the broker is fenced after the shutdown

Review Comment:
   Is there any way to avoid this? My fear is that it can create a flaky test when you have a slow environment, like when you run along with a bunch of other tests on the pipeline. 



##########
core/src/test/scala/integration/kafka/api/PlaintextAdminIntegrationTest.scala:
##########
@@ -615,6 +615,42 @@ class PlaintextAdminIntegrationTest extends BaseAdminIntegrationTest {
     assertEquals(brokerStrs.mkString(","), nodeStrs.mkString(","))
   }
 
+  @ParameterizedTest
+  @ValueSource(strings = Array("kraft"))
+  def testListNodesNotIncludingFencedBrokers(quorum: String): Unit = {
+    client = createAdminClient
+    val fencedBrokerId = brokers.last.config.brokerId
+    killBroker(fencedBrokerId)
+    Thread.sleep(10000) //sleep is needed to ensure the broker is fenced after the shutdown
+
+    val nodes = client.describeCluster().nodes().get().asScala
+    assertTrue(nodes.size.equals(brokers.size - 1))
+    nodes.foreach(node => {
+      assertFalse(node.isFenced)
+      assertFalse(node.id().equals(fencedBrokerId))
+    })
+  }
+
+  @ParameterizedTest
+  @ValueSource(strings = Array("kraft"))
+  def testListNodesIncludingFencedBrokers(quorum: String): Unit = {
+    client = createAdminClient
+    val fencedBrokerId = brokers.last.config.brokerId
+    killBroker(fencedBrokerId)
+    Thread.sleep(10000) //sleep is needed to ensure the broker is fenced after the shutdown

Review Comment:
   See the other similar 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] KIP-1073: Return fenced brokers in DescribeCluster response [kafka]

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


##########
core/src/test/scala/integration/kafka/api/PlaintextAdminIntegrationTest.scala:
##########
@@ -615,6 +615,42 @@ class PlaintextAdminIntegrationTest extends BaseAdminIntegrationTest {
     assertEquals(brokerStrs.mkString(","), nodeStrs.mkString(","))
   }
 
+  @ParameterizedTest
+  @ValueSource(strings = Array("kraft"))
+  def testListNodesNotIncludingFencedBrokers(quorum: String): Unit = {
+    client = createAdminClient
+    val fencedBrokerId = brokers.last.config.brokerId
+    killBroker(fencedBrokerId)
+    Thread.sleep(10000) //sleep is needed to ensure the broker is fenced after the shutdown

Review Comment:
   This is my concern as well. It seems to take at least a few seconds for the broker to become fenced after killing it and was hoping that 10000ms would be more than enough (need to rerun it a number of times in Jenkins to confirm). I understand there is a risk of it not being enough resulting in flakiness. I see that some of the integration tests also use TestUtils.retry() to retry when there is an assertion error, until the max timeout is reached. This still does not guarantee, but I wonder if that's a better solution with a larger max timeout, than the sleep. 



-- 
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] KIP-1073: Return fenced brokers in DescribeCluster response [kafka]

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


##########
core/src/main/scala/kafka/server/KafkaApis.scala:
##########
@@ -3611,12 +3611,17 @@ class KafkaApis(val requestChannel: RequestChannel,
       clusterId,
       () => {
         val brokers = new DescribeClusterResponseData.DescribeClusterBrokerCollection()
-        metadataCache.getAliveBrokerNodes(request.context.listenerName).foreach { node =>
+        val describeClusterRequest = request.body[DescribeClusterRequest]
+        metadataCache.getBrokerNodes(request.context.listenerName).foreach { node =>
+          if (node.isFenced && !describeClusterRequest.data().includeFencedBrokers()) {
+          } else {

Review Comment:
   What do we want to do in the if block? log something? Or remove if / else?



##########
core/src/main/scala/kafka/server/metadata/ZkMetadataCache.scala:
##########
@@ -354,6 +354,10 @@ class ZkMetadataCache(
     metadataSnapshot.aliveBrokers.values.flatMap(_.getNode(listenerName))
   }
 
+  override def getBrokerNodes(listenerName: ListenerName): Iterable[Node] = {
+    getAliveBrokerNodes(listenerName)
+  }
+

Review Comment:
   Since we're targeting v4.0.0, this can be removed.



##########
tools/src/test/java/org/apache/kafka/tools/ClusterToolTest.java:
##########
@@ -69,6 +69,28 @@ public void testUnregister(ClusterInstance clusterInstance) {
         }
     }
 
+    @ClusterTest(brokers = 1, types = {Type.KRAFT, Type.CO_KRAFT})
+    public void testListEndpointsWithBootstrapServer(ClusterInstance clusterInstance) {
+        String output = ToolsTestUtils.captureStandardOut(() ->
+                assertDoesNotThrow(() -> ClusterTool.execute("list-endpoints", "--bootstrap-server", clusterInstance.bootstrapServers())));
+        String port = clusterInstance.bootstrapServers().split(":")[1];
+        int id = clusterInstance.brokerIds().iterator().next();
+        String format = "%-10s %-9s %-10s %-10s %-10s %-15s%n%-10s %-9s %-10s %-10s %-10s %-6s";
+        String expected = String.format(format, "ID", "HOST", "PORT", "RACK", "STATE", "ENDPOINT_TYPE", id, "localhost", port, "null", "unfenced", "broker");
+        assertTrue(output.equals(expected));
+    }
+
+    @ClusterTest(brokers = 1, types = {Type.KRAFT, Type.CO_KRAFT})
+    public void testListEndpointsArgumentWithBootstrapServer(ClusterInstance clusterInstance) {

Review Comment:
   Could we add a test to make sure the "fenced" broker state can be correctly returned and output?



##########
clients/src/test/java/org/apache/kafka/clients/admin/KafkaAdminClientTest.java:
##########
@@ -3194,6 +3194,25 @@ public void testListGroupsWithTypesOlderBrokerVersion() throws Exception {
         }
     }
 
+    @Test
+    public void testDescribeClusterHandleUnsupportedVersionForIncludingFencedBrokers() {
+        ApiVersion describeClusterV1 = new ApiVersion()
+            .setApiKey(ApiKeys.DESCRIBE_CLUSTER.id)
+            .setMinVersion((short) 0)
+            .setMaxVersion((short) 1);
+        try (AdminClientUnitTestEnv env = new AdminClientUnitTestEnv(mockCluster(1, 0))) {
+            env.kafkaClient().setNodeApiVersions(NodeApiVersions.create(Collections.singletonList(describeClusterV1)));
+
+            env.kafkaClient().prepareUnsupportedVersionResponse(
+                    request -> request instanceof DescribeClusterRequest);
+
+            final DescribeClusterResult result = env.adminClient().describeCluster(new DescribeClusterOptions().includeFencedBrokers(true));
+            TestUtils.assertFutureThrows(result.nodes(),
+                    UnsupportedVersionException.class, "Including fenced broker endpoints is not supported with version 1");
+

Review Comment:
   nit: additional empty line.



-- 
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] KIP-1073: Return fenced brokers in DescribeCluster response [kafka]

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


##########
clients/src/main/java/org/apache/kafka/clients/admin/KafkaAdminClient.java:
##########
@@ -2554,6 +2557,10 @@ boolean handleUnsupportedVersionException(final UnsupportedVersionException exce
                     return false;
                 }
 
+                if (exception.getMessage().contains("Including fenced broker endpoints is not supported with version")) {
+                    return false;
+                }
+
                 useMetadataRequest = true;
                 return true;

Review Comment:
   So, in [KIP-700](https://cwiki.apache.org/confluence/display/KAFKA/KIP-700%3A+Add+Describe+Cluster+API), we implement a fallback to metadata request mechanism when describe cluster failed with unsupported version. So if we failed due to `Including fenced broker endpoints is not supported with version`, shouldn't we fallback to use metadata request? And the follow-up question, what will it be in the admin client result?



-- 
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] KIP-1073: Return fenced brokers in DescribeCluster response [kafka]

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


-- 
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] KIP-1073: Return fenced brokers in DescribeCluster response [kafka]

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


##########
clients/src/main/java/org/apache/kafka/common/requests/DescribeClusterRequest.java:
##########
@@ -51,6 +52,13 @@ public String toString() {
     public DescribeClusterRequest(DescribeClusterRequestData data, short version) {
         super(ApiKeys.DESCRIBE_CLUSTER, version);
         this.data = data;
+        validateVersionForIncludingFencedBrokers(version, data.includeFencedBrokers());
+    }
+
+    private void validateVersionForIncludingFencedBrokers(short version, boolean includeFencedBrokers) {
+        if (version < 2 && includeFencedBrokers) {
+            throw new UnsupportedVersionException("Including fenced broker endpoints is not supported with version " + version);
+        }

Review Comment:
   This doesn't seem to be the case when I tested it by running new AdminClient against an old broker. For example, if we remove this validation, testDescribeClusterHandleUnsupportedVersionForIncludingFencedBrokers() test fails. Also this helps Admin to handle the UnsupportedVersion exception differently, otherwise we fall back to metadata request and it's not clear to users why the request the failed. 



-- 
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] KIP-1073: Return fenced brokers in DescribeCluster response [kafka]

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


##########
clients/src/main/java/org/apache/kafka/common/requests/DescribeClusterRequest.java:
##########
@@ -51,6 +52,13 @@ public String toString() {
     public DescribeClusterRequest(DescribeClusterRequestData data, short version) {
         super(ApiKeys.DESCRIBE_CLUSTER, version);
         this.data = data;
+        validateVersionForIncludingFencedBrokers(version, data.includeFencedBrokers());
+    }
+
+    private void validateVersionForIncludingFencedBrokers(short version, boolean includeFencedBrokers) {
+        if (version < 2 && includeFencedBrokers) {
+            throw new UnsupportedVersionException("Including fenced broker endpoints is not supported with version " + version);
+        }

Review Comment:
   1. Currently, the `testDescribeClusterHandleUnsupportedVersionForIncludingFencedBrokers` will return `UnsupportedVersionException` with `Api DESCRIBE_CLUSTER with version 1` from [here](https://github.com/apache/kafka/blob/48d60efe9802786451458aec9136b7b585fecd92/clients/src/test/java/org/apache/kafka/clients/MockClient.java#L261). That's why it will fail. So, basically, it will fail with `UnsupportedVersionException` as what we expected. 
   
   2. I understand why we need this different message as described in this [comment](https://github.com/apache/kafka/pull/17524#discussion_r1850837344).
   > We fallback to metadata request, if the broker does not support the new DescribeCluster API. In this case, DescribeCluster API is supported but the option to include fenced broker is not. So this is why we are checking the specific error message to differentiate the cause of UnsupportedVersion exception.
   
   But I think using the error message as a condition is really weak. I think, like you said, the reason we can't fallback to metadata request is because the user added an option to _include fenced broker_. That is, when user requests to "include fenced broker", this is the case that we should not fallback to metadata request, even if it returned `UnsupportedVersionException`. After all, the metadata request response won't include fenced broker, it is meaningless to users. So, like how we treat `usingBootstrapControllers`, we can do similar thing to this case, WDYT?
   
   That is:
   ```
   boolean handleUnsupportedVersionException(final UnsupportedVersionException exception) {
     if (metadataManager.usingBootstrapControllers()) {
        return false;
     }
     // add some comments here
     if (options.includeFencedBrokers()) {
       return false;
     }
   ```
   
   Also, we should have an integration test for this unsupported version case. Like [this test](https://github.com/apache/kafka/blob/48d60efe9802786451458aec9136b7b585fecd92/core/src/test/scala/integration/kafka/server/KRaftClusterTest.scala#L1354) did.



-- 
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] KIP-1073: Return fenced brokers in DescribeCluster response [kafka]

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


##########
clients/src/main/java/org/apache/kafka/clients/admin/KafkaAdminClient.java:
##########
@@ -2557,7 +2557,10 @@ boolean handleUnsupportedVersionException(final UnsupportedVersionException exce
                     return false;
                 }
 
-                if (exception.getMessage().contains("Including fenced broker endpoints is not supported with version")) {
+                // If unsupportedVersion exception was caused by the option to include fenced brokers (only supported for version 1+)
+                // then we should not fall back to the metadataRequest.
+                if (options.includeFencedBrokers()) {
+                    log.error("Including fenced broker endpoints is not supported with " + exception.getMessage());

Review Comment:
   Right. The actual error message you get is `Attempted to write a non-default includeFencedBrokers at version 1`. Perhaps this is self explanatory so don't need this log? 



-- 
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] KIP-1073: Return fenced brokers in DescribeCluster response [kafka]

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


##########
core/src/test/scala/integration/kafka/api/PlaintextAdminIntegrationTest.scala:
##########
@@ -615,6 +615,42 @@ class PlaintextAdminIntegrationTest extends BaseAdminIntegrationTest {
     assertEquals(brokerStrs.mkString(","), nodeStrs.mkString(","))
   }
 
+  @ParameterizedTest
+  @ValueSource(strings = Array("kraft"))
+  def testListNodesNotIncludingFencedBrokers(quorum: String): Unit = {
+    client = createAdminClient
+    val fencedBrokerId = brokers.last.config.brokerId
+    killBroker(fencedBrokerId)
+    Thread.sleep(10000) //sleep is needed to ensure the broker is fenced after the shutdown

Review Comment:
   This is my concern as well. It seems to take at least a few seconds for the broker to become fenced after killing it and was hoping that 10000ms would be more than enough (need to rerun it a number of times in Jenkins to confirm). I understand there is a risk of it not being enough resulting in flakiness. I see that some of the integration tests also use TestUtils.retry() to retry when there is an assertion error, until the max timeout is reached. This still does not guarantee, but I wonder if that's a better solution with a larger max timeout, than the sleep. 



-- 
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] KIP-1073: Return fenced brokers in DescribeCluster response [kafka]

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


##########
tools/src/main/java/org/apache/kafka/tools/ClusterTool.java:
##########
@@ -108,6 +117,17 @@ static void execute(String... args) throws Exception {
                 }
                 break;
             }
+            case "list-endpoints": {
+                try (Admin adminClient = Admin.create(properties)) {
+                    boolean includeFencedBrokers = Optional.of(namespace.getBoolean("include_fenced_brokers")).orElse(false);
+                    boolean listControllerEndpoints = namespace.getString("bootstrap_controller") != null;
+                    if (includeFencedBrokers && listControllerEndpoints) {
+                        throw new RuntimeException("Cannot use --include-fenced-brokers with command " + command);

Review Comment:
   ```suggestion
                           throw new IllegalArgumentException("The option --include-fenced-brokers is only supported with --bootstrap-server option");
   ```



-- 
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] KIP-1073: Return fenced brokers in DescribeCluster response [kafka]

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


##########
clients/src/main/java/org/apache/kafka/common/requests/DescribeClusterRequest.java:
##########
@@ -51,6 +52,13 @@ public String toString() {
     public DescribeClusterRequest(DescribeClusterRequestData data, short version) {
         super(ApiKeys.DESCRIBE_CLUSTER, version);
         this.data = data;
+        validateVersionForIncludingFencedBrokers(version, data.includeFencedBrokers());
+    }
+
+    private void validateVersionForIncludingFencedBrokers(short version, boolean includeFencedBrokers) {
+        if (version < 2 && includeFencedBrokers) {
+            throw new UnsupportedVersionException("Including fenced broker endpoints is not supported with version " + version);
+        }

Review Comment:
   In the generated clients/build/generated/main/java/org/apache/kafka/common/message/DescribeClusterRequestData.java, the `UnsupportedVersionException` will be thrown when trying to add `includeFencedBrokers` into version < 2, so we don't have to do it by our own 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


Re: [PR] KIP-1073: Return fenced brokers in DescribeCluster response [kafka]

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


##########
clients/src/main/java/org/apache/kafka/common/requests/DescribeClusterRequest.java:
##########
@@ -51,6 +52,13 @@ public String toString() {
     public DescribeClusterRequest(DescribeClusterRequestData data, short version) {
         super(ApiKeys.DESCRIBE_CLUSTER, version);
         this.data = data;
+        validateVersionForIncludingFencedBrokers(version, data.includeFencedBrokers());
+    }
+
+    private void validateVersionForIncludingFencedBrokers(short version, boolean includeFencedBrokers) {
+        if (version < 2 && includeFencedBrokers) {
+            throw new UnsupportedVersionException("Including fenced broker endpoints is not supported with version " + version);
+        }

Review Comment:
   I agree that checking the option instead of the error message is much better solution here. I made an update to add an error level log, instead of validating describe request and throwing a specific error for includeFencedBrokers option. 
   
   In terms of the integration test, I'm going to look into to it a little more. KRaftClusterTest.scala you pointed, seems like more cluster level tests. Since this is testing Admin specific option, it should probably be added to AdminIntegrationTest but I'm currently not sure how to set the test cluster's version or it's supported API version. 



-- 
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] KIP-1073: Return fenced brokers in DescribeCluster response [kafka]

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

   thank you @showuon!


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