[ 
https://issues.apache.org/jira/browse/KAFKA-7139?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16592691#comment-16592691
 ] 

ASF GitHub Bot commented on KAFKA-7139:
---------------------------------------

hachikuji closed pull request #5349: KAFKA-7139 Support to exclude the internal 
topics in kafka-topics.sh …
URL: https://github.com/apache/kafka/pull/5349
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/core/src/main/scala/kafka/admin/TopicCommand.scala 
b/core/src/main/scala/kafka/admin/TopicCommand.scala
index 3914b564eda..8d89f1050f4 100755
--- a/core/src/main/scala/kafka/admin/TopicCommand.scala
+++ b/core/src/main/scala/kafka/admin/TopicCommand.scala
@@ -83,12 +83,13 @@ object TopicCommand extends Logging {
 
   private def getTopics(zkClient: KafkaZkClient, opts: TopicCommandOptions): 
Seq[String] = {
     val allTopics = zkClient.getAllTopicsInCluster.sorted
+    val excludeInternalTopics = opts.options.has(opts.excludeInternalTopicOpt)
     if (opts.options.has(opts.topicOpt)) {
       val topicsSpec = opts.options.valueOf(opts.topicOpt)
       val topicsFilter = new Whitelist(topicsSpec)
-      allTopics.filter(topicsFilter.isTopicAllowed(_, excludeInternalTopics = 
false))
+      allTopics.filter(topicsFilter.isTopicAllowed(_, excludeInternalTopics))
     } else
-      allTopics
+      allTopics.filterNot(Topic.isInternal(_) && excludeInternalTopics)
   }
 
   def createTopic(zkClient: KafkaZkClient, opts: TopicCommandOptions) {
@@ -355,6 +356,8 @@ object TopicCommand extends Logging {
 
     val forceOpt = parser.accepts("force", "Suppress console prompts")
 
+    val excludeInternalTopicOpt = parser.accepts("exclude-internal", "exclude 
internal topics when running list or describe command. The internal topics will 
be listed by default")
+
     val options = parser.parse(args : _*)
 
     val allTopicLevelOpts: Set[OptionSpec[_]] = Set(alterOpt, createOpt, 
describeOpt, listOpt, deleteOpt)
@@ -381,6 +384,7 @@ object TopicCommand extends Logging {
         allTopicLevelOpts -- Set(describeOpt) + 
reportUnderReplicatedPartitionsOpt + reportUnavailablePartitionsOpt)
       CommandLineUtils.checkInvalidArgs(parser, options, ifExistsOpt, 
allTopicLevelOpts -- Set(alterOpt, deleteOpt))
       CommandLineUtils.checkInvalidArgs(parser, options, ifNotExistsOpt, 
allTopicLevelOpts -- Set(createOpt))
+      CommandLineUtils.checkInvalidArgs(parser, options, 
excludeInternalTopicOpt, allTopicLevelOpts -- Set(listOpt, describeOpt))
     }
   }
 
diff --git a/core/src/test/scala/unit/kafka/admin/TopicCommandTest.scala 
b/core/src/test/scala/unit/kafka/admin/TopicCommandTest.scala
index 782fcf539f3..13f23e69b53 100644
--- a/core/src/test/scala/unit/kafka/admin/TopicCommandTest.scala
+++ b/core/src/test/scala/unit/kafka/admin/TopicCommandTest.scala
@@ -242,4 +242,28 @@ class TopicCommandTest extends ZooKeeperTestHarness with 
Logging with RackAwareT
     }
   }
 
+  @Test
+  def testDescribeAndListTopicsWithoutInternalTopics() {
+    val brokers = List(0)
+    val topic = "testDescribeAndListTopicsWithoutInternalTopics"
+    TestUtils.createBrokersInZk(zkClient, brokers)
+
+    TopicCommand.createTopic(zkClient,
+      new TopicCommandOptions(Array("--partitions", "1", 
"--replication-factor", "1", "--topic", topic)))
+    // create a internal topic
+    TopicCommand.createTopic(zkClient,
+      new TopicCommandOptions(Array("--partitions", "1", 
"--replication-factor", "1", "--topic", Topic.GROUP_METADATA_TOPIC_NAME)))
+
+    // test describe
+    var output = 
TestUtils.grabConsoleOutput(TopicCommand.describeTopic(zkClient,
+      new TopicCommandOptions(Array("--describe", "--exclude-internal"))))
+    assertTrue(output.contains(topic))
+    assertFalse(output.contains(Topic.GROUP_METADATA_TOPIC_NAME))
+
+    // test list
+    output = TestUtils.grabConsoleOutput(TopicCommand.listTopics(zkClient,
+      new TopicCommandOptions(Array("--list", "--exclude-internal"))))
+    assertTrue(output.contains(topic))
+    assertFalse(output.contains(Topic.GROUP_METADATA_TOPIC_NAME))
+  }
 }


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> Support to exclude the internal topics in kafka-topics.sh command
> -----------------------------------------------------------------
>
>                 Key: KAFKA-7139
>                 URL: https://issues.apache.org/jira/browse/KAFKA-7139
>             Project: Kafka
>          Issue Type: Task
>            Reporter: Chia-Ping Tsai
>            Assignee: Chia-Ping Tsai
>            Priority: Minor
>             Fix For: 2.1.0
>
>
> _{color:#333333}Usually we have no interest in internal topics when using the 
> kafka-topics.sh command . However, the kafka-topics.sh can't exclude the 
> internal topics simply. We have to write the regular to exclude the internal 
> topics. This kip tries to add a flag (perhaps "exclude-internal") to 
> kafka-topics.sh. If user set the flag, all internal topics will be excluded 
> by the following commands - "list" and "describe"{color}_



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to