Skip to content

Commit 4a62494

Browse files
Xtansiareta
andauthored
[Backport 2.x] Bump org.apache.logging.log4j:log4j-core from 2.17.1 to 2.20.0 (#8645)
* Bump org.apache.logging.log4j:log4j-core from 2.17.1 to 2.20.0 (#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 <[email protected]> Signed-off-by: Daniel (dB.) Doubrovkine <[email protected]> Signed-off-by: Thomas Farr <[email protected]> Co-authored-by: Daniel (dB.) Doubrovkine <[email protected]> Co-authored-by: Andrew Ross <[email protected]> (cherry picked from commit 0b42c2c) * ignoreMissingClasses Signed-off-by: Thomas Farr <[email protected]> --------- Signed-off-by: Thomas Farr <[email protected]> Signed-off-by: Andriy Redko <[email protected]> Co-authored-by: Andriy Redko <[email protected]>
1 parent e8a29e9 commit 4a62494

32 files changed

+64
-52
lines changed

.gitignore

+4-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ out/
1616
benchmarks/src/main/generated/*
1717
benchmarks/bin/*
1818
benchmarks/build-eclipse-default/*
19+
server/bin/*
20+
server/build-eclipse-default/*
21+
test/framework/build-eclipse-default/*
1922

2023
# eclipse files
2124
.project
@@ -60,4 +63,4 @@ testfixtures_shared/
6063
.ci/jobs/
6164

6265
# build files generated
63-
doc-tools/missing-doclet/bin/
66+
doc-tools/missing-doclet/bin/

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
7474
- 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))
7575
- Bump `com.networknt:json-schema-validator` from 1.0.85 to 1.0.86 ([#8573](https://github.com/opensearch-project/OpenSearch/pull/8573))
7676
- Bump `com.google.jimfs:jimfs` from 1.2 to 1.3.0 (#8577)
77+
- Bump `org.apache.logging.log4j:log4j-core` from 2.17.1 to 2.20.0 ([#8307](https://github.com/opensearch-project/OpenSearch/pull/8307))
7778
- Bump `com.azure:azure-storage-blob` from 12.22.2 to 12.22.3 (#8572)
7879

7980
### Changed

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
@@ -12,8 +12,7 @@ jackson_databind = 2.15.2
1212
snakeyaml = 2.0
1313
icu4j = 70.1
1414
supercsv = 2.4.0
15-
# Update to 2.17.2+ is breaking OpenSearchJsonLayout (see https://issues.apache.org/jira/browse/LOG4J2-3562)
16-
log4j = 2.17.1
15+
log4j = 2.20.0
1716
slf4j = 1.7.36
1817
asm = 9.5
1918
jettison = 1.5.4

libs/core/build.gradle

+3
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ tasks.named("thirdPartyAudit").configure {
108108
'org.osgi.framework.BundleActivator',
109109
'org.osgi.framework.BundleContext',
110110
'org.osgi.framework.BundleEvent',
111+
'org.osgi.framework.FrameworkUtil',
112+
'org.osgi.framework.ServiceReference',
113+
'org.osgi.framework.ServiceRegistration',
111114
'org.osgi.framework.SynchronousBundleListener',
112115
'org.osgi.framework.wiring.BundleWire',
113116
'org.osgi.framework.wiring.BundleWiring'

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

+9
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'
@@ -286,7 +291,9 @@ tasks.named("thirdPartyAudit").configure {
286291
'com.lmax.disruptor.LifecycleAware',
287292
'com.lmax.disruptor.RingBuffer',
288293
'com.lmax.disruptor.Sequence',
294+
'com.lmax.disruptor.SequenceBarrier',
289295
'com.lmax.disruptor.SequenceReportingEventHandler',
296+
'com.lmax.disruptor.TimeoutException',
290297
'com.lmax.disruptor.WaitStrategy',
291298
'com.lmax.disruptor.dsl.Disruptor',
292299
'com.lmax.disruptor.dsl.ProducerType',
@@ -315,6 +322,7 @@ tasks.named("thirdPartyAudit").configure {
315322
'org.apache.commons.csv.QuoteMode',
316323
'org.apache.kafka.clients.producer.Producer',
317324
'org.apache.kafka.clients.producer.RecordMetadata',
325+
'org.apache.kafka.common.serialization.ByteArraySerializer',
318326
'org.codehaus.stax2.XMLStreamWriter2',
319327
'org.jctools.queues.MpscArrayQueue',
320328
'org.osgi.framework.Bundle',
@@ -323,6 +331,7 @@ tasks.named("thirdPartyAudit").configure {
323331
'org.osgi.framework.BundleEvent',
324332
'org.osgi.framework.BundleReference',
325333
'org.osgi.framework.FrameworkUtil',
334+
'org.osgi.framework.ServiceReference',
326335
'org.osgi.framework.ServiceRegistration',
327336
'org.osgi.framework.SynchronousBundleListener',
328337
'org.osgi.framework.wiring.BundleWire',

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
@@ -43,7 +43,6 @@
4343
import org.apache.logging.log4j.core.config.builder.api.ConfigurationBuilderFactory;
4444
import org.apache.logging.log4j.core.config.builder.impl.BuiltConfiguration;
4545
import org.apache.logging.log4j.core.config.composite.CompositeConfiguration;
46-
import org.apache.logging.log4j.core.config.plugins.util.PluginManager;
4746
import org.apache.logging.log4j.core.config.properties.PropertiesConfiguration;
4847
import org.apache.logging.log4j.core.config.properties.PropertiesConfigurationBuilder;
4948
import org.apache.logging.log4j.core.config.properties.PropertiesConfigurationFactory;
@@ -147,13 +146,6 @@ public static void configure(final Environment environment) throws IOException,
147146
configure(environment.settings(), environment.configFile(), environment.logsFile());
148147
}
149148

150-
/**
151-
* Load logging plugins so we can have {@code node_name} in the pattern.
152-
*/
153-
public static void loadLog4jPlugins() {
154-
PluginManager.addPackage(LogConfigurator.class.getPackage().getName());
155-
}
156-
157149
/**
158150
* Sets the node name. This is called before logging is configured if the
159151
* node name is set in opensearch.yml. Otherwise it is called as soon
@@ -179,8 +171,6 @@ private static void configure(final Settings settings, final Path configsPath, f
179171
Objects.requireNonNull(configsPath);
180172
Objects.requireNonNull(logsPath);
181173

182-
loadLog4jPlugins();
183-
184174
setLogConfigurationSystemProperty(logsPath, settings);
185175
// we initialize the status logger immediately otherwise Log4j will complain when we try to get the context
186176
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;
@@ -238,7 +237,6 @@ public void tearDown() throws Exception {
238237
static {
239238
TEST_WORKER_VM_ID = System.getProperty(TEST_WORKER_SYS_PROPERTY, DEFAULT_TEST_WORKER_ID);
240239
setTestSysProps();
241-
LogConfigurator.loadLog4jPlugins();
242240

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

0 commit comments

Comments
 (0)