Skip to content

Commit

Permalink
build: bump version.log4j from 2.12.4 to 2.24.0 (#3792)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
3 people authored Sep 18, 2024
1 parent 2f99ecc commit 81eea87
Show file tree
Hide file tree
Showing 13 changed files with 130 additions and 328 deletions.
3 changes: 2 additions & 1 deletion apm-agent-plugins/apm-ecs-logging-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.23.1</version>
<!-- fixate the log4j version to the one used by the agent, otherwise the agent uses the incorrect version during tests -->
<version>${version.log4j}</version>
<scope>provided</scope>
<optional>true</optional>
</dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>co.elastic.apm</groupId>
<artifactId>apm-logging-plugin</artifactId>
<version>1.51.1-SNAPSHOT</version>
</parent>

<artifactId>apm-log4j2-plugin-tests</artifactId>
<name>${project.groupId}:${project.artifactId}</name>

<properties>
<apm-agent-parent.base.dir>${project.basedir}/../../..</apm-agent-parent.base.dir>
</properties>

<!--
This module contains just the tests for apm-log4j2-plugin.
The reason a separate module is required because the plugin needs to be written against the latest version
of log4j2, but during tests the version required by the agent needs to be on classpath.
Because maven doesn't support different versions of the same dependency for compilation and testing,
we need to use separate modules.
-->

<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>apm-log4j2-plugin</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>${version.log4j}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>apm-logging-plugin-common</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.ivy</groupId>
<artifactId>ivy</artifactId>
<scope>test</scope>
</dependency>
</dependencies>


</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package co.elastic.apm.agent.log4j2;

import co.elastic.apm.agent.testutils.TestClassWithDependencyRunner;
import org.junit.jupiter.api.condition.DisabledOnOs;
import org.junit.jupiter.api.condition.OS;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;

import java.util.List;

@DisabledOnOs(OS.WINDOWS)
public class Log4j2InstrumentationTest {

@ParameterizedTest
@ValueSource(strings = {"2.6", "2.17.1", "2.24.0"})
public void testInstrumentation(String version) throws Exception {
List<String> dependencies = List.of(
"org.apache.logging.log4j:log4j-core:" + version,
"org.apache.logging.log4j:log4j-api:" + version,
"co.elastic.logging:log4j2-ecs-layout:1.3.2"
);
new TestClassWithDependencyRunner(dependencies, Log4j2InstrumentationTestDefinitions.class.getName(),
Log4j2InstrumentationTestDefinitions.Log4j2LoggerFacade.class.getName())
.run();
}

@ParameterizedTest
@ValueSource(strings = {"2.6", "2.17.1", "2.24.0"})
public void testErrorCapture(String version) throws Exception {
List<String> dependencies = List.of(
"org.apache.logging.log4j:log4j-core:" + version,
"org.apache.logging.log4j:log4j-api:" + version
);
new TestClassWithDependencyRunner(dependencies, Log4j2LoggerErrorCapturingInstrumentationTest.class.getName())
.run();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@
*/
package co.elastic.apm.agent.log4j2;

import co.elastic.apm.agent.loginstr.LoggingInstrumentationTest;
import co.elastic.apm.agent.loginstr.LoggerFacade;
import co.elastic.apm.agent.logging.LoggingConfigurationImpl;
import co.elastic.apm.agent.loginstr.LoggerFacade;
import co.elastic.apm.agent.loginstr.LoggingInstrumentationTest;
import co.elastic.apm.agent.testutils.TestClassWithDependencyRunner;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.Marker;
Expand All @@ -32,7 +33,6 @@
import org.apache.logging.log4j.core.config.ConfigurationFactory;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Disabled;

import java.net.URI;
import java.net.URISyntaxException;
Expand All @@ -45,8 +45,8 @@
* 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,
* the proper way to test integration tests with log4j2 is only through dedicated class loaders.
*/
@Disabled
public class Log4j2InstrumentationTest extends LoggingInstrumentationTest {
@TestClassWithDependencyRunner.DisableOutsideOfRunner
public class Log4j2InstrumentationTestDefinitions extends LoggingInstrumentationTest {

@BeforeAll
static void resetConfigFactory() {
Expand All @@ -60,6 +60,11 @@ static void reInitLogging() {

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

@Override
public void testSendLogs() {
//TODO: fix me, log sending is currently broken for log4j2
}

@Override
protected LoggerFacade createLoggerFacade() {
return new Log4j2LoggerFacade();
Expand All @@ -86,7 +91,7 @@ static class Log4j2LoggerFacade implements LoggerFacade {

public Log4j2LoggerFacade() {
try {
configLocation = Objects.requireNonNull(Log4j2InstrumentationTest.class.getClassLoader()
configLocation = Objects.requireNonNull(Log4j2InstrumentationTestDefinitions.class.getClassLoader()
.getResource("log4j2.xml")).toURI();
} catch (URISyntaxException e) {
e.printStackTrace();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,20 @@
* specific language governing permissions and limitations
* under the License.
*/
package co.elastic.apm.agent.log4j2.error;
package co.elastic.apm.agent.log4j2;

import co.elastic.apm.agent.loginstr.error.AbstractErrorLoggingInstrumentationTest;
import co.elastic.apm.agent.testutils.TestClassWithDependencyRunner;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.message.ParameterizedMessageFactory;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;

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

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

@Test
void captureErrorExceptionWithMessageMessage() {
logger.error(ParameterizedMessageFactory.INSTANCE.newMessage("exception captured with parameter {}", "foo"), new RuntimeException("some business exception"));
logger.error(ParameterizedMessageFactory.INSTANCE.newMessage("exception captured with parameter {}", new Object[]{"foo"}), new RuntimeException("some business exception"));
verifyExceptionCaptured("some business exception", RuntimeException.class);
}

Expand Down
14 changes: 1 addition & 13 deletions apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,14 @@
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.23.1</version>
<version>2.24.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>co.elastic.logging</groupId>
<artifactId>log4j2-ecs-layout</artifactId>
<version>${version.ecs.logging}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>apm-logging-plugin-common</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.ivy</groupId>
<artifactId>ivy</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

</project>

This file was deleted.

Loading

0 comments on commit 81eea87

Please sign in to comment.