You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by GitBox <gi...@apache.org> on 2021/07/13 12:38:57 UTC

[GitHub] [kafka] dajac commented on a change in pull request #11008: KAFKA-10588 Rename kafka-console-consumer CLI command line arguments for KIP-629

dajac commented on a change in pull request #11008:
URL: https://github.com/apache/kafka/pull/11008#discussion_r668716740



##########
File path: core/src/main/scala/kafka/tools/ConsoleConsumer.scala
##########
@@ -191,9 +191,15 @@ object ConsoleConsumer extends Logging {
       .withRequiredArg
       .describedAs("topic")
       .ofType(classOf[String])
-    val whitelistOpt = parser.accepts("whitelist", "Regular expression specifying whitelist of topics to include for consumption.")
+    val whitelistOpt = parser.accepts("whitelist",
+      "DEPRECATED, use --include instead; ignored if --include specified. Regular expression specifying list of topics to include for consumption.")

Review comment:
       We could remove `ignored if --include specified` if we don't accept both together. 

##########
File path: core/src/test/scala/unit/kafka/tools/ConsoleConsumerTest.scala
##########
@@ -130,6 +130,58 @@ class ConsoleConsumerTest {
     assertEquals(true, config.fromBeginning)
   }
 
+  @Test
+  def shouldParseIncludeArgument(): Unit = {
+    //Given
+    val args: Array[String] = Array(
+      "--bootstrap-server", "localhost:9092",
+      "--include", "includeTest*",
+      "--from-beginning")
+
+    //When
+    val config = new ConsoleConsumer.ConsumerConfig(args)
+
+    //Then
+    assertEquals("localhost:9092", config.bootstrapServer)
+    assertEquals("includeTest*", config.includedTopicsArg)
+    assertEquals(true, config.fromBeginning)
+  }
+
+  @Test
+  def shouldParseWhitelistArgument(): Unit = {
+    //Given
+    val args: Array[String] = Array(
+      "--bootstrap-server", "localhost:9092",
+      "--whitelist", "whitelistTest*",
+      "--from-beginning")
+
+    //When
+    val config = new ConsoleConsumer.ConsumerConfig(args)
+
+    //Then
+    assertEquals("localhost:9092", config.bootstrapServer)
+    assertEquals("whitelistTest*", config.includedTopicsArg)
+    assertEquals(true, config.fromBeginning)
+  }
+
+  @Test
+  def shouldIgnoreWhitelistArgumentIfIncludeSpecified(): Unit = {

Review comment:
       This test must be updated if we don't accept both options together.

##########
File path: core/src/main/scala/kafka/tools/ConsoleConsumer.scala
##########
@@ -315,11 +321,23 @@ object ConsoleConsumer extends Logging {
 
     formatter.configure(formatterArgs.asScala.asJava)
 
-    val topicOrFilterOpt = List(topicOpt, whitelistOpt).filter(options.has)
-    if (topicOrFilterOpt.size != 1)
-      CommandLineUtils.printUsageAndDie(parser, "Exactly one of whitelist/topic is required.")
+    val filterOpts = List(includeOpt, whitelistOpt).filter(options.has)
+    if (filterOpts.size == 2) {
+      CommandLineUtils.warn("--whitelist is DEPRECATED and ignored if --include specified.")
+    }
+
     topicArg = options.valueOf(topicOpt)
-    whitelistArg = options.valueOf(whitelistOpt)
+    includedTopicsArg = if (options.has(includeOpt))
+      options.valueOf(includeOpt)
+    else
+      options.valueOf(whitelistOpt)
+
+    val topicOrFilterOptArgs = Seq(topicArg, includedTopicsArg).filterNot(value => value == null)
+
+    if (topicOrFilterOptArgs.size != 1)
+      CommandLineUtils.printUsageAndDie(parser, s"Exactly one of include/topic is required. " +

Review comment:
       nit: Should we prefix all the options with `--` to be consistent in the error message?

##########
File path: core/src/main/scala/kafka/tools/ConsoleConsumer.scala
##########
@@ -315,11 +321,23 @@ object ConsoleConsumer extends Logging {
 
     formatter.configure(formatterArgs.asScala.asJava)
 
-    val topicOrFilterOpt = List(topicOpt, whitelistOpt).filter(options.has)
-    if (topicOrFilterOpt.size != 1)
-      CommandLineUtils.printUsageAndDie(parser, "Exactly one of whitelist/topic is required.")
+    val filterOpts = List(includeOpt, whitelistOpt).filter(options.has)
+    if (filterOpts.size == 2) {
+      CommandLineUtils.warn("--whitelist is DEPRECATED and ignored if --include specified.")

Review comment:
       Checking this is a very good idea. However, I would `printUsageAndDie` when both are used together instead of ignoring `--whitelist`. We could say `Options --include and --whitelist cannot be specified together. --whitelist is DEPRECATED, use --include instead.`. 

##########
File path: core/src/main/scala/kafka/tools/ConsoleConsumer.scala
##########
@@ -315,11 +321,23 @@ object ConsoleConsumer extends Logging {
 
     formatter.configure(formatterArgs.asScala.asJava)
 
-    val topicOrFilterOpt = List(topicOpt, whitelistOpt).filter(options.has)
-    if (topicOrFilterOpt.size != 1)
-      CommandLineUtils.printUsageAndDie(parser, "Exactly one of whitelist/topic is required.")
+    val filterOpts = List(includeOpt, whitelistOpt).filter(options.has)
+    if (filterOpts.size == 2) {
+      CommandLineUtils.warn("--whitelist is DEPRECATED and ignored if --include specified.")
+    }
+
     topicArg = options.valueOf(topicOpt)
-    whitelistArg = options.valueOf(whitelistOpt)
+    includedTopicsArg = if (options.has(includeOpt))
+      options.valueOf(includeOpt)
+    else
+      options.valueOf(whitelistOpt)
+
+    val topicOrFilterOptArgs = Seq(topicArg, includedTopicsArg).filterNot(value => value == null)
+
+    if (topicOrFilterOptArgs.size != 1)

Review comment:
       nit: Would it be simpler to check `topicArg != null && includedTopicsArg != null` in the `if`?

##########
File path: core/src/main/scala/kafka/tools/ConsoleConsumer.scala
##########
@@ -191,9 +191,15 @@ object ConsoleConsumer extends Logging {
       .withRequiredArg
       .describedAs("topic")
       .ofType(classOf[String])
-    val whitelistOpt = parser.accepts("whitelist", "Regular expression specifying whitelist of topics to include for consumption.")
+    val whitelistOpt = parser.accepts("whitelist",
+      "DEPRECATED, use --include instead; ignored if --include specified. Regular expression specifying list of topics to include for consumption.")
       .withRequiredArg
-      .describedAs("whitelist")
+      .describedAs("Java regex (String)")
+      .ofType(classOf[String])
+    val includeOpt = parser.accepts("include",
+      "Regular expression specifying list of topics to include for consumption.")
+      .withRequiredArg()

Review comment:
       nit: The parenthesis are not necessary. I would remove them in order to be consistent with the other arguments.




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