-
Notifications
You must be signed in to change notification settings - Fork 14k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
KAFKA-9366: Upgrade log4j to log4j2 #17373
base: trunk
Are you sure you want to change the base?
Conversation
This is the initial version. I'd like to run it on CI first. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for tackling this @frankvicky.
Is it really necessary to rename the log4j config files? The KIP mentions a system property that allows us to load log4j.properties files https://cwiki.apache.org/confluence/pages/viewpage.action?pageId=158870552#KIP653:Upgradelog4jtolog4j2-Compatibility,Deprecation,andMigrationPlan
I could understand migrating our internal log4j configs for tests and such, but I think we should avoid forcing a change in our production configs.
I also see that this page mentions a log4j to log4j2 bridge https://logging.apache.org/log4j/2.x/migrate-from-log4j1.html. Would that help us at all?
build.gradle
Outdated
testRuntimeOnly libs.slf4jLog4j2 | ||
testRuntimeOnly libs.junitPlatformLanucher |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These (and other similar testRuntimeOnly
) should be put into the runtimeTestLibs
definition
build.gradle
Outdated
@@ -2596,6 +2626,7 @@ project(':streams') { | |||
implementation libs.slf4jApi | |||
implementation libs.jacksonAnnotations | |||
implementation libs.jacksonDatabind | |||
implementation libs.bndlib |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's this dependency for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @mumrah
I add this to fix the warning during build:
/home/frankvicky/.gradle/caches/modules-2/files-2.1/org.apache.logging.log4j/log4j-api/2.24.1/7ebeb12c20606373005af4232cd0ecca72613dda/log4j-api-2.24.1.jar(/org/apache/logging/log4j/Level.class): warning: Cannot find annotation method 'value()' in type 'BaselineIgnore': class file for aQute.bnd.annotation.baseline.BaselineIgnore not found
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not convinced we need that dependency. Also it seems to complain about an annotation so at least we should not need it at runtime, so we should not include it in our distribution package. Currently it's included in the artifact generated by releaseTarGz
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair enough, I will try to solve this one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The BND annotations are intentionally in the provided
Maven scope of all Log4j artifacts, so that these annotations with CLASS
retention do not end up in the runtime classpath. You can do the same and add them as compileOnly
in Gradle.
The compiler warnings should disappear once JDK-8342833 is fixed.
Untile then we will remove the outdated ones (see apache/logging-log4j2#3133) in the next Log4j release, which should remove the warning on Level
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the information.
I have already changed its scope to compile time.
PTAL 😄
@@ -22,7 +22,7 @@ fi | |||
base_dir=$(dirname $0) | |||
|
|||
if [ "x$KAFKA_LOG4J_OPTS" = "x" ]; then | |||
export KAFKA_LOG4J_OPTS="-Dlog4j.configuration=file:$base_dir/../config/log4j.properties" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could break some existing Kafka installations. If users are extracting in place or copying previous config files to a new installation directory, they will be expecting the log4j.properties to still work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The switch from the legacy to the new configuration format can be based on the presence of specific files:
if [ -f "$base_dir/../config/log4j.properties" ]; then
echo DEPRECATED: Using Log4j 1.x configuration file \$KAFKA_HOME/config/log4j.properties >&2
echo To use a Log4j 2.x configuration, create a \$KAFKA_HOME/config/log4j2.xml file and remove the Log4j 1.x configration. >&2
echo See https://logging.apache.org/log4j/2.x/migrate-from-log4j1.html#Log4j2ConfigurationFormat for details about Log4j configuration file migration. >&2
export KAFKA_LOG4J_OPTS="-Dlog4j.configuration=file:$base_dir/../config/log4j.properties"
elif [ -f "$base_dir/../config/log4j2.xml" ]; then
export KAFKA_LOG4J_OPTS="-Dlog4j2.configurationFile=$base_dir/../config/log4j2.xml"
fi
Hello @mumrah |
0ecc326
to
9fc1203
Compare
0c1e6bf
to
4b722a5
Compare
4b722a5
to
7200b43
Compare
revert unnecessary change
will roger that :) |
dcc2ac1
to
5e1eaf5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@frankvicky thanks for this patch. please check my latest comments to fix e2e
tests/kafkatest/services/connect.py
Outdated
@@ -364,7 +364,7 @@ def start_node(self, node, **kwargs): | |||
if self.external_config_template_func: | |||
node.account.create_file(self.EXTERNAL_CONFIGS_FILE, self.external_config_template_func(node)) | |||
node.account.create_file(self.CONFIG_FILE, self.config_template_func(node)) | |||
node.account.create_file(self.LOG4J_CONFIG_FILE, self.render('connect_log4j.properties', log_file=self.LOG_FILE)) | |||
node.account.create_file(self.LOG4J_CONFIG_FILE, self.render('connect_log4j2.properties', log_file=self.LOG_FILE)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in the e2e we could run kafak on different version, so we must check the version before applying the config file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it seems connect e2e does not run different version for workers, so you can just change them to connect_log4j2.yaml
. However, please change the -Dlog4j.configuration
to -Dlog4j2.configurationFile
tests/kafkatest/services/connect.py
Outdated
@@ -421,7 +421,7 @@ def start_node(self, node, **kwargs): | |||
if self.external_config_template_func: | |||
node.account.create_file(self.EXTERNAL_CONFIGS_FILE, self.external_config_template_func(node)) | |||
node.account.create_file(self.CONFIG_FILE, self.config_template_func(node)) | |||
node.account.create_file(self.LOG4J_CONFIG_FILE, self.render('connect_log4j.properties', log_file=self.LOG_FILE)) | |||
node.account.create_file(self.LOG4J_CONFIG_FILE, self.render('connect_log4j2.properties', log_file=self.LOG_FILE)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
@@ -874,7 +874,7 @@ def start_node(self, node, timeout_sec=60, **kwargs): | |||
self.logger.info("kafka.properties:") | |||
self.logger.info(prop_file) | |||
node.account.create_file(KafkaService.CONFIG_FILE, prop_file) | |||
node.account.create_file(self.LOG4J_CONFIG, self.render('log4j.properties', log_dir=KafkaService.OPERATIONAL_LOG_DIR)) | |||
node.account.create_file(self.LOG4J_CONFIG, self.render('log4j2.properties', log_dir=KafkaService.OPERATIONAL_LOG_DIR)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please noted that the previous version should use -Dlog4j.configuration
and trunk version should use -Dlog4j2.configurationFile
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems that tons of code needs to apply this change.
I will prepare it asap.
Yes you totally deserve being marked as a co-author. Thanks! |
8505f70
to
a1c2294
Compare
da3045d
to
f3a68e1
Compare
I'm having issues with the latest code (f3a68e1).
Running
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@frankvicky please double check the yaml format. I leave some comments about the incorrect format.
immediateFlush: true | ||
PatternLayout: | ||
pattern: "${logPattern}" | ||
TimeBasedTriggeringPolicy: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Policies:
TimeBasedTriggeringPolicy:
modulate: true
interval: 1
|
||
RollingFile: | ||
- name: FILE | ||
fileName: {{ log_file }} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please add filePattern
config/log4j2.yaml
Outdated
Polices: | ||
TimeBasedTriggeringPolicy: | ||
modulate: true | ||
interval: 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since there is only one triggering policy, there is no need to wrap it in a Policies
wrapper.
BTW: there is a typo in the plugin name: it should be Policies
, instead of Polices
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for information 😄
a85ddc0
to
bbed45a
Compare
bbed45a
to
40a80f4
Compare
e6a2fd8
to
e488b0a
Compare
JIRA: KAFKA-9366
Committer Checklist (excluded from commit message)