-
Notifications
You must be signed in to change notification settings - Fork 25.5k
Upgrade to log4j 2.25.1 #132166
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
base: main
Are you sure you want to change the base?
Upgrade to log4j 2.25.1 #132166
Conversation
Pinging @elastic/es-core-infra (Team:Core/Infra) |
@elasticsearchmachine test this please |
@elasticmachine test this please |
Looks like this is suffering from apache/logging-log4j2#3437 |
Updating this having merged #132238 |
@breskeby is looking into the transitive dependency issue mentioned above, this needs further fixes / improvements in our build to be properly handled. |
Thanks for flagging this potential dependency concern. |
@Rassyan Can you rebase against latest master? I think some thirdparty check tasks will start failing with the update that probably need to be adjusted too. You should be able to reproduce those by running |
Hi @breskeby, Thanks for the pointer. I've rebased onto the latest main (which includes your #134169) and now encounter a dependency resolution failure when running ./gradlew precommit, even before applying my Log4j upgrade changes. The error occurs in the :benchmarks:compileJava configuration:
This suggests the new component metadata rules might be conflicting with the benchmarks project's dependency graph. Could this be the kind of third-party check failure you anticipated? I'm not sure what adjustments are needed here, as the issue seems related to the new dependency resolution setup. Could you please take a look when you have a moment? Thanks! |
can you run the build with --stacktrace? and share the output (maybe a bulid scan or share directly here). you likely need add the transitive provided dependencies now to the verification file in gradle/*. you can do that automatically by running the |
This comment was marked as outdated.
This comment was marked as outdated.
Unfortunately there's more issues, our use of package scanning for log4j2 plugins causes deprecation warnings that fail tests.
https://logging.apache.org/log4j/2.x/faq.html#package-scanning I gave this a quick look trying to migrate to the annotation processor, but didn't get it to work without having to dig deeper. diff --git a/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/ElasticsearchJavaBasePlugin.java b/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/ElasticsearchJavaBasePlugin.java
index 4cedd69d9b7..470eb283e80 100644
--- a/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/ElasticsearchJavaBasePlugin.java
+++ b/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/ElasticsearchJavaBasePlugin.java
@@ -98,7 +98,7 @@ public class ElasticsearchJavaBasePlugin implements Plugin<Project> {
// TODO Discuss moving compileOptions.getCompilerArgs() to use provider api with Gradle team.
List<String> compilerArgs = compileOptions.getCompilerArgs();
compilerArgs.add("-Werror");
- compilerArgs.add("-Xlint:all,-path,-serial,-options,-deprecation,-try,-removal");
+ compilerArgs.add("-Xlint:all,-path,-serial,-options,-deprecation,-try,-removal,-processing");
compilerArgs.add("-Xdoclint:all");
compilerArgs.add("-Xdoclint:-missing");
compileOptions.setEncoding("UTF-8");
diff --git a/server/build.gradle b/server/build.gradle
index 2bcd6e5322d..69b42635727 100644
--- a/server/build.gradle
+++ b/server/build.gradle
@@ -67,6 +67,10 @@ dependencies {
api "org.apache.logging.log4j:log4j-api:${versions.log4j}"
api "org.apache.logging.log4j:log4j-core:${versions.log4j}"
+ annotationProcessor("org.apache.logging.log4j:log4j-api:${versions.log4j}")
+ annotationProcessor("org.apache.logging.log4j:log4j-core:${versions.log4j}")
+
+
// access to native functions
implementation project(':libs:native')
@@ -85,6 +89,12 @@ dependencies {
internalClusterTestImplementation(project(':modules:data-streams'))
}
+compileJava {
+ // annotation processor to generate the Log4j2 plugin descriptors
+ options.compilerArgs << '-Alog4j.graalvm.groupId=org.elasticsearch'
+ options.compilerArgs << '-Alog4j.graalvm.artifactId=elasticsearch'
+}
+
spotless {
java {
targetExclude "src/main/java/org/elasticsearch/index/IndexVersion.java"
diff --git a/server/src/main/java/org/elasticsearch/common/logging/LogConfigurator.java b/server/src/main/java/org/elasticsearch/common/logging/LogConfigurator.java
index 134f7746ba6..ebd2e4fa4c0 100644
--- a/server/src/main/java/org/elasticsearch/common/logging/LogConfigurator.java
+++ b/server/src/main/java/org/elasticsearch/common/logging/LogConfigurator.java
@@ -154,7 +154,7 @@ public class LogConfigurator {
* Load logging plugins so we can have {@code node_name} in the pattern.
*/
public static void loadLog4jPlugins() {
- PluginManager.addPackage(LogConfigurator.class.getPackage().getName());
+ //PluginManager.addPackage(LogConfigurator.class.getPackage().getName());
}
/** |
Hi @mosche, Thanks for the detailed explanation about the Log4j2 package scanning deprecation and its impact on the tests. I understand that the recommended long-term solution is to migrate to the annotation processor for plugin registration. However, as you noted, that requires deeper changes to the build setup. As a near-term workaround to address the failing tests caused by the deprecation warning, I propose suppressing this specific warning message in our test framework's allowed list. This aligns with how we handle other similar Log4j warnings (like the JNDI and JMX lookup warnings). I've tested the following change locally, and it successfully prevents the tests from failing due to this warning: diff --git a/test/framework/src/main/java/org/elasticsearch/test/ESTestCase.java b/test/framework/src/main/java/org/elasticsearch/test/ESTestCase.java
--- a/test/framework/src/main/java/org/elasticsearch/test/ESTestCase.java (revision c332dca5e16cced6f0bc1918a834066059bb0545)
+++ b/test/framework/src/main/java/org/elasticsearch/test/ESTestCase.java (date 1758167624811)
@@ -823,7 +823,8 @@
"JNDI lookup class is not available because this JRE does not support JNDI. "
+ "JNDI string lookups will not be available, continuing configuration.",
"JMX runtime input lookup class is not available because this JRE does not support JMX. "
- + "JMX lookups will not be available, continuing configuration. "
+ + "JMX lookups will not be available, continuing configuration. ",
+ "The use of package scanning to locate Log4j plugins is deprecated."
);
// separate method so that this can be checked again after suite scoped cluster is shut down
@@ -839,7 +840,8 @@
anyOf(
emptyCollectionOf(String.class),
contains(startsWith(LOG_4J_MSG_PREFIXES.get(0)), startsWith(LOG_4J_MSG_PREFIXES.get(1))),
- contains(startsWith(LOG_4J_MSG_PREFIXES.get(1)))
+ contains(startsWith(LOG_4J_MSG_PREFIXES.get(1))),
+ contains(startsWith(LOG_4J_MSG_PREFIXES.get(2)))
)
);
} finally { Given that the deprecated addPackage() method is only scheduled for removal in Log4j 3.0 (as per LOG4J2-3644), suppressing this warning in tests seems like a safe and pragmatic step for now. It unblocks development and CI while we plan the migration to the annotation processor. Would you be open to accepting this change as a temporary fix? We can then track the migration to the annotation processor (Log4j2Plugins.dat) as a separate issue. Let me know your thoughts. |
Thanks @Rassyan, that's probably the best way forward without significantly increasing the scope of this! |
Thanks @mosche! 🙌 Just pushed the change. Really appreciate your guidance through this - it's been a great learning experience collaborating with you. Excited to see the test results! 🚀 |
@elasticmachine test this please |
@Rassyan could you run the test suites below, there's some more warnings.
Specifically |
Hi @mosche, I dug into In both versions, the warning
This level shift in 2.19.0 breaks I’m unsure whether we should suppress these warnings or address the listener behavior directly. Would you have any advice on how you’d like to proceed? I’m happy to help implement the right fix. Attached:
![]() ![]() ![]() |
That's a great find, thanks for digging into that! |
@elasticmachine test this please |
@elasticmachine test this please |
@elasticmachine test this please |
@elasticmachine test this please |
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.
LGTM
@elasticmachine test this please |
CI surfaced a log4j2 concurrency bug |
Upgrade to log4j 2.25.1
closes #132035