Skip to content

Commit 83a4054

Browse files
authored
Fix aws sdk latest dep tests (#8423)
1 parent 3ff44fa commit 83a4054

File tree

3 files changed

+118
-35
lines changed

3 files changed

+118
-35
lines changed

instrumentation/aws-sdk/aws-sdk-2.2/javaagent/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ dependencies {
2525
testImplementation(project(":instrumentation:apache-httpclient:apache-httpclient-4.0:javaagent"))
2626
testImplementation(project(":instrumentation:netty:netty-4.1:javaagent"))
2727

28-
latestDepTestLibrary("software.amazon.awssdk:aws-json-protocol:2.17.+")
28+
latestDepTestLibrary("software.amazon.awssdk:aws-json-protocol:+")
2929
latestDepTestLibrary("software.amazon.awssdk:aws-core:+")
3030
latestDepTestLibrary("software.amazon.awssdk:dynamodb:+")
3131
latestDepTestLibrary("software.amazon.awssdk:ec2:+")

instrumentation/aws-sdk/aws-sdk-2.2/testing/src/main/groovy/io/opentelemetry/instrumentation/awssdk/v2_2/AbstractAws2ClientTest.groovy

Lines changed: 113 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ package io.opentelemetry.instrumentation.awssdk.v2_2
77

88
import io.opentelemetry.instrumentation.test.InstrumentationSpecification
99
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes
10+
import io.opentelemetry.testing.internal.armeria.common.HttpData
1011
import io.opentelemetry.testing.internal.armeria.common.HttpResponse
1112
import io.opentelemetry.testing.internal.armeria.common.HttpStatus
1213
import io.opentelemetry.testing.internal.armeria.common.MediaType
14+
import io.opentelemetry.testing.internal.armeria.common.ResponseHeaders
1315
import io.opentelemetry.testing.internal.armeria.testing.junit5.server.mock.MockWebServerExtension
1416
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials
1517
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider
@@ -52,6 +54,7 @@ import software.amazon.awssdk.services.sqs.model.SendMessageRequest
5254
import spock.lang.Shared
5355
import spock.lang.Unroll
5456

57+
import java.nio.charset.StandardCharsets
5558
import java.time.Duration
5659
import java.util.concurrent.Future
5760

@@ -326,7 +329,13 @@ abstract class AbstractAws2ClientTest extends InstrumentationSpecification {
326329
.region(Region.AP_NORTHEAST_1)
327330
.credentialsProvider(CREDENTIALS_PROVIDER)
328331
.build()
329-
server.enqueue(HttpResponse.of(HttpStatus.OK, MediaType.PLAIN_TEXT_UTF_8, body))
332+
333+
if (body instanceof Closure) {
334+
server.enqueue(body.call())
335+
} else {
336+
server.enqueue(HttpResponse.of(HttpStatus.OK, MediaType.PLAIN_TEXT_UTF_8, body))
337+
}
338+
330339
def response = call.call(client)
331340

332341
if (response instanceof Future) {
@@ -379,22 +388,54 @@ abstract class AbstractAws2ClientTest extends InstrumentationSpecification {
379388
"S3" | "CreateBucket" | "PUT" | path("somebucket") | "UNKNOWN" | S3Client.builder() | { c -> c.createBucket(CreateBucketRequest.builder().bucket("somebucket").build()) } | ""
380389
"S3" | "GetObject" | "GET" | path("somebucket", "somekey") | "UNKNOWN" | S3Client.builder() | { c -> c.getObject(GetObjectRequest.builder().bucket("somebucket").key("somekey").build()) } | ""
381390
"Kinesis" | "DeleteStream" | "POST" | "" | "UNKNOWN" | KinesisClient.builder() | { c -> c.deleteStream(DeleteStreamRequest.builder().streamName("somestream").build()) } | ""
382-
"Sqs" | "CreateQueue" | "POST" | "" | "7a62c49f-347e-4fc4-9331-6e8e7a96aa73" | SqsClient.builder() | { c -> c.createQueue(CreateQueueRequest.builder().queueName("somequeue").build()) } | """
383-
<CreateQueueResponse>
384-
<CreateQueueResult><QueueUrl>https://queue.amazonaws.com/123456789012/MyQueue</QueueUrl></CreateQueueResult>
385-
<ResponseMetadata><RequestId>7a62c49f-347e-4fc4-9331-6e8e7a96aa73</RequestId></ResponseMetadata>
386-
</CreateQueueResponse>
387-
"""
388-
"Sqs" | "SendMessage" | "POST" | "" | "27daac76-34dd-47df-bd01-1f6e873584a0" | SqsClient.builder() | { c -> c.sendMessage(SendMessageRequest.builder().queueUrl("someurl").messageBody("").build()) } | """
389-
<SendMessageResponse>
390-
<SendMessageResult>
391-
<MD5OfMessageBody>d41d8cd98f00b204e9800998ecf8427e</MD5OfMessageBody>
392-
<MD5OfMessageAttributes>3ae8f24a165a8cedc005670c81a27295</MD5OfMessageAttributes>
393-
<MessageId>5fea7756-0ea4-451a-a703-a558b933e274</MessageId>
394-
</SendMessageResult>
395-
<ResponseMetadata><RequestId>27daac76-34dd-47df-bd01-1f6e873584a0</RequestId></ResponseMetadata>
396-
</SendMessageResponse>
397-
"""
391+
"Sqs" | "CreateQueue" | "POST" | "" | "7a62c49f-347e-4fc4-9331-6e8e7a96aa73" | SqsClient.builder() | { c -> c.createQueue(CreateQueueRequest.builder().queueName("somequeue").build()) } | {
392+
if (!Boolean.getBoolean("testLatestDeps")) {
393+
def content = """
394+
<CreateQueueResponse>
395+
<CreateQueueResult><QueueUrl>https://queue.amazonaws.com/123456789012/MyQueue</QueueUrl></CreateQueueResult>
396+
<ResponseMetadata><RequestId>7a62c49f-347e-4fc4-9331-6e8e7a96aa73</RequestId></ResponseMetadata>
397+
</CreateQueueResponse>
398+
"""
399+
return HttpResponse.of(HttpStatus.OK, MediaType.PLAIN_TEXT_UTF_8, content)
400+
}
401+
def content = """
402+
{
403+
"QueueUrl":"https://queue.amazonaws.com/123456789012/MyQueue"
404+
}
405+
"""
406+
ResponseHeaders headers = ResponseHeaders.builder(HttpStatus.OK)
407+
.contentType(MediaType.PLAIN_TEXT_UTF_8)
408+
.add("x-amzn-RequestId", "7a62c49f-347e-4fc4-9331-6e8e7a96aa73")
409+
.build()
410+
return HttpResponse.of(headers, HttpData.of(StandardCharsets.UTF_8, content))
411+
}
412+
"Sqs" | "SendMessage" | "POST" | "" | "27daac76-34dd-47df-bd01-1f6e873584a0" | SqsClient.builder() | { c -> c.sendMessage(SendMessageRequest.builder().queueUrl("someurl").messageBody("").build()) } | {
413+
if (!Boolean.getBoolean("testLatestDeps")) {
414+
def content = """
415+
<SendMessageResponse>
416+
<SendMessageResult>
417+
<MD5OfMessageBody>d41d8cd98f00b204e9800998ecf8427e</MD5OfMessageBody>
418+
<MD5OfMessageAttributes>3ae8f24a165a8cedc005670c81a27295</MD5OfMessageAttributes>
419+
<MessageId>5fea7756-0ea4-451a-a703-a558b933e274</MessageId>
420+
</SendMessageResult>
421+
<ResponseMetadata><RequestId>27daac76-34dd-47df-bd01-1f6e873584a0</RequestId></ResponseMetadata>
422+
</SendMessageResponse>
423+
"""
424+
return HttpResponse.of(HttpStatus.OK, MediaType.PLAIN_TEXT_UTF_8, content)
425+
}
426+
def content = """
427+
{
428+
"MD5OfMessageBody":"d41d8cd98f00b204e9800998ecf8427e",
429+
"MD5OfMessageAttributes":"3ae8f24a165a8cedc005670c81a27295",
430+
"MessageId":"5fea7756-0ea4-451a-a703-a558b933e274"
431+
}
432+
"""
433+
ResponseHeaders headers = ResponseHeaders.builder(HttpStatus.OK)
434+
.contentType(MediaType.PLAIN_TEXT_UTF_8)
435+
.add("x-amzn-RequestId", "27daac76-34dd-47df-bd01-1f6e873584a0")
436+
.build()
437+
return HttpResponse.of(headers, HttpData.of(StandardCharsets.UTF_8, content))
438+
}
398439
"Ec2" | "AllocateAddress" | "POST" | "" | "59dbff89-35bd-4eac-99ed-be587EXAMPLE" | Ec2Client.builder() | { c -> c.allocateAddress() } | """
399440
<AllocateAddressResponse xmlns="http://ec2.amazonaws.com/doc/2016-11-15/">
400441
<requestId>59dbff89-35bd-4eac-99ed-be587EXAMPLE</requestId>
@@ -417,7 +458,13 @@ abstract class AbstractAws2ClientTest extends InstrumentationSpecification {
417458
.region(Region.AP_NORTHEAST_1)
418459
.credentialsProvider(CREDENTIALS_PROVIDER)
419460
.build()
420-
server.enqueue(HttpResponse.of(HttpStatus.OK, MediaType.PLAIN_TEXT_UTF_8, body))
461+
462+
if (body instanceof Closure) {
463+
server.enqueue(body.call())
464+
} else {
465+
server.enqueue(HttpResponse.of(HttpStatus.OK, MediaType.PLAIN_TEXT_UTF_8, body))
466+
}
467+
421468
def response = call.call(client)
422469

423470
if (response instanceof Future) {
@@ -470,22 +517,54 @@ abstract class AbstractAws2ClientTest extends InstrumentationSpecification {
470517
"S3" | "GetObject" | "GET" | path("somebucket", "somekey") | "UNKNOWN" | S3AsyncClient.builder() | { c -> c.getObject(GetObjectRequest.builder().bucket("somebucket").key("somekey").build(), AsyncResponseTransformer.toBytes()) } | "1234567890"
471518
// Kinesis seems to expect an http2 response which is incompatible with our test server.
472519
// "Kinesis" | "DeleteStream" | "POST" | "/" | "UNKNOWN" | KinesisAsyncClient.builder() | { c -> c.deleteStream(DeleteStreamRequest.builder().streamName("somestream").build()) } | ""
473-
"Sqs" | "CreateQueue" | "POST" | "" | "7a62c49f-347e-4fc4-9331-6e8e7a96aa73" | SqsAsyncClient.builder() | { c -> c.createQueue(CreateQueueRequest.builder().queueName("somequeue").build()) } | """
474-
<CreateQueueResponse>
475-
<CreateQueueResult><QueueUrl>https://queue.amazonaws.com/123456789012/MyQueue</QueueUrl></CreateQueueResult>
476-
<ResponseMetadata><RequestId>7a62c49f-347e-4fc4-9331-6e8e7a96aa73</RequestId></ResponseMetadata>
477-
</CreateQueueResponse>
478-
"""
479-
"Sqs" | "SendMessage" | "POST" | "" | "27daac76-34dd-47df-bd01-1f6e873584a0" | SqsAsyncClient.builder() | { c -> c.sendMessage(SendMessageRequest.builder().queueUrl("someurl").messageBody("").build()) } | """
480-
<SendMessageResponse>
481-
<SendMessageResult>
482-
<MD5OfMessageBody>d41d8cd98f00b204e9800998ecf8427e</MD5OfMessageBody>
483-
<MD5OfMessageAttributes>3ae8f24a165a8cedc005670c81a27295</MD5OfMessageAttributes>
484-
<MessageId>5fea7756-0ea4-451a-a703-a558b933e274</MessageId>
485-
</SendMessageResult>
486-
<ResponseMetadata><RequestId>27daac76-34dd-47df-bd01-1f6e873584a0</RequestId></ResponseMetadata>
487-
</SendMessageResponse>
488-
"""
520+
"Sqs" | "CreateQueue" | "POST" | "" | "7a62c49f-347e-4fc4-9331-6e8e7a96aa73" | SqsAsyncClient.builder() | { c -> c.createQueue(CreateQueueRequest.builder().queueName("somequeue").build()) } | {
521+
if (!Boolean.getBoolean("testLatestDeps")) {
522+
def content = """
523+
<CreateQueueResponse>
524+
<CreateQueueResult><QueueUrl>https://queue.amazonaws.com/123456789012/MyQueue</QueueUrl></CreateQueueResult>
525+
<ResponseMetadata><RequestId>7a62c49f-347e-4fc4-9331-6e8e7a96aa73</RequestId></ResponseMetadata>
526+
</CreateQueueResponse>
527+
"""
528+
return HttpResponse.of(HttpStatus.OK, MediaType.PLAIN_TEXT_UTF_8, content)
529+
}
530+
def content = """
531+
{
532+
"QueueUrl":"https://queue.amazonaws.com/123456789012/MyQueue"
533+
}
534+
"""
535+
ResponseHeaders headers = ResponseHeaders.builder(HttpStatus.OK)
536+
.contentType(MediaType.PLAIN_TEXT_UTF_8)
537+
.add("x-amzn-RequestId", "7a62c49f-347e-4fc4-9331-6e8e7a96aa73")
538+
.build()
539+
return HttpResponse.of(headers, HttpData.of(StandardCharsets.UTF_8, content))
540+
}
541+
"Sqs" | "SendMessage" | "POST" | "" | "27daac76-34dd-47df-bd01-1f6e873584a0" | SqsAsyncClient.builder() | { c -> c.sendMessage(SendMessageRequest.builder().queueUrl("someurl").messageBody("").build()) } | {
542+
if (!Boolean.getBoolean("testLatestDeps")) {
543+
def content = """
544+
<SendMessageResponse>
545+
<SendMessageResult>
546+
<MD5OfMessageBody>d41d8cd98f00b204e9800998ecf8427e</MD5OfMessageBody>
547+
<MD5OfMessageAttributes>3ae8f24a165a8cedc005670c81a27295</MD5OfMessageAttributes>
548+
<MessageId>5fea7756-0ea4-451a-a703-a558b933e274</MessageId>
549+
</SendMessageResult>
550+
<ResponseMetadata><RequestId>27daac76-34dd-47df-bd01-1f6e873584a0</RequestId></ResponseMetadata>
551+
</SendMessageResponse>
552+
"""
553+
return HttpResponse.of(HttpStatus.OK, MediaType.PLAIN_TEXT_UTF_8, content)
554+
}
555+
def content = """
556+
{
557+
"MD5OfMessageBody":"d41d8cd98f00b204e9800998ecf8427e",
558+
"MD5OfMessageAttributes":"3ae8f24a165a8cedc005670c81a27295",
559+
"MessageId":"5fea7756-0ea4-451a-a703-a558b933e274"
560+
}
561+
"""
562+
ResponseHeaders headers = ResponseHeaders.builder(HttpStatus.OK)
563+
.contentType(MediaType.PLAIN_TEXT_UTF_8)
564+
.add("x-amzn-RequestId", "27daac76-34dd-47df-bd01-1f6e873584a0")
565+
.build()
566+
return HttpResponse.of(headers, HttpData.of(StandardCharsets.UTF_8, content))
567+
}
489568
"Ec2" | "AllocateAddress" | "POST" | "" | "59dbff89-35bd-4eac-99ed-be587EXAMPLE" | Ec2AsyncClient.builder() | { c -> c.allocateAddress() } | """
490569
<AllocateAddressResponse xmlns="http://ec2.amazonaws.com/doc/2016-11-15/">
491570
<requestId>59dbff89-35bd-4eac-99ed-be587EXAMPLE</requestId>

instrumentation/aws-sdk/aws-sdk-2.2/testing/src/main/groovy/io/opentelemetry/instrumentation/awssdk/v2_2/AbstractAws2SqsTracingTest.groovy

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import io.opentelemetry.instrumentation.test.InstrumentationSpecification
99
import io.opentelemetry.instrumentation.test.utils.PortUtils
1010
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes
1111
import org.elasticmq.rest.sqs.SQSRestServerBuilder
12+
import org.junit.Assume
1213
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials
1314
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider
1415
import software.amazon.awssdk.core.client.builder.SdkClientBuilder
@@ -64,6 +65,9 @@ abstract class AbstractAws2SqsTracingTest extends InstrumentationSpecification {
6465
}
6566

6667
def "simple sqs producer-consumer services"() {
68+
// sqs implementation used for testing does not work with the latest aws sqs client
69+
Assume.assumeFalse(Boolean.getBoolean("testLatestDeps"))
70+
6771
setup:
6872
CreateQueueRequest createQueueRequest = CreateQueueRequest.builder()
6973
.queueName("testSdkSqs")

0 commit comments

Comments
 (0)