diff --git a/.github/workflows/create_release.yml b/.github/workflows/create_release.yml index 3bb12b15..8c14fab9 100644 --- a/.github/workflows/create_release.yml +++ b/.github/workflows/create_release.yml @@ -24,13 +24,13 @@ jobs: uses: actions/setup-java@v4 with: distribution: 'zulu' # zulu as it supports a wide version range - java-version: '11' # earliest LTS and last that can compile the 1.6 release profile. + java-version: '17' # earliest LTS and last that can compile the 1.6 release profile. - name: Cache local Maven repository uses: actions/cache@v3 with: path: ~/.m2/repository - key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} - restore-keys: ${{ runner.os }}-maven- + key: ${{ runner.os }}-jdk-17-maven-${{ hashFiles('**/pom.xml') }} + restore-keys: ${{ runner.os }}-jdk-17-maven- - name: Create Release env: # GH_USER= diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 1d7ba5f2..c5567683 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -27,13 +27,13 @@ jobs: uses: actions/setup-java@v4 with: distribution: 'zulu' # zulu as it supports a wide version range - java-version: '11' # earliest LTS and last that can compile the 1.6 release profile. + java-version: '17' # earliest LTS supported by Spring Boot 3 - name: Cache local Maven repository uses: actions/cache@v3 with: path: ~/.m2/repository - key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} - restore-keys: ${{ runner.os }}-maven- + key: ${{ runner.os }}-jdk-17-maven-${{ hashFiles('**/pom.xml') }} + restore-keys: ${{ runner.os }}-jdk-17-maven- # Don't attempt to cache Docker. Sensitive information can be stolen # via forks, and login session ends up in ~/.docker. This is ok because # we publish DOCKER_PARENT_IMAGE to ghcr.io, hence local to the runner. diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 472dad6d..f34aa28d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -28,13 +28,13 @@ jobs: uses: actions/setup-java@v4 with: distribution: 'zulu' # zulu as it supports a wide version range - java-version: '11' # earliest LTS and last that can compile the 1.6 release profile. + java-version: '17' # earliest LTS supported by Spring Boot 3 - name: Cache local Maven repository uses: actions/cache@v3 with: path: ~/.m2/repository - key: ${{ runner.os }}-jdk-11-maven-${{ hashFiles('**/pom.xml') }} - restore-keys: ${{ runner.os }}-jdk-11-maven- + key: ${{ runner.os }}-jdk-17-maven-${{ hashFiles('**/pom.xml') }} + restore-keys: ${{ runner.os }}-jdk-17-maven- - name: Build JavaDoc run: ./mvnw clean javadoc:aggregate -Prelease @@ -46,7 +46,7 @@ jobs: fail-fast: false # don't fail fast as sometimes failures are operating system specific matrix: # use latest available versions and be consistent on all workflows! include: - - java_version: 11 # Last that can compile zipkin core to 1.6 for zipkin-reporter + - java_version: 17 # earliest LTS supported by Spring Boot 3 maven_args: -Prelease -Dgpg.skip -Dmaven.javadoc.skip=true - java_version: 21 # Most recent LTS steps: @@ -69,4 +69,4 @@ jobs: # via forks, and login session ends up in ~/.docker. This is ok because # we publish DOCKER_PARENT_IMAGE to ghcr.io, hence local to the runner. - name: Test - run: build-bin/configure_test && build-bin/test + run: build-bin/configure_test && build-bin/test ${{ matrix.maven_args }} diff --git a/aws-junit/pom.xml b/aws-junit/pom.xml index b2135fe4..88eb2648 100644 --- a/aws-junit/pom.xml +++ b/aws-junit/pom.xml @@ -29,6 +29,11 @@ ${project.basedir}/.. + + + 17 + 17 + 17 diff --git a/aws-junit/src/main/java/zipkin2/junit/aws/AmazonSQSExtension.java b/aws-junit/src/main/java/zipkin2/junit/aws/AmazonSQSExtension.java index 89f07664..d7dc6767 100644 --- a/aws-junit/src/main/java/zipkin2/junit/aws/AmazonSQSExtension.java +++ b/aws-junit/src/main/java/zipkin2/junit/aws/AmazonSQSExtension.java @@ -59,7 +59,7 @@ public AmazonSQSExtension() { client = AmazonSQSClientBuilder.standard() .withCredentials(new AWSStaticCredentialsProvider(new BasicAWSCredentials("x", "x"))) .withEndpointConfiguration( - new EndpointConfiguration(String.format("http://localhost:%d", serverPort), null)) + new EndpointConfiguration("http://localhost:%d".formatted(serverPort), null)) .build(); queueUrl = client.createQueue("zipkin").getQueueUrl(); } @@ -75,7 +75,7 @@ public AmazonSQSExtension() { client = null; } - if (server == null) { + if (server != null) { server.stopAndWait(); server = null; } @@ -112,7 +112,7 @@ public List getSpans(boolean delete) { ReceiveMessageResult result = client.receiveMessage(queueUrl); - while (result != null && result.getMessages().size() > 0) { + while (result != null && !result.getMessages().isEmpty()) { spans = Stream.concat(spans, result.getMessages().stream().flatMap(AmazonSQSExtension::decodeSpans)); @@ -123,7 +123,7 @@ public List getSpans(boolean delete) { List deletes = result.getMessages() .stream() .map(m -> new DeleteMessageRequest(queueUrl, m.getReceiptHandle())) - .collect(Collectors.toList()); + .toList(); deletes.forEach(d -> client.deleteMessage(d)); } } diff --git a/brave/instrumentation-aws-java-sdk-core/src/test/java/brave/instrumentation/aws/AwsClientTracingTest.java b/brave/instrumentation-aws-java-sdk-core/src/test/java/brave/instrumentation/aws/AwsClientTracingTest.java index 8ae20856..0f2a39a1 100644 --- a/brave/instrumentation-aws-java-sdk-core/src/test/java/brave/instrumentation/aws/AwsClientTracingTest.java +++ b/brave/instrumentation-aws-java-sdk-core/src/test/java/brave/instrumentation/aws/AwsClientTracingTest.java @@ -45,7 +45,7 @@ class AwsClientTracingTest extends ITRemote { public MockWebServer mockServer = new MockWebServer(); @SystemStub - private EnvironmentVariables variables = new EnvironmentVariables(); + private final EnvironmentVariables variables = new EnvironmentVariables(); private AmazonDynamoDB dbClient; private AmazonS3 s3Client; @@ -68,7 +68,7 @@ class AwsClientTracingTest extends ITRemote { .enableForceGlobalBucketAccess()); } - @Test void testSpanCreatedAndTagsApplied() throws InterruptedException { + @Test void testSpanCreatedAndTagsApplied() { mockServer.enqueue(createDeleteItemResponse()); dbClient.deleteItem("test", Collections.singletonMap("key", new AttributeValue("value"))); @@ -89,7 +89,7 @@ class AwsClientTracingTest extends ITRemote { AwsClientTracing.create(httpTracing).build(AmazonDynamoDBAsyncClientBuilder.standard()); } - @Test void testInternalAwsRequestsDoNotThrowNPE() throws InterruptedException { + @Test void testInternalAwsRequestsDoNotThrowNPE() { // Responds to the internal HEAD request mockServer.enqueue(new MockResponse() .setResponseCode(400) @@ -125,22 +125,23 @@ private MockResponse createDeleteItemResponse() { } private MockResponse getExistsResponse() { - return new MockResponse().setBody("\n" - + " \n" - + " 75aa57f09aa0c8caeab4f8c24e99d10f8e7faeebf76c078efc7c6caea54ba06a\n" - + " CustomersName@amazon.com\n" - + " \n" - + " \n" - + " \n" - + " \n" - + " 75aa57f09aa0c8caeab4f8c24e99d10f8e7faeebf76c078efc7c6caea54ba06a\n" - + " CustomersName@amazon.com\n" - + " \n" - + " FULL_CONTROL\n" - + " \n" - + " \n" - + " ") + return new MockResponse().setBody(""" + + + 75aa57f09aa0c8caeab4f8c24e99d10f8e7faeebf76c078efc7c6caea54ba06a + CustomersName@amazon.com + + + + + 75aa57f09aa0c8caeab4f8c24e99d10f8e7faeebf76c078efc7c6caea54ba06a + CustomersName@amazon.com + + FULL_CONTROL + + + """) .setResponseCode(200) .addHeader("x-amz-request-id", "abcd"); } diff --git a/brave/instrumentation-aws-java-sdk-v2-core/src/main/java/brave/instrumentation/awsv2/TracingExecutionInterceptor.java b/brave/instrumentation-aws-java-sdk-v2-core/src/main/java/brave/instrumentation/awsv2/TracingExecutionInterceptor.java index f326aaa5..95e74a86 100644 --- a/brave/instrumentation-aws-java-sdk-v2-core/src/main/java/brave/instrumentation/awsv2/TracingExecutionInterceptor.java +++ b/brave/instrumentation-aws-java-sdk-v2-core/src/main/java/brave/instrumentation/awsv2/TracingExecutionInterceptor.java @@ -31,13 +31,13 @@ /** * Traces AWS Java SDK V2 calls. Adds on the standard zipkin/brave http tags, as well as tags that * align with the XRay data model. - * + *

