Skip to content

Commit 81eea87

Browse files
dependabot[bot]jackshiraziJonasKunz
authored
build: bump version.log4j from 2.12.4 to 2.24.0 (#3792)
* build: bump version.log4j from 2.12.4 to 2.24.0 Bumps `version.log4j` from 2.12.4 to 2.24.0. Updates `org.apache.logging.log4j:log4j-core` from 2.12.4 to 2.24.0 Updates `org.apache.logging.log4j:log4j-slf4j-impl` from 2.12.4 to 2.24.0 --- updated-dependencies: - dependency-name: org.apache.logging.log4j:log4j-core dependency-type: direct:production update-type: version-update:semver-minor - dependency-name: org.apache.logging.log4j:log4j-slf4j-impl dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]> * revert the change * Fix classpath for log4j2 tests * Upgrade log4j2 tests to JUnit5, disable broken tests * Fix error capturing test for 2.6 --------- Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: jackshirazi <[email protected]> Co-authored-by: Jonas Kunz <[email protected]>
1 parent 2f99ecc commit 81eea87

File tree

13 files changed

+130
-328
lines changed

13 files changed

+130
-328
lines changed

apm-agent-plugins/apm-ecs-logging-plugin/pom.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@
4141
<dependency>
4242
<groupId>org.apache.logging.log4j</groupId>
4343
<artifactId>log4j-core</artifactId>
44-
<version>2.23.1</version>
44+
<!-- fixate the log4j version to the one used by the agent, otherwise the agent uses the incorrect version during tests -->
45+
<version>${version.log4j}</version>
4546
<scope>provided</scope>
4647
<optional>true</optional>
4748
</dependency>
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
<parent>
7+
<groupId>co.elastic.apm</groupId>
8+
<artifactId>apm-logging-plugin</artifactId>
9+
<version>1.51.1-SNAPSHOT</version>
10+
</parent>
11+
12+
<artifactId>apm-log4j2-plugin-tests</artifactId>
13+
<name>${project.groupId}:${project.artifactId}</name>
14+
15+
<properties>
16+
<apm-agent-parent.base.dir>${project.basedir}/../../..</apm-agent-parent.base.dir>
17+
</properties>
18+
19+
<!--
20+
This module contains just the tests for apm-log4j2-plugin.
21+
The reason a separate module is required because the plugin needs to be written against the latest version
22+
of log4j2, but during tests the version required by the agent needs to be on classpath.
23+
Because maven doesn't support different versions of the same dependency for compilation and testing,
24+
we need to use separate modules.
25+
-->
26+
27+
<dependencies>
28+
<dependency>
29+
<groupId>${project.groupId}</groupId>
30+
<artifactId>apm-log4j2-plugin</artifactId>
31+
<version>${project.version}</version>
32+
<scope>test</scope>
33+
</dependency>
34+
<dependency>
35+
<groupId>org.apache.logging.log4j</groupId>
36+
<artifactId>log4j-core</artifactId>
37+
<version>${version.log4j}</version>
38+
<scope>test</scope>
39+
</dependency>
40+
<dependency>
41+
<groupId>${project.groupId}</groupId>
42+
<artifactId>apm-logging-plugin-common</artifactId>
43+
<version>${project.version}</version>
44+
<type>test-jar</type>
45+
<scope>test</scope>
46+
</dependency>
47+
<dependency>
48+
<groupId>org.apache.ivy</groupId>
49+
<artifactId>ivy</artifactId>
50+
<scope>test</scope>
51+
</dependency>
52+
</dependencies>
53+
54+
55+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Licensed to Elasticsearch B.V. under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch B.V. licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package co.elastic.apm.agent.log4j2;
20+
21+
import co.elastic.apm.agent.testutils.TestClassWithDependencyRunner;
22+
import org.junit.jupiter.api.condition.DisabledOnOs;
23+
import org.junit.jupiter.api.condition.OS;
24+
import org.junit.jupiter.params.ParameterizedTest;
25+
import org.junit.jupiter.params.provider.ValueSource;
26+
27+
import java.util.List;
28+
29+
@DisabledOnOs(OS.WINDOWS)
30+
public class Log4j2InstrumentationTest {
31+
32+
@ParameterizedTest
33+
@ValueSource(strings = {"2.6", "2.17.1", "2.24.0"})
34+
public void testInstrumentation(String version) throws Exception {
35+
List<String> dependencies = List.of(
36+
"org.apache.logging.log4j:log4j-core:" + version,
37+
"org.apache.logging.log4j:log4j-api:" + version,
38+
"co.elastic.logging:log4j2-ecs-layout:1.3.2"
39+
);
40+
new TestClassWithDependencyRunner(dependencies, Log4j2InstrumentationTestDefinitions.class.getName(),
41+
Log4j2InstrumentationTestDefinitions.Log4j2LoggerFacade.class.getName())
42+
.run();
43+
}
44+
45+
@ParameterizedTest
46+
@ValueSource(strings = {"2.6", "2.17.1", "2.24.0"})
47+
public void testErrorCapture(String version) throws Exception {
48+
List<String> dependencies = List.of(
49+
"org.apache.logging.log4j:log4j-core:" + version,
50+
"org.apache.logging.log4j:log4j-api:" + version
51+
);
52+
new TestClassWithDependencyRunner(dependencies, Log4j2LoggerErrorCapturingInstrumentationTest.class.getName())
53+
.run();
54+
}
55+
}
Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@
1818
*/
1919
package co.elastic.apm.agent.log4j2;
2020

