Skip to content

Commit 498deb6

Browse files
committed
KAFKA-18773: Migrate the log4j1 config to log4j 2 for native image and README
Signed-off-by: PoAn Yang <[email protected]>
1 parent 53543bc commit 498deb6

12 files changed

+1434
-57
lines changed

build.gradle

-1
Original file line numberDiff line numberDiff line change
@@ -1072,7 +1072,6 @@ project(':core') {
10721072
implementation libs.argparse4j
10731073
implementation libs.commonsValidator
10741074
implementation libs.jacksonDatabind
1075-
implementation libs.jacksonModuleScala
10761075
implementation libs.jacksonDataformatCsv
10771076
implementation libs.jacksonJDK8Datatypes
10781077
implementation libs.jacksonDatabindYaml

core/src/main/scala/kafka/docker/KafkaDockerWrapper.scala

+1-5
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ object KafkaDockerWrapper extends Logging {
110110
case Some(str) => str
111111
case None => throw new RuntimeException("CLUSTER_ID environment variable is not set.")
112112
}
113-
Array("format", "--cluster-id=" + clusterId, "-c", s"${configsPath.toString}/server.properties")
113+
Array("format", "--cluster-id=" + clusterId, "-c", s"${configsPath.toString}/server.properties", "--standalone")
114114
}
115115

