From f0aebc87c0f593c44c2fefdcdeb19b6f86f3a79b Mon Sep 17 00:00:00 2001 From: Staffan Olsson Date: Sat, 15 Aug 2020 07:10:15 +0200 Subject: [PATCH 01/25] Removes unused java distributions --- jdk-oracle-open/Dockerfile | 30 ---------------------------- jdk-zulu/Dockerfile | 41 -------------------------------------- 2 files changed, 71 deletions(-) delete mode 100644 jdk-oracle-open/Dockerfile delete mode 100644 jdk-zulu/Dockerfile diff --git a/jdk-oracle-open/Dockerfile b/jdk-oracle-open/Dockerfile deleted file mode 100644 index 7205296..0000000 --- a/jdk-oracle-open/Dockerfile +++ /dev/null @@ -1,30 +0,0 @@ -FROM debian:stretch-slim@sha256:6c31161e090aa3f62b9ee1414b58f0a352b42b2b7827166e57724a8662fe4b38 - -# See https://jdk.java.net/11/ -ENV JDK11_VERSION=11.0.2 \ - JDK11_BUILD=7 \ - JDK11_TGZ_SHA256=62ee5758af12bbad04f376bf2b61f114076f6d8ffe4ba8db13bb5a63b5ef0d29 - -RUN set -ex; \ - export DEBIAN_FRONTEND=noninteractive; \ - runDeps=''; \ - buildDeps='curl ca-certificates'; \ - apt-get update && apt-get install -y $runDeps $buildDeps --no-install-recommends; \ - \ - cd /usr/lib; \ - mkdir jvm; \ - cd jvm; \ - curl -SLs -o jdk.tar.gz https://download.java.net/java/GA/jdk11/${JDK11_BUILD}/GPL/openjdk-${JDK11_VERSION}_linux-x64_bin.tar.gz; \ - echo "${JDK11_TGZ_SHA256} jdk.tar.gz" | sha256sum -c -; \ - tar xvzf jdk.tar.gz; \ - rm jdk.tar.gz; \ - mv jdk-11.0.2 jdk-11; \ - \ - rm -v jdk-11/lib/src.zip; \ - \ - apt-get purge -y --auto-remove $buildDeps; \ - rm -rf /var/lib/apt/lists/*; \ - rm -rf /var/log/dpkg.log /var/log/alternatives.log /var/log/apt - -# Instead of: find /usr/lib/jvm/jdk-11/bin/ -executable -exec ln -s '{}' /usr/local/bin/ -ENV PATH="$PATH:/usr/lib/jvm/jdk-11/bin" diff --git a/jdk-zulu/Dockerfile b/jdk-zulu/Dockerfile deleted file mode 100644 index 7ee2ae3..0000000 --- a/jdk-zulu/Dockerfile +++ /dev/null @@ -1,41 +0,0 @@ -FROM debian:stretch-slim@sha256:bade11bf1835c9f09b011b5b1cf9f7428328416410b238d2f937966ea820be74 - -ENV ZULU_OPENJDK_VERSION="11=11.31+11" - -RUN set -ex; \ - runDeps='locales procps'; \ - buildDeps='gnupg dirmngr'; \ - export DEBIAN_FRONTEND=noninteractive; \ - apt-get update && apt-get install -y $runDeps $buildDeps --no-install-recommends; \ - \ - apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 0x219BD9C9; \ - echo 'deb http://repos.azulsystems.com/debian stable main' > /etc/apt/sources.list.d/zulu.list; \ - mkdir /usr/share/man/man1; \ - apt-get update; \ - apt-get -s install zulu-8 | grep zulu-; \ - apt-get -s install zulu-11 | grep zulu-; \ - apt-get -s install zulu-12 | grep zulu-; \ - apt-get install -y zulu-${ZULU_OPENJDK_VERSION} --no-install-recommends; \ - rm -rf /usr/share/man/man1; \ - \ - cd /usr/lib/jvm/zulu-11-amd64/; \ - rm -rf demo man sample src.zip; \ - \ - apt-get purge -y --auto-remove $buildDeps; \ - rm -rf /var/lib/apt/lists/*; \ - rm -rf /var/log/dpkg.log /var/log/alternatives.log /var/log/apt - -ENV JAVA_HOME=/usr/lib/jvm/zulu-11-amd64 - -# If a downstream image changes these values it must also re-run locale-gen as below -ENV LANG=en_US.UTF-8 LANGUAGE=en_US:en LC_ALL=en_US.UTF-8 - -RUN set -ex; \ - sed -i -e "s/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/" /etc/locale.gen; \ - sed -i -e "s/# $LANG/$LANG/" /etc/locale.gen; \ - echo "LANG=\"$LANG\"" > /etc/default/locale; \ - \ - cat /etc/locale.gen | grep -v "^#"; \ - cat /etc/default/locale; \ - ls -la /usr/share/locale/locale.alias | grep /etc/locale.alias; \ - LC_ALL=C dpkg-reconfigure --frontend=noninteractive locales; From 9f0a6de5330d4969f66639021e73a987779ebd09 Mon Sep 17 00:00:00 2001 From: Staffan Olsson Date: Sat, 15 Aug 2020 07:40:56 +0200 Subject: [PATCH 02/25] Fixes a step arg so the command runs properly --- native/docker-compose.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/native/docker-compose.yml b/native/docker-compose.yml index 5fbe428..c35447d 100644 --- a/native/docker-compose.yml +++ b/native/docker-compose.yml @@ -133,7 +133,8 @@ - --group=testgroup - --topic=topic1 - --reset-offsets - - --to-offset 0 + - --to-offset=0 + #- --execute intentionally left out, for the dry-run use case step7: image: solsson/kafka:nativeagent-kafka-consumer-groups From cfdd618a12b04b6a13cfcbb02dec246a2d6d6b62 Mon Sep 17 00:00:00 2001 From: Staffan Olsson Date: Sat, 15 Aug 2020 07:47:08 +0200 Subject: [PATCH 03/25] Adds the jopts exception class to reflect config --- native/docker-compose.yml | 6 ++++++ native/native-usecases.sh | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/native/docker-compose.yml b/native/docker-compose.yml index c35447d..2619ae2 100644 --- a/native/docker-compose.yml +++ b/native/docker-compose.yml @@ -166,6 +166,12 @@ - --add-config - max.message.bytes=2048 + step10: + image: solsson/kafka:nativeagent-kafka-consumer-groups + volumes: [ ./configs/kafka-consumer-groups:/home/nonroot/native-config ] + command: + - --intentionally wrong + kafkacat: image: edenhill/kafkacat:1.5.0 depends_on: diff --git a/native/native-usecases.sh b/native/native-usecases.sh index a347a4e..55f7f37 100755 --- a/native/native-usecases.sh +++ b/native/native-usecases.sh @@ -33,6 +33,6 @@ $compose up -d kafka-0 $compose up -d kafkacat $compose ps -for step in $(seq 1 9); do +for step in $(seq 1 10); do $compose up step$step done From 7e4ea0c7a612d16bdb8c6f0b301138dd40598df8 Mon Sep 17 00:00:00 2001 From: Staffan Olsson Date: Sat, 15 Aug 2020 07:45:40 +0200 Subject: [PATCH 04/25] Regenerate native configs with Kafka 2.6.0 --- README.md | 1 + .../configs/kafka-configs/reflect-config.json | 15 +++---- .../kafka-consumer-groups/reflect-config.json | 3 ++ .../kafka-server-start/reflect-config.json | 41 ++++++++----------- .../configs/kafka-topics/reflect-config.json | 6 +-- 5 files changed, 29 insertions(+), 37 deletions(-) diff --git a/README.md b/README.md index 660d1a6..6bd1310 100644 --- a/README.md +++ b/README.md @@ -74,6 +74,7 @@ Very experimental. NOPUSH=true IMAGE_NAME=solsson/kafka:nativeagent ./hooks/build docker-compose -f native/docker-compose.yml down docker run --rm --entrypoint chown -v $(pwd)/native/configs:/configs busybox -R $(id -u) /configs +# after reviewing config changes with git add -p native/configs NOPUSH=true IMAGE_NAME=solsson/kafka:native ./hooks/build ``` diff --git a/native/configs/kafka-configs/reflect-config.json b/native/configs/kafka-configs/reflect-config.json index 4e66b16..bc43994 100644 --- a/native/configs/kafka-configs/reflect-config.json +++ b/native/configs/kafka-configs/reflect-config.json @@ -48,6 +48,9 @@ "name":"java.lang.ThreadLocal", "methods":[{"name":"remove","parameterTypes":[] }] }, +{ + "name":"java.lang.invoke.VarHandle" +}, { "name":"java.util.AbstractMap", "allDeclaredFields":true, @@ -102,16 +105,10 @@ "methods":[{"name":"","parameterTypes":["org.apache.zookeeper.client.ZKClientConfig"] }] }, { - "name":"scala.Serializable", - "allDeclaredMethods":true -}, -{ - "name":"scala.Tuple2[]" -}, -{ - "name":"scala.collection.convert.Wrappers$MapWrapper", + "name":"scala.collection.convert.JavaCollectionWrappers$MapWrapper", "allDeclaredFields":true, - "allDeclaredMethods":true + "allDeclaredMethods":true, + "allDeclaredConstructors":true }, { "name":"sun.security.provider.ConfigFile", diff --git a/native/configs/kafka-consumer-groups/reflect-config.json b/native/configs/kafka-consumer-groups/reflect-config.json index 2534c81..8248bbb 100644 --- a/native/configs/kafka-consumer-groups/reflect-config.json +++ b/native/configs/kafka-consumer-groups/reflect-config.json @@ -11,6 +11,9 @@ "name":"java.lang.Thread", "methods":[{"name":"getContextClassLoader","parameterTypes":[] }] }, +{ + "name":"java.lang.invoke.VarHandle" +}, { "name":"kafka.admin.ConsumerGroupCommand$PartitionAssignmentState[]" }, diff --git a/native/configs/kafka-server-start/reflect-config.json b/native/configs/kafka-server-start/reflect-config.json index bf25a34..57803e8 100644 --- a/native/configs/kafka-server-start/reflect-config.json +++ b/native/configs/kafka-server-start/reflect-config.json @@ -35,9 +35,6 @@ "allDeclaredFields":true, "allDeclaredMethods":true }, -{ - "name":"java.lang.Runnable[]" -}, { "name":"java.lang.Runtime", "methods":[{"name":"version","parameterTypes":[] }] @@ -61,6 +58,9 @@ "name":"java.lang.ThreadLocal", "methods":[{"name":"remove","parameterTypes":[] }] }, +{ + "name":"java.lang.invoke.VarHandle" +}, { "name":"java.util.AbstractCollection", "allDeclaredFields":true, @@ -91,16 +91,10 @@ { "name":"java.util.zip.CRC32C" }, -{ - "name":"kafka.server.DelayedOperationPurgatory$WatcherList[]" -}, { "name":"kafka.utils.Log4jController", "methods":[{"name":"","parameterTypes":[] }] }, -{ - "name":"kafka.utils.timer.TimerTaskList[]" -}, { "name":"org.apache.kafka.common.protocol.types.Struct[]" }, @@ -150,35 +144,32 @@ "allDeclaredMethods":true }, { - "name":"scala.Serializable", - "allDeclaredMethods":true -}, -{ - "name":"scala.Tuple2[]" -}, -{ - "name":"scala.collection.convert.Wrappers$IterableWrapperTrait", + "name":"scala.collection.convert.JavaCollectionWrappers$IterableWrapperTrait", "allDeclaredMethods":true }, { - "name":"scala.collection.convert.Wrappers$MapWrapper", + "name":"scala.collection.convert.JavaCollectionWrappers$MapWrapper", "allDeclaredFields":true, - "allDeclaredMethods":true + "allDeclaredMethods":true, + "allDeclaredConstructors":true }, { - "name":"scala.collection.convert.Wrappers$MutableBufferWrapper", + "name":"scala.collection.convert.JavaCollectionWrappers$MutableBufferWrapper", "allDeclaredFields":true, - "allDeclaredMethods":true + "allDeclaredMethods":true, + "allDeclaredConstructors":true }, { - "name":"scala.collection.convert.Wrappers$MutableMapWrapper", + "name":"scala.collection.convert.JavaCollectionWrappers$MutableMapWrapper", "allDeclaredFields":true, - "allDeclaredMethods":true + "allDeclaredMethods":true, + "allDeclaredConstructors":true }, { - "name":"scala.collection.convert.Wrappers$SeqWrapper", + "name":"scala.collection.convert.JavaCollectionWrappers$SeqWrapper", "allDeclaredFields":true, - "allDeclaredMethods":true + "allDeclaredMethods":true, + "allDeclaredConstructors":true }, { "name":"sun.misc.Signal", diff --git a/native/configs/kafka-topics/reflect-config.json b/native/configs/kafka-topics/reflect-config.json index 1a87c3d..5ef3464 100644 --- a/native/configs/kafka-topics/reflect-config.json +++ b/native/configs/kafka-topics/reflect-config.json @@ -33,6 +33,9 @@ "name":"java.lang.ThreadLocal", "methods":[{"name":"remove","parameterTypes":[] }] }, +{ + "name":"java.lang.invoke.VarHandle" +}, { "name":"kafka.utils.Log4jController", "methods":[{"name":"","parameterTypes":[] }] @@ -74,9 +77,6 @@ "name":"org.apache.zookeeper.ClientCnxnSocketNIO", "methods":[{"name":"","parameterTypes":["org.apache.zookeeper.client.ZKClientConfig"] }] }, -{ - "name":"scala.Tuple2[]" -}, { "name":"sun.security.provider.ConfigFile", "methods":[{"name":"","parameterTypes":[] }] From 2f21a61d941eefc86b9c8787e1526d5aac29dffc Mon Sep 17 00:00:00 2001 From: Staffan Olsson Date: Sat, 15 Aug 2020 08:07:51 +0200 Subject: [PATCH 05/25] Current Quarkus --- native/admincmd.Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/native/admincmd.Dockerfile b/native/admincmd.Dockerfile index e70bcb4..e5d3004 100644 --- a/native/admincmd.Dockerfile +++ b/native/admincmd.Dockerfile @@ -7,7 +7,7 @@ FROM curlimages/curl@sha256:aa45e9d93122a3cfdf8d7de272e2798ea63733eeee6d06bd2ee4 USER root RUN curl -sLS -o /slf4j-nop-1.7.30.jar https://repo1.maven.org/maven2/org/slf4j/slf4j-nop/1.7.30/slf4j-nop-1.7.30.jar -RUN curl -sLS -o /quarkus-kafka-client-1.6.0.Final.jar https://repo1.maven.org/maven2/io/quarkus/quarkus-kafka-client/1.6.0.Final/quarkus-kafka-client-1.6.0.Final.jar +RUN curl -sLS -o /quarkus-kafka-client-1.7.0.Final.jar https://repo1.maven.org/maven2/io/quarkus/quarkus-kafka-client/1.7.0.Final/quarkus-kafka-client-1.7.0.Final.jar FROM solsson/kafka:nativebase as native From 576ecd528f765c97cbfc4f1fc98e9c2298c2d933 Mon Sep 17 00:00:00 2001 From: Staffan Olsson Date: Sat, 15 Aug 2020 17:52:19 +0200 Subject: [PATCH 06/25] Fixes a warning emitted at build time --- native/admincmd.Dockerfile | 1 - .../configs-manual-additions/kafka-topics/reflect-config.json | 3 --- native/configs/kafka-topics/reflect-config.json | 3 --- 3 files changed, 7 deletions(-) diff --git a/native/admincmd.Dockerfile b/native/admincmd.Dockerfile index e5d3004..dd8b041 100644 --- a/native/admincmd.Dockerfile +++ b/native/admincmd.Dockerfile @@ -29,7 +29,6 @@ RUN native-image \ -H:IncludeResourceBundles=joptsimple.ExceptionMessages \ -H:ConfigurationFileDirectories=/home/nonroot/native-config \ # When testing the build for a new version we should remove this one, but then it tends to come back - --allow-incomplete-classpath \ --report-unsupported-elements-at-runtime \ # -D options from entrypoint -Djava.awt.headless=true \ diff --git a/native/configs-manual-additions/kafka-topics/reflect-config.json b/native/configs-manual-additions/kafka-topics/reflect-config.json index 6530591..f24a429 100644 --- a/native/configs-manual-additions/kafka-topics/reflect-config.json +++ b/native/configs-manual-additions/kafka-topics/reflect-config.json @@ -2,9 +2,6 @@ { "name": "org.apache.log4j.helpers.Loader" }, - { - "name": "io.netty.util.internal.logging.Log4J2Logger" - }, { "name": "sun.security.provider.ConfigFile", "methods": [ diff --git a/native/configs/kafka-topics/reflect-config.json b/native/configs/kafka-topics/reflect-config.json index 5ef3464..3e79dd6 100644 --- a/native/configs/kafka-topics/reflect-config.json +++ b/native/configs/kafka-topics/reflect-config.json @@ -3,9 +3,6 @@ "name":"com.fasterxml.jackson.databind.ext.Java7SupportImpl", "methods":[{"name":"","parameterTypes":[] }] }, -{ - "name":"io.netty.util.internal.logging.Log4J2Logger" -}, { "name":"java.lang.Integer", "methods":[{"name":"valueOf","parameterTypes":["java.lang.String"] }] From 4e46018df2401b140cbf3b34718c0bca3e25c7dd Mon Sep 17 00:00:00 2001 From: Staffan Olsson Date: Sat, 15 Aug 2020 17:52:32 +0200 Subject: [PATCH 07/25] Scala issues about the native-image + java.lang.invoke.MemberName recommend this setting, and failing at build time is preferrable over runtime --- native/admincmd.Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/native/admincmd.Dockerfile b/native/admincmd.Dockerfile index dd8b041..8c3446d 100644 --- a/native/admincmd.Dockerfile +++ b/native/admincmd.Dockerfile @@ -29,7 +29,7 @@ RUN native-image \ -H:IncludeResourceBundles=joptsimple.ExceptionMessages \ -H:ConfigurationFileDirectories=/home/nonroot/native-config \ # When testing the build for a new version we should remove this one, but then it tends to come back - --report-unsupported-elements-at-runtime \ + --initialize-at-build-time \ # -D options from entrypoint -Djava.awt.headless=true \ -Dkafka.logs.dir=/opt/kafka/bin/../logs \ From bdd2195c65e8ca38e70d70ecd81cc76c7f0227f5 Mon Sep 17 00:00:00 2001 From: Staffan Olsson Date: Sun, 16 Aug 2020 10:17:37 +0200 Subject: [PATCH 08/25] Dammit scala --- native/substitutions/admincmd/.gitignore | 4 ++ native/substitutions/admincmd/pom.xml | 25 ++++++++++ .../substitutions/kafka/admincmd/JMX.java | 46 +++++++++++++++++++ 3 files changed, 75 insertions(+) create mode 100644 native/substitutions/admincmd/.gitignore create mode 100644 native/substitutions/admincmd/pom.xml create mode 100644 native/substitutions/admincmd/src/main/java/se/repos/substitutions/kafka/admincmd/JMX.java diff --git a/native/substitutions/admincmd/.gitignore b/native/substitutions/admincmd/.gitignore new file mode 100644 index 0000000..beef00d --- /dev/null +++ b/native/substitutions/admincmd/.gitignore @@ -0,0 +1,4 @@ +.classpath +.project +.settings +target diff --git a/native/substitutions/admincmd/pom.xml b/native/substitutions/admincmd/pom.xml new file mode 100644 index 0000000..5ef2634 --- /dev/null +++ b/native/substitutions/admincmd/pom.xml @@ -0,0 +1,25 @@ + + 4.0.0 + se.repos.substitutions.kafka + admincmd + 1.0.0 + + 3.8.1 + true + 8 + 8 + + + + org.graalvm.nativeimage + svm + 20.1.0 + provided + + + org.scala-lang.modules + scala-collection-compat_2.13 + 2.1.6 + + + diff --git a/native/substitutions/admincmd/src/main/java/se/repos/substitutions/kafka/admincmd/JMX.java b/native/substitutions/admincmd/src/main/java/se/repos/substitutions/kafka/admincmd/JMX.java new file mode 100644 index 0000000..c65a98c --- /dev/null +++ b/native/substitutions/admincmd/src/main/java/se/repos/substitutions/kafka/admincmd/JMX.java @@ -0,0 +1,46 @@ +package se.repos.substitutions.kafka.admincmd; + +import com.oracle.svm.core.annotate.Substitute; +import com.oracle.svm.core.annotate.TargetClass; + +/* +Call path from entry point to kafka.metrics.KafkaYammerMetrics.defaultRegistry(): + at kafka.metrics.KafkaYammerMetrics.defaultRegistry(KafkaYammerMetrics.java:44) + at kafka.metrics.KafkaMetricsGroup.removeMetric(KafkaMetricsGroup.scala:80) + at kafka.metrics.KafkaMetricsGroup.removeMetric$(KafkaMetricsGroup.scala:79) + at kafka.zk.KafkaZkClient.removeMetric(KafkaZkClient.scala:53) + at kafka.zk.KafkaZkClient.close(KafkaZkClient.scala:1450) + at kafka.admin.TopicCommand$ZookeeperTopicService.close(TopicCommand.scala:507) + at kafka.admin.TopicCommand$.main(TopicCommand.scala:77) + at kafka.admin.TopicCommand.main(TopicCommand.scala) + at com.oracle.svm.core.JavaMainWrapper.runCore(JavaMainWrapper.java:149) + at com.oracle.svm.core.JavaMainWrapper.run(JavaMainWrapper.java:184) + at com.oracle.svm.core.code.IsolateEnterStub.JavaMainWrapper_run_5087f5482cc9a6abc971913ece43acb471d2631b(generated:0) + + at com.oracle.graal.pointsto.constraints.UnsupportedFeatures.report(UnsupportedFeatures.java:129) + at com.oracle.svm.hosted.NativeImageGenerator.runPointsToAnalysis(NativeImageGenerator.java:750) + ... 8 more +*/ + +/* +import com.yammer.metrics.core.MetricsRegistry; + +@TargetClass(className = "scala.collection.immutable.VM") +class JMX { + + @Substitute + public static MetricsRegistry defaultRegistry() { + return null; + } + +} +*/ + +@TargetClass(className = "kafka.metrics.KafkaMetricsGroup") +class JMX { + + @Substitute + public void removeMetric(String name, scala.collection.Map tags) { + } + +} From fc8a77fe5a290775882c9dd34c5f4434866b4014 Mon Sep 17 00:00:00 2001 From: Staffan Olsson Date: Sun, 16 Aug 2020 11:12:00 +0200 Subject: [PATCH 09/25] Fixes the zookeeper native-image JMX NPE, see #31 --- .../zookeeper-server-start/.gitignore | 4 ++ .../zookeeper-server-start/pom.xml | 25 ++++++++++ .../substitutions/kafka/zookeeper/NoJMX.java | 49 +++++++++++++++++++ native/zookeeper-server-start.Dockerfile | 9 +++- 4 files changed, 86 insertions(+), 1 deletion(-) create mode 100644 native/substitutions/zookeeper-server-start/.gitignore create mode 100644 native/substitutions/zookeeper-server-start/pom.xml create mode 100644 native/substitutions/zookeeper-server-start/src/main/java/se/repos/substitutions/kafka/zookeeper/NoJMX.java diff --git a/native/substitutions/zookeeper-server-start/.gitignore b/native/substitutions/zookeeper-server-start/.gitignore new file mode 100644 index 0000000..beef00d --- /dev/null +++ b/native/substitutions/zookeeper-server-start/.gitignore @@ -0,0 +1,4 @@ +.classpath +.project +.settings +target diff --git a/native/substitutions/zookeeper-server-start/pom.xml b/native/substitutions/zookeeper-server-start/pom.xml new file mode 100644 index 0000000..1a12eda --- /dev/null +++ b/native/substitutions/zookeeper-server-start/pom.xml @@ -0,0 +1,25 @@ + + 4.0.0 + se.repos.substitutions.kafka + zookeeper-substitutions + 1.0.0 + + 3.8.1 + true + 8 + 8 + + + + org.graalvm.nativeimage + svm + 20.1.0 + provided + + + org.apache.zookeeper + zookeeper + 3.5.8 + + + diff --git a/native/substitutions/zookeeper-server-start/src/main/java/se/repos/substitutions/kafka/zookeeper/NoJMX.java b/native/substitutions/zookeeper-server-start/src/main/java/se/repos/substitutions/kafka/zookeeper/NoJMX.java new file mode 100644 index 0000000..c59a211 --- /dev/null +++ b/native/substitutions/zookeeper-server-start/src/main/java/se/repos/substitutions/kafka/zookeeper/NoJMX.java @@ -0,0 +1,49 @@ +package se.repos.substitutions.kafka.zookeeper; + +import com.oracle.svm.core.annotate.Substitute; +import com.oracle.svm.core.annotate.TargetClass; + +import org.apache.zookeeper.jmx.ZKMBeanInfo; + +import java.util.HashSet; +import java.util.Set; + +import javax.management.JMException; + +/* +zoo-2_1 | [QuorumPeer[myid=3](plain=0.0.0.0:2181)(secure=disabled)] WARN org.apache.zookeeper.server.ZooKeeperServer - Failed to register with JMX +zoo-2_1 | java.lang.NullPointerException +zoo-2_1 | at org.apache.zookeeper.jmx.MBeanRegistry.register(MBeanRegistry.java:108) +zoo-2_1 | at org.apache.zookeeper.server.quorum.LearnerZooKeeperServer.registerJMX(LearnerZooKeeperServer.java:105) +zoo-2_1 | at org.apache.zookeeper.server.ZooKeeperServer.startup(ZooKeeperServer.java:461) +zoo-2_1 | at org.apache.zookeeper.server.quorum.Learner.syncWithLeader(Learner.java:572) +zoo-2_1 | at org.apache.zookeeper.server.quorum.Follower.followLeader(Follower.java:89) +zoo-2_1 | at org.apache.zookeeper.server.quorum.QuorumPeer.run(QuorumPeer.java:1253) +zoo-2_1 | at com.oracle.svm.core.thread.JavaThreads.threadStartRoutine(JavaThreads.java:517) +zoo-2_1 | at com.oracle.svm.core.posix.thread.PosixJavaThreads.pthreadStartRoutine(PosixJavaThreads.java:193) +*/ + +@TargetClass(org.apache.zookeeper.jmx.MBeanRegistry.class) +final class NoJMX { + + @Substitute + public void register(ZKMBeanInfo bean, ZKMBeanInfo parent) + throws JMException { + } + + @Substitute + private void unregister(String path,ZKMBeanInfo bean) throws JMException { + } + + @Substitute + public Set getRegisteredBeans() { + return new HashSet<>(); + } + + @Substitute + public void unregister(ZKMBeanInfo bean) { + } + + + +} diff --git a/native/zookeeper-server-start.Dockerfile b/native/zookeeper-server-start.Dockerfile index 26953c6..ee182ff 100644 --- a/native/zookeeper-server-start.Dockerfile +++ b/native/zookeeper-server-start.Dockerfile @@ -1,3 +1,9 @@ +FROM solsson/kafka:graalvm as substitutions + +WORKDIR /workspace +COPY substitutions/zookeeper-server-start . +RUN mvn package + FROM curlimages/curl@sha256:aa45e9d93122a3cfdf8d7de272e2798ea63733eeee6d06bd2ee4f2f8c4027d7c \ as extralibs @@ -8,8 +14,9 @@ RUN curl -sLS -o /log4j-over-slf4j-1.7.30.jar https://repo1.maven.org/maven2/org FROM solsson/kafka:nativebase as native #ARG classpath=/opt/kafka/libs/slf4j-log4j12-1.7.30.jar:/opt/kafka/libs/log4j-1.2.17.jar:/opt/kafka/libs/slf4j-api-1.7.30.jar:/opt/kafka/libs/zookeeper-3.5.8.jar:/opt/kafka/libs/zookeeper-jute-3.5.8.jar +COPY --from=substitutions /workspace/target/*.jar /opt/kafka/libs/substitutions.jar COPY --from=extralibs /*.jar /opt/kafka/libs/extensions/ -ARG classpath=/opt/kafka/libs/slf4j-api-1.7.30.jar:/opt/kafka/libs/extensions/slf4j-simple-1.7.30.jar:/opt/kafka/libs/extensions/log4j-over-slf4j-1.7.30.jar:/opt/kafka/libs/zookeeper-3.5.8.jar:/opt/kafka/libs/zookeeper-jute-3.5.8.jar +ARG classpath=/opt/kafka/libs/substitutions.jar:/opt/kafka/libs/slf4j-api-1.7.30.jar:/opt/kafka/libs/extensions/slf4j-simple-1.7.30.jar:/opt/kafka/libs/extensions/log4j-over-slf4j-1.7.30.jar:/opt/kafka/libs/zookeeper-3.5.8.jar:/opt/kafka/libs/zookeeper-jute-3.5.8.jar COPY configs/zookeeper-server-start /home/nonroot/native-config From 7da9b9b8bd29093fbfb9a8981bd622429d955689 Mon Sep 17 00:00:00 2001 From: Staffan Olsson Date: Sun, 16 Aug 2020 11:18:07 +0200 Subject: [PATCH 10/25] We've gotten rid of log4j and JMX; fix native-image warnings --- .../reflect-config.json | 27 +------------------ 1 file changed, 1 insertion(+), 26 deletions(-) diff --git a/native/configs/zookeeper-server-start/reflect-config.json b/native/configs/zookeeper-server-start/reflect-config.json index 544a81d..d3643ea 100644 --- a/native/configs/zookeeper-server-start/reflect-config.json +++ b/native/configs/zookeeper-server-start/reflect-config.json @@ -25,17 +25,10 @@ "name":"org.apache.log4j.Category", "methods":[{"name":"getName","parameterTypes":[] }] }, -{ - "name":"org.apache.log4j.CategoryKey" -}, { "name":"org.apache.log4j.ConsoleAppender", "methods":[{"name":"","parameterTypes":[] }] }, -{ - "name":"org.apache.log4j.Hierarchy", - "methods":[{"name":"getCurrentLoggers","parameterTypes":[] }] -}, { "name":"org.apache.log4j.Layout" }, @@ -43,8 +36,7 @@ "name":"org.apache.log4j.Level" }, { - "name":"org.apache.log4j.LogManager", - "methods":[{"name":"getLoggerRepository","parameterTypes":[] }] + "name":"org.apache.log4j.LogManager" }, { "name":"org.apache.log4j.Logger", @@ -57,23 +49,6 @@ { "name":"org.apache.log4j.Priority" }, -{ - "name":"org.apache.log4j.jmx.AppenderDynamicMBean", - "allPublicConstructors":true -}, -{ - "name":"org.apache.log4j.jmx.HierarchyDynamicMBean", - "allPublicConstructors":true, - "methods":[{"name":"addLoggerMBean","parameterTypes":["java.lang.String"] }] -}, -{ - "name":"org.apache.log4j.jmx.LayoutDynamicMBean", - "allPublicConstructors":true -}, -{ - "name":"org.apache.log4j.jmx.LoggerDynamicMBean", - "allPublicConstructors":true -}, { "name":"org.apache.log4j.spi.OptionHandler" }, From b9901ef4078ee0c5fd8e86a503bdd6a68386d7ad Mon Sep 17 00:00:00 2001 From: Staffan Olsson Date: Sun, 16 Aug 2020 11:33:52 +0200 Subject: [PATCH 11/25] Can we do scala substitutions without scala libs? --- native/substitutions/admincmd/pom.xml | 5 ----- .../main/java/se/repos/substitutions/kafka/admincmd/JMX.java | 5 ++++- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/native/substitutions/admincmd/pom.xml b/native/substitutions/admincmd/pom.xml index 5ef2634..d4eaf1b 100644 --- a/native/substitutions/admincmd/pom.xml +++ b/native/substitutions/admincmd/pom.xml @@ -16,10 +16,5 @@ 20.1.0 provided - - org.scala-lang.modules - scala-collection-compat_2.13 - 2.1.6 - diff --git a/native/substitutions/admincmd/src/main/java/se/repos/substitutions/kafka/admincmd/JMX.java b/native/substitutions/admincmd/src/main/java/se/repos/substitutions/kafka/admincmd/JMX.java index c65a98c..ec5c482 100644 --- a/native/substitutions/admincmd/src/main/java/se/repos/substitutions/kafka/admincmd/JMX.java +++ b/native/substitutions/admincmd/src/main/java/se/repos/substitutions/kafka/admincmd/JMX.java @@ -22,6 +22,9 @@ ... 8 more */ +//import scala.collection.Map; +import java.util.Map; + /* import com.yammer.metrics.core.MetricsRegistry; @@ -40,7 +43,7 @@ public static MetricsRegistry defaultRegistry() { class JMX { @Substitute - public void removeMetric(String name, scala.collection.Map tags) { + public void removeMetric(String name, Map tags) { } } From 90fe465064b544bb7e82140237953d267ab7a50d Mon Sep 17 00:00:00 2001 From: Staffan Olsson Date: Sun, 16 Aug 2020 11:34:32 +0200 Subject: [PATCH 12/25] Various experiments that failed to fix "unresolved" X509Util stuff --- native/zookeeper-server-start.Dockerfile | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/native/zookeeper-server-start.Dockerfile b/native/zookeeper-server-start.Dockerfile index ee182ff..14ac5bb 100644 --- a/native/zookeeper-server-start.Dockerfile +++ b/native/zookeeper-server-start.Dockerfile @@ -34,10 +34,11 @@ RUN native-image \ -H:+ReportExceptionStackTraces \ --no-fallback \ -H:ConfigurationFileDirectories=/home/nonroot/native-config \ - # Added because of org.apache.zookeeper.common.X509Util, org.apache.zookeeper.common.ZKConfig, javax.net.ssl.SSLContext ... - --allow-incomplete-classpath \ - # Added because of "ClassNotFoundException: org.apache.zookeeper.server.NIOServerCnxnFactory" - --report-unsupported-elements-at-runtime \ + # Incompatible change of initialization policy for javax.net.ssl.SSLContext: trying to change BUILD_TIME from the command line to RERUN for substitutions + #--initialize-at-build-time=javax.net.ssl.SSLContext \ + --enable-http --enable-https \ + # https://quarkus.io/guides/native-and-ssl + -H:EnableURLProtocols=http,https --enable-all-security-services -H:+JNI \ # -D options from entrypoint -Djava.awt.headless=true \ -Dkafka.logs.dir=/opt/kafka/bin/../logs \ From 94704b3a744052fd5f62f0e5ad72f7e7dd7170e6 Mon Sep 17 00:00:00 2001 From: Staffan Olsson Date: Sun, 16 Aug 2020 11:37:07 +0200 Subject: [PATCH 13/25] Scope out TLS support, again, until represented in native-usecases --- native/zookeeper-server-start.Dockerfile | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/native/zookeeper-server-start.Dockerfile b/native/zookeeper-server-start.Dockerfile index 14ac5bb..4ef95c7 100644 --- a/native/zookeeper-server-start.Dockerfile +++ b/native/zookeeper-server-start.Dockerfile @@ -34,11 +34,8 @@ RUN native-image \ -H:+ReportExceptionStackTraces \ --no-fallback \ -H:ConfigurationFileDirectories=/home/nonroot/native-config \ - # Incompatible change of initialization policy for javax.net.ssl.SSLContext: trying to change BUILD_TIME from the command line to RERUN for substitutions - #--initialize-at-build-time=javax.net.ssl.SSLContext \ - --enable-http --enable-https \ - # https://quarkus.io/guides/native-and-ssl - -H:EnableURLProtocols=http,https --enable-all-security-services -H:+JNI \ + # Added because of org.apache.zookeeper.common.X509Util, org.apache.zookeeper.common.ZKConfig, javax.net.ssl.SSLContext ... + --allow-incomplete-classpath \ # -D options from entrypoint -Djava.awt.headless=true \ -Dkafka.logs.dir=/opt/kafka/bin/../logs \ From abaf38237fd02486f52cdd4aebf1e7a1391f29ac Mon Sep 17 00:00:00 2001 From: Staffan Olsson Date: Sun, 16 Aug 2020 11:47:41 +0200 Subject: [PATCH 14/25] Consistent builds. Admincmd fails to substitute the scala signature. --- native/.dockerignore | 2 ++ native/admincmd.Dockerfile | 7 +++++++ native/substitutions/admincmd/pom.xml | 2 +- .../substitutions/kafka/admincmd/{JMX.java => NoJMX.java} | 2 +- native/zookeeper-server-start.Dockerfile | 4 ++-- 5 files changed, 13 insertions(+), 4 deletions(-) create mode 100644 native/.dockerignore rename native/substitutions/admincmd/src/main/java/se/repos/substitutions/kafka/admincmd/{JMX.java => NoJMX.java} (98%) diff --git a/native/.dockerignore b/native/.dockerignore new file mode 100644 index 0000000..814578e --- /dev/null +++ b/native/.dockerignore @@ -0,0 +1,2 @@ +**/.* +**/target diff --git a/native/admincmd.Dockerfile b/native/admincmd.Dockerfile index 8c3446d..34a14c2 100644 --- a/native/admincmd.Dockerfile +++ b/native/admincmd.Dockerfile @@ -1,3 +1,9 @@ +FROM solsson/kafka:graalvm as substitutions + +WORKDIR /workspace +COPY substitutions/admincmd . +RUN mvn package + FROM adoptopenjdk:11.0.8_10-jdk-hotspot-bionic@sha256:0513c0a82a82d1c9f4bfed18ef57bd5551ced2656342426a772c4772286dae1e \ as nonlibs RUN echo "class Empty {public static void main(String[] a){}}" > Empty.java && javac Empty.java && jar --create --file /empty.jar Empty.class @@ -13,6 +19,7 @@ FROM solsson/kafka:nativebase as native ARG classpath=/opt/kafka/libs/extensions/*:/opt/kafka/libs/* +COPY --from=substitutions /workspace/target/*.jar /opt/kafka/libs/extensions/substitutions.jar COPY --from=extralibs /*.jar /opt/kafka/libs/extensions/ # docker run --rm --entrypoint ls solsson/kafka -l /opt/kafka/libs/ | grep log diff --git a/native/substitutions/admincmd/pom.xml b/native/substitutions/admincmd/pom.xml index d4eaf1b..d4246c2 100644 --- a/native/substitutions/admincmd/pom.xml +++ b/native/substitutions/admincmd/pom.xml @@ -1,7 +1,7 @@ 4.0.0 se.repos.substitutions.kafka - admincmd + admincmd-substitutions 1.0.0 3.8.1 diff --git a/native/substitutions/admincmd/src/main/java/se/repos/substitutions/kafka/admincmd/JMX.java b/native/substitutions/admincmd/src/main/java/se/repos/substitutions/kafka/admincmd/NoJMX.java similarity index 98% rename from native/substitutions/admincmd/src/main/java/se/repos/substitutions/kafka/admincmd/JMX.java rename to native/substitutions/admincmd/src/main/java/se/repos/substitutions/kafka/admincmd/NoJMX.java index ec5c482..3312598 100644 --- a/native/substitutions/admincmd/src/main/java/se/repos/substitutions/kafka/admincmd/JMX.java +++ b/native/substitutions/admincmd/src/main/java/se/repos/substitutions/kafka/admincmd/NoJMX.java @@ -40,7 +40,7 @@ public static MetricsRegistry defaultRegistry() { */ @TargetClass(className = "kafka.metrics.KafkaMetricsGroup") -class JMX { +final class NoJMX { @Substitute public void removeMetric(String name, Map tags) { diff --git a/native/zookeeper-server-start.Dockerfile b/native/zookeeper-server-start.Dockerfile index 4ef95c7..e33353a 100644 --- a/native/zookeeper-server-start.Dockerfile +++ b/native/zookeeper-server-start.Dockerfile @@ -14,9 +14,9 @@ RUN curl -sLS -o /log4j-over-slf4j-1.7.30.jar https://repo1.maven.org/maven2/org FROM solsson/kafka:nativebase as native #ARG classpath=/opt/kafka/libs/slf4j-log4j12-1.7.30.jar:/opt/kafka/libs/log4j-1.2.17.jar:/opt/kafka/libs/slf4j-api-1.7.30.jar:/opt/kafka/libs/zookeeper-3.5.8.jar:/opt/kafka/libs/zookeeper-jute-3.5.8.jar -COPY --from=substitutions /workspace/target/*.jar /opt/kafka/libs/substitutions.jar +COPY --from=substitutions /workspace/target/*.jar /opt/kafka/libs/extensions/substitutions.jar COPY --from=extralibs /*.jar /opt/kafka/libs/extensions/ -ARG classpath=/opt/kafka/libs/substitutions.jar:/opt/kafka/libs/slf4j-api-1.7.30.jar:/opt/kafka/libs/extensions/slf4j-simple-1.7.30.jar:/opt/kafka/libs/extensions/log4j-over-slf4j-1.7.30.jar:/opt/kafka/libs/zookeeper-3.5.8.jar:/opt/kafka/libs/zookeeper-jute-3.5.8.jar +ARG classpath=/opt/kafka/libs/extensions/substitutions.jar:/opt/kafka/libs/slf4j-api-1.7.30.jar:/opt/kafka/libs/extensions/slf4j-simple-1.7.30.jar:/opt/kafka/libs/extensions/log4j-over-slf4j-1.7.30.jar:/opt/kafka/libs/zookeeper-3.5.8.jar:/opt/kafka/libs/zookeeper-jute-3.5.8.jar COPY configs/zookeeper-server-start /home/nonroot/native-config From 1e33b4e9a069d1beb5531380ffe1a4221c279f97 Mon Sep 17 00:00:00 2001 From: Staffan Olsson Date: Sun, 16 Aug 2020 12:03:53 +0200 Subject: [PATCH 15/25] Betting that CLIs don't actually need metrics. We'd see runtime errors. --- native/substitutions/admincmd/pom.xml | 5 +++++ .../substitutions/kafka/admincmd/NoJMX.java | 21 +++++-------------- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/native/substitutions/admincmd/pom.xml b/native/substitutions/admincmd/pom.xml index d4246c2..e69de35 100644 --- a/native/substitutions/admincmd/pom.xml +++ b/native/substitutions/admincmd/pom.xml @@ -16,5 +16,10 @@ 20.1.0 provided + + com.yammer.metrics + metrics-core + 2.2.0 + diff --git a/native/substitutions/admincmd/src/main/java/se/repos/substitutions/kafka/admincmd/NoJMX.java b/native/substitutions/admincmd/src/main/java/se/repos/substitutions/kafka/admincmd/NoJMX.java index 3312598..bdf22e8 100644 --- a/native/substitutions/admincmd/src/main/java/se/repos/substitutions/kafka/admincmd/NoJMX.java +++ b/native/substitutions/admincmd/src/main/java/se/repos/substitutions/kafka/admincmd/NoJMX.java @@ -22,28 +22,17 @@ ... 8 more */ -//import scala.collection.Map; -import java.util.Map; - -/* import com.yammer.metrics.core.MetricsRegistry; -@TargetClass(className = "scala.collection.immutable.VM") -class JMX { +@TargetClass(className = "kafka.metrics.KafkaYammerMetrics") +final class NoJMX { @Substitute public static MetricsRegistry defaultRegistry() { - return null; + throw new UnsupportedOperationException("Metrics unsupported in native-image builds, see https://github.com/solsson/dockerfiles/pull/31"); } -} -*/ - -@TargetClass(className = "kafka.metrics.KafkaMetricsGroup") -final class NoJMX { - - @Substitute - public void removeMetric(String name, Map tags) { - } + // https://github.com/apache/kafka/blob/2.6.0/core/src/main/scala/kafka/metrics/KafkaMetricsGroup.scala#L67 + // ... could be stubbed but we'd need to stub all the return types also } From 695f84f016bb181747e873748fcf810b402920c2 Mon Sep 17 00:00:00 2001 From: Staffan Olsson Date: Sun, 16 Aug 2020 12:17:24 +0200 Subject: [PATCH 16/25] Fixes native-image build error \"unresolved type during parsing\" Error: com.oracle.graal.pointsto.constraints.UnresolvedElementException: Discovered unresolved type during parsing: io.netty.util.internal.logging.Log4J2Logger. To diagnose the issue you can use the --allow-incomplete-classpath option. The missing type is then reported at run time when it is accessed the first time. Detailed message: Trace: at parsing io.netty.util.internal.logging.Log4J2LoggerFactory.newInstance(Log4J2LoggerFactory.java:33) Call path from entry point to io.netty.util.internal.logging.Log4J2LoggerFactory.newInstance(String): no path found from entry point to target method --- native/substitutions/admincmd/pom.xml | 5 +++++ .../admincmd/NettyLog4J2LoggerFactory.java | 17 +++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 native/substitutions/admincmd/src/main/java/se/repos/substitutions/kafka/admincmd/NettyLog4J2LoggerFactory.java diff --git a/native/substitutions/admincmd/pom.xml b/native/substitutions/admincmd/pom.xml index e69de35..a4adab8 100644 --- a/native/substitutions/admincmd/pom.xml +++ b/native/substitutions/admincmd/pom.xml @@ -21,5 +21,10 @@ metrics-core 2.2.0 + + io.netty + netty-common + 4.1.50.Final + diff --git a/native/substitutions/admincmd/src/main/java/se/repos/substitutions/kafka/admincmd/NettyLog4J2LoggerFactory.java b/native/substitutions/admincmd/src/main/java/se/repos/substitutions/kafka/admincmd/NettyLog4J2LoggerFactory.java new file mode 100644 index 0000000..b0ba8fd --- /dev/null +++ b/native/substitutions/admincmd/src/main/java/se/repos/substitutions/kafka/admincmd/NettyLog4J2LoggerFactory.java @@ -0,0 +1,17 @@ +package se.repos.substitutions.kafka.admincmd; + +import com.oracle.svm.core.annotate.Substitute; +import com.oracle.svm.core.annotate.TargetClass; + +import io.netty.util.internal.logging.InternalLogger; + +@TargetClass(io.netty.util.internal.logging.Log4J2LoggerFactory.class) +final public class NettyLog4J2LoggerFactory { + + @Substitute + public InternalLogger newInstance(String name) { + // InternalLogger is an interface so if needed we could return a stub + throw new UnsupportedOperationException("Log4J2 unsupported in native-image builds, see https://github.com/solsson/dockerfiles/pull/31"); + } + +} From f4dfdf96b0531961d6d44f3cb9301e51f380bdcb Mon Sep 17 00:00:00 2001 From: Staffan Olsson Date: Sun, 16 Aug 2020 13:02:41 +0200 Subject: [PATCH 17/25] Explicit initialization config could be quite interesting for https://github.com/Yolean/kubernetes-kafka/pull/310 because when I investigated the timeouts there I found reports that similar errors had been fixed by cleaning up (or trashing) persisted state. > Detected a direct/mapped ByteBuffer in the image heap. > A direct ByteBuffer has a pointer to unmanaged C memory, > and C memory from the image generator is not available at image run time. > A mapped ByteBuffer references a file descriptor, > which is no longer open and mapped at run time. Error: com.oracle.graal.pointsto.constraints.UnsupportedFeatureException: Detected a direct/mapped ByteBuffer in the image heap. A direct ByteBuffer has a pointer to unmanaged C memory, and C memory from the image generator is not available at image run time.A mapped ByteBuffer references a file descriptor, which is no longer open and mapped at run time. To see how this object got instantiated use -H:+TraceClassInitialization. The object was probably created by a class initializer and is reachable from a static field. You can request class initialization at image run time by using the option --initialize-at-run-time=. Or you can write your own initialization methods and call them explicitly from your main entry point. Detailed message: Trace: at parsing org.apache.zookeeper.server.persistence.FilePadding.padFile(FilePadding.java:78) Call path from entry point to org.apache.zookeeper.server.persistence.FilePadding.padFile(FileChannel): at org.apache.zookeeper.server.persistence.FilePadding.padFile(FilePadding.java:76) --- native/zookeeper-server-start.Dockerfile | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/native/zookeeper-server-start.Dockerfile b/native/zookeeper-server-start.Dockerfile index e33353a..a5e2755 100644 --- a/native/zookeeper-server-start.Dockerfile +++ b/native/zookeeper-server-start.Dockerfile @@ -34,6 +34,10 @@ RUN native-image \ -H:+ReportExceptionStackTraces \ --no-fallback \ -H:ConfigurationFileDirectories=/home/nonroot/native-config \ + --initialize-at-build-time \ + --initialize-at-run-time=org.apache.zookeeper.server.persistence.FileTxnLog \ + --initialize-at-run-time=org.apache.zookeeper.server.persistence.TxnLogToolkit \ + --initialize-at-run-time=org.apache.zookeeper.server.persistence.FilePadding \ # Added because of org.apache.zookeeper.common.X509Util, org.apache.zookeeper.common.ZKConfig, javax.net.ssl.SSLContext ... --allow-incomplete-classpath \ # -D options from entrypoint From 6b7d99cd4916b8221be6b62b784fa761c9345438 Mon Sep 17 00:00:00 2001 From: Staffan Olsson Date: Sun, 16 Aug 2020 13:23:09 +0200 Subject: [PATCH 18/25] Fixes all warnings about incomplete classpath with initialize-at-build-time --- native/zookeeper-server-start.Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/native/zookeeper-server-start.Dockerfile b/native/zookeeper-server-start.Dockerfile index a5e2755..330aeeb 100644 --- a/native/zookeeper-server-start.Dockerfile +++ b/native/zookeeper-server-start.Dockerfile @@ -16,7 +16,7 @@ FROM solsson/kafka:nativebase as native #ARG classpath=/opt/kafka/libs/slf4j-log4j12-1.7.30.jar:/opt/kafka/libs/log4j-1.2.17.jar:/opt/kafka/libs/slf4j-api-1.7.30.jar:/opt/kafka/libs/zookeeper-3.5.8.jar:/opt/kafka/libs/zookeeper-jute-3.5.8.jar COPY --from=substitutions /workspace/target/*.jar /opt/kafka/libs/extensions/substitutions.jar COPY --from=extralibs /*.jar /opt/kafka/libs/extensions/ -ARG classpath=/opt/kafka/libs/extensions/substitutions.jar:/opt/kafka/libs/slf4j-api-1.7.30.jar:/opt/kafka/libs/extensions/slf4j-simple-1.7.30.jar:/opt/kafka/libs/extensions/log4j-over-slf4j-1.7.30.jar:/opt/kafka/libs/zookeeper-3.5.8.jar:/opt/kafka/libs/zookeeper-jute-3.5.8.jar +ARG classpath=/opt/kafka/libs/extensions/substitutions.jar:/opt/kafka/libs/slf4j-api-1.7.30.jar:/opt/kafka/libs/extensions/slf4j-simple-1.7.30.jar:/opt/kafka/libs/extensions/log4j-over-slf4j-1.7.30.jar:/opt/kafka/libs/zookeeper-3.5.8.jar:/opt/kafka/libs/zookeeper-jute-3.5.8.jar:/opt/kafka/libs/jetty-server-9.4.24.v20191120.jar:/opt/kafka/libs/jetty-util-9.4.24.v20191120.jar:/opt/kafka/libs/jetty-io-9.4.24.v20191120.jar:/opt/kafka/libs/jetty-http-9.4.24.v20191120.jar:/opt/kafka/libs/netty-handler-4.1.50.Final.jar:/opt/kafka/libs/javax.servlet-api-3.1.0.jar COPY configs/zookeeper-server-start /home/nonroot/native-config From 9826bffa16e90f1f1956b181e482655ea5d54199 Mon Sep 17 00:00:00 2001 From: Staffan Olsson Date: Sun, 16 Aug 2020 13:32:41 +0200 Subject: [PATCH 19/25] Despite the addition of these classpath entries, that do include the .class files, I fail to get rid of: Error: Unsupported features in 2 methods Detailed message: Error: com.oracle.graal.pointsto.constraints.UnresolvedElementException: Discovered unresolved method during parsing: io.netty.buffer.Unpooled.wrappedBuffer(byte[]). To diagnose the issue you can use the --allow-incomplete-classpath option. The missing method is then reported at run time when it is accessed the first time. Trace: at parsing org.apache.zookeeper.server.quorum.UnifiedServerSocket$UnifiedSocket.detectMode(UnifiedServerSocket.java:265) Call path from entry point to org.apache.zookeeper.server.quorum.UnifiedServerSocket$UnifiedSocket.detectMode(): at org.apache.zookeeper.server.quorum.UnifiedServerSocket$UnifiedSocket.detectMode(UnifiedServerSocket.java:240) at org.apache.zookeeper.server.quorum.UnifiedServerSocket$UnifiedSocket.getSocket(UnifiedServerSocket.java:301) Error: com.oracle.graal.pointsto.constraints.UnresolvedElementException: Discovered unresolved method during parsing: org.eclipse.jetty.servlet.ServletContextHandler.(int). To diagnose the issue you can use the --allow-incomplete-classpath option. The missing method is then reported at run time when it is accessed the first time. Trace: at parsing org.apache.zookeeper.server.admin.JettyAdminServer.(JettyAdminServer.java:90) Call path from entry point to org.apache.zookeeper.server.admin.JettyAdminServer.(String, int, int, String): at org.apache.zookeeper.server.admin.JettyAdminServer.(JettyAdminServer.java:77) at org.apache.zookeeper.server.admin.JettyAdminServer.(JettyAdminServer.java:71) --- native/zookeeper-server-start.Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/native/zookeeper-server-start.Dockerfile b/native/zookeeper-server-start.Dockerfile index 330aeeb..23c45cb 100644 --- a/native/zookeeper-server-start.Dockerfile +++ b/native/zookeeper-server-start.Dockerfile @@ -16,7 +16,7 @@ FROM solsson/kafka:nativebase as native #ARG classpath=/opt/kafka/libs/slf4j-log4j12-1.7.30.jar:/opt/kafka/libs/log4j-1.2.17.jar:/opt/kafka/libs/slf4j-api-1.7.30.jar:/opt/kafka/libs/zookeeper-3.5.8.jar:/opt/kafka/libs/zookeeper-jute-3.5.8.jar COPY --from=substitutions /workspace/target/*.jar /opt/kafka/libs/extensions/substitutions.jar COPY --from=extralibs /*.jar /opt/kafka/libs/extensions/ -ARG classpath=/opt/kafka/libs/extensions/substitutions.jar:/opt/kafka/libs/slf4j-api-1.7.30.jar:/opt/kafka/libs/extensions/slf4j-simple-1.7.30.jar:/opt/kafka/libs/extensions/log4j-over-slf4j-1.7.30.jar:/opt/kafka/libs/zookeeper-3.5.8.jar:/opt/kafka/libs/zookeeper-jute-3.5.8.jar:/opt/kafka/libs/jetty-server-9.4.24.v20191120.jar:/opt/kafka/libs/jetty-util-9.4.24.v20191120.jar:/opt/kafka/libs/jetty-io-9.4.24.v20191120.jar:/opt/kafka/libs/jetty-http-9.4.24.v20191120.jar:/opt/kafka/libs/netty-handler-4.1.50.Final.jar:/opt/kafka/libs/javax.servlet-api-3.1.0.jar +ARG classpath=/opt/kafka/libs/extensions/substitutions.jar:/opt/kafka/libs/slf4j-api-1.7.30.jar:/opt/kafka/libs/extensions/slf4j-simple-1.7.30.jar:/opt/kafka/libs/extensions/log4j-over-slf4j-1.7.30.jar:/opt/kafka/libs/zookeeper-3.5.8.jar:/opt/kafka/libs/zookeeper-jute-3.5.8.jar:/opt/kafka/libs/jetty-server-9.4.24.v20191120.jar:/opt/kafka/libs/jetty-util-9.4.24.v20191120.jar:/opt/kafka/libs/jetty-io-9.4.24.v20191120.jar:/opt/kafka/libs/jetty-http-9.4.24.v20191120.jar:/opt/kafka/libs/jetty-servlet-9.4.24.v20191120.jar:/opt/kafka/libs/netty-handler-4.1.50.Final.jar:/opt/kafka/libs/netty-buffer-4.1.50.Final.jar:/opt/kafka/libs/javax.servlet-api-3.1.0.jar COPY configs/zookeeper-server-start /home/nonroot/native-config @@ -38,7 +38,7 @@ RUN native-image \ --initialize-at-run-time=org.apache.zookeeper.server.persistence.FileTxnLog \ --initialize-at-run-time=org.apache.zookeeper.server.persistence.TxnLogToolkit \ --initialize-at-run-time=org.apache.zookeeper.server.persistence.FilePadding \ - # Added because of org.apache.zookeeper.common.X509Util, org.apache.zookeeper.common.ZKConfig, javax.net.ssl.SSLContext ... + # Added because of io.netty.buffer.Unpooled.wrappedBuffer(byte[]), org.eclipse.jetty.servlet.ServletContextHandler.(int) --allow-incomplete-classpath \ # -D options from entrypoint -Djava.awt.headless=true \ From e8da8a75adf5d7518007bc897706bd456ddf4de3 Mon Sep 17 00:00:00 2001 From: Staffan Olsson Date: Sun, 16 Aug 2020 13:37:05 +0200 Subject: [PATCH 20/25] Maybe --initialize-at-build-time should be removed after we've tracked down after we've resolved classpath issues. The stdout prints of config are gone now, but this print remains: INFO org.apache.zookeeper.common.X509Util - Setting -D jdk.tls.rejectClientInitiatedRenegotiation=true to disable client-initiated TLS renegotiation --- native/zookeeper-server-start.Dockerfile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/native/zookeeper-server-start.Dockerfile b/native/zookeeper-server-start.Dockerfile index 23c45cb..9334a6b 100644 --- a/native/zookeeper-server-start.Dockerfile +++ b/native/zookeeper-server-start.Dockerfile @@ -38,6 +38,9 @@ RUN native-image \ --initialize-at-run-time=org.apache.zookeeper.server.persistence.FileTxnLog \ --initialize-at-run-time=org.apache.zookeeper.server.persistence.TxnLogToolkit \ --initialize-at-run-time=org.apache.zookeeper.server.persistence.FilePadding \ + # Can we instantiate at build time things that depend on config file contents? + --initialize-at-run-time=org.apache.zookeeper.server.quorum.Leader \ + --initialize-at-run-time=org.apache.zookeeper.server.ZooKeeperServer \ # Added because of io.netty.buffer.Unpooled.wrappedBuffer(byte[]), org.eclipse.jetty.servlet.ServletContextHandler.(int) --allow-incomplete-classpath \ # -D options from entrypoint From 510f8ba055c6424656b9c0bab698fc0b754ab4c1 Mon Sep 17 00:00:00 2001 From: Staffan Olsson Date: Sun, 16 Aug 2020 16:43:10 +0200 Subject: [PATCH 21/25] Actually with the more ambitious classpath we're stuck with initialization at runtime, for the same reason as the admincmd build: "All methods from java.lang.invoke should have been replaced during image building" This reverts commit e8da8a75adf5d7518007bc897706bd456ddf4de3. --- native/zookeeper-server-start.Dockerfile | 3 --- 1 file changed, 3 deletions(-) diff --git a/native/zookeeper-server-start.Dockerfile b/native/zookeeper-server-start.Dockerfile index 9334a6b..23c45cb 100644 --- a/native/zookeeper-server-start.Dockerfile +++ b/native/zookeeper-server-start.Dockerfile @@ -38,9 +38,6 @@ RUN native-image \ --initialize-at-run-time=org.apache.zookeeper.server.persistence.FileTxnLog \ --initialize-at-run-time=org.apache.zookeeper.server.persistence.TxnLogToolkit \ --initialize-at-run-time=org.apache.zookeeper.server.persistence.FilePadding \ - # Can we instantiate at build time things that depend on config file contents? - --initialize-at-run-time=org.apache.zookeeper.server.quorum.Leader \ - --initialize-at-run-time=org.apache.zookeeper.server.ZooKeeperServer \ # Added because of io.netty.buffer.Unpooled.wrappedBuffer(byte[]), org.eclipse.jetty.servlet.ServletContextHandler.(int) --allow-incomplete-classpath \ # -D options from entrypoint From b43a8daf190ad4cbdd55ca969ffb96b785366e68 Mon Sep 17 00:00:00 2001 From: Staffan Olsson Date: Sun, 16 Aug 2020 16:07:47 +0200 Subject: [PATCH 22/25] Has been solved with substitution --- native/zookeeper-server-start.Dockerfile | 3 --- 1 file changed, 3 deletions(-) diff --git a/native/zookeeper-server-start.Dockerfile b/native/zookeeper-server-start.Dockerfile index 23c45cb..1f106b6 100644 --- a/native/zookeeper-server-start.Dockerfile +++ b/native/zookeeper-server-start.Dockerfile @@ -24,9 +24,6 @@ COPY configs/zookeeper-server-start /home/nonroot/native-config # - java.lang.NoClassDefFoundError: Could not initialize class org.apache.zookeeper.server.admin.JettyAdminServer # which is fine because https://github.com/apache/zookeeper/blob/release-3.5.7/zookeeper-server/src/main/java/org/apache/zookeeper/server/admin/AdminServerFactory.java # documents that admin server is optional and it's only at startup -# - WARN org.apache.zookeeper.server.ZooKeeperServer - Failed to register with JMX -# java.lang.NullPointerException at org.apache.zookeeper.jmx.MBeanRegistry.register(MBeanRegistry.java:108) -# is very annoying because it happens a lot so it fills logs RUN native-image \ --no-server \ From 6cb12025f2f4b17b2c6b1f0bfbfe50bd34ba4c0c Mon Sep 17 00:00:00 2001 From: Staffan Olsson Date: Sun, 16 Aug 2020 16:14:57 +0200 Subject: [PATCH 23/25] Maybe down this rabbit hole we should use the entire libs folder again --- native/zookeeper-server-start.Dockerfile | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/native/zookeeper-server-start.Dockerfile b/native/zookeeper-server-start.Dockerfile index 1f106b6..7fad0e4 100644 --- a/native/zookeeper-server-start.Dockerfile +++ b/native/zookeeper-server-start.Dockerfile @@ -16,15 +16,11 @@ FROM solsson/kafka:nativebase as native #ARG classpath=/opt/kafka/libs/slf4j-log4j12-1.7.30.jar:/opt/kafka/libs/log4j-1.2.17.jar:/opt/kafka/libs/slf4j-api-1.7.30.jar:/opt/kafka/libs/zookeeper-3.5.8.jar:/opt/kafka/libs/zookeeper-jute-3.5.8.jar COPY --from=substitutions /workspace/target/*.jar /opt/kafka/libs/extensions/substitutions.jar COPY --from=extralibs /*.jar /opt/kafka/libs/extensions/ -ARG classpath=/opt/kafka/libs/extensions/substitutions.jar:/opt/kafka/libs/slf4j-api-1.7.30.jar:/opt/kafka/libs/extensions/slf4j-simple-1.7.30.jar:/opt/kafka/libs/extensions/log4j-over-slf4j-1.7.30.jar:/opt/kafka/libs/zookeeper-3.5.8.jar:/opt/kafka/libs/zookeeper-jute-3.5.8.jar:/opt/kafka/libs/jetty-server-9.4.24.v20191120.jar:/opt/kafka/libs/jetty-util-9.4.24.v20191120.jar:/opt/kafka/libs/jetty-io-9.4.24.v20191120.jar:/opt/kafka/libs/jetty-http-9.4.24.v20191120.jar:/opt/kafka/libs/jetty-servlet-9.4.24.v20191120.jar:/opt/kafka/libs/netty-handler-4.1.50.Final.jar:/opt/kafka/libs/netty-buffer-4.1.50.Final.jar:/opt/kafka/libs/javax.servlet-api-3.1.0.jar +# For running without JettyAdminServer we're probably fine with only substitutions + slf4j + zokeeper+zookeeper-jute; see https://github.com/solsson/dockerfiles/pull/31 +ARG classpath=/opt/kafka/libs/extensions/substitutions.jar:/opt/kafka/libs/slf4j-api-1.7.30.jar:/opt/kafka/libs/extensions/slf4j-simple-1.7.30.jar:/opt/kafka/libs/extensions/log4j-over-slf4j-1.7.30.jar:/opt/kafka/libs/zookeeper-3.5.8.jar:/opt/kafka/libs/zookeeper-jute-3.5.8.jar:/opt/kafka/libs/jetty-server-9.4.24.v20191120.jar:/opt/kafka/libs/jetty-util-9.4.24.v20191120.jar:/opt/kafka/libs/jetty-io-9.4.24.v20191120.jar:/opt/kafka/libs/jetty-http-9.4.24.v20191120.jar:/opt/kafka/libs/jetty-servlet-9.4.24.v20191120.jar:/opt/kafka/libs/jetty-security-9.4.24.v20191120.jar:/opt/kafka/libs/netty-common-4.1.50.Final.jar:/opt/kafka/libs/netty-handler-4.1.50.Final.jar:/opt/kafka/libs/netty-buffer-4.1.50.Final.jar:/opt/kafka/libs/javax.servlet-api-3.1.0.jar COPY configs/zookeeper-server-start /home/nonroot/native-config -# Remaining issues: -# - java.lang.NoClassDefFoundError: Could not initialize class org.apache.zookeeper.server.admin.JettyAdminServer -# which is fine because https://github.com/apache/zookeeper/blob/release-3.5.7/zookeeper-server/src/main/java/org/apache/zookeeper/server/admin/AdminServerFactory.java -# documents that admin server is optional and it's only at startup - RUN native-image \ --no-server \ --install-exit-handlers \ From 37ca8d6a09cfa6c9ea175f8211a0d0526a283dc7 Mon Sep 17 00:00:00 2001 From: Staffan Olsson Date: Sun, 16 Aug 2020 16:17:23 +0200 Subject: [PATCH 24/25] Fixes a warning about incomplete classpath --- native/zookeeper-server-start.Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/native/zookeeper-server-start.Dockerfile b/native/zookeeper-server-start.Dockerfile index 7fad0e4..dee5a61 100644 --- a/native/zookeeper-server-start.Dockerfile +++ b/native/zookeeper-server-start.Dockerfile @@ -17,7 +17,7 @@ FROM solsson/kafka:nativebase as native COPY --from=substitutions /workspace/target/*.jar /opt/kafka/libs/extensions/substitutions.jar COPY --from=extralibs /*.jar /opt/kafka/libs/extensions/ # For running without JettyAdminServer we're probably fine with only substitutions + slf4j + zokeeper+zookeeper-jute; see https://github.com/solsson/dockerfiles/pull/31 -ARG classpath=/opt/kafka/libs/extensions/substitutions.jar:/opt/kafka/libs/slf4j-api-1.7.30.jar:/opt/kafka/libs/extensions/slf4j-simple-1.7.30.jar:/opt/kafka/libs/extensions/log4j-over-slf4j-1.7.30.jar:/opt/kafka/libs/zookeeper-3.5.8.jar:/opt/kafka/libs/zookeeper-jute-3.5.8.jar:/opt/kafka/libs/jetty-server-9.4.24.v20191120.jar:/opt/kafka/libs/jetty-util-9.4.24.v20191120.jar:/opt/kafka/libs/jetty-io-9.4.24.v20191120.jar:/opt/kafka/libs/jetty-http-9.4.24.v20191120.jar:/opt/kafka/libs/jetty-servlet-9.4.24.v20191120.jar:/opt/kafka/libs/jetty-security-9.4.24.v20191120.jar:/opt/kafka/libs/netty-common-4.1.50.Final.jar:/opt/kafka/libs/netty-handler-4.1.50.Final.jar:/opt/kafka/libs/netty-buffer-4.1.50.Final.jar:/opt/kafka/libs/javax.servlet-api-3.1.0.jar +ARG classpath=/opt/kafka/libs/extensions/substitutions.jar:/opt/kafka/libs/slf4j-api-1.7.30.jar:/opt/kafka/libs/extensions/slf4j-simple-1.7.30.jar:/opt/kafka/libs/extensions/log4j-over-slf4j-1.7.30.jar:/opt/kafka/libs/zookeeper-3.5.8.jar:/opt/kafka/libs/zookeeper-jute-3.5.8.jar:/opt/kafka/libs/jetty-server-9.4.24.v20191120.jar:/opt/kafka/libs/jetty-util-9.4.24.v20191120.jar:/opt/kafka/libs/jetty-io-9.4.24.v20191120.jar:/opt/kafka/libs/jetty-http-9.4.24.v20191120.jar:/opt/kafka/libs/jetty-servlet-9.4.24.v20191120.jar:/opt/kafka/libs/jetty-security-9.4.24.v20191120.jar:/opt/kafka/libs/netty-common-4.1.50.Final.jar:/opt/kafka/libs/netty-handler-4.1.50.Final.jar:/opt/kafka/libs/netty-buffer-4.1.50.Final.jar:/opt/kafka/libs/javax.servlet-api-3.1.0.jar:/opt/kafka/libs/jackson-core-2.10.2.jar COPY configs/zookeeper-server-start /home/nonroot/native-config From 4187935c65fccc107d199d8dc7bc2165206d0b00 Mon Sep 17 00:00:00 2001 From: Staffan Olsson Date: Sun, 16 Aug 2020 20:45:39 +0200 Subject: [PATCH 25/25] Zero warnings about incomplete classpath --- native/zookeeper-server-start.Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/native/zookeeper-server-start.Dockerfile b/native/zookeeper-server-start.Dockerfile index dee5a61..50c010d 100644 --- a/native/zookeeper-server-start.Dockerfile +++ b/native/zookeeper-server-start.Dockerfile @@ -17,7 +17,7 @@ FROM solsson/kafka:nativebase as native COPY --from=substitutions /workspace/target/*.jar /opt/kafka/libs/extensions/substitutions.jar COPY --from=extralibs /*.jar /opt/kafka/libs/extensions/ # For running without JettyAdminServer we're probably fine with only substitutions + slf4j + zokeeper+zookeeper-jute; see https://github.com/solsson/dockerfiles/pull/31 -ARG classpath=/opt/kafka/libs/extensions/substitutions.jar:/opt/kafka/libs/slf4j-api-1.7.30.jar:/opt/kafka/libs/extensions/slf4j-simple-1.7.30.jar:/opt/kafka/libs/extensions/log4j-over-slf4j-1.7.30.jar:/opt/kafka/libs/zookeeper-3.5.8.jar:/opt/kafka/libs/zookeeper-jute-3.5.8.jar:/opt/kafka/libs/jetty-server-9.4.24.v20191120.jar:/opt/kafka/libs/jetty-util-9.4.24.v20191120.jar:/opt/kafka/libs/jetty-io-9.4.24.v20191120.jar:/opt/kafka/libs/jetty-http-9.4.24.v20191120.jar:/opt/kafka/libs/jetty-servlet-9.4.24.v20191120.jar:/opt/kafka/libs/jetty-security-9.4.24.v20191120.jar:/opt/kafka/libs/netty-common-4.1.50.Final.jar:/opt/kafka/libs/netty-handler-4.1.50.Final.jar:/opt/kafka/libs/netty-buffer-4.1.50.Final.jar:/opt/kafka/libs/javax.servlet-api-3.1.0.jar:/opt/kafka/libs/jackson-core-2.10.2.jar +ARG classpath=/opt/kafka/libs/extensions/substitutions.jar:/opt/kafka/libs/slf4j-api-1.7.30.jar:/opt/kafka/libs/extensions/slf4j-simple-1.7.30.jar:/opt/kafka/libs/extensions/log4j-over-slf4j-1.7.30.jar:/opt/kafka/libs/zookeeper-3.5.8.jar:/opt/kafka/libs/zookeeper-jute-3.5.8.jar:/opt/kafka/libs/jetty-server-9.4.24.v20191120.jar:/opt/kafka/libs/jetty-util-9.4.24.v20191120.jar:/opt/kafka/libs/jetty-io-9.4.24.v20191120.jar:/opt/kafka/libs/jetty-http-9.4.24.v20191120.jar:/opt/kafka/libs/jetty-servlet-9.4.24.v20191120.jar:/opt/kafka/libs/jetty-security-9.4.24.v20191120.jar:/opt/kafka/libs/netty-common-4.1.50.Final.jar:/opt/kafka/libs/netty-handler-4.1.50.Final.jar:/opt/kafka/libs/netty-buffer-4.1.50.Final.jar:/opt/kafka/libs/javax.servlet-api-3.1.0.jar:/opt/kafka/libs/jackson-core-2.10.2.jar:/opt/kafka/libs/jackson-databind-2.10.2.jar:/opt/kafka/libs/jackson-annotations-2.10.2.jar COPY configs/zookeeper-server-start /home/nonroot/native-config