JiayaoS commented on code in PR #23837:
URL: https://github.com/apache/kafka/pull/23837#discussion_r4323067913


##########
core/src/test/java/kafka/docker/NativeImageConfigTest.java:
##########
@@ -0,0 +1,238 @@
+/*
+ * 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 kafka.docker;
+
+import org.apache.kafka.common.config.ConfigDef;
+import org.apache.kafka.server.config.AbstractKafkaConfig;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+
+import java.io.File;
+import java.io.IOException;
+import java.lang.reflect.Modifier;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeSet;
+
+import io.github.classgraph.ClassGraph;
+import io.github.classgraph.ClassInfo;
+import io.github.classgraph.ScanResult;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+/**
+ * The native image can only create the classes registered in 
reflect-config.json by reflection, and a missing
+ * entry fails at runtime rather than at build time. See KAFKA-19583, 
KAFKA-19584 and KAFKA-21045.
+ */
+public class NativeImageConfigTest {
+
+    private static final Path REFLECT_CONFIG = 
Path.of(System.getProperty("user.dir"),
+            "..", "docker", "native", "native-image-configs", 
"reflect-config.json");
+
+    private static final String HOW_TO_FIX = "Register their no-arg 
constructors in " + REFLECT_CONFIG
+            + ", or instantiate them without reflection (see KAFKA-20825).";
+
+    // Interfaces whose implementations may be instantiated reflectively by 
class name.
+    // To find more, search for Utils.newInstance and getConfiguredInstance(s).
+    private static final List<String> PLUGGABLE_INTERFACES = List.of(
+            "javax.security.auth.spi.LoginModule",
+            "javax.security.sasl.SaslClientFactory",
+            "javax.security.sasl.SaslServerFactory",
+            "kafka.metrics.KafkaMetricsReporter",
+            "org.apache.kafka.common.config.provider.ConfigProvider",
+            "org.apache.kafka.common.metrics.MetricsReporter",
+            "org.apache.kafka.common.replica.ReplicaSelector",
+            
"org.apache.kafka.common.security.auth.AuthenticateCallbackHandler",
+            "org.apache.kafka.common.security.auth.KafkaPrincipalBuilder",
+            "org.apache.kafka.common.security.auth.Login",
+            "org.apache.kafka.common.security.auth.SecurityProviderCreator",
+            "org.apache.kafka.common.security.auth.SslEngineFactory",
+            "org.apache.kafka.common.security.oauthbearer.JwtRetriever",
+            "org.apache.kafka.common.security.oauthbearer.JwtValidator",
+            
"org.apache.kafka.coordinator.group.api.assignor.ConsumerGroupPartitionAssignor",
+            
"org.apache.kafka.coordinator.group.api.assignor.ShareGroupPartitionAssignor",
+            
"org.apache.kafka.coordinator.group.api.streams.StreamsGroupTopologyDescriptionPlugin",
+            
"org.apache.kafka.coordinator.group.api.streams.assignor.TaskAssignor",
+            "org.apache.kafka.coordinator.group.streams.AssignmentRefiner",
+            "org.apache.kafka.server.authorizer.Authorizer",
+            
"org.apache.kafka.server.log.remote.storage.RemoteLogMetadataManager",
+            "org.apache.kafka.server.log.remote.storage.RemoteStorageManager",
+            "org.apache.kafka.server.policy.AlterConfigPolicy",
+            "org.apache.kafka.server.policy.CreateTopicPolicy",
+            "org.apache.kafka.server.quota.ClientQuotaCallback"
+    );

Review Comment:
   > Thanks for taking a look on this ... its unfortunate that there is no 
simple way to derive it but lets take the static list as a starting point, it 
at least gives us a check that the current config works.
   > 
   > Could we make it discoverable for whoever adds a new pluggable interface, 
though? For instance, a short note in the Javadoc of Utils.newInstance / 
AbstractConfig.getConfiguredInstance and maybe also in 
`docker/native/README.md` saying new interfaces must be added to 
NativeImageConfigTest.PLUGGABLE_INTERFACES (and registered in 
reflect-config.json).
   
   Thanks for the suggestion! I've added a note to Utils.newInstance, 
AbstractConfig.getConfiguredInstance and docker/native/README.md. Could you 
take another look when you have time?



-- 
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: [email protected]

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

Reply via email to