From 8e86704c6256f21767b5356db21251093a202d05 Mon Sep 17 00:00:00 2001 From: Crypt Keeper <64215+codefromthecrypt@users.noreply.github.com> Date: Thu, 14 Dec 2023 14:16:08 +0700 Subject: [PATCH] updates integration tests and benchmarks to use log4j (#224) Similar to Brave, we don't want a large amount of clutter. To reduce a lot of it, I moved anything that uses MockWebServer to an IT (because it spams logs). I didn't move normal tests to log4j because we have a log capturing test that would fail. If someone wants to take a pass later at that, they could. Signed-off-by: Adrian Cole --- activemq-client/pom.xml | 3 ++ .../src/test/resources/log4j2.properties | 8 ++++ .../src/test/resources/logback.xml | 13 ------ .../src/test/resources/log4j2.properties | 8 ++++ amqp-client/src/test/resources/logback.xml | 13 ------ benchmarks/pom.xml | 26 +++++++++-- .../zipkin2/reporter/SenderBenchmarks.java | 14 +++--- .../src/main/resources/log4j.properties | 22 --------- .../src/main/resources/log4j2.properties | 15 +++++++ benchmarks/src/main/resources/logback.xml | 34 -------------- .../src/main/resources/zipkin2-client.json | 32 ------------- kafka/src/test/resources/log4j2.properties | 23 ++++++++++ kafka/src/test/resources/logback.xml | 25 ----------- .../src/test/resources/log4j2.properties | 8 ++++ libthrift/src/test/resources/logback.xml | 13 ------ okhttp3/pom.xml | 1 + okhttp3/src/it/okhttp3_v3/pom.xml | 34 ++++++++++++-- .../brave/okhttp3_v3/OkHttpSenderTest.java | 17 ------- .../reporter/okhttp3_v3/ITOkHttpSender.java} | 4 +- .../reporter/okhttp3/HttpCallTest.java | 2 +- ...ttpSenderTest.java => ITOkHttpSender.java} | 2 +- okhttp3/src/test/resources/log4j2.properties | 8 ++++ pom.xml | 45 ++++++++++++++----- spring-beans/pom.xml | 8 ++-- .../src/test/resources/log4j2.properties | 11 +++++ spring-beans/src/test/resources/logback.xml | 15 ------- ...erTest.java => ITURLConnectionSender.java} | 2 +- 27 files changed, 191 insertions(+), 215 deletions(-) create mode 100755 activemq-client/src/test/resources/log4j2.properties delete mode 100644 activemq-client/src/test/resources/logback.xml create mode 100755 amqp-client/src/test/resources/log4j2.properties delete mode 100644 amqp-client/src/test/resources/logback.xml delete mode 100644 benchmarks/src/main/resources/log4j.properties create mode 100755 benchmarks/src/main/resources/log4j2.properties delete mode 100644 benchmarks/src/main/resources/logback.xml delete mode 100644 benchmarks/src/main/resources/zipkin2-client.json create mode 100755 kafka/src/test/resources/log4j2.properties delete mode 100644 kafka/src/test/resources/logback.xml create mode 100755 libthrift/src/test/resources/log4j2.properties delete mode 100644 libthrift/src/test/resources/logback.xml delete mode 100644 okhttp3/src/it/okhttp3_v3/src/test/java/brave/okhttp3_v3/OkHttpSenderTest.java rename okhttp3/src/it/okhttp3_v3/src/test/java/{brave/okhttp3_v3/HttpCallTest.java => zipkin2/reporter/okhttp3_v3/ITOkHttpSender.java} (83%) rename okhttp3/src/test/java/zipkin2/reporter/okhttp3/{OkHttpSenderTest.java => ITOkHttpSender.java} (99%) create mode 100755 okhttp3/src/test/resources/log4j2.properties create mode 100755 spring-beans/src/test/resources/log4j2.properties delete mode 100644 spring-beans/src/test/resources/logback.xml rename urlconnection/src/test/java/zipkin2/reporter/urlconnection/{URLConnectionSenderTest.java => ITURLConnectionSender.java} (99%) diff --git a/activemq-client/pom.xml b/activemq-client/pom.xml index 946203bd..748c6743 100644 --- a/activemq-client/pom.xml +++ b/activemq-client/pom.xml @@ -30,6 +30,9 @@ zipkin2.reporter.activemq ${project.basedir}/.. + 5.18.3 - - %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n - - - - - - - diff --git a/amqp-client/src/test/resources/log4j2.properties b/amqp-client/src/test/resources/log4j2.properties new file mode 100755 index 00000000..a9b5e43b --- /dev/null +++ b/amqp-client/src/test/resources/log4j2.properties @@ -0,0 +1,8 @@ +appenders=console +appender.console.type=Console +appender.console.name=STDOUT +appender.console.layout.type=PatternLayout +appender.console.layout.pattern=%d{ABSOLUTE} %-5p [%t] %C{2} (%F:%L) - %m%n +rootLogger.level=warn +rootLogger.appenderRefs=stdout +rootLogger.appenderRef.stdout.ref=STDOUT diff --git a/amqp-client/src/test/resources/logback.xml b/amqp-client/src/test/resources/logback.xml deleted file mode 100644 index 492858ca..00000000 --- a/amqp-client/src/test/resources/logback.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n - - - - - - - diff --git a/benchmarks/pom.xml b/benchmarks/pom.xml index 5a46a310..def9c19a 100644 --- a/benchmarks/pom.xml +++ b/benchmarks/pom.xml @@ -120,10 +120,30 @@ https://github.com/charithe/kafka-junit --> 4.2.10 + + + + org.apache.logging.log4j + log4j-core + ${log4j.version} + + + + org.apache.logging.log4j + log4j-jul + ${log4j.version} + + + + org.apache.logging.log4j + log4j-1.2-api + ${log4j.version} + + - ch.qos.logback - logback-classic - ${logback.version} + org.apache.logging.log4j + log4j-slf4j-impl + ${log4j.version} diff --git a/benchmarks/src/main/java/zipkin2/reporter/SenderBenchmarks.java b/benchmarks/src/main/java/zipkin2/reporter/SenderBenchmarks.java index 3b58fd8e..e0b7e838 100644 --- a/benchmarks/src/main/java/zipkin2/reporter/SenderBenchmarks.java +++ b/benchmarks/src/main/java/zipkin2/reporter/SenderBenchmarks.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 The OpenZipkin Authors + * Copyright 2016-2023 The OpenZipkin Authors * * Licensed 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 @@ -34,7 +34,8 @@ import org.openjdk.jmh.annotations.Warmup; import zipkin2.CheckResult; import zipkin2.Span; -import zipkin2.codec.SpanBytesDecoder; +import zipkin2.TestObjects; +import zipkin2.codec.SpanBytesEncoder; /** * This benchmark reports spans as fast as possible. The sender clears the queue as fast as @@ -59,15 +60,18 @@ public abstract class SenderBenchmarks { public int messageMaxBytes; - static final byte[] clientSpanBytes = spanFromResource("/zipkin2-client.json"); - static final Span clientSpan = SpanBytesDecoder.JSON_V2.decodeOne(clientSpanBytes); - + static final Span clientSpan = TestObjects.CLIENT_SPAN; + static final byte[] clientSpanBytes = SpanBytesEncoder.JSON_V2.encode(clientSpan); static final InMemoryReporterMetrics metrics = new InMemoryReporterMetrics(); @AuxCounters @State(Scope.Thread) public static class InMemoryReporterMetricsAsCounters { + static { + System.setProperty("java.util.logging.manager", "org.apache.logging.log4j.jul.LogManager"); + } + public long spans() { return metrics.spans() - metrics.spansDropped(); } diff --git a/benchmarks/src/main/resources/log4j.properties b/benchmarks/src/main/resources/log4j.properties deleted file mode 100644 index 36e99c91..00000000 --- a/benchmarks/src/main/resources/log4j.properties +++ /dev/null @@ -1,22 +0,0 @@ -# -# Copyright 2016-2019 The OpenZipkin Authors -# -# Licensed 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. -# - -# By default, everything goes to console and file -log4j.rootLogger=WARN, A1 - -# A1 is set to be a ConsoleAppender. -log4j.appender.A1=org.apache.log4j.ConsoleAppender -log4j.appender.A1.layout=org.apache.log4j.PatternLayout -log4j.appender.A1.layout.ConversionPattern=%d [%t] %-5p %c - %m%n -log4j.appender.A1.ImmediateFlush=true diff --git a/benchmarks/src/main/resources/log4j2.properties b/benchmarks/src/main/resources/log4j2.properties new file mode 100755 index 00000000..8ca61d1c --- /dev/null +++ b/benchmarks/src/main/resources/log4j2.properties @@ -0,0 +1,15 @@ +appenders=console +appender.console.type=Console +appender.console.name=STDOUT +appender.console.layout.type=PatternLayout +appender.console.layout.pattern=%d{ABSOLUTE} %-5p [%t] %C{2} (%F:%L) - %m%n +rootLogger.level=warn +rootLogger.appenderRefs=stdout +rootLogger.appenderRef.stdout.ref=STDOUT +# uncomment to include kafka consumer configuration in test logs +#logger.kafka-clients.name=org.apache.kafka.clients +#logger.kafka-clients.level=info +logger.kafkaunit.name=com.github.charithe.kafka +logger.kafkaunit.level=off +logger.kafka.name=zipkin2.reporter.kafka +logger.kafka.level=debug diff --git a/benchmarks/src/main/resources/logback.xml b/benchmarks/src/main/resources/logback.xml deleted file mode 100644 index edfa428d..00000000 --- a/benchmarks/src/main/resources/logback.xml +++ /dev/null @@ -1,34 +0,0 @@ - - - - - - - %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n - - - - - - - - - - - - diff --git a/benchmarks/src/main/resources/zipkin2-client.json b/benchmarks/src/main/resources/zipkin2-client.json deleted file mode 100644 index 44df5c06..00000000 --- a/benchmarks/src/main/resources/zipkin2-client.json +++ /dev/null @@ -1,32 +0,0 @@ -{ - "traceId": "4d1e00c0db9010db86154a4ba6e91385", - "parentId": "86154a4ba6e91385", - "id": "4d1e00c0db9010db", - "kind": "CLIENT", - "name": "get", - "timestamp": 1472470996199000, - "duration": 207000, - "localEndpoint": { - "serviceName": "frontend", - "ipv6": "7::0.128.128.127" - }, - "remoteEndpoint": { - "serviceName": "backend", - "ipv4": "192.168.99.101", - "port": 9000 - }, - "annotations": [ - { - "timestamp": 1472470996238000, - "value": "foo" - }, - { - "timestamp": 1472470996403000, - "value": "bar" - } - ], - "tags": { - "http.path": "/api", - "clnt/finagle.version": "6.45.0" - } -} diff --git a/kafka/src/test/resources/log4j2.properties b/kafka/src/test/resources/log4j2.properties new file mode 100755 index 00000000..1cf21c26 --- /dev/null +++ b/kafka/src/test/resources/log4j2.properties @@ -0,0 +1,23 @@ +appenders=console +appender.console.type=Console +appender.console.name=STDOUT +appender.console.layout.type=PatternLayout +appender.console.layout.pattern=%d{ABSOLUTE} %-5p [%t] %C{2} (%F:%L) - %m%n +rootLogger.level=warn +rootLogger.appenderRefs=stdout +rootLogger.appenderRef.stdout.ref=STDOUT +# uncomment to include kafka consumer configuration in test logs +#logger.kafka-clients.name=org.apache.kafka.clients +#logger.kafka-clients.level=info +logger.kafka.name=zipkin2.reporter.kafka +logger.kafka.level=debug + +# hush the unit test runner +logger.BrokerMetadataCheckpoint.name=kafka.server.BrokerMetadataCheckpoint +logger.BrokerMetadataCheckpoint.level=off + +# don't waste logs when ZK check fails +logger.ClientCnxn.name=org.apache.zookeeper.ClientCnxn +logger.ClientCnxn.level=off +logger.NetworkClient.name=org.apache.kafka.clients.NetworkClient +logger.NetworkClient.level=off diff --git a/kafka/src/test/resources/logback.xml b/kafka/src/test/resources/logback.xml deleted file mode 100644 index 4c6e3814..00000000 --- a/kafka/src/test/resources/logback.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n - - - - - - - - - - - - - - - - - - - diff --git a/libthrift/src/test/resources/log4j2.properties b/libthrift/src/test/resources/log4j2.properties new file mode 100755 index 00000000..a9b5e43b --- /dev/null +++ b/libthrift/src/test/resources/log4j2.properties @@ -0,0 +1,8 @@ +appenders=console +appender.console.type=Console +appender.console.name=STDOUT +appender.console.layout.type=PatternLayout +appender.console.layout.pattern=%d{ABSOLUTE} %-5p [%t] %C{2} (%F:%L) - %m%n +rootLogger.level=warn +rootLogger.appenderRefs=stdout +rootLogger.appenderRef.stdout.ref=STDOUT diff --git a/libthrift/src/test/resources/logback.xml b/libthrift/src/test/resources/logback.xml deleted file mode 100644 index 492858ca..00000000 --- a/libthrift/src/test/resources/logback.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n - - - - - - - diff --git a/okhttp3/pom.xml b/okhttp3/pom.xml index f094b690..e9e688d6 100644 --- a/okhttp3/pom.xml +++ b/okhttp3/pom.xml @@ -88,6 +88,7 @@ mockwebserver ${old-okhttp.version} MAIN + jar diff --git a/okhttp3/src/it/okhttp3_v3/pom.xml b/okhttp3/src/it/okhttp3_v3/pom.xml index 8b3d3c35..0ae0ae37 100644 --- a/okhttp3/src/it/okhttp3_v3/pom.xml +++ b/okhttp3/src/it/okhttp3_v3/pom.xml @@ -68,26 +68,54 @@ zipkin-tests @zipkin.version@ + + + + org.apache.logging.log4j + log4j-core + @log4j.version@ + + + org.apache.logging.log4j + log4j-jul + @log4j.version@ + @project.build.testSourceDirectory@ + + + @project.basedir@/src/test/resources + + maven-compiler-plugin @maven-compiler-plugin.version@ - **/*Test.java + **/IT*.java + maven-surefire-plugin @maven-surefire-plugin.version@ - - false + true + + **/IT*.java + + + false + + false + + org.apache.logging.log4j.jul.LogManager + diff --git a/okhttp3/src/it/okhttp3_v3/src/test/java/brave/okhttp3_v3/OkHttpSenderTest.java b/okhttp3/src/it/okhttp3_v3/src/test/java/brave/okhttp3_v3/OkHttpSenderTest.java deleted file mode 100644 index e3251d60..00000000 --- a/okhttp3/src/it/okhttp3_v3/src/test/java/brave/okhttp3_v3/OkHttpSenderTest.java +++ /dev/null @@ -1,17 +0,0 @@ -/* - * Copyright 2016-2023 The OpenZipkin Authors - * - * Licensed 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 zipkin2.reporter.okhttp3.okhttp3_v3; - -public class OkHttpSenderTest extends zipkin2.reporter.okhttp3.OkHttpSenderTest { -} diff --git a/okhttp3/src/it/okhttp3_v3/src/test/java/brave/okhttp3_v3/HttpCallTest.java b/okhttp3/src/it/okhttp3_v3/src/test/java/zipkin2/reporter/okhttp3_v3/ITOkHttpSender.java similarity index 83% rename from okhttp3/src/it/okhttp3_v3/src/test/java/brave/okhttp3_v3/HttpCallTest.java rename to okhttp3/src/it/okhttp3_v3/src/test/java/zipkin2/reporter/okhttp3_v3/ITOkHttpSender.java index 30044d54..d686810b 100644 --- a/okhttp3/src/it/okhttp3_v3/src/test/java/brave/okhttp3_v3/HttpCallTest.java +++ b/okhttp3/src/it/okhttp3_v3/src/test/java/zipkin2/reporter/okhttp3_v3/ITOkHttpSender.java @@ -11,7 +11,7 @@ * or implied. See the License for the specific language governing permissions and limitations under * the License. */ -package zipkin2.reporter.okhttp3.okhttp3_v3; +package zipkin2.reporter.okhttp3_v3; -public class HttpCallTest extends zipkin2.reporter.okhttp3.HttpCallTest { +public class ITOkHttpSender extends zipkin2.reporter.okhttp3.ITOkHttpSender { } diff --git a/okhttp3/src/test/java/zipkin2/reporter/okhttp3/HttpCallTest.java b/okhttp3/src/test/java/zipkin2/reporter/okhttp3/HttpCallTest.java index d7a8ae6d..ab62dd58 100644 --- a/okhttp3/src/test/java/zipkin2/reporter/okhttp3/HttpCallTest.java +++ b/okhttp3/src/test/java/zipkin2/reporter/okhttp3/HttpCallTest.java @@ -25,7 +25,7 @@ import static org.assertj.core.api.Assertions.assertThat; -public class HttpCallTest { // public for use in src/it +class HttpCallTest { @Test void parseResponse_closesBody() throws Exception { // It is difficult to prove close was called, this approach looks at an underlying stream diff --git a/okhttp3/src/test/java/zipkin2/reporter/okhttp3/OkHttpSenderTest.java b/okhttp3/src/test/java/zipkin2/reporter/okhttp3/ITOkHttpSender.java similarity index 99% rename from okhttp3/src/test/java/zipkin2/reporter/okhttp3/OkHttpSenderTest.java rename to okhttp3/src/test/java/zipkin2/reporter/okhttp3/ITOkHttpSender.java index bafe3b87..aa95d594 100644 --- a/okhttp3/src/test/java/zipkin2/reporter/okhttp3/OkHttpSenderTest.java +++ b/okhttp3/src/test/java/zipkin2/reporter/okhttp3/ITOkHttpSender.java @@ -44,7 +44,7 @@ import static org.assertj.core.api.Assertions.failBecauseExceptionWasNotThrown; import static zipkin2.TestObjects.CLIENT_SPAN; -public class OkHttpSenderTest { // public for use in src/it +public class ITOkHttpSender { // public for use in src/it MockWebServer server = new MockWebServer(); @AfterEach void closeServer() throws IOException { diff --git a/okhttp3/src/test/resources/log4j2.properties b/okhttp3/src/test/resources/log4j2.properties new file mode 100755 index 00000000..a9b5e43b --- /dev/null +++ b/okhttp3/src/test/resources/log4j2.properties @@ -0,0 +1,8 @@ +appenders=console +appender.console.type=Console +appender.console.name=STDOUT +appender.console.layout.type=PatternLayout +appender.console.layout.pattern=%d{ABSOLUTE} %-5p [%t] %C{2} (%F:%L) - %m%n +rootLogger.level=warn +rootLogger.appenderRefs=stdout +rootLogger.appenderRef.stdout.ref=STDOUT diff --git a/pom.xml b/pom.xml index 057688bc..d76e5ed2 100755 --- a/pom.xml +++ b/pom.xml @@ -65,8 +65,7 @@ 5.10.1 3.24.2 4.12.0 - - 1.2.13 + 2.22.0 1.19.3 ${skipTests} @@ -179,10 +178,32 @@ test + - ch.qos.logback - logback-classic - ${logback.version} + org.apache.logging.log4j + log4j-core + ${log4j.version} + test + + + + org.apache.logging.log4j + log4j-jul + ${log4j.version} + test + + + + org.apache.logging.log4j + log4j-1.2-api + ${log4j.version} + test + + + + org.apache.logging.log4j + log4j-slf4j-impl + ${log4j.version} test @@ -330,11 +351,12 @@ !release ${project.build.directory}/local-repo + verify - true ${skipTests} - true + -Dorg.slf4j.simpleLogger.defaultLogLevel=WARN @@ -384,10 +406,6 @@ maven-surefire-plugin ${maven-surefire-plugin.version} - - - false - @@ -408,6 +426,9 @@ false false + + org.apache.logging.log4j.jul.LogManager + @@ -459,7 +480,7 @@ SCRIPT_STYLE - **/logback.xml + **/log4j2.properties .editorconfig .gitattributes .gitignore diff --git a/spring-beans/pom.xml b/spring-beans/pom.xml index 8d7f2fcc..f729a9a7 100644 --- a/spring-beans/pom.xml +++ b/spring-beans/pom.xml @@ -104,10 +104,12 @@ 2.5.6 provided + + - org.slf4j - jcl-over-slf4j - 1.7.36 + org.apache.logging.log4j + log4j-jcl + ${log4j.version} test diff --git a/spring-beans/src/test/resources/log4j2.properties b/spring-beans/src/test/resources/log4j2.properties new file mode 100755 index 00000000..cd38229a --- /dev/null +++ b/spring-beans/src/test/resources/log4j2.properties @@ -0,0 +1,11 @@ +appenders=console +appender.console.type=Console +appender.console.name=STDOUT +appender.console.layout.type=PatternLayout +appender.console.layout.pattern=%d{ABSOLUTE} %-5p [%t] %C{2} (%F:%L) - %m%n +rootLogger.level=warn +rootLogger.appenderRefs=stdout +rootLogger.appenderRef.stdout.ref=STDOUT + +logger.TypeConverterDelegate.name=org.springframework.beans.TypeConverterDelegate +logger.TypeConverterDelegate.level=off diff --git a/spring-beans/src/test/resources/logback.xml b/spring-beans/src/test/resources/logback.xml deleted file mode 100644 index b7b72635..00000000 --- a/spring-beans/src/test/resources/logback.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n - - - - - - - - - diff --git a/urlconnection/src/test/java/zipkin2/reporter/urlconnection/URLConnectionSenderTest.java b/urlconnection/src/test/java/zipkin2/reporter/urlconnection/ITURLConnectionSender.java similarity index 99% rename from urlconnection/src/test/java/zipkin2/reporter/urlconnection/URLConnectionSenderTest.java rename to urlconnection/src/test/java/zipkin2/reporter/urlconnection/ITURLConnectionSender.java index 5e715827..f13c73d7 100644 --- a/urlconnection/src/test/java/zipkin2/reporter/urlconnection/URLConnectionSenderTest.java +++ b/urlconnection/src/test/java/zipkin2/reporter/urlconnection/ITURLConnectionSender.java @@ -39,7 +39,7 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy; import static zipkin2.TestObjects.CLIENT_SPAN; -class URLConnectionSenderTest { +class ITURLConnectionSender { MockWebServer server = new MockWebServer(); @AfterEach void closeServer() throws IOException {