116116
private def prepareConfigs(defaultConfigsPath: Path, mountedConfigsPath: Path, finalConfigsPath: Path): Unit = {
@@ -250,10 +250,6 @@ object KafkaDockerWrapper extends Logging {
250250
}
251251
val config = yaml.getConfiguration
252252

253-
if (config == null && loggerFromEnv.isEmpty && rootOption.isEmpty) {
254-
return
255-
}
256-
257253
if (config == null) {
258254
generateDefaultLog4jConfig(loggerFromEnv, rootOption, filepath, mapper)
259255
} else {

docker/examples/README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,11 @@ It is also possible to use the input file to have a common set of configurations
4848

4949
- To provide configs to log4j property files, following points should be considered:
5050
- log4j properties provided via environment variables will be appended to the default properties file (log4j properties files bundled with Kafka).
51-
- `KAFKA_LOG4J_ROOT_LOGLEVEL` can be provided to set the value of `log4j.rootLogger` in log4j.properties and `tools-log4j.properties`.
52-
- log4j loggers can be added to log4j.properties by setting them in `KAFKA_LOG4J_LOGGERS` environment variable in a single comma separated string.
51+
- `KAFKA_LOG4J_ROOT_LOGLEVEL` can be provided to set the value of `log4j.rootLogger` in `log4j2.yaml` and `tools-log4j2.yaml`.
52+
- log4j loggers can be added to `log4j2.yaml` by setting them in `KAFKA_LOG4J_LOGGERS` environment variable in a single comma separated string.
5353
- Example:
5454
- Assuming that `KAFKA_LOG4J_LOGGERS='property1=value1,property2=value2'` environment variable is provided to Docker container.
55-
- `log4j.logger.property1=value1` and `log4j.logger.property2=value2` will be added to the `log4j.properties` file inside Docker container.
55+
- `log4j.logger.property1=value1` and `log4j.logger.property2=value2` will be added to the `log4j2.yaml` file inside Docker container.
5656

5757
Running in SSL mode
5858
-------------------

docker/native/README.md

+5
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ These metadata configs are provided in the `native-image-configs` directory.
1515
GraalVM provide an option to create these configs automatically by running the application normally with the [native-image agent](https://www.graalvm.org/latest/reference-manual/native-image/metadata/AutomaticMetadataCollection/) attached.
1616
The configs in the `native-image-configs` directory are generated by running existing Apache Kafka System Tests(using GraalVM JIT and attaching the native-image agent to the process) as they are quite exhaustive.
1717

18+
To update reachability metadata, users can set following environment variable and run related jar files. New metadata configs will be generated in the `native-image-configs` directory.
19+
```bash
20+
export JAVA_TOOL_OPTIONS="-agentlib:native-image-agent=config-merge-dir=/path/to/kafka/docker/native/native-image-configs"
21+
```
22+
1823
## Limitations of Native Apache Kafka executable
1924
- Dynamic Features: For any new dynamic feature added or modified in Apache Kafka, the corresponding metadata configurations must be added or updated in the `native-image-configs`. As of now these configs are static.
2025
- Runtime Jars: Native Kafka Executable does not support capabilities that require a new runtime jar provided by the user, as the jar's information is not available during build time. In such cases, a new native Kafka binary must be built, including that jar in the classpath during the build.

docker/native/launch

+2-3
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,11 @@ fi
4141
result=$(/opt/kafka/kafka.Kafka setup \
4242
--default-configs-dir /etc/kafka/docker \
4343
--mounted-configs-dir /mnt/shared/config \
44-
--final-configs-dir /opt/kafka/config \
45-
-Dlog4j.configuration=file:/opt/kafka/config/tools-log4j.properties 2>&1) || \
44+
--final-configs-dir /opt/kafka/config 2>&1) || \
4645
echo $result | grep -i "already formatted" || \
4746
{ echo $result && (exit 1) }
4847

4948
echo "WARNING: THIS IS AN EXPERIMENTAL DOCKER IMAGE RECOMMENDED FOR LOCAL TESTING AND DEVELOPMENT PURPOSES."
5049

51-
KAFKA_LOG4J_CMD_OPTS="-Dkafka.logs.dir=/opt/kafka/logs/ -Dlog4j.configuration=file:/opt/kafka/config/log4j.properties"
50+
KAFKA_LOG4J_CMD_OPTS="-Dkafka.logs.dir=/opt/kafka/logs/ -Dlog4j2.configurationFile=file:/opt/kafka/config/log4j2.yaml"
5251
exec /opt/kafka/kafka.Kafka start --config /opt/kafka/config/server.properties $KAFKA_LOG4J_CMD_OPTS $KAFKA_JMX_OPTS ${KAFKA_OPTS-}

docker/native/native-image-configs/jni-config.json

+21-1
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,32 @@
2424
{
2525
"name":"java.lang.OutOfMemoryError"
2626
},
27+
{
28+
"name":"java.lang.String",
29+
"methods":[{"name":"lastIndexOf","parameterTypes":["int"] }, {"name":"substring","parameterTypes":["int"] }]
30+
},
31+
{
32+
"name":"java.lang.System",
33+
"methods":[{"name":"getProperty","parameterTypes":["java.lang.String"] }, {"name":"setProperty","parameterTypes":["java.lang.String","java.lang.String"] }]
34+
},
35+
{
36+
"name":"java.lang.VersionProps",
37+
"methods":[{"name":"print","parameterTypes":["boolean"] }]
38+
},
2739
{
2840
"name":"java.util.Arrays",
2941
"methods":[{"name":"asList","parameterTypes":["java.lang.Object[]"] }]
3042
},
43+
{
44+
"name":"kafka.Kafka",
45+
"methods":[{"name":"main","parameterTypes":["java.lang.String[]"] }]
46+
},
47+
{
48+
"name":"kafka.tools.StorageTool",
49+
"methods":[{"name":"main","parameterTypes":["java.lang.String[]"] }]
50+
},
3151
{
3252
"name":"sun.management.VMManagementImpl",
3353
"fields":[{"name":"compTimeMonitoringSupport"}, {"name":"currentThreadCpuTimeSupport"}, {"name":"objectMonitorUsageSupport"}, {"name":"otherThreadCpuTimeSupport"}, {"name":"remoteDiagnosticCommandsSupport"}, {"name":"synchronizerUsageSupport"}, {"name":"threadAllocatedMemorySupport"}, {"name":"threadContentionMonitoringSupport"}]
3454
}
35-
]
55+
]

docker/native/native-image-configs/predefined-classes-config.json

+1
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55
]
66
}
77
]
8+

docker/native/native-image-configs/proxy-config.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
{
33
"interfaces":["sun.misc.SignalHandler"]
44
}
5-
]
5+
]

0 commit comments

Comments
 (0)