Remove latest dep limit for aws2 sqs test (#9902)

This commit is contained in:
Lauri Tulmin 2023-11-21 13:50:55 +02:00 committed by GitHub
parent e148b84536
commit 9d65926094
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 152 additions and 60 deletions

View File

@ -84,9 +84,6 @@ dependencies {
testLibrary("software.amazon.awssdk:sqs:2.2.0")
testLibrary("software.amazon.awssdk:sns:2.2.0")
testLibrary("software.amazon.awssdk:ses:2.2.0")
// last version that does not use json protocol
latestDepTestLibrary("software.amazon.awssdk:sqs:2.21.17")
}
val latestDepTest = findProperty("testLatestDeps") as Boolean
@ -139,6 +136,7 @@ tasks {
// TODO run tests both with and without experimental span attributes
systemProperty("otel.instrumentation.aws-sdk.experimental-span-attributes", "true")
systemProperty("otel.instrumentation.aws-sdk.experimental-record-individual-http-error", "true")
systemProperty("testLatestDeps", findProperty("testLatestDeps") as Boolean)
}
withType<com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar>().configureEach {

View File

@ -29,7 +29,6 @@ dependencies {
tasks {
test {
systemProperty("otel.instrumentation.aws-sdk.experimental-span-attributes", true)
systemProperty("otel.instrumentation.aws-sdk.experimental-use-propagator-for-messaging", true)
systemProperty("otel.instrumentation.aws-sdk.experimental-record-individual-http-error", true)
systemProperty("otel.instrumentation.messaging.experimental.capture-headers", "test-message-header")
}

View File

@ -19,9 +19,6 @@ dependencies {
testLibrary("software.amazon.awssdk:rds:2.2.0")
testLibrary("software.amazon.awssdk:s3:2.2.0")
testLibrary("software.amazon.awssdk:ses:2.2.0")
// last version that does not use json protocol
latestDepTestLibrary("software.amazon.awssdk:sqs:2.21.17")
}
testing {
@ -56,6 +53,6 @@ tasks {
// NB: If you'd like to change these, there is some cleanup work to be done, as most tests ignore this and
// set the value directly (the "library" does not normally query it, only library-autoconfigure)
systemProperty("otel.instrumentation.aws-sdk.experimental-span-attributes", true)
systemProperty("otel.instrumentation.aws-sdk.experimental-use-propagator-for-messaging", true)
systemProperty("testLatestDeps", findProperty("testLatestDeps") as Boolean)
}
}

View File

@ -21,7 +21,7 @@ dependencies {
compileOnly("software.amazon.awssdk:ses:2.2.0")
// needed for SQS - using emq directly as localstack references emq v0.15.7 ie WITHOUT AWS trace header propagation
implementation("org.elasticmq:elasticmq-rest-sqs_2.12:1.0.0")
implementation("org.elasticmq:elasticmq-rest-sqs_2.13:1.5.1")
implementation("com.google.guava:guava")

View File

@ -7,9 +7,11 @@ package io.opentelemetry.instrumentation.awssdk.v2_2
import io.opentelemetry.semconv.SemanticAttributes
import io.opentelemetry.testing.internal.armeria.common.HttpData
import io.opentelemetry.testing.internal.armeria.common.HttpResponse
import io.opentelemetry.testing.internal.armeria.common.HttpStatus
import io.opentelemetry.testing.internal.armeria.common.MediaType
import io.opentelemetry.testing.internal.armeria.common.ResponseHeaders
import org.junit.jupiter.api.Assumptions
import software.amazon.awssdk.core.ResponseInputStream
import software.amazon.awssdk.core.async.AsyncResponseTransformer
@ -35,6 +37,7 @@ import software.amazon.awssdk.services.sqs.model.CreateQueueRequest
import software.amazon.awssdk.services.sqs.model.SendMessageRequest
import spock.lang.Unroll
import java.nio.charset.StandardCharsets
import java.time.Duration
import java.util.concurrent.Future
@ -59,6 +62,22 @@ abstract class AbstractAws2ClientTest extends AbstractAws2ClientCoreTest {
// bucket name as label.
def clientUri = URI.create("http://localhost:${server.httpPort()}")
def s3ClientBuilder() {
def builder = S3Client.builder()
if (Boolean.getBoolean("testLatestDeps")) {
builder.forcePathStyle(true)
}
return builder
}
def s3AsyncClientBuilder() {
def builder = S3AsyncClient.builder()
if (Boolean.getBoolean("testLatestDeps")) {
builder.forcePathStyle(true)
}
return builder
}
def "send #operation request with builder #builder.class.getName() mocked response"() {
assumeSupportedConfig(service, operation)
@ -69,9 +88,14 @@ abstract class AbstractAws2ClientTest extends AbstractAws2ClientCoreTest {
.region(Region.AP_NORTHEAST_1)
.credentialsProvider(CREDENTIALS_PROVIDER)
.build()
server.enqueue(HttpResponse.of(HttpStatus.OK, MediaType.PLAIN_TEXT_UTF_8, body))
def response = call.call(client)
if (body instanceof Closure) {
server.enqueue(body.call())
} else {
server.enqueue(HttpResponse.of(HttpStatus.OK, MediaType.PLAIN_TEXT_UTF_8, body))
}
def response = call.call(client)
if (response instanceof Future) {
response = response.get()
}
@ -131,25 +155,57 @@ abstract class AbstractAws2ClientTest extends AbstractAws2ClientCoreTest {
where:
service | operation | method | requestId | builder | call | body
"S3" | "CreateBucket" | "PUT" | "UNKNOWN" | S3Client.builder() | { c -> c.createBucket(CreateBucketRequest.builder().bucket("somebucket").build()) } | ""
"S3" | "GetObject" | "GET" | "UNKNOWN" | S3Client.builder() | { c -> c.getObject(GetObjectRequest.builder().bucket("somebucket").key("somekey").build()) } | ""
"S3" | "CreateBucket" | "PUT" | "UNKNOWN" | s3ClientBuilder() | { c -> c.createBucket(CreateBucketRequest.builder().bucket("somebucket").build()) } | ""
"S3" | "GetObject" | "GET" | "UNKNOWN" | s3ClientBuilder() | { c -> c.getObject(GetObjectRequest.builder().bucket("somebucket").key("somekey").build()) } | ""
"Kinesis" | "DeleteStream" | "POST" | "UNKNOWN" | KinesisClient.builder() | { c -> c.deleteStream(DeleteStreamRequest.builder().streamName("somestream").build()) } | ""
"Sqs" | "CreateQueue" | "POST" | "7a62c49f-347e-4fc4-9331-6e8e7a96aa73" | SqsClient.builder() | { c -> c.createQueue(CreateQueueRequest.builder().queueName("somequeue").build()) } | """
<CreateQueueResponse>
<CreateQueueResult><QueueUrl>https://queue.amazonaws.com/123456789012/MyQueue</QueueUrl></CreateQueueResult>
<ResponseMetadata><RequestId>7a62c49f-347e-4fc4-9331-6e8e7a96aa73</RequestId></ResponseMetadata>
</CreateQueueResponse>
"""
"Sqs" | "SendMessage" | "POST" | "27daac76-34dd-47df-bd01-1f6e873584a0" | SqsClient.builder() | { c -> c.sendMessage(SendMessageRequest.builder().queueUrl(QUEUE_URL).messageBody("").build()) } | """
<SendMessageResponse>
<SendMessageResult>
<MD5OfMessageBody>d41d8cd98f00b204e9800998ecf8427e</MD5OfMessageBody>
<MD5OfMessageAttributes>3ae8f24a165a8cedc005670c81a27295</MD5OfMessageAttributes>
<MessageId>5fea7756-0ea4-451a-a703-a558b933e274</MessageId>
</SendMessageResult>
<ResponseMetadata><RequestId>27daac76-34dd-47df-bd01-1f6e873584a0</RequestId></ResponseMetadata>
</SendMessageResponse>
"""
"Sqs" | "CreateQueue" | "POST" | "7a62c49f-347e-4fc4-9331-6e8e7a96aa73" | SqsClient.builder() | { c -> c.createQueue(CreateQueueRequest.builder().queueName("somequeue").build()) } | {
if (!Boolean.getBoolean("testLatestDeps")) {
def content = """
<CreateQueueResponse>
<CreateQueueResult><QueueUrl>https://queue.amazonaws.com/123456789012/MyQueue</QueueUrl></CreateQueueResult>
<ResponseMetadata><RequestId>7a62c49f-347e-4fc4-9331-6e8e7a96aa73</RequestId></ResponseMetadata>
</CreateQueueResponse>
"""
return HttpResponse.of(HttpStatus.OK, MediaType.PLAIN_TEXT_UTF_8, content)
}
def content = """
{
"QueueUrl":"https://queue.amazonaws.com/123456789012/MyQueue"
}
"""
ResponseHeaders headers = ResponseHeaders.builder(HttpStatus.OK)
.contentType(MediaType.PLAIN_TEXT_UTF_8)
.add("x-amzn-RequestId", "7a62c49f-347e-4fc4-9331-6e8e7a96aa73")
.build()
return HttpResponse.of(headers, HttpData.of(StandardCharsets.UTF_8, content))
}
"Sqs" | "SendMessage" | "POST" | "27daac76-34dd-47df-bd01-1f6e873584a0" | SqsClient.builder() | { c -> c.sendMessage(SendMessageRequest.builder().queueUrl(QUEUE_URL).messageBody("").build()) } | {
if (!Boolean.getBoolean("testLatestDeps")) {
def content = """
<SendMessageResponse>
<SendMessageResult>
<MD5OfMessageBody>d41d8cd98f00b204e9800998ecf8427e</MD5OfMessageBody>
<MD5OfMessageAttributes>3ae8f24a165a8cedc005670c81a27295</MD5OfMessageAttributes>
<MessageId>5fea7756-0ea4-451a-a703-a558b933e274</MessageId>
</SendMessageResult>
<ResponseMetadata><RequestId>27daac76-34dd-47df-bd01-1f6e873584a0</RequestId></ResponseMetadata>
</SendMessageResponse>
"""
return HttpResponse.of(HttpStatus.OK, MediaType.PLAIN_TEXT_UTF_8, content)
}
def content = """
{
"MD5OfMessageBody":"d41d8cd98f00b204e9800998ecf8427e",
"MD5OfMessageAttributes":"3ae8f24a165a8cedc005670c81a27295",
"MessageId":"5fea7756-0ea4-451a-a703-a558b933e274"
}
"""
ResponseHeaders headers = ResponseHeaders.builder(HttpStatus.OK)
.contentType(MediaType.PLAIN_TEXT_UTF_8)
.add("x-amzn-RequestId", "27daac76-34dd-47df-bd01-1f6e873584a0")
.build()
return HttpResponse.of(headers, HttpData.of(StandardCharsets.UTF_8, content))
}
"Ec2" | "AllocateAddress" | "POST" | "59dbff89-35bd-4eac-99ed-be587EXAMPLE" | Ec2Client.builder() | { c -> c.allocateAddress() } | """
<AllocateAddressResponse xmlns="http://ec2.amazonaws.com/doc/2016-11-15/">
<requestId>59dbff89-35bd-4eac-99ed-be587EXAMPLE</requestId>
@ -173,9 +229,14 @@ abstract class AbstractAws2ClientTest extends AbstractAws2ClientCoreTest {
.region(Region.AP_NORTHEAST_1)
.credentialsProvider(CREDENTIALS_PROVIDER)
.build()
server.enqueue(HttpResponse.of(HttpStatus.OK, MediaType.PLAIN_TEXT_UTF_8, body))
def response = call.call(client)
if (body instanceof Closure) {
server.enqueue(body.call())
} else {
server.enqueue(HttpResponse.of(HttpStatus.OK, MediaType.PLAIN_TEXT_UTF_8, body))
}
def response = call.call(client)
if (response instanceof Future) {
response = response.get()
}
@ -199,7 +260,7 @@ abstract class AbstractAws2ClientTest extends AbstractAws2ClientCoreTest {
"$SemanticAttributes.HTTP_URL" { it.startsWith("http://somebucket.localhost:${server.httpPort()}") || it.startsWith("http://localhost:${server.httpPort()}") }
} else {
"$SemanticAttributes.NET_PEER_NAME" "localhost"
"$SemanticAttributes.HTTP_URL" "http://localhost:${server.httpPort()}"
"$SemanticAttributes.HTTP_URL" { it == "http://localhost:${server.httpPort()}" || it == "http://localhost:${server.httpPort()}/" }
}
"$SemanticAttributes.NET_PEER_PORT" server.httpPort()
"$SemanticAttributes.HTTP_METHOD" "$method"
@ -245,26 +306,58 @@ abstract class AbstractAws2ClientTest extends AbstractAws2ClientCoreTest {
where:
service | operation | method | requestId | builder | call | body
"S3" | "CreateBucket" | "PUT" | "UNKNOWN" | S3AsyncClient.builder() | { c -> c.createBucket(CreateBucketRequest.builder().bucket("somebucket").build()) } | ""
"S3" | "GetObject" | "GET" | "UNKNOWN" | S3AsyncClient.builder() | { c -> c.getObject(GetObjectRequest.builder().bucket("somebucket").key("somekey").build(), AsyncResponseTransformer.toBytes()) } | "1234567890"
"S3" | "CreateBucket" | "PUT" | "UNKNOWN" | s3AsyncClientBuilder() | { c -> c.createBucket(CreateBucketRequest.builder().bucket("somebucket").build()) } | ""
"S3" | "GetObject" | "GET" | "UNKNOWN" | s3AsyncClientBuilder() | { c -> c.getObject(GetObjectRequest.builder().bucket("somebucket").key("somekey").build(), AsyncResponseTransformer.toBytes()) } | "1234567890"
// Kinesis seems to expect an http2 response which is incompatible with our test server.
// "Kinesis" | "DeleteStream" | "POST" | "/" | "UNKNOWN" | KinesisAsyncClient.builder() | { c -> c.deleteStream(DeleteStreamRequest.builder().streamName("somestream").build()) } | ""
"Sqs" | "CreateQueue" | "POST" | "7a62c49f-347e-4fc4-9331-6e8e7a96aa73" | SqsAsyncClient.builder() | { c -> c.createQueue(CreateQueueRequest.builder().queueName("somequeue").build()) } | """
<CreateQueueResponse>
<CreateQueueResult><QueueUrl>https://queue.amazonaws.com/123456789012/MyQueue</QueueUrl></CreateQueueResult>
<ResponseMetadata><RequestId>7a62c49f-347e-4fc4-9331-6e8e7a96aa73</RequestId></ResponseMetadata>
</CreateQueueResponse>
"""
"Sqs" | "SendMessage" | "POST" | "27daac76-34dd-47df-bd01-1f6e873584a0" | SqsAsyncClient.builder() | { c -> c.sendMessage(SendMessageRequest.builder().queueUrl(QUEUE_URL).messageBody("").build()) } | """
<SendMessageResponse>
<SendMessageResult>
<MD5OfMessageBody>d41d8cd98f00b204e9800998ecf8427e</MD5OfMessageBody>
<MD5OfMessageAttributes>3ae8f24a165a8cedc005670c81a27295</MD5OfMessageAttributes>
<MessageId>5fea7756-0ea4-451a-a703-a558b933e274</MessageId>
</SendMessageResult>
<ResponseMetadata><RequestId>27daac76-34dd-47df-bd01-1f6e873584a0</RequestId></ResponseMetadata>
</SendMessageResponse>
"""
"Sqs" | "CreateQueue" | "POST" | "7a62c49f-347e-4fc4-9331-6e8e7a96aa73" | SqsAsyncClient.builder() | { c -> c.createQueue(CreateQueueRequest.builder().queueName("somequeue").build()) } | {
if (!Boolean.getBoolean("testLatestDeps")) {
def content = """
<CreateQueueResponse>
<CreateQueueResult><QueueUrl>https://queue.amazonaws.com/123456789012/MyQueue</QueueUrl></CreateQueueResult>
<ResponseMetadata><RequestId>7a62c49f-347e-4fc4-9331-6e8e7a96aa73</RequestId></ResponseMetadata>
</CreateQueueResponse>
"""
return HttpResponse.of(HttpStatus.OK, MediaType.PLAIN_TEXT_UTF_8, content)
}
def content = """
{
"QueueUrl":"https://queue.amazonaws.com/123456789012/MyQueue"
}
"""
ResponseHeaders headers = ResponseHeaders.builder(HttpStatus.OK)
.contentType(MediaType.PLAIN_TEXT_UTF_8)
.add("x-amzn-RequestId", "7a62c49f-347e-4fc4-9331-6e8e7a96aa73")
.build()
return HttpResponse.of(headers, HttpData.of(StandardCharsets.UTF_8, content))
}
"Sqs" | "SendMessage" | "POST" | "27daac76-34dd-47df-bd01-1f6e873584a0" | SqsAsyncClient.builder() | { c -> c.sendMessage(SendMessageRequest.builder().queueUrl(QUEUE_URL).messageBody("").build()) } | {
if (!Boolean.getBoolean("testLatestDeps")) {
def content = """
<SendMessageResponse>
<SendMessageResult>
<MD5OfMessageBody>d41d8cd98f00b204e9800998ecf8427e</MD5OfMessageBody>
<MD5OfMessageAttributes>3ae8f24a165a8cedc005670c81a27295</MD5OfMessageAttributes>
<MessageId>5fea7756-0ea4-451a-a703-a558b933e274</MessageId>
</SendMessageResult>
<ResponseMetadata><RequestId>27daac76-34dd-47df-bd01-1f6e873584a0</RequestId></ResponseMetadata>
</SendMessageResponse>
"""
return HttpResponse.of(HttpStatus.OK, MediaType.PLAIN_TEXT_UTF_8, content)
}
def content = """
{
"MD5OfMessageBody":"d41d8cd98f00b204e9800998ecf8427e",
"MD5OfMessageAttributes":"3ae8f24a165a8cedc005670c81a27295",
"MessageId":"5fea7756-0ea4-451a-a703-a558b933e274"
}
"""
ResponseHeaders headers = ResponseHeaders.builder(HttpStatus.OK)
.contentType(MediaType.PLAIN_TEXT_UTF_8)
.add("x-amzn-RequestId", "27daac76-34dd-47df-bd01-1f6e873584a0")
.build()
return HttpResponse.of(headers, HttpData.of(StandardCharsets.UTF_8, content))
}
"Ec2" | "AllocateAddress" | "POST" | "59dbff89-35bd-4eac-99ed-be587EXAMPLE" | Ec2AsyncClient.builder() | { c -> c.allocateAddress() } | """
<AllocateAddressResponse xmlns="http://ec2.amazonaws.com/doc/2016-11-15/">
<requestId>59dbff89-35bd-4eac-99ed-be587EXAMPLE</requestId>
@ -297,7 +390,7 @@ abstract class AbstractAws2ClientTest extends AbstractAws2ClientCoreTest {
// One retry so two requests.
server.enqueue(HttpResponse.delayed(HttpResponse.of(HttpStatus.OK), Duration.ofMillis(5000)))
server.enqueue(HttpResponse.delayed(HttpResponse.of(HttpStatus.OK), Duration.ofMillis(5000)))
def client = S3Client.builder()
def builder = S3Client.builder()
.overrideConfiguration(createOverrideConfigurationBuilder()
.retryPolicy(RetryPolicy.builder().numRetries(1).build())
.build())
@ -305,7 +398,12 @@ abstract class AbstractAws2ClientTest extends AbstractAws2ClientCoreTest {
.region(Region.AP_NORTHEAST_1)
.credentialsProvider(CREDENTIALS_PROVIDER)
.httpClientBuilder(ApacheHttpClient.builder().socketTimeout(Duration.ofMillis(50)))
.build()
if (Boolean.getBoolean("testLatestDeps")) {
builder.forcePathStyle(true)
}
def client = builder.build()
when:
client.getObject(GetObjectRequest.builder().bucket("somebucket").key("somekey").build())

View File

@ -125,7 +125,7 @@ abstract class AbstractAws2SqsSuppressReceiveSpansTest extends InstrumentationSp
attributes {
"aws.agent" "java-aws-sdk"
"aws.queue.name" "testSdkSqs"
"aws.requestId" "00000000-0000-0000-0000-000000000000"
"aws.requestId" { it == "00000000-0000-0000-0000-000000000000" || it == "UNKNOWN" }
"rpc.system" "aws-api"
"rpc.service" "Sqs"
"rpc.method" "CreateQueue"
@ -147,7 +147,7 @@ abstract class AbstractAws2SqsSuppressReceiveSpansTest extends InstrumentationSp
attributes {
"aws.agent" "java-aws-sdk"
"aws.queue.url" "http://localhost:$sqsPort/000000000000/testSdkSqs"
"aws.requestId" "00000000-0000-0000-0000-000000000000"
"aws.requestId" { it == "00000000-0000-0000-0000-000000000000" || it == "UNKNOWN" }
"rpc.system" "aws-api"
"rpc.method" "SendMessage"
"rpc.service" "Sqs"
@ -209,7 +209,7 @@ abstract class AbstractAws2SqsSuppressReceiveSpansTest extends InstrumentationSp
hasNoLinks()
attributes {
"aws.agent" "java-aws-sdk"
"aws.requestId" "00000000-0000-0000-0000-000000000000"
"aws.requestId" { it == "00000000-0000-0000-0000-000000000000" || it == "UNKNOWN" }
"rpc.method" "ReceiveMessage"
"aws.queue.url" "http://localhost:$sqsPort/000000000000/testSdkSqs"
"rpc.system" "aws-api"
@ -323,7 +323,7 @@ abstract class AbstractAws2SqsSuppressReceiveSpansTest extends InstrumentationSp
attributes {
"aws.agent" "java-aws-sdk"
"aws.queue.url" "http://localhost:$sqsPort/000000000000/testSdkSqs"
"aws.requestId" "00000000-0000-0000-0000-000000000000"
"aws.requestId" { it.trim() == "00000000-0000-0000-0000-000000000000" || it == "UNKNOWN" }
"rpc.system" "aws-api"
"rpc.method" "SendMessageBatch"
"rpc.service" "Sqs"

View File

@ -127,7 +127,7 @@ abstract class AbstractAws2SqsTracingTest extends InstrumentationSpecification {
attributes {
"aws.agent" "java-aws-sdk"
"aws.queue.name" "testSdkSqs"
"aws.requestId" "00000000-0000-0000-0000-000000000000"
"aws.requestId" { it == "00000000-0000-0000-0000-000000000000" || it == "UNKNOWN" }
"rpc.system" "aws-api"
"rpc.service" "Sqs"
"rpc.method" "CreateQueue"
@ -149,7 +149,7 @@ abstract class AbstractAws2SqsTracingTest extends InstrumentationSpecification {
attributes {
"aws.agent" "java-aws-sdk"
"aws.queue.url" "http://localhost:$sqsPort/000000000000/testSdkSqs"
"aws.requestId" "00000000-0000-0000-0000-000000000000"
"aws.requestId" { it == "00000000-0000-0000-0000-000000000000" || it == "UNKNOWN" }
"rpc.system" "aws-api"
"rpc.method" "SendMessage"
"rpc.service" "Sqs"
@ -189,7 +189,7 @@ abstract class AbstractAws2SqsTracingTest extends InstrumentationSpecification {
hasNoLinks()
attributes {
"aws.agent" "java-aws-sdk"
"aws.requestId" "00000000-0000-0000-0000-000000000000"
"aws.requestId" { it == "00000000-0000-0000-0000-000000000000" || it == "UNKNOWN" }
"rpc.method" "ReceiveMessage"
"aws.queue.url" "http://localhost:$sqsPort/000000000000/testSdkSqs"
"rpc.system" "aws-api"
@ -389,7 +389,7 @@ abstract class AbstractAws2SqsTracingTest extends InstrumentationSpecification {
attributes {
"aws.agent" "java-aws-sdk"
"aws.queue.url" "http://localhost:$sqsPort/000000000000/testSdkSqs"
"aws.requestId" "00000000-0000-0000-0000-000000000000"
"aws.requestId" { it.trim() == "00000000-0000-0000-0000-000000000000" || it == "UNKNOWN" }
"rpc.system" "aws-api"
"rpc.method" "SendMessageBatch"
"rpc.service" "Sqs"