21-
import co.elastic.apm.agent.loginstr.LoggingInstrumentationTest;
22-
import co.elastic.apm.agent.loginstr.LoggerFacade;
2321
import co.elastic.apm.agent.logging.LoggingConfigurationImpl;
22+
import co.elastic.apm.agent.loginstr.LoggerFacade;
23+
import co.elastic.apm.agent.loginstr.LoggingInstrumentationTest;
24+
import co.elastic.apm.agent.testutils.TestClassWithDependencyRunner;
2425
import org.apache.logging.log4j.LogManager;
2526
import org.apache.logging.log4j.Logger;
2627
import org.apache.logging.log4j.Marker;
@@ -32,7 +33,6 @@
3233
import org.apache.logging.log4j.core.config.ConfigurationFactory;
3334
import org.junit.jupiter.api.AfterAll;
3435
import org.junit.jupiter.api.BeforeAll;
35-
import org.junit.jupiter.api.Disabled;
3636

3737
import java.net.URI;
3838
import java.net.URISyntaxException;
@@ -45,8 +45,8 @@
4545
* Since the agent core uses log4j 2.12.4, and since both agent core and tests are loaded by the system class loader in unit tests,
4646
* the proper way to test integration tests with log4j2 is only through dedicated class loaders.
4747
*/
48-
@Disabled
49-
public class Log4j2InstrumentationTest extends LoggingInstrumentationTest {
48+
@TestClassWithDependencyRunner.DisableOutsideOfRunner
49+
public class Log4j2InstrumentationTestDefinitions extends LoggingInstrumentationTest {
5050

5151
@BeforeAll
5252
static void resetConfigFactory() {
@@ -60,6 +60,11 @@ static void reInitLogging() {
6060

6161
private static final Marker TEST_MARKER = MarkerManager.getMarker("TEST");
6262

63+
@Override
64+
public void testSendLogs() {
65+
//TODO: fix me, log sending is currently broken for log4j2
66+
}
67+
6368
@Override
6469
protected LoggerFacade createLoggerFacade() {
6570
return new Log4j2LoggerFacade();
@@ -86,7 +91,7 @@ static class Log4j2LoggerFacade implements LoggerFacade {
8691

8792
public Log4j2LoggerFacade() {
8893
try {
89-
configLocation = Objects.requireNonNull(Log4j2InstrumentationTest.class.getClassLoader()
94+
configLocation = Objects.requireNonNull(Log4j2InstrumentationTestDefinitions.class.getClassLoader()
9095
.getResource("log4j2.xml")).toURI();
9196
} catch (URISyntaxException e) {
9297
e.printStackTrace();
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,20 @@
1616
* specific language governing permissions and limitations
1717
* under the License.
1818
*/
19-
package co.elastic.apm.agent.log4j2.error;
19+
package co.elastic.apm.agent.log4j2;
2020

2121
import co.elastic.apm.agent.loginstr.error.AbstractErrorLoggingInstrumentationTest;
22+
import co.elastic.apm.agent.testutils.TestClassWithDependencyRunner;
2223
import org.apache.logging.log4j.LogManager;
2324
import org.apache.logging.log4j.Logger;
2425
import org.apache.logging.log4j.message.ParameterizedMessageFactory;
25-
import org.junit.jupiter.api.Disabled;
2626
import org.junit.jupiter.api.Test;
2727

2828
/**
2929
* Only tested through dedicated class loaders for latest and oldest-supported versions.
30-
* See {@link Log4j2ErrorCapturingTestVersions}
30+
* See {@link co.elastic.apm.agent.log4j2.Log4j2InstrumentationTest}
3131
*/
32-
@Disabled
32+
@TestClassWithDependencyRunner.DisableOutsideOfRunner
3333
public class Log4j2LoggerErrorCapturingInstrumentationTest extends AbstractErrorLoggingInstrumentationTest {
3434

3535
private static final Logger logger = LogManager.getLogger(Log4j2LoggerErrorCapturingInstrumentationTest.class);
@@ -42,7 +42,7 @@ void captureErrorExceptionWithStringMessage() {
4242

4343
@Test
4444
void captureErrorExceptionWithMessageMessage() {
45-
logger.error(ParameterizedMessageFactory.INSTANCE.newMessage("exception captured with parameter {}", "foo"), new RuntimeException("some business exception"));
45+
logger.error(ParameterizedMessageFactory.INSTANCE.newMessage("exception captured with parameter {}", new Object[]{"foo"}), new RuntimeException("some business exception"));
4646
verifyExceptionCaptured("some business exception", RuntimeException.class);
4747
}
4848

apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin/pom.xml

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,26 +24,14 @@
2424
<dependency>
2525
<groupId>org.apache.logging.log4j</groupId>
2626
<artifactId>log4j-core</artifactId>
27-
<version>2.23.1</version>
27+
<version>2.24.0</version>
2828
<scope>provided</scope>
2929
</dependency>
3030
<dependency>
3131
<groupId>co.elastic.logging</groupId>
3232
<artifactId>log4j2-ecs-layout</artifactId>
3333
<version>${version.ecs.logging}</version>
3434
</dependency>
35-
<dependency>
36-
<groupId>${project.groupId}</groupId>
37-
<artifactId>apm-logging-plugin-common</artifactId>
38-
<version>${project.version}</version>
39-
<type>test-jar</type>
40-
<scope>test</scope>
41-
</dependency>
42-
<dependency>
43-
<groupId>org.apache.ivy</groupId>
44-
<artifactId>ivy</artifactId>
45-
<scope>test</scope>
46-
</dependency>
4735
</dependencies>
4836

4937
</project>

apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin/src/test/java/co/elastic/apm/agent/log4j2/Log4j2InstrumentationTestVersions.java

Lines changed: 0 additions & 118 deletions
This file was deleted.

0 commit comments

Comments
 (0)