rhauch commented on a change in pull request #10841:
URL: https://github.com/apache/kafka/pull/10841#discussion_r651200941



##########
File path: 
connect/runtime/src/main/java/org/apache/kafka/connect/runtime/WorkerConfig.java
##########
@@ -497,6 +476,37 @@ static void validateHeaderConfigAction(String action) {
                     + "Expected one of %s", action, HEADER_ACTIONS));
         }
     }
+    private static class ListenersValidator implements ConfigDef.Validator {
+        @Override
+        public void ensureValid(String name, Object value) {
+            if (value == null) {
+                throw new ConfigException("Invalid value, at least one URI is 
expected, ex: http://localhost:8080,https://localhost:8443.";);
+            }
+
+            if (!(value instanceof List)) {
+                throw new ConfigException("Invalid value type (list 
expected).");
+            }
+
+            List items = (List) value;
+            if (items.isEmpty()) {
+                throw new ConfigException("Invalid value, at least one URI is 
expected, ex: http://localhost:8080,https://localhost:8443.";);
+            }
+
+            for (Object item: items) {
+                if (!(item instanceof String)) {
+                    throw new ConfigException("Invalid type for listener 
(expected String).");
+                }
+                if (Utils.isBlank((String) item)) {
+                    throw new ConfigException("Empty listener found when 
parsing list.");

Review comment:
       Nit: should we say "listener URL" instead of just "listener"? Or maybe 
"Empty URL found when parsing listeners list"?

##########
File path: 
connect/runtime/src/test/java/org/apache/kafka/connect/runtime/WorkerConfigTest.java
##########
@@ -56,6 +57,39 @@
             "set X-Frame-Options:DENY, add  :no-cache, no-store, 
must-revalidate "
     );
 
+    @Test
+    public void testListenersConfigAllowedValues() {
+        Map<String, String> props = baseProps();
+
+        // no value set for "listeners"
+        WorkerConfig config = new WorkerConfig(WorkerConfig.baseConfigDef(), 
props);
+        assertEquals(LISTENERS_DEFAULT, 
config.getList(WorkerConfig.LISTENERS_CONFIG));
+
+        props.put(WorkerConfig.LISTENERS_CONFIG, "http://a.b:9999";);
+        config = new WorkerConfig(WorkerConfig.baseConfigDef(), props);
+        assertEquals(config.getList(WorkerConfig.LISTENERS_CONFIG), 
Arrays.asList("http://a.b:9999";));
+
+        props.put(WorkerConfig.LISTENERS_CONFIG, "http://a.b:9999, 
https://a.b:7812";);
+        config = new WorkerConfig(WorkerConfig.baseConfigDef(), props);
+        assertEquals(config.getList(WorkerConfig.LISTENERS_CONFIG), 
Arrays.asList("http://a.b:9999";, "https://a.b:7812";));
+
+        new WorkerConfig(WorkerConfig.baseConfigDef(), props);
+    }
+
+    @Test
+    public void testListenersConfigNotAllowedValues() {
+        Map<String, String> props = baseProps();
+
+        props.put(WorkerConfig.LISTENERS_CONFIG, "");
+        assertThrows(ConfigException.class, () -> new 
WorkerConfig(WorkerConfig.baseConfigDef(), props)).printStackTrace();
+
+        props.put(WorkerConfig.LISTENERS_CONFIG, "http://a.b:9999,";);
+        assertThrows(ConfigException.class, () -> new 
WorkerConfig(WorkerConfig.baseConfigDef(), props));

Review comment:
       Should you check that the exception message contains an expected string? 
Technically, catching this exception doesn't ensure that the `listeners` 
property is the one that failed.

##########
File path: docs/upgrade.html
##########
@@ -69,7 +69,9 @@ <h5><a id="upgrade_300_notable" 
href="#upgrade_300_notable">Notable changes in 3
             
<code>org.apache.kafka.clients.consumer.ConsumerPartitionAssignor</code> 
instead.</li>
         <li>The <code>quota.producer.default</code> and 
<code>quota.consumer.default</code> configurations were removed (<a 
href="https://issues.apache.org/jira/browse/KAFKA-12591";>KAFKA-12591</a>).
             Dynamic quota defaults must be used instead.</li>
-        <li>The default value for the consumer configuration 
<code>session.timeout.ms</code> was increased from 10s to 45s. See 
+        <li>The deprecated worker configurations <code>rest.host.name</code> 
and <code>rest.port</code> were removed (<a 
href="https://issues.apache.org/jira/browse/KAFKA-12482";>KAFKA-12482</a>) in 
the Kafka Connect.

Review comment:
       Also, should probably add `connect` to the list on line 32.

##########
File path: 
connect/runtime/src/test/java/org/apache/kafka/connect/runtime/WorkerConfigTest.java
##########
@@ -56,6 +57,39 @@
             "set X-Frame-Options:DENY, add  :no-cache, no-store, 
must-revalidate "
     );
 
+    @Test
+    public void testListenersConfigAllowedValues() {
+        Map<String, String> props = baseProps();
+
+        // no value set for "listeners"
+        WorkerConfig config = new WorkerConfig(WorkerConfig.baseConfigDef(), 
props);
+        assertEquals(LISTENERS_DEFAULT, 
config.getList(WorkerConfig.LISTENERS_CONFIG));
+
+        props.put(WorkerConfig.LISTENERS_CONFIG, "http://a.b:9999";);
+        config = new WorkerConfig(WorkerConfig.baseConfigDef(), props);
+        assertEquals(config.getList(WorkerConfig.LISTENERS_CONFIG), 
Arrays.asList("http://a.b:9999";));

Review comment:
       The old JUnit `assertEquals` has the expected value as the first 
parameter and the actual value as the second, so this is backwards. Check other 
call points, too.

##########
File path: 
connect/runtime/src/test/java/org/apache/kafka/connect/runtime/WorkerConfigTest.java
##########
@@ -56,6 +57,39 @@
             "set X-Frame-Options:DENY, add  :no-cache, no-store, 
must-revalidate "
     );
 
+    @Test
+    public void testListenersConfigAllowedValues() {
+        Map<String, String> props = baseProps();
+
+        // no value set for "listeners"
+        WorkerConfig config = new WorkerConfig(WorkerConfig.baseConfigDef(), 
props);
+        assertEquals(LISTENERS_DEFAULT, 
config.getList(WorkerConfig.LISTENERS_CONFIG));
+
+        props.put(WorkerConfig.LISTENERS_CONFIG, "http://a.b:9999";);
+        config = new WorkerConfig(WorkerConfig.baseConfigDef(), props);
+        assertEquals(config.getList(WorkerConfig.LISTENERS_CONFIG), 
Arrays.asList("http://a.b:9999";));
+
+        props.put(WorkerConfig.LISTENERS_CONFIG, "http://a.b:9999, 
https://a.b:7812";);
+        config = new WorkerConfig(WorkerConfig.baseConfigDef(), props);
+        assertEquals(config.getList(WorkerConfig.LISTENERS_CONFIG), 
Arrays.asList("http://a.b:9999";, "https://a.b:7812";));
+
+        new WorkerConfig(WorkerConfig.baseConfigDef(), props);
+    }
+
+    @Test
+    public void testListenersConfigNotAllowedValues() {
+        Map<String, String> props = baseProps();

Review comment:
       Maybe check that `props` is valid on its own before the modifications, 
so that any changes to `props` are the only ones that _should_ fail.

##########
File path: docs/upgrade.html
##########
@@ -69,7 +69,9 @@ <h5><a id="upgrade_300_notable" 
href="#upgrade_300_notable">Notable changes in 3
             
<code>org.apache.kafka.clients.consumer.ConsumerPartitionAssignor</code> 
instead.</li>
         <li>The <code>quota.producer.default</code> and 
<code>quota.consumer.default</code> configurations were removed (<a 
href="https://issues.apache.org/jira/browse/KAFKA-12591";>KAFKA-12591</a>).
             Dynamic quota defaults must be used instead.</li>
-        <li>The default value for the consumer configuration 
<code>session.timeout.ms</code> was increased from 10s to 45s. See 
+        <li>The deprecated worker configurations <code>rest.host.name</code> 
and <code>rest.port</code> were removed (<a 
href="https://issues.apache.org/jira/browse/KAFKA-12482";>KAFKA-12482</a>) in 
the Kafka Connect.

Review comment:
       > ... in the Kafka Connect.
   
   This seems like a fragment. Perhaps "in the Kafka Connect worker 
configuration"?
   
   And probably should be "removed ... from" rather than "removed ... in".

##########
File path: 
connect/runtime/src/main/java/org/apache/kafka/connect/runtime/WorkerConfig.java
##########
@@ -497,6 +476,37 @@ static void validateHeaderConfigAction(String action) {
                     + "Expected one of %s", action, HEADER_ACTIONS));
         }
     }
+    private static class ListenersValidator implements ConfigDef.Validator {
+        @Override
+        public void ensureValid(String name, Object value) {
+            if (value == null) {
+                throw new ConfigException("Invalid value, at least one URI is 
expected, ex: http://localhost:8080,https://localhost:8443.";);
+            }
+
+            if (!(value instanceof List)) {
+                throw new ConfigException("Invalid value type (list 
expected).");
+            }
+
+            List items = (List) value;
+            if (items.isEmpty()) {
+                throw new ConfigException("Invalid value, at least one URI is 
expected, ex: http://localhost:8080,https://localhost:8443.";);

Review comment:
       Technically we require URLs since they must include the "how to access" 
(e.g., "http" or "https"), right? So should we say "URL" here and other 
validation error messages?

##########
File path: 
connect/runtime/src/test/java/org/apache/kafka/connect/runtime/WorkerConfigTest.java
##########
@@ -56,6 +57,39 @@
             "set X-Frame-Options:DENY, add  :no-cache, no-store, 
must-revalidate "
     );
 
+    @Test
+    public void testListenersConfigAllowedValues() {
+        Map<String, String> props = baseProps();
+
+        // no value set for "listeners"
+        WorkerConfig config = new WorkerConfig(WorkerConfig.baseConfigDef(), 
props);
+        assertEquals(LISTENERS_DEFAULT, 
config.getList(WorkerConfig.LISTENERS_CONFIG));
+
+        props.put(WorkerConfig.LISTENERS_CONFIG, "http://a.b:9999";);
+        config = new WorkerConfig(WorkerConfig.baseConfigDef(), props);
+        assertEquals(config.getList(WorkerConfig.LISTENERS_CONFIG), 
Arrays.asList("http://a.b:9999";));
+
+        props.put(WorkerConfig.LISTENERS_CONFIG, "http://a.b:9999, 
https://a.b:7812";);
+        config = new WorkerConfig(WorkerConfig.baseConfigDef(), props);
+        assertEquals(config.getList(WorkerConfig.LISTENERS_CONFIG), 
Arrays.asList("http://a.b:9999";, "https://a.b:7812";));
+
+        new WorkerConfig(WorkerConfig.baseConfigDef(), props);
+    }
+
+    @Test
+    public void testListenersConfigNotAllowedValues() {
+        Map<String, String> props = baseProps();
+
+        props.put(WorkerConfig.LISTENERS_CONFIG, "");
+        assertThrows(ConfigException.class, () -> new 
WorkerConfig(WorkerConfig.baseConfigDef(), props)).printStackTrace();

Review comment:
       Did you consider adding another check for a list with all blank 
values`,,,`? It may not be handled any differently than the next check, so 
maybe its not worth it. The benefit is that it _might_ help as a test against 
future regressions if the logic is changed.




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

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to