Skip to content

Commit 0b42c2c

Browse files
Xtansiadblockandrross
authored
Bump org.apache.logging.log4j:log4j-core from 2.17.1 to 2.20.0 (opensearch-project#8307)
- Use log4j's PluginProcessor annotation processor for plugin discovery - Remove usage of deprecated explicit plugin discovery - Pass through Configuration in OpenSearchJsonLayout to work around https://issues.apache.org/jira/browse/LOG4J2-3562 Signed-off-by: Thomas <tsfarr@amazon.com> Signed-off-by: Daniel (dB.) Doubrovkine <dblock@amazon.com> Signed-off-by: Thomas Farr <tsfarr@amazon.com> Co-authored-by: Daniel (dB.) Doubrovkine <dblock@amazon.com> Co-authored-by: Andrew Ross <andrross@amazon.com>
1 parent 4ccbf9d commit 0b42c2c

31 files changed

+57
-52
lines changed

.gitignore

+4-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ out/
1717
benchmarks/src/main/generated/*
1818
benchmarks/bin/*
1919
benchmarks/build-eclipse-default/*
20+
server/bin/*
21+
server/build-eclipse-default/*
22+
test/framework/build-eclipse-default/*
2023

2124
# eclipse files
2225
.project
@@ -61,4 +64,4 @@ testfixtures_shared/
6164
.ci/jobs/
6265

6366
# build files generated
64-
doc-tools/missing-doclet/bin/
67+
doc-tools/missing-doclet/bin/

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
143143
- Bump `com.google.jimfs:jimfs` from 1.2 to 1.3.0 (#8577, #8571)
144144
- Bump `com.networknt:json-schema-validator` from 1.0.85 to 1.0.86 ([#8573](https://github.com/opensearch-project/OpenSearch/pull/8573))
145145
- Bump `com.google.cloud:google-cloud-core-http` from 2.17.0 to 2.21.0 ([#8586](https://github.com/opensearch-project/OpenSearch/pull/8586))
146+
- Bump `org.apache.logging.log4j:log4j-core` from 2.17.1 to 2.20.0 ([#8307](https://github.com/opensearch-project/OpenSearch/pull/8307))
146147

147148
### Changed
148149
- Replace jboss-annotations-api_1.2_spec with jakarta.annotation-api ([#7836](https://github.com/opensearch-project/OpenSearch/pull/7836))

buildSrc/src/testKit/thirdPartyAudit/sample_jars/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ repositories {
1616
mavenCentral()
1717
}
1818
dependencies {
19-
implementation 'org.apache.logging.log4j:log4j-core:2.20.0'
19+
implementation "org.apache.logging.log4j:log4j-core:2.20.0"
2020
}
2121

2222
["0.0.1", "0.0.2"].forEach { v ->

buildSrc/version.properties

+1-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ jackson_databind = 2.15.2
1414
snakeyaml = 2.0
1515
icu4j = 70.1
1616
supercsv = 2.4.0
17-
# Update to 2.17.2+ is breaking OpenSearchJsonLayout (see https://issues.apache.org/jira/browse/LOG4J2-3562)
18-
log4j = 2.17.1
17+
log4j = 2.20.0
1918
slf4j = 1.7.36
2019
asm = 9.5
2120
jettison = 1.5.4

libs/core/licenses/log4j-api-2.17.1.jar.sha1

-1
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1fe6082e660daf07c689a89c94dc0f49c26b44bb

plugins/discovery-azure-classic/licenses/log4j-1.2-api-2.17.1.jar.sha1

-1
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
689151374756cb809cb029f2501015bdc7733179

plugins/discovery-ec2/licenses/log4j-1.2-api-2.17.1.jar.sha1

-1
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
689151374756cb809cb029f2501015bdc7733179

plugins/discovery-gce/licenses/log4j-1.2-api-2.17.1.jar.sha1

-1
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
689151374756cb809cb029f2501015bdc7733179

plugins/repository-gcs/licenses/log4j-1.2-api-2.17.1.jar.sha1

-1
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
689151374756cb809cb029f2501015bdc7733179

plugins/repository-hdfs/licenses/log4j-slf4j-impl-2.17.1.jar.sha1

-1
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
7ab4f082fd162f60afcaf2b8744a3d959feab3e8

plugins/repository-s3/licenses/log4j-1.2-api-2.17.1.jar.sha1

-1
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
689151374756cb809cb029f2501015bdc7733179

qa/wildfly/build.gradle

+1-2
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,10 @@ dependencies {
5858
api "com.fasterxml.jackson.jakarta.rs:jackson-jakarta-rs-base:${versions.jackson}"
5959
api "com.fasterxml.jackson.jakarta.rs:jackson-jakarta-rs-json-provider:${versions.jackson}"
6060
api "com.github.fge:json-patch:1.9"
61-
api "org.apache.logging.log4j:log4j-api:${versions.log4j}"
62-
api "org.apache.logging.log4j:log4j-core:${versions.log4j}"
6361
api(project(path: ':client:rest-high-level')) {
6462
exclude module: 'jakarta.annotation-api'
6563
}
64+
testImplementation "org.apache.logging.log4j:log4j-slf4j-impl:${versions.log4j}"
6665
testImplementation(project(':test:framework')) {
6766
exclude module: 'jakarta.annotation-api'
6867
}

qa/wildfly/src/main/resources/log4j2.properties

-20
This file was deleted.

server/build.gradle

+5
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ dependencies {
146146
api "org.apache.logging.log4j:log4j-api:${versions.log4j}"
147147
api "org.apache.logging.log4j:log4j-jul:${versions.log4j}"
148148
api "org.apache.logging.log4j:log4j-core:${versions.log4j}", optional
149+
annotationProcessor "org.apache.logging.log4j:log4j-core:${versions.log4j}"
149150

150151
// jna
151152
api "net.java.dev.jna:jna:${versions.jna}"
@@ -175,6 +176,10 @@ tasks.withType(JavaCompile).configureEach {
175176
options.compilerArgs -= '-Xlint:unchecked'
176177
}
177178

179+
compileJava {
180+
options.compilerArgs += ['-processor', 'org.apache.logging.log4j.core.config.plugins.processor.PluginProcessor']
181+
}
182+
178183
tasks.named("internalClusterTest").configure {
179184
// TODO: these run faster with C2 only because they run for so, so long
180185
jvmArgs -= '-XX:TieredStopAtLevel=1'

server/licenses/log4j-api-2.17.1.jar.sha1

-1
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1fe6082e660daf07c689a89c94dc0f49c26b44bb

server/licenses/log4j-core-2.17.1.jar.sha1

-1
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
eb2a9a47b1396e00b5eee1264296729a70565cc0

server/licenses/log4j-jul-2.17.1.jar.sha1

-1
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
8170e6118eac1ab332046c179718a0f107f688e1

server/src/main/java/org/opensearch/common/logging/LogConfigurator.java

-10
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
import org.apache.logging.log4j.core.config.builder.api.ConfigurationBuilderFactory;
4242
import org.apache.logging.log4j.core.config.builder.impl.BuiltConfiguration;
4343
import org.apache.logging.log4j.core.config.composite.CompositeConfiguration;
44-
import org.apache.logging.log4j.core.config.plugins.util.PluginManager;
4544
import org.apache.logging.log4j.core.config.properties.PropertiesConfiguration;
4645
import org.apache.logging.log4j.core.config.properties.PropertiesConfigurationFactory;
4746
import org.apache.logging.log4j.status.StatusConsoleListener;
@@ -140,13 +139,6 @@ public static void configure(final Environment environment) throws IOException,
140139
configure(environment.settings(), environment.configDir(), environment.logsDir());
141140
}
142141

143-
/**
144-
* Load logging plugins so we can have {@code node_name} in the pattern.
145-
*/
146-
public static void loadLog4jPlugins() {
147-
PluginManager.addPackage(LogConfigurator.class.getPackage().getName());
148-
}
149-
150142
/**
151143
* Sets the node name. This is called before logging is configured if the
152144
* node name is set in opensearch.yml. Otherwise it is called as soon
@@ -172,8 +164,6 @@ private static void configure(final Settings settings, final Path configsPath, f
172164
Objects.requireNonNull(configsPath);
173165
Objects.requireNonNull(logsPath);
174166

175-
loadLog4jPlugins();
176-
177167
setLogConfigurationSystemProperty(logsPath, settings);
178168
// we initialize the status logger immediately otherwise Log4j will complain when we try to get the context
179169
configureStatusLogger();

server/src/main/java/org/opensearch/common/logging/OpenSearchJsonLayout.java

+31-4
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,12 @@
3434

3535
import org.apache.logging.log4j.core.Layout;
3636
import org.apache.logging.log4j.core.LogEvent;
37+
import org.apache.logging.log4j.core.config.Configuration;
3738
import org.apache.logging.log4j.core.config.Node;
3839
import org.apache.logging.log4j.core.config.plugins.Plugin;
3940
import org.apache.logging.log4j.core.config.plugins.PluginAttribute;
4041
import org.apache.logging.log4j.core.config.plugins.PluginBuilderFactory;
42+
import org.apache.logging.log4j.core.config.plugins.PluginConfiguration;
4143
import org.apache.logging.log4j.core.config.plugins.PluginFactory;
4244
import org.apache.logging.log4j.core.layout.AbstractStringLayout;
4345
import org.apache.logging.log4j.core.layout.ByteBufferDestination;
@@ -94,11 +96,18 @@ public class OpenSearchJsonLayout extends AbstractStringLayout {
9496

9597
private final PatternLayout patternLayout;
9698

97-
protected OpenSearchJsonLayout(String typeName, Charset charset, String[] opensearchMessageFields, int maxMessageLength) {
99+
protected OpenSearchJsonLayout(
100+
String typeName,
101+
Charset charset,
102+
String[] opensearchMessageFields,
103+
int maxMessageLength,
104+
Configuration configuration
105+
) {
98106
super(charset);
99107
this.patternLayout = PatternLayout.newBuilder()
100108
.withPattern(pattern(typeName, opensearchMessageFields, maxMessageLength))
101109
.withAlwaysWriteExceptions(false)
110+
.withConfiguration(configuration)
102111
.build();
103112
}
104113

@@ -173,8 +182,14 @@ private String inQuotes(String s) {
173182
}
174183

175184
@PluginFactory
176-
public static OpenSearchJsonLayout createLayout(String type, Charset charset, String[] opensearchmessagefields, int maxMessageLength) {
177-
return new OpenSearchJsonLayout(type, charset, opensearchmessagefields, maxMessageLength);
185+
public static OpenSearchJsonLayout createLayout(
186+
String type,
187+
Charset charset,
188+
String[] opensearchmessagefields,
189+
int maxMessageLength,
190+
Configuration configuration
191+
) {
192+
return new OpenSearchJsonLayout(type, charset, opensearchmessagefields, maxMessageLength, configuration);
178193
}
179194

180195
PatternLayout getPatternLayout() {
@@ -202,6 +217,9 @@ public static class Builder<B extends OpenSearchJsonLayout.Builder<B>> extends A
202217
@PluginAttribute(value = "maxmessagelength", defaultInt = 10000)
203218
private int maxMessageLength;
204219

220+
@PluginConfiguration
221+
private Configuration configuration;
222+
205223
public Builder() {
206224
setCharset(StandardCharsets.UTF_8);
207225
setMaxMessageLength(10000);
@@ -210,7 +228,7 @@ public Builder() {
210228
@Override
211229
public OpenSearchJsonLayout build() {
212230
String[] split = Strings.isNullOrEmpty(opensearchMessageFields) ? new String[] {} : opensearchMessageFields.split(",");
213-
return OpenSearchJsonLayout.createLayout(type, charset, split, maxMessageLength);
231+
return OpenSearchJsonLayout.createLayout(type, charset, split, maxMessageLength, configuration);
214232
}
215233

216234
public Charset getCharset() {
@@ -248,6 +266,15 @@ public B setMaxMessageLength(final int maxMessageLength) {
248266
this.maxMessageLength = maxMessageLength;
249267
return asBuilder();
250268
}
269+
270+
public Configuration getConfiguration() {
271+
return configuration;
272+
}
273+
274+
public B setConfiguration(final Configuration configuration) {
275+
this.configuration = configuration;
276+
return asBuilder();
277+
}
251278
}
252279

253280
@PluginBuilderFactory

test/framework/build.gradle

+3
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,14 @@ dependencies {
4949
api "org.mockito:mockito-core:${versions.mockito}"
5050
api "net.bytebuddy:byte-buddy:${versions.bytebuddy}"
5151
api "org.objenesis:objenesis:${versions.objenesis}"
52+
53+
annotationProcessor "org.apache.logging.log4j:log4j-core:${versions.log4j}"
5254
}
5355

5456
compileJava.options.compilerArgs -= '-Xlint:cast'
5557
compileJava.options.compilerArgs -= '-Xlint:rawtypes'
5658
compileJava.options.compilerArgs -= '-Xlint:unchecked'
59+
compileJava.options.compilerArgs += ['-processor', 'org.apache.logging.log4j.core.config.plugins.processor.PluginProcessor']
5760
compileTestJava.options.compilerArgs -= '-Xlint:rawtypes'
5861

5962
// the main files are actually test files, so use the appropriate forbidden api sigs

test/framework/src/main/java/org/opensearch/test/OpenSearchTestCase.java

-2
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@
8383
import org.opensearch.common.logging.DeprecatedMessage;
8484
import org.opensearch.common.logging.HeaderWarning;
8585
import org.opensearch.common.logging.HeaderWarningAppender;
86-
import org.opensearch.common.logging.LogConfigurator;
8786
import org.opensearch.common.logging.Loggers;
8887
import org.opensearch.common.settings.Setting;
8988
import org.opensearch.common.settings.Settings;
@@ -239,7 +238,6 @@ public void tearDown() throws Exception {
239238
static {
240239
TEST_WORKER_VM_ID = System.getProperty(TEST_WORKER_SYS_PROPERTY, DEFAULT_TEST_WORKER_ID);
241240
setTestSysProps();
242-
LogConfigurator.loadLog4jPlugins();
243241

244242
String leakLoggerName = "io.netty.util.ResourceLeakDetector";
245243
Logger leakLogger = LogManager.getLogger(leakLoggerName);

0 commit comments

Comments
 (0)