* This implementation creates 2 types of spans to allow for better error visibility. - * + *

* The outer span, "Application Span", wraps the whole SDK operation. This span uses the AWS service * as it's name and will NOT have a remoteService configuration, making it a local span. If the * entire operation results in an error then this span will have an error tag with the cause. - * + *

* The inner span, "Client Span", is created for each outgoing HTTP request. This span will be of * type CLIENT. The remoteService will be the name of the AWS service, and the span name will be the * name of the operation being done. If the request results in an error then the span will be tagged diff --git a/brave/propagation-aws/src/test/java/brave/propagation/aws/AWSPropagationTest.java b/brave/propagation-aws/src/test/java/brave/propagation/aws/AWSPropagationTest.java index 006be625..4567457e 100644 --- a/brave/propagation-aws/src/test/java/brave/propagation/aws/AWSPropagationTest.java +++ b/brave/propagation-aws/src/test/java/brave/propagation/aws/AWSPropagationTest.java @@ -55,9 +55,11 @@ class AWSPropagationTest { @Test void traceIdWhenPassThrough() { carrier.put( "x-amzn-trace-id", - "Robot=Hello;Self=1-582113d1-1e48b74b3603af8479078ed6; " - + "Root=1-58211399-36d228ad5d99923122bbe354; " - + "TotalTimeSoFar=112ms;CalledFrom=Foo"); + """ + Robot=Hello;Self=1-582113d1-1e48b74b3603af8479078ed6; \ + Root=1-58211399-36d228ad5d99923122bbe354; \ + TotalTimeSoFar=112ms;CalledFrom=Foo\ + """); TraceContext context = contextWithPassThrough(); @@ -186,9 +188,11 @@ TraceContext contextWithPassThrough() { // we currently permit them carrier.put( "x-amzn-trace-id", - "Robot=Hello;Self=1-582113d1-1e48b74b3603af8479078ed6; " - + "Root=1-58211399-36d228ad5d99923122bbe354; " - + "TotalTimeSoFar=112ms;CalledFrom=Foo"); + """ + Robot=Hello;Self=1-582113d1-1e48b74b3603af8479078ed6; \ + Root=1-58211399-36d228ad5d99923122bbe354; \ + TotalTimeSoFar=112ms;CalledFrom=Foo\ + """); TraceContextOrSamplingFlags extracted = extractor.extract(carrier); assertThat(extracted.traceIdContext()) diff --git a/collector/kinesis/pom.xml b/collector/kinesis/pom.xml index c5c4946d..3aac84b3 100644 --- a/collector/kinesis/pom.xml +++ b/collector/kinesis/pom.xml @@ -29,6 +29,11 @@ ${project.basedir}/../.. + + + 17 + 17 + 17 diff --git a/collector/kinesis/src/main/java/zipkin2/collector/kinesis/KinesisCollector.java b/collector/kinesis/src/main/java/zipkin2/collector/kinesis/KinesisCollector.java index 1a18c029..24a9a54e 100644 --- a/collector/kinesis/src/main/java/zipkin2/collector/kinesis/KinesisCollector.java +++ b/collector/kinesis/src/main/java/zipkin2/collector/kinesis/KinesisCollector.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2020 The OpenZipkin Authors + * Copyright 2016-2024 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 @@ -103,9 +103,8 @@ public KinesisCollector build() { private final Executor executor; private Worker worker; - private IRecordProcessorFactory processor; - KinesisCollector(Builder builder) { + KinesisCollector(Builder builder) { this.collector = builder.delegate.build(); this.metrics = builder.metrics; this.appName = builder.appName; @@ -133,7 +132,7 @@ public KinesisCollector start() { new KinesisClientLibConfiguration(appName, streamName, credentialsProvider, workerId); config.withRegionName(regionName); - processor = new KinesisRecordProcessorFactory(collector, metrics); + IRecordProcessorFactory processor = new KinesisRecordProcessorFactory(collector, metrics); worker = new Worker.Builder().recordProcessorFactory(processor).config(config).build(); executor.execute(worker); diff --git a/collector/kinesis/src/main/java/zipkin2/collector/kinesis/KinesisSpanProcessor.java b/collector/kinesis/src/main/java/zipkin2/collector/kinesis/KinesisSpanProcessor.java index e65305bd..891b7c91 100644 --- a/collector/kinesis/src/main/java/zipkin2/collector/kinesis/KinesisSpanProcessor.java +++ b/collector/kinesis/src/main/java/zipkin2/collector/kinesis/KinesisSpanProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2020 The OpenZipkin Authors + * Copyright 2016-2024 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 @@ -23,14 +23,15 @@ import zipkin2.collector.CollectorMetrics; final class KinesisSpanProcessor implements IRecordProcessor { - static final Callback NOOP = - new Callback() { - @Override - public void onSuccess(Void value) {} + static final Callback NOOP = new Callback<>() { + @Override + public void onSuccess(Void value) { + } - @Override - public void onError(Throwable t) {} - }; + @Override + public void onError(Throwable t) { + } + }; final Collector collector; final CollectorMetrics metrics; @@ -41,7 +42,8 @@ public void onError(Throwable t) {} } @Override - public void initialize(InitializationInput initializationInput) {} + public void initialize(InitializationInput initializationInput) { + } @Override public void processRecords(ProcessRecordsInput processRecordsInput) { @@ -54,5 +56,6 @@ public void processRecords(ProcessRecordsInput processRecordsInput) { } @Override - public void shutdown(ShutdownInput shutdownInput) {} + public void shutdown(ShutdownInput shutdownInput) { + } } diff --git a/collector/kinesis/src/test/java/zipkin2/collector/kinesis/KinesisSpanProcessorTest.java b/collector/kinesis/src/test/java/zipkin2/collector/kinesis/KinesisSpanProcessorTest.java index b9858b59..b73cdaf7 100644 --- a/collector/kinesis/src/test/java/zipkin2/collector/kinesis/KinesisSpanProcessorTest.java +++ b/collector/kinesis/src/test/java/zipkin2/collector/kinesis/KinesisSpanProcessorTest.java @@ -40,7 +40,7 @@ class KinesisSpanProcessorTest { TestObjects.LOTS_OF_SPANS[0], TestObjects.LOTS_OF_SPANS[1], TestObjects.LOTS_OF_SPANS[2]); private InMemoryStorage storage; - private InMemoryCollectorMetrics metrics = new InMemoryCollectorMetrics(); + private final InMemoryCollectorMetrics metrics = new InMemoryCollectorMetrics(); private Collector collector; private KinesisSpanProcessor kinesisSpanProcessor; @@ -80,7 +80,7 @@ class KinesisSpanProcessorTest { void messageWithMultipleSpans(SpanBytesEncoder encoder) { byte[] message = encoder.encodeList(spans); - List records = Arrays.asList(new Record().withData(ByteBuffer.wrap(message))); + List records = Collections.singletonList(new Record().withData(ByteBuffer.wrap(message))); kinesisSpanProcessor.processRecords(new ProcessRecordsInput().withRecords(records)); assertThat(storage.spanStore().getTraces().size()).isEqualTo(spans.size()); diff --git a/collector/sqs/pom.xml b/collector/sqs/pom.xml index a53fc1ec..83d6d991 100644 --- a/collector/sqs/pom.xml +++ b/collector/sqs/pom.xml @@ -29,6 +29,11 @@ ${project.basedir}/../.. + + + 17 + 17 + 17 diff --git a/collector/sqs/src/main/java/zipkin2/collector/sqs/SQSSpanProcessor.java b/collector/sqs/src/main/java/zipkin2/collector/sqs/SQSSpanProcessor.java index f70790d2..ea975e39 100644 --- a/collector/sqs/src/main/java/zipkin2/collector/sqs/SQSSpanProcessor.java +++ b/collector/sqs/src/main/java/zipkin2/collector/sqs/SQSSpanProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2020 The OpenZipkin Authors + * Copyright 2016-2024 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 @@ -16,11 +16,11 @@ import com.amazonaws.AbortedException; import com.amazonaws.services.sqs.AmazonSQS; import com.amazonaws.services.sqs.model.DeleteMessageBatchRequestEntry; -import com.amazonaws.services.sqs.model.DeleteMessageBatchResult; import com.amazonaws.services.sqs.model.Message; import com.amazonaws.services.sqs.model.ReceiveMessageRequest; import com.amazonaws.util.Base64; import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; import java.util.concurrent.atomic.AtomicBoolean; @@ -37,7 +37,7 @@ final class SQSSpanProcessor extends Component implements Runnable { private static final Logger logger = Logger.getLogger(SQSSpanProcessor.class.getName()); - private static final Charset UTF_8 = Charset.forName("UTF-8"); + private static final Charset UTF_8 = StandardCharsets.UTF_8; private static final long DEFAULT_BACKOFF = 100; private static final long MAX_BACKOFF = 30000; @@ -96,7 +96,7 @@ public void run() { } private void process(final List messages) { - if (messages.size() == 0) return; + if (messages.isEmpty()) return; final List toDelete = new ArrayList<>(); int count = 0; @@ -110,26 +110,24 @@ private void process(final List messages) { stringBody.charAt(0) == '[' ? stringBody.getBytes(UTF_8) : Base64.decode(stringBody); metrics.incrementMessages(); metrics.incrementBytes(serialized.length); - collector.acceptSpans( - serialized, - new Callback() { - @Override - public void onSuccess(Void value) { - toDelete.add( - new DeleteMessageBatchRequestEntry(deleteId, message.getReceiptHandle())); - } - - @Override - public void onError(Throwable t) { - logger.log(Level.WARNING, "collector accept failed", t); - // for cases that are not recoverable just discard the message, - // otherwise ignore so processing can be retried. - if (t instanceof IllegalArgumentException) { - toDelete.add( - new DeleteMessageBatchRequestEntry(deleteId, message.getReceiptHandle())); - } - } - }); + collector.acceptSpans(serialized, new Callback<>() { + @Override + public void onSuccess(Void value) { + toDelete.add( + new DeleteMessageBatchRequestEntry(deleteId, message.getReceiptHandle())); + } + + @Override + public void onError(Throwable t) { + logger.log(Level.WARNING, "collector accept failed", t); + // for cases that are not recoverable just discard the message, + // otherwise ignore so processing can be retried. + if (t instanceof IllegalArgumentException) { + toDelete.add( + new DeleteMessageBatchRequestEntry(deleteId, message.getReceiptHandle())); + } + } + }); } catch (RuntimeException | Error e) { logger.log(Level.WARNING, "message decoding failed", e); toDelete.add(new DeleteMessageBatchRequestEntry(deleteId, message.getReceiptHandle())); @@ -141,11 +139,11 @@ public void onError(Throwable t) { } } - private DeleteMessageBatchResult delete(List entries) { - return client.deleteMessageBatch(queueUrl, entries); + private void delete(List entries) { + client.deleteMessageBatch(queueUrl, entries); } - @Override public final String toString() { + @Override public String toString() { return "SQSSpanProcessor{queueUrl=" + queueUrl + "}"; } } diff --git a/docker/Dockerfile b/docker/Dockerfile index 6071ab03..f8b4423a 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -13,7 +13,7 @@ # # zipkin version should match zipkin.version in /pom.xml -ARG zipkin_version=2.27.0 +ARG zipkin_version=3.0.0 # java_version is used during the installation process to build or download the module jar. # diff --git a/module/README.md b/module/README.md index 76d66015..0ea025cc 100644 --- a/module/README.md +++ b/module/README.md @@ -25,7 +25,7 @@ $ curl -sSL https://zipkin.io/quickstart.sh | bash -s $ curl -sSL https://zipkin.io/quickstart.sh | bash -s io.zipkin.aws:zipkin-module-aws:LATEST:module sqs.jar $ SQS_QUEUE_URL=https://ap-southeast-1.queue.amazonaws.com/012345678901/zipkin \ java -Dloader.path='aws.jar,aws.jar!/lib' -Dspring.profiles.active=aws \ - -cp zipkin.jar org.springframework.boot.loader.PropertiesLauncher + -cp zipkin.jar org.springframework.boot.loader.launch.PropertiesLauncher ``` *Note:* By default, this module will search for credentials in the $HOME/.aws directory. @@ -70,7 +70,7 @@ Example usage: ```bash $ KINESIS_STREAM_NAME=zipkin \ java -Dloader.path='aws.jar,aws.jar!/lib' -Dspring.profiles.active=aws \ - -cp zipkin.jar org.springframework.boot.loader.PropertiesLauncher + -cp zipkin.jar org.springframework.boot.loader.launch.PropertiesLauncher ``` #### Security @@ -148,7 +148,7 @@ Example usage: ```bash $ SQS_QUEUE_URL=https://ap-southeast-1.queue.amazonaws.com/012345678901/zipkin \ java -Dloader.path='aws.jar,aws.jar!/lib' -Dspring.profiles.active=aws \ - -cp zipkin.jar org.springframework.boot.loader.PropertiesLauncher + -cp zipkin.jar org.springframework.boot.loader.launch.PropertiesLauncher ``` #### Security @@ -215,14 +215,14 @@ Example usage: ```bash $ STORAGE_TYPE=elasticsearch ES_HOSTS=https://search-mydomain-2rlih66ibw43ftlk4342ceeewu.ap-southeast-1.es.amazonaws.com \ java -Dloader.path='aws.jar,aws.jar!/lib' -Dspring.profiles.active=aws \ - -cp zipkin.jar org.springframework.boot.loader.PropertiesLauncher + -cp zipkin.jar org.springframework.boot.loader.launch.PropertiesLauncher ``` Alternatively, you can have zipkin implicitly lookup your domain's URL: ```bash $ STORAGE_TYPE=elasticsearch ES_AWS_DOMAIN=mydomain ES_AWS_REGION=ap-southeast-1 \ java -Dloader.path='aws.jar,aws.jar!/lib' -Dspring.profiles.active=aws \ - -cp zipkin.jar org.springframework.boot.loader.PropertiesLauncher + -cp zipkin.jar org.springframework.boot.loader.launch.PropertiesLauncher ``` #### Security @@ -258,7 +258,7 @@ Example usage: ```bash $ STORAGE_TYPE=xray java -Dloader.path='aws.jar,aws.jar!/lib' -Dspring.profiles.active=aws \ - -cp zipkin.jar org.springframework.boot.loader.PropertiesLauncher + -cp zipkin.jar org.springframework.boot.loader.launch.PropertiesLauncher ``` #### Experimental diff --git a/module/pom.xml b/module/pom.xml index c11ea893..f701fbcc 100644 --- a/module/pom.xml +++ b/module/pom.xml @@ -28,6 +28,11 @@ ${project.basedir}/.. + + + 17 + 17 + 17 @@ -52,6 +57,11 @@ ${spring-boot.version} provided + + org.apache.logging.log4j + log4j-core + ${log4j.version} + org.springframework.boot @@ -129,7 +139,7 @@ module - ${zipkin.groupId},org.springframework.boot,org.springframework,com.fasterxml.jackson.core,com.google.auto.value,com.google.code.gson,org.reactivestreams,com.google.code.findbugs,javax.annotation,org.slf4j,io.netty,io.micrometer,org.hdrhistogram,org.latencyutils,${armeria.groupId},javax.inject,com.fasterxml.jackson.datatype + ${zipkin.groupId},org.springframework.boot,org.springframework,com.fasterxml.jackson.core,com.google.auto.value,com.google.code.gson,org.reactivestreams,com.google.code.findbugs,javax.annotation,org.slf4j,io.netty,io.micrometer,org.hdrhistogram,org.latencyutils,${armeria.groupId},javax.inject,com.fasterxml.jackson.datatype,com.aayushatharva.brotli4j,commons-logging diff --git a/module/src/main/java/zipkin/module/aws/elasticsearch/AWSSignatureVersion4.java b/module/src/main/java/zipkin/module/aws/elasticsearch/AWSSignatureVersion4.java index 4a68fd8b..d54a1eaa 100644 --- a/module/src/main/java/zipkin/module/aws/elasticsearch/AWSSignatureVersion4.java +++ b/module/src/main/java/zipkin/module/aws/elasticsearch/AWSSignatureVersion4.java @@ -41,7 +41,6 @@ import static com.linecorp.armeria.common.HttpHeaderNames.AUTHORITY; import static com.linecorp.armeria.common.HttpHeaderNames.HOST; -import static java.lang.String.format; import static java.nio.charset.StandardCharsets.UTF_8; // http://docs.aws.amazon.com/general/latest/gr/signature-version-4.html @@ -171,8 +170,8 @@ static void writeToSign( static byte[] sha256(HttpData data) { final ByteBuffer buf; - if (data instanceof ByteBufHolder) { - buf = ((ByteBufHolder) data).content().nioBuffer(); + if (data instanceof ByteBufHolder holder) { + buf = holder.content().nioBuffer(); } else { buf = ByteBuffer.wrap(data.array()); } @@ -250,7 +249,7 @@ AggregatedHttpRequest sign(ClientRequestContext ctx, AggregatedHttpRequest req) } static String credentialScope(String yyyyMMdd, String region) { - return format("%s/%s/%s/%s", yyyyMMdd, region, SERVICE, "aws4_request"); + return "%s/%s/%s/%s".formatted(yyyyMMdd, region, SERVICE, "aws4_request"); } byte[] signatureKey(String secretKey, String yyyyMMdd) { diff --git a/module/src/main/java/zipkin/module/aws/elasticsearch/ZipkinElasticsearchAwsStorageModule.java b/module/src/main/java/zipkin/module/aws/elasticsearch/ZipkinElasticsearchAwsStorageModule.java index f7948873..c390e4e7 100644 --- a/module/src/main/java/zipkin/module/aws/elasticsearch/ZipkinElasticsearchAwsStorageModule.java +++ b/module/src/main/java/zipkin/module/aws/elasticsearch/ZipkinElasticsearchAwsStorageModule.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2020 The OpenZipkin Authors + * Copyright 2016-2024 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 @@ -44,8 +44,6 @@ import org.springframework.core.env.Environment; import org.springframework.core.type.AnnotatedTypeMetadata; -import static java.lang.String.format; - @Configuration @EnableConfigurationProperties(ZipkinElasticsearchAwsStorageProperties.class) @Conditional(ZipkinElasticsearchAwsStorageModule.AwsMagic.class) @@ -87,10 +85,12 @@ Consumer awsSignatureVersion4(String region, hosts = ZipkinElasticsearchAwsStorageProperties.emptyToNull(hosts); String domain = aws.getDomain(); if (hosts != null && domain != null) { - log.warning(format( - "Expected exactly one of hosts or domain: instead saw hosts '%s' and domain '%s'." - + " Ignoring hosts and proceeding to look for domain. Either unset ES_HOSTS or " - + "ES_AWS_DOMAIN to suppress this message.", + log.warning(( + """ + Expected exactly one of hosts or domain: instead saw hosts '%s' and domain '%s'.\ + Ignoring hosts and proceeding to look for domain. Either unset ES_HOSTS or \ + ES_AWS_DOMAIN to suppress this message.\ + """).formatted( hosts, domain)); } @@ -115,8 +115,8 @@ AWSCredentials.Provider credentials() { @Override public AWSCredentials get() { com.amazonaws.auth.AWSCredentials result = delegate.getCredentials(); String sessionToken = - result instanceof AWSSessionCredentials - ? ((AWSSessionCredentials) result).getSessionToken() + result instanceof AWSSessionCredentials awssc + ? awssc.getSessionToken() : null; return new AWSCredentials( result.getAWSAccessKeyId(), result.getAWSSecretKey(), sessionToken); diff --git a/module/src/main/java/zipkin/module/aws/kinesis/ZipkinKinesisCredentialsConfiguration.java b/module/src/main/java/zipkin/module/aws/kinesis/ZipkinKinesisCredentialsConfiguration.java index 7fec3e67..7b2a895b 100644 --- a/module/src/main/java/zipkin/module/aws/kinesis/ZipkinKinesisCredentialsConfiguration.java +++ b/module/src/main/java/zipkin/module/aws/kinesis/ZipkinKinesisCredentialsConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2020 The OpenZipkin Authors + * Copyright 2016-2024 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 @@ -69,8 +69,8 @@ private static AWSCredentialsProvider getDefaultCredentialsProvider( AWSCredentialsProvider provider = new DefaultAWSCredentialsProviderChain(); // Create credentials provider from ID and secret if given. - if (!isNullOrEmpty(properties.getAwsAccessKeyId()) - && !isNullOrEmpty(properties.getAwsSecretAccessKey())) { + if (notNullOrEmpty(properties.getAwsAccessKeyId()) + && notNullOrEmpty(properties.getAwsSecretAccessKey())) { provider = new AWSStaticCredentialsProvider( new BasicAWSCredentials(properties.getAwsAccessKeyId(), properties.getAwsSecretAccessKey())); @@ -79,8 +79,8 @@ private static AWSCredentialsProvider getDefaultCredentialsProvider( return provider; } - private static boolean isNullOrEmpty(String value) { - return (value == null || value.equals("")); + private static boolean notNullOrEmpty(String value) { + return (value != null && !value.isEmpty()); } /** diff --git a/module/src/main/java/zipkin/module/aws/sqs/ZipkinSQSCredentialsConfiguration.java b/module/src/main/java/zipkin/module/aws/sqs/ZipkinSQSCredentialsConfiguration.java index 923d7acf..7f39895a 100644 --- a/module/src/main/java/zipkin/module/aws/sqs/ZipkinSQSCredentialsConfiguration.java +++ b/module/src/main/java/zipkin/module/aws/sqs/ZipkinSQSCredentialsConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2020 The OpenZipkin Authors + * Copyright 2016-2024 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 @@ -69,8 +69,8 @@ private static AWSCredentialsProvider getDefaultCredentialsProvider( AWSCredentialsProvider provider = new DefaultAWSCredentialsProviderChain(); // Create credentials provider from ID and secret if given. - if (!isNullOrEmpty(properties.awsAccessKeyId) - && !isNullOrEmpty(properties.awsSecretAccessKey)) { + if (notNullOrEmpty(properties.awsAccessKeyId) + && notNullOrEmpty(properties.awsSecretAccessKey)) { provider = new AWSStaticCredentialsProvider( new BasicAWSCredentials(properties.awsAccessKeyId, properties.awsSecretAccessKey)); @@ -79,8 +79,8 @@ private static AWSCredentialsProvider getDefaultCredentialsProvider( return provider; } - private static boolean isNullOrEmpty(String value) { - return (value == null || value.equals("")); + private static boolean notNullOrEmpty(String value) { + return (value != null && !value.isEmpty()); } /** diff --git a/module/src/test/java/zipkin/module/aws/elasticsearch/AWSSignatureVersion4Test.java b/module/src/test/java/zipkin/module/aws/elasticsearch/AWSSignatureVersion4Test.java index f607444f..5bc183c4 100644 --- a/module/src/test/java/zipkin/module/aws/elasticsearch/AWSSignatureVersion4Test.java +++ b/module/src/test/java/zipkin/module/aws/elasticsearch/AWSSignatureVersion4Test.java @@ -125,15 +125,16 @@ class AWSSignatureVersion4Test { writeCanonicalString(ctx, request.headers(), request.content(), result); // Ensure that the canonical string encodes commas with %2C - assertThat(result.toString(UTF_8)).isEqualTo("" - + "POST\n" - + "/zipkin-2016-10-05%2Czipkin-2016-10-06/dependencylink/_search\n" - + "allow_no_indices=true&expand_wildcards=open&ignore_unavailable=true\n" - + "host:search-zipkin-2rlyh66ibw43ftlk4342ceeewu.ap-southeast-1.es.amazonaws.com\n" - + "x-amz-date:20161004T132314Z\n" - + "\n" - + "host;x-amz-date\n" - + "2fd35cb36e5de91bbae279313c371fb630a6b3aab1478df378c5e73e667a1747"); + assertThat(result.toString(UTF_8)).isEqualTo(""" + POST + /zipkin-2016-10-05%2Czipkin-2016-10-06/dependencylink/_search + allow_no_indices=true&expand_wildcards=open&ignore_unavailable=true + host:search-zipkin-2rlyh66ibw43ftlk4342ceeewu.ap-southeast-1.es.amazonaws.com + x-amz-date:20161004T132314Z + + host;x-amz-date + 2fd35cb36e5de91bbae279313c371fb630a6b3aab1478df378c5e73e667a1747\ + """); } /** Starting with Zipkin 1.31 colons are used to delimit index types in ES */ @@ -153,15 +154,16 @@ class AWSSignatureVersion4Test { writeCanonicalString(ctx, request.headers(), request.content(), result); // Ensure that the canonical string encodes commas with %2C - assertThat(result.toString(UTF_8)).isEqualTo("" - + "GET\n" - + "/_cluster/health/zipkin%3Aspan-%2A\n" - + "\n" - + "host:search-zipkin53-mhdyquzbwwzwvln6phfzr3mmdi.ap-southeast-1.es.amazonaws.com\n" - + "x-amz-date:20170830T143137Z\n" - + "\n" - + "host;x-amz-date\n" - + "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"); + assertThat(result.toString(UTF_8)).isEqualTo(""" + GET + /_cluster/health/zipkin%3Aspan-%2A + + host:search-zipkin53-mhdyquzbwwzwvln6phfzr3mmdi.ap-southeast-1.es.amazonaws.com + x-amz-date:20170830T143137Z + + host;x-amz-date + e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855\ + """); } @Test void canonicalString_getDomain() { @@ -180,24 +182,24 @@ class AWSSignatureVersion4Test { writeCanonicalString(ctx, request.headers(), request.content(), canonicalString); - assertThat(canonicalString.toString(UTF_8)).isEqualTo("" - + "GET\n" - + "/2015-01-01/es/domain/zipkin\n" - + "\n" - + "host:es.ap-southeast-1.amazonaws.com\n" - + "x-amz-date:" + timestamp + "\n" - + "\n" - + "host;x-amz-date\n" - + "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"); + assertThat(canonicalString.toString(UTF_8)).isEqualTo("GET\n" + + "/2015-01-01/es/domain/zipkin\n" + + "\n" + + "host:es.ap-southeast-1.amazonaws.com\n" + + "x-amz-date:" + timestamp + "\n" + + "\n" + + "host;x-amz-date\n" + + "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"); ByteBuf toSign = Unpooled.buffer(); AWSSignatureVersion4.writeToSign(timestamp, AWSSignatureVersion4.credentialScope(yyyyMMdd, "ap-southeast-1"), canonicalString, toSign); - assertThat(toSign.toString(UTF_8)).isEqualTo("" - + "AWS4-HMAC-SHA256\n" - + "20190730T134617Z\n" - + "20190730/ap-southeast-1/es/aws4_request\n" - + "129dd8ded740553cd28544b4000982b8f88d7199b36a013fa89ee8e56c23f80e"); + assertThat(toSign.toString(UTF_8)).isEqualTo(""" + AWS4-HMAC-SHA256 + 20190730T134617Z + 20190730/ap-southeast-1/es/aws4_request + 129dd8ded740553cd28544b4000982b8f88d7199b36a013fa89ee8e56c23f80e\ + """); } } diff --git a/module/src/test/java/zipkin/module/aws/elasticsearch/ElasticsearchDomainEndpointTest.java b/module/src/test/java/zipkin/module/aws/elasticsearch/ElasticsearchDomainEndpointTest.java index f17f5f58..e6836f28 100644 --- a/module/src/test/java/zipkin/module/aws/elasticsearch/ElasticsearchDomainEndpointTest.java +++ b/module/src/test/java/zipkin/module/aws/elasticsearch/ElasticsearchDomainEndpointTest.java @@ -64,12 +64,14 @@ class ElasticsearchDomainEndpointTest { MOCK_RESPONSE.set(AggregatedHttpResponse.of( HttpStatus.OK, MediaType.JSON_UTF_8, - "{\n" - + " \"DomainStatus\": {\n" - + " \"Endpoint\": \"search-zipkin53-mhdyquzbwwzwvln6phfzr3lldi.ap-southeast-1.es.amazonaws.com\",\n" - + " \"Endpoints\": null\n" - + " }\n" - + "}")); + """ + { + "DomainStatus": { + "Endpoint": "search-zipkin53-mhdyquzbwwzwvln6phfzr3lldi.ap-southeast-1.es.amazonaws.com", + "Endpoints": null + } + }\ + """)); assertThat(client.get()).extracting("hostname") .isEqualTo( @@ -80,14 +82,16 @@ class ElasticsearchDomainEndpointTest { MOCK_RESPONSE.set(AggregatedHttpResponse.of( HttpStatus.OK, MediaType.JSON_UTF_8, - "{\n" - + " \"DomainStatus\": {\n" - + " \"Endpoint\": null,\n" - + " \"Endpoints\": {\n" - + " \"vpc\":\"search-zipkin53-mhdyquzbwwzwvln6phfzr3lldi.ap-southeast-1.es.amazonaws.com\"\n" - + " }\n" - + " }\n" - + "}")); + """ + { + "DomainStatus": { + "Endpoint": null, + "Endpoints": { + "vpc":"search-zipkin53-mhdyquzbwwzwvln6phfzr3lldi.ap-southeast-1.es.amazonaws.com" + } + } + }\ + """)); assertThat(client.get()).extracting("hostname") .isEqualTo( @@ -98,14 +102,16 @@ class ElasticsearchDomainEndpointTest { MOCK_RESPONSE.set(AggregatedHttpResponse.of( HttpStatus.OK, MediaType.JSON_UTF_8, - "{\n" - + " \"DomainStatus\": {\n" - + " \"Endpoint\": \"isnotvpc\",\n" - + " \"Endpoints\": {\n" - + " \"vpc\":\"isvpc\"\n" - + " }\n" - + " }\n" - + "}")); + """ + { + "DomainStatus": { + "Endpoint": "isnotvpc", + "Endpoints": { + "vpc":"isvpc" + } + } + }\ + """)); assertThat(client.get()).extracting("hostname") .isEqualTo("isvpc"); @@ -115,12 +121,14 @@ class ElasticsearchDomainEndpointTest { MOCK_RESPONSE.set(AggregatedHttpResponse.of( HttpStatus.OK, MediaType.JSON_UTF_8, - "{\n" - + " \"DomainStatus\": {\n" - + " \"Endpoint\": \"isnotvpc\",\n" - + " \"Endpoints\": {}\n" - + " }\n" - + "}")); + """ + { + "DomainStatus": { + "Endpoint": "isnotvpc", + "Endpoints": {} + } + }\ + """)); assertThat(client.get()).extracting("hostname") .isEqualTo("isnotvpc"); diff --git a/pom.xml b/pom.xml index c8a43c24..a6054221 100644 --- a/pom.xml +++ b/pom.xml @@ -70,23 +70,24 @@ 8 - 11 - 11 - 11 + 17 + 17 + 17 io.zipkin.zipkin2 - 2.27.1 - 3.0.2 - 2.7.18 + 3.0.0 + 3.1.1 + 3.2.1 2.16.1 com.linecorp.armeria 1.26.4 4.1.100.Final + 2.21.1 @@ -97,7 +98,6 @@ 1.12.633 2.22.13 - 2.22.1 4.12.0 3.25.1 diff --git a/reporter/reporter-xray-udp/src/main/java/zipkin2/reporter/xray_udp/XRayUDPReporter.java b/reporter/reporter-xray-udp/src/main/java/zipkin2/reporter/xray_udp/XRayUDPReporter.java index 4461bb81..51c1cd93 100644 --- a/reporter/reporter-xray-udp/src/main/java/zipkin2/reporter/xray_udp/XRayUDPReporter.java +++ b/reporter/reporter-xray-udp/src/main/java/zipkin2/reporter/xray_udp/XRayUDPReporter.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2020 The OpenZipkin Authors + * Copyright 2016-2024 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 @@ -25,7 +25,7 @@ /** * Reports Zipkin spans to AWS X-Ray via the X-Ray daemon, contacted using UDP. - * + *

* Note that, unlike AsyncReporter, this reporter attempts to encode and send * the span immediately on the calling thread. As UDP is used, there is no * latency in waiting for the daemon to accept and respond to the data. diff --git a/reporter/sender-awssdk-sqs/src/test/java/zipkin2/reporter/awssdk/sqs/SQSAsyncSenderTest.java b/reporter/sender-awssdk-sqs/src/test/java/zipkin2/reporter/awssdk/sqs/SQSAsyncSenderTest.java index b4a4c4fa..f0624a34 100644 --- a/reporter/sender-awssdk-sqs/src/test/java/zipkin2/reporter/awssdk/sqs/SQSAsyncSenderTest.java +++ b/reporter/sender-awssdk-sqs/src/test/java/zipkin2/reporter/awssdk/sqs/SQSAsyncSenderTest.java @@ -39,40 +39,45 @@ import static zipkin2.TestObjects.CLIENT_SPAN; class SQSAsyncSenderTest { - @RegisterExtension AmazonSQSExtension sqs = new AmazonSQSExtension(); + @RegisterExtension + AmazonSQSExtension sqs = new AmazonSQSExtension(); - private SqsClient sqsClient; private SQSSender sender; - @BeforeEach public void setup() { - sqsClient = SqsClient.builder() - .httpClient(UrlConnectionHttpClient.create()) - .region(Region.US_EAST_1) - .endpointOverride(URI.create(sqs.queueUrl())) - .credentialsProvider( - StaticCredentialsProvider.create(AwsBasicCredentials.create("x", "x"))) - .build(); + @BeforeEach + public void setup() { + SqsClient sqsClient = SqsClient.builder() + .httpClient(UrlConnectionHttpClient.create()) + .region(Region.US_EAST_1) + .endpointOverride(URI.create(sqs.queueUrl())) + .credentialsProvider( + StaticCredentialsProvider.create( + AwsBasicCredentials.create("x", "x"))) + .build(); sender = SQSSender.newBuilder() - .queueUrl(sqs.queueUrl()) - .sqsClient(sqsClient) - .build(); + .queueUrl(sqs.queueUrl()) + .sqsClient(sqsClient) + .build(); } - @Test void sendsSpans() throws Exception { + @Test + void sendsSpans() throws Exception { send(CLIENT_SPAN, CLIENT_SPAN).execute(); assertThat(readSpans()).containsExactly(CLIENT_SPAN, CLIENT_SPAN); } - @Test void sendsSpans_json_unicode() throws Exception { + @Test + void sendsSpans_json_unicode() throws Exception { Span unicode = CLIENT_SPAN.toBuilder().putTag("error", "\uD83D\uDCA9").build(); send(unicode).execute(); assertThat(readSpans()).containsExactly(unicode); } - @Test void sendsSpans_PROTO3() throws Exception { + @Test + void sendsSpans_PROTO3() throws Exception { sender.close(); sender = sender.toBuilder().encoding(Encoding.PROTO3).build(); @@ -81,30 +86,31 @@ class SQSAsyncSenderTest { assertThat(readSpans()).containsExactly(CLIENT_SPAN, CLIENT_SPAN); } - @Test void outOfBandCancel() throws Exception { + @Test + void outOfBandCancel() throws Exception { SQSSender.SQSCall call = (SQSSender.SQSCall) send(CLIENT_SPAN, CLIENT_SPAN); assertThat(call.isCanceled()).isFalse(); // sanity check CountDownLatch latch = new CountDownLatch(1); - call.enqueue( - new Callback() { - @Override - public void onSuccess(Void aVoid) { - call.cancel(); - latch.countDown(); - } - - @Override - public void onError(Throwable throwable) { - latch.countDown(); - } - }); + call.enqueue(new Callback<>() { + @Override + public void onSuccess(Void aVoid) { + call.cancel(); + latch.countDown(); + } + + @Override + public void onError(Throwable throwable) { + latch.countDown(); + } + }); latch.await(5, TimeUnit.SECONDS); assertThat(call.isCanceled()).isTrue(); } - @Test void checkOk() { + @Test + void checkOk() { assertThat(sender.check()).isEqualTo(CheckResult.OK); } diff --git a/reporter/sender-awssdk-sqs/src/test/java/zipkin2/reporter/awssdk/sqs/SQSSenderTest.java b/reporter/sender-awssdk-sqs/src/test/java/zipkin2/reporter/awssdk/sqs/SQSSenderTest.java index 39fbe5e3..208d130e 100644 --- a/reporter/sender-awssdk-sqs/src/test/java/zipkin2/reporter/awssdk/sqs/SQSSenderTest.java +++ b/reporter/sender-awssdk-sqs/src/test/java/zipkin2/reporter/awssdk/sqs/SQSSenderTest.java @@ -39,40 +39,45 @@ import static zipkin2.TestObjects.CLIENT_SPAN; class SQSSenderTest { - @RegisterExtension AmazonSQSExtension sqs = new AmazonSQSExtension(); + @RegisterExtension + AmazonSQSExtension sqs = new AmazonSQSExtension(); - private SqsClient sqsClient; private SQSSender sender; - @BeforeEach public void setup() { - sqsClient = SqsClient.builder() - .httpClient(UrlConnectionHttpClient.create()) - .region(Region.US_EAST_1) - .endpointOverride(URI.create(sqs.queueUrl())) - .credentialsProvider( - StaticCredentialsProvider.create(AwsBasicCredentials.create("x", "x"))) - .build(); + @BeforeEach + public void setup() { + SqsClient sqsClient = SqsClient.builder() + .httpClient(UrlConnectionHttpClient.create()) + .region(Region.US_EAST_1) + .endpointOverride(URI.create(sqs.queueUrl())) + .credentialsProvider( + StaticCredentialsProvider.create( + AwsBasicCredentials.create("x", "x"))) + .build(); sender = SQSSender.newBuilder() - .queueUrl(sqs.queueUrl()) - .sqsClient(sqsClient) - .build(); + .queueUrl(sqs.queueUrl()) + .sqsClient(sqsClient) + .build(); } - @Test void sendsSpans() throws Exception { + @Test + void sendsSpans() throws Exception { send(CLIENT_SPAN, CLIENT_SPAN).execute(); assertThat(readSpans()).containsExactly(CLIENT_SPAN, CLIENT_SPAN); } - @Test void sendsSpans_json_unicode() throws Exception { + @Test + void sendsSpans_json_unicode() throws Exception { Span unicode = CLIENT_SPAN.toBuilder().putTag("error", "\uD83D\uDCA9").build(); send(unicode).execute(); assertThat(readSpans()).containsExactly(unicode); } - @Test void sendsSpans_PROTO3() throws Exception { + @Test + void sendsSpans_PROTO3() throws Exception { sender.close(); sender = sender.toBuilder().encoding(Encoding.PROTO3).build(); @@ -81,30 +86,31 @@ class SQSSenderTest { assertThat(readSpans()).containsExactly(CLIENT_SPAN, CLIENT_SPAN); } - @Test void outOfBandCancel() throws Exception { + @Test + void outOfBandCancel() throws Exception { SQSSender.SQSCall call = (SQSSender.SQSCall) send(CLIENT_SPAN, CLIENT_SPAN); assertThat(call.isCanceled()).isFalse(); // sanity check CountDownLatch latch = new CountDownLatch(1); - call.enqueue( - new Callback() { - @Override - public void onSuccess(Void aVoid) { - call.cancel(); - latch.countDown(); - } - - @Override - public void onError(Throwable throwable) { - latch.countDown(); - } - }); + call.enqueue(new Callback<>() { + @Override + public void onSuccess(Void aVoid) { + call.cancel(); + latch.countDown(); + } + + @Override + public void onError(Throwable throwable) { + latch.countDown(); + } + }); latch.await(5, TimeUnit.SECONDS); assertThat(call.isCanceled()).isTrue(); } - @Test void checkOk() { + @Test + void checkOk() { assertThat(sender.check()).isEqualTo(CheckResult.OK); } diff --git a/reporter/sender-kinesis/src/test/java/zipkin2/reporter/kinesis/KinesisSenderTest.java b/reporter/sender-kinesis/src/test/java/zipkin2/reporter/kinesis/KinesisSenderTest.java index aff3ae1f..58428681 100644 --- a/reporter/sender-kinesis/src/test/java/zipkin2/reporter/kinesis/KinesisSenderTest.java +++ b/reporter/sender-kinesis/src/test/java/zipkin2/reporter/kinesis/KinesisSenderTest.java @@ -52,17 +52,20 @@ class KinesisSenderTest { ObjectMapper mapper = new ObjectMapper(new CBORFactory()); KinesisSender sender; - @BeforeEach void setup() { + @BeforeEach + void setup() { sender = KinesisSender.newBuilder() .streamName("test") .endpointConfiguration( new EndpointConfiguration(server.url("/").toString(), "us-east-1")) - .credentialsProvider(new AWSStaticCredentialsProvider(new AnonymousAWSCredentials())) + .credentialsProvider( + new AWSStaticCredentialsProvider(new AnonymousAWSCredentials())) .build(); } - @Test void sendsSpans() throws Exception { + @Test + void sendsSpans() throws Exception { server.enqueue(new MockResponse()); send(CLIENT_SPAN, CLIENT_SPAN).execute(); @@ -71,7 +74,8 @@ class KinesisSenderTest { .containsExactly(CLIENT_SPAN, CLIENT_SPAN); } - @Test void sendsSpans_PROTO3() throws Exception { + @Test + void sendsSpans_PROTO3() throws Exception { server.enqueue(new MockResponse()); sender.close(); @@ -83,32 +87,33 @@ class KinesisSenderTest { .containsExactly(CLIENT_SPAN, CLIENT_SPAN); } - @Test void outOfBandCancel() throws Exception { + @Test + void outOfBandCancel() throws Exception { server.enqueue(new MockResponse()); KinesisSender.KinesisCall call = (KinesisSender.KinesisCall) send(CLIENT_SPAN, CLIENT_SPAN); assertThat(call.isCanceled()).isFalse(); // sanity check CountDownLatch latch = new CountDownLatch(1); - call.enqueue( - new Callback() { - @Override - public void onSuccess(Void aVoid) { - call.future.cancel(true); - latch.countDown(); - } - - @Override - public void onError(Throwable throwable) { - latch.countDown(); - } - }); + call.enqueue(new Callback<>() { + @Override + public void onSuccess(Void aVoid) { + call.future.cancel(true); + latch.countDown(); + } + + @Override + public void onError(Throwable throwable) { + latch.countDown(); + } + }); latch.await(5, TimeUnit.SECONDS); assertThat(call.isCanceled()).isTrue(); } - @Test void sendsSpans_json_unicode() throws Exception { + @Test + void sendsSpans_json_unicode() throws Exception { server.enqueue(new MockResponse()); Span unicode = CLIENT_SPAN.toBuilder().putTag("error", "\uD83D\uDCA9").build(); @@ -117,7 +122,8 @@ public void onError(Throwable throwable) { assertThat(extractSpans(server.takeRequest().getBody())).containsExactly(unicode); } - @Test void checkPasses() throws Exception { + @Test + void checkPasses() throws Exception { enqueueCborResponse( mapper .createObjectNode() @@ -127,7 +133,8 @@ public void onError(Throwable throwable) { assertThat(result.ok()).isTrue(); } - @Test void checkFailsWithStreamNotActive() throws Exception { + @Test + void checkFailsWithStreamNotActive() throws Exception { enqueueCborResponse( mapper .createObjectNode() @@ -138,7 +145,8 @@ public void onError(Throwable throwable) { assertThat(result.error()).isInstanceOf(IllegalStateException.class); } - @Test void checkFailsWithException() { + @Test + void checkFailsWithException() { server.enqueue(new MockResponse().setSocketPolicy(SocketPolicy.DISCONNECT_DURING_REQUEST_BODY)); // 3 retries after initial failure server.enqueue(new MockResponse().setSocketPolicy(SocketPolicy.DISCONNECT_DURING_REQUEST_BODY)); @@ -171,7 +179,8 @@ Call send(zipkin2.Span... spans) { return sender.sendSpans(Stream.of(spans).map(bytesEncoder::encode).collect(toList())); } - @AfterEach void afterEachTest() throws IOException { + @AfterEach + void afterEachTest() throws IOException { server.close(); } } diff --git a/reporter/sender-sqs/src/test/java/zipkin2/reporter/sqs/SQSSenderTest.java b/reporter/sender-sqs/src/test/java/zipkin2/reporter/sqs/SQSSenderTest.java index 8983f0f9..b6a25a7e 100644 --- a/reporter/sender-sqs/src/test/java/zipkin2/reporter/sqs/SQSSenderTest.java +++ b/reporter/sender-sqs/src/test/java/zipkin2/reporter/sqs/SQSSenderTest.java @@ -36,33 +36,39 @@ import static zipkin2.TestObjects.CLIENT_SPAN; class SQSSenderTest { - @RegisterExtension AmazonSQSExtension sqs = new AmazonSQSExtension(); + @RegisterExtension + AmazonSQSExtension sqs = new AmazonSQSExtension(); private SQSSender sender; - @BeforeEach public void setup() { + @BeforeEach + public void setup() { sender = - SQSSender.newBuilder() - .queueUrl(sqs.queueUrl()) - .endpointConfiguration(new EndpointConfiguration(sqs.queueUrl(), "us-east-1")) - .credentialsProvider(new AWSStaticCredentialsProvider(new BasicAWSCredentials("x", "x"))) - .build(); + SQSSender.newBuilder() + .queueUrl(sqs.queueUrl()) + .endpointConfiguration(new EndpointConfiguration(sqs.queueUrl(), "us-east-1")) + .credentialsProvider( + new AWSStaticCredentialsProvider(new BasicAWSCredentials("x", "x"))) + .build(); } - @Test void sendsSpans() throws Exception { + @Test + void sendsSpans() throws Exception { send(CLIENT_SPAN, CLIENT_SPAN).execute(); assertThat(readSpans()).containsExactly(CLIENT_SPAN, CLIENT_SPAN); } - @Test void sendsSpans_json_unicode() throws Exception { + @Test + void sendsSpans_json_unicode() throws Exception { Span unicode = CLIENT_SPAN.toBuilder().putTag("error", "\uD83D\uDCA9").build(); send(unicode).execute(); assertThat(readSpans()).containsExactly(unicode); } - @Test void sendsSpans_PROTO3() throws Exception { + @Test + void sendsSpans_PROTO3() throws Exception { sender.close(); sender = sender.toBuilder().encoding(Encoding.PROTO3).build(); @@ -71,30 +77,31 @@ class SQSSenderTest { assertThat(readSpans()).containsExactly(CLIENT_SPAN, CLIENT_SPAN); } - @Test void outOfBandCancel() throws Exception { + @Test + void outOfBandCancel() throws Exception { SQSSender.SQSCall call = (SQSSender.SQSCall) send(CLIENT_SPAN, CLIENT_SPAN); assertThat(call.isCanceled()).isFalse(); // sanity check CountDownLatch latch = new CountDownLatch(1); - call.enqueue( - new Callback() { - @Override - public void onSuccess(Void aVoid) { - call.future.cancel(true); - latch.countDown(); - } - - @Override - public void onError(Throwable throwable) { - latch.countDown(); - } - }); + call.enqueue(new Callback<>() { + @Override + public void onSuccess(Void aVoid) { + call.future.cancel(true); + latch.countDown(); + } + + @Override + public void onError(Throwable throwable) { + latch.countDown(); + } + }); latch.await(5, TimeUnit.SECONDS); assertThat(call.isCanceled()).isTrue(); } - @Test void checkOk() { + @Test + void checkOk() { assertThat(sender.check()).isEqualTo(CheckResult.OK); } diff --git a/storage/xray-udp/pom.xml b/storage/xray-udp/pom.xml index d8fb0600..aab2f30b 100644 --- a/storage/xray-udp/pom.xml +++ b/storage/xray-udp/pom.xml @@ -28,6 +28,11 @@ ${project.basedir}/../.. + + + 17 + 17 + 17 diff --git a/storage/xray-udp/src/main/java/zipkin2/storage/xray_udp/XRayUDPStorage.java b/storage/xray-udp/src/main/java/zipkin2/storage/xray_udp/XRayUDPStorage.java index 43325143..f2b14007 100644 --- a/storage/xray-udp/src/main/java/zipkin2/storage/xray_udp/XRayUDPStorage.java +++ b/storage/xray-udp/src/main/java/zipkin2/storage/xray_udp/XRayUDPStorage.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2020 The OpenZipkin Authors + * Copyright 2016-2024 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 @@ -36,13 +36,7 @@ public final class XRayUDPStorage extends StorageComponent implements SpanStore, SpanConsumer { static final int PACKET_LENGTH = 256 * 1024; - static final ThreadLocal BUF = - new ThreadLocal() { - @Override - protected byte[] initialValue() { - return new byte[PACKET_LENGTH]; - } - }; + static final ThreadLocal BUF = ThreadLocal.withInitial(() -> new byte[PACKET_LENGTH]); public static Builder newBuilder() { return new Builder(); @@ -178,7 +172,7 @@ public Builder address(String address) { } } - @Override public final String toString() { + @Override public String toString() { return "XRayUDPStorage{address=" + address + "}"; } diff --git a/storage/xray-udp/src/test/java/zipkin2/storage/xray_udp/XRayUDPStorageTest.java b/storage/xray-udp/src/test/java/zipkin2/storage/xray_udp/XRayUDPStorageTest.java index a6403175..039dc73f 100644 --- a/storage/xray-udp/src/test/java/zipkin2/storage/xray_udp/XRayUDPStorageTest.java +++ b/storage/xray-udp/src/test/java/zipkin2/storage/xray_udp/XRayUDPStorageTest.java @@ -104,7 +104,7 @@ public static void stopServer() { assertThat(receivedPayloads).isEmpty(); } - @Test void sendAfterClose() throws Exception { + @Test void sendAfterClose() { XRayUDPStorage storage = XRayUDPStorage.newBuilder() .address("localhost:" + ((InetSocketAddress)serverChannel.localAddress()).getPort()) .build();