Skip to content

Commit

Permalink
aws-sdk-1: fix latestDepTests (#6190)
Browse files Browse the repository at this point in the history
  • Loading branch information
amarziali authored Nov 10, 2023
1 parent a221305 commit 8f45302
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ dependencies {

// needed for kinesis:
testImplementation group: 'com.fasterxml.jackson.dataformat', name: 'jackson-dataformat-cbor', version: versions.jackson
testImplementation group: 'org.json', name: 'json', version: '20231013'


test_before_1_11_106Implementation(group: 'com.amazonaws', name: 'aws-java-sdk-s3') {
version {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import datadog.trace.api.Config
import datadog.trace.api.DDSpanTypes
import datadog.trace.bootstrap.instrumentation.api.Tags
import datadog.trace.test.util.Flaky
import org.json.XML
import spock.lang.AutoCleanup
import spock.lang.Shared

Expand All @@ -61,12 +62,23 @@ abstract class AWS1ClientTest extends VersionedNamingTestBase {
def credentialsProvider = new AWSStaticCredentialsProvider(new AnonymousAWSCredentials())
@Shared
def responseBody = new AtomicReference<String>()
@Shared
def jsonPointer = new AtomicReference<String>()

@AutoCleanup
@Shared
def server = httpServer {
handlers {
all {
response.status(200).send(responseBody.get())
def body = responseBody.get()
if (request.headers.get("Content-Type")?.contains("json")) {
def json = XML.toJSONObject(body)
if (jsonPointer.get() != null) {
json = json.query(jsonPointer.get())
}
body = json.toString()
}
response.status(200).send(body)
}
}
}
Expand Down Expand Up @@ -131,6 +143,7 @@ abstract class AWS1ClientTest extends VersionedNamingTestBase {
def "send #operation request with mocked response"() {
setup:
responseBody.set(body)
jsonPointer.set(jsonPointerStr)

when:
def response = call.call(client)
Expand Down Expand Up @@ -181,19 +194,22 @@ abstract class AWS1ClientTest extends VersionedNamingTestBase {
server.lastRequest.headers.get("x-datadog-trace-id") == null
server.lastRequest.headers.get("x-datadog-parent-id") == null

cleanup:
jsonPointer.set(null)

where:
service | operation | method | path | client | call | additionalTags | body | peerService
"S3" | "CreateBucket" | "PUT" | "/testbucket/" | AmazonS3ClientBuilder.standard().withPathStyleAccessEnabled(true).withEndpointConfiguration(endpoint).withCredentials(credentialsProvider).build() | { c -> c.createBucket("testbucket") } | ["aws.bucket.name": "testbucket", "bucketname": "testbucket"] | "" | "aws.bucket.name"
"S3" | "GetObject" | "GET" | "/someBucket/someKey" | AmazonS3ClientBuilder.standard().withPathStyleAccessEnabled(true).withEndpointConfiguration(endpoint).withCredentials(credentialsProvider).build() | { c -> c.getObject("someBucket", "someKey") } | ["aws.bucket.name": "someBucket", "bucketname": "someBucket"] | "" | "aws.bucket.name"
"DynamoDBv2" | "CreateTable" | "POST" | "/" | AmazonDynamoDBClientBuilder.standard().withEndpointConfiguration(endpoint).withCredentials(credentialsProvider).build() | { c -> c.createTable(new CreateTableRequest("sometable", null)) } | ["aws.table.name": "sometable", "tablename": "sometable"] | "" | "aws.table.name"
"Kinesis" | "DeleteStream" | "POST" | "/" | AmazonKinesisClientBuilder.standard().withEndpointConfiguration(endpoint).withCredentials(credentialsProvider).build() | { c -> c.deleteStream(new DeleteStreamRequest().withStreamName("somestream")) } | ["aws.stream.name": "somestream", "streamname": "somestream"] | "" | "aws.stream.name"
service | operation | method | path | client | call | additionalTags | body | peerService | jsonPointerStr
"S3" | "CreateBucket" | "PUT" | "/testbucket/" | AmazonS3ClientBuilder.standard().withPathStyleAccessEnabled(true).withEndpointConfiguration(endpoint).withCredentials(credentialsProvider).build() | { c -> c.createBucket("testbucket") } | ["aws.bucket.name": "testbucket", "bucketname": "testbucket"] | "" | "aws.bucket.name" | null
"S3" | "GetObject" | "GET" | "/someBucket/someKey" | AmazonS3ClientBuilder.standard().withPathStyleAccessEnabled(true).withEndpointConfiguration(endpoint).withCredentials(credentialsProvider).build() | { c -> c.getObject("someBucket", "someKey") } | ["aws.bucket.name": "someBucket", "bucketname": "someBucket"] | "" | "aws.bucket.name" | null
"DynamoDBv2" | "CreateTable" | "POST" | "/" | AmazonDynamoDBClientBuilder.standard().withEndpointConfiguration(endpoint).withCredentials(credentialsProvider).build() | { c -> c.createTable(new CreateTableRequest("sometable", null)) } | ["aws.table.name": "sometable", "tablename": "sometable"] | "" | "aws.table.name" | null
"Kinesis" | "DeleteStream" | "POST" | "/" | AmazonKinesisClientBuilder.standard().withEndpointConfiguration(endpoint).withCredentials(credentialsProvider).build() | { c -> c.deleteStream(new DeleteStreamRequest().withStreamName("somestream")) } | ["aws.stream.name": "somestream", "streamname": "somestream"] | "" | "aws.stream.name" | null
"SQS" | "CreateQueue" | "POST" | "/" | AmazonSQSClientBuilder.standard().withEndpointConfiguration(endpoint).withCredentials(credentialsProvider).build() | { c -> c.createQueue(new CreateQueueRequest("somequeue")) } | ["aws.queue.name": "somequeue", "queuename": "somequeue"] | """
<CreateQueueResponse>
<CreateQueueResult><QueueUrl>https://queue.amazonaws.com/123456789012/MyQueue</QueueUrl></CreateQueueResult>
<ResponseMetadata><RequestId>7a62c49f-347e-4fc4-9331-6e8e7a96aa73</RequestId></ResponseMetadata>
</CreateQueueResponse>
""" | "aws.queue.name"
""" | "aws.queue.name" | "/CreateQueueResponse/CreateQueueResult"
"SQS" | "SendMessage" | "POST" | "/someurl" | AmazonSQSClientBuilder.standard().withEndpointConfiguration(endpoint).withCredentials(credentialsProvider).build() | { c -> c.sendMessage(new SendMessageRequest("someurl", "")) } | ["aws.queue.url": "someurl"] | """
<SendMessageResponse>
<SendMessageResult>
Expand All @@ -203,30 +219,29 @@ abstract class AWS1ClientTest extends VersionedNamingTestBase {
</SendMessageResult>
<ResponseMetadata><RequestId>27daac76-34dd-47df-bd01-1f6e873584a0</RequestId></ResponseMetadata>
</SendMessageResponse>
""" | "aws.queue.url"
""" | "aws.queue.url" | "/SendMessageResponse/SendMessageResult"
"SNS" | "Publish" | "POST" | "/" | AmazonSNSClientBuilder.standard().withEndpointConfiguration(endpoint).withCredentials(credentialsProvider).build() | { c -> c.publish(new PublishRequest("arn:aws:sns::123:some-topic", "")) } | ["aws.topic.name": "some-topic", "topicname": "some-topic"] | """
<PublishResponse xmlns="https://sns.amazonaws.com/doc/2010-03-31/">
<PublishResult>
<MessageId>567910cd-659e-55d4-8ccb-5aaf14679dc0</MessageId>
</PublishResult>
<ResponseMetadata><RequestId>d74b8436-ae13-5ab4-a9ff-ce54dfea72a0</RequestId></ResponseMetadata>
</PublishResponse>
""" | "aws.topic.name"
""" | "aws.topic.name" | "/PublishResponse/PublishResult"
"EC2" | "AllocateAddress" | "POST" | "/" | AmazonEC2ClientBuilder.standard().withEndpointConfiguration(endpoint).withCredentials(credentialsProvider).build() | { c -> c.allocateAddress() } | [:] | """
<AllocateAddressResponse xmlns="http://ec2.amazonaws.com/doc/2016-11-15/">
<requestId>59dbff89-35bd-4eac-99ed-be587EXAMPLE</requestId>
<publicIp>192.0.2.1</publicIp>
<domain>standard</domain>
</AllocateAddressResponse>
""" | null

""" | null | "/AllocateAddressResponse"
"RDS" | "DeleteOptionGroup" | "POST" | "/" | AmazonRDSClientBuilder.standard().withEndpointConfiguration(endpoint).withCredentials(credentialsProvider).build() | { c -> c.deleteOptionGroup(new DeleteOptionGroupRequest()) } | [:] | """
<DeleteOptionGroupResponse xmlns="http://rds.amazonaws.com/doc/2014-09-01/">
<ResponseMetadata>
<RequestId>0ac9cda2-bbf4-11d3-f92b-31fa5e8dbc99</RequestId>
</ResponseMetadata>
</DeleteOptionGroupResponse>
""" | null
""" | null | null
}

def "send #operation request to closed port"() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import datadog.trace.bootstrap.instrumentation.api.Tags
import datadog.trace.test.util.Flaky
import org.apache.http.conn.HttpHostConnectException
import org.apache.http.impl.execchain.RequestAbortedException
import org.json.XML
import spock.lang.AutoCleanup
import spock.lang.Shared

Expand Down Expand Up @@ -68,12 +69,23 @@ class LegacyAWS1ClientForkedTest extends AgentTestRunner {
def credentialsProvider = new AWSStaticCredentialsProvider(new AnonymousAWSCredentials())
@Shared
def responseBody = new AtomicReference<String>()
@Shared
def jsonPointer = new AtomicReference<String>()

@AutoCleanup
@Shared
def server = httpServer {
handlers {
all {
response.status(200).send(responseBody.get())
def body = responseBody.get()
if (request.headers.get("Content-Type")?.contains("json")) {
def json = XML.toJSONObject(body)
if (jsonPointer.get() != null) {
json = json.query(jsonPointer.get())
}
body = json.toString()
}
response.status(200).send(body)
}
}
}
Expand Down Expand Up @@ -124,6 +136,7 @@ class LegacyAWS1ClientForkedTest extends AgentTestRunner {
def "send #operation request with mocked response"() {
setup:
responseBody.set(body)
jsonPointer.set(jsonPointerStr)

when:
def response = call.call(client)
Expand Down Expand Up @@ -187,18 +200,21 @@ class LegacyAWS1ClientForkedTest extends AgentTestRunner {
server.lastRequest.headers.get("x-datadog-trace-id") == null
server.lastRequest.headers.get("x-datadog-parent-id") == null

cleanup:
jsonPointer.set(null)

where:
service | operation | ddService | method | path | client | call | additionalTags | body
"S3" | "CreateBucket" | "java-aws-sdk" | "PUT" | "/testbucket/" | AmazonS3ClientBuilder.standard().withPathStyleAccessEnabled(true).withEndpointConfiguration(endpoint).withCredentials(credentialsProvider).build() | { c -> c.createBucket("testbucket") } | ["aws.bucket.name": "testbucket", "bucketname": "testbucket"] | ""
"S3" | "GetObject" | "java-aws-sdk" | "GET" | "/someBucket/someKey" | AmazonS3ClientBuilder.standard().withPathStyleAccessEnabled(true).withEndpointConfiguration(endpoint).withCredentials(credentialsProvider).build() | { c -> c.getObject("someBucket", "someKey") } | ["aws.bucket.name": "someBucket", "bucketname": "someBucket"] | ""
"DynamoDBv2" | "CreateTable" | "java-aws-sdk" | "POST" | "/" | AmazonDynamoDBClientBuilder.standard().withEndpointConfiguration(endpoint).withCredentials(credentialsProvider).build() | { c -> c.createTable(new CreateTableRequest("sometable", null)) } | ["aws.table.name": "sometable", "tablename": "sometable"] | ""
"Kinesis" | "DeleteStream" | "java-aws-sdk" | "POST" | "/" | AmazonKinesisClientBuilder.standard().withEndpointConfiguration(endpoint).withCredentials(credentialsProvider).build() | { c -> c.deleteStream(new DeleteStreamRequest().withStreamName("somestream")) } | ["aws.stream.name": "somestream", "streamname": "somestream"] | ""
service | operation | ddService | method | path | client | call | additionalTags | body | jsonPointerStr
"S3" | "CreateBucket" | "java-aws-sdk" | "PUT" | "/testbucket/" | AmazonS3ClientBuilder.standard().withPathStyleAccessEnabled(true).withEndpointConfiguration(endpoint).withCredentials(credentialsProvider).build() | { c -> c.createBucket("testbucket") } | ["aws.bucket.name": "testbucket", "bucketname": "testbucket"] | "" | null
"S3" | "GetObject" | "java-aws-sdk" | "GET" | "/someBucket/someKey" | AmazonS3ClientBuilder.standard().withPathStyleAccessEnabled(true).withEndpointConfiguration(endpoint).withCredentials(credentialsProvider).build() | { c -> c.getObject("someBucket", "someKey") } | ["aws.bucket.name": "someBucket", "bucketname": "someBucket"] | "" | null
"DynamoDBv2" | "CreateTable" | "java-aws-sdk" | "POST" | "/" | AmazonDynamoDBClientBuilder.standard().withEndpointConfiguration(endpoint).withCredentials(credentialsProvider).build() | { c -> c.createTable(new CreateTableRequest("sometable", null)) } | ["aws.table.name": "sometable", "tablename": "sometable"] | "" | null
"Kinesis" | "DeleteStream" | "java-aws-sdk" | "POST" | "/" | AmazonKinesisClientBuilder.standard().withEndpointConfiguration(endpoint).withCredentials(credentialsProvider).build() | { c -> c.deleteStream(new DeleteStreamRequest().withStreamName("somestream")) } | ["aws.stream.name": "somestream", "streamname": "somestream"] | "" | null
"SQS" | "CreateQueue" | "java-aws-sdk" | "POST" | "/" | AmazonSQSClientBuilder.standard().withEndpointConfiguration(endpoint).withCredentials(credentialsProvider).build() | { c -> c.createQueue(new CreateQueueRequest("somequeue")) } | ["aws.queue.name": "somequeue", "queuename": "somequeue"] | """
<CreateQueueResponse>
<CreateQueueResult><QueueUrl>https://queue.amazonaws.com/123456789012/MyQueue</QueueUrl></CreateQueueResult>
<ResponseMetadata><RequestId>7a62c49f-347e-4fc4-9331-6e8e7a96aa73</RequestId></ResponseMetadata>
</CreateQueueResponse>
"""
""" | "/CreateQueueResponse/CreateQueueResult"
"SQS" | "SendMessage" | "sqs" | "POST" | "/someurl" | AmazonSQSClientBuilder.standard().withEndpointConfiguration(endpoint).withCredentials(credentialsProvider).build() | { c -> c.sendMessage(new SendMessageRequest("someurl", "")) } | ["aws.queue.url": "someurl"] | """
<SendMessageResponse>
<SendMessageResult>
Expand All @@ -208,29 +224,29 @@ class LegacyAWS1ClientForkedTest extends AgentTestRunner {
</SendMessageResult>
<ResponseMetadata><RequestId>27daac76-34dd-47df-bd01-1f6e873584a0</RequestId></ResponseMetadata>
</SendMessageResponse>
"""
""" | "/SendMessageResponse/SendMessageResult"
"SNS" | "Publish" | "sns" | "POST" | "/" | AmazonSNSClientBuilder.standard().withEndpointConfiguration(endpoint).withCredentials(credentialsProvider).build() | { c -> c.publish(new PublishRequest("arn:aws:sns::123:some-topic", "")) } | ["aws.topic.name": "some-topic", "topicname": "some-topic"] | """
<PublishResponse xmlns="https://sns.amazonaws.com/doc/2010-03-31/">
<PublishResult>
<MessageId>567910cd-659e-55d4-8ccb-5aaf14679dc0</MessageId>
</PublishResult>
<ResponseMetadata><RequestId>d74b8436-ae13-5ab4-a9ff-ce54dfea72a0</RequestId></ResponseMetadata>
</PublishResponse>
"""
""" | "/PublishResponse/PublishResult"
"EC2" | "AllocateAddress" | "java-aws-sdk" | "POST" | "/" | AmazonEC2ClientBuilder.standard().withEndpointConfiguration(endpoint).withCredentials(credentialsProvider).build() | { c -> c.allocateAddress() } | [:] | """
<AllocateAddressResponse xmlns="http://ec2.amazonaws.com/doc/2016-11-15/">
<requestId>59dbff89-35bd-4eac-99ed-be587EXAMPLE</requestId>
<publicIp>192.0.2.1</publicIp>
<domain>standard</domain>
</AllocateAddressResponse>
"""
""" | null
"RDS" | "DeleteOptionGroup" | "java-aws-sdk" | "POST" | "/" | AmazonRDSClientBuilder.standard().withEndpointConfiguration(endpoint).withCredentials(credentialsProvider).build() | { c -> c.deleteOptionGroup(new DeleteOptionGroupRequest()) } | [:] | """
<DeleteOptionGroupResponse xmlns="http://rds.amazonaws.com/doc/2014-09-01/">
<ResponseMetadata>
<RequestId>0ac9cda2-bbf4-11d3-f92b-31fa5e8dbc99</RequestId>
</ResponseMetadata>
</DeleteOptionGroupResponse>
"""
""" | null
}

def "send #operation request to closed port"() {
Expand Down
3 changes: 2 additions & 1 deletion dd-java-agent/instrumentation/aws-java-sqs-1.0/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ muzzle {
apply from: "$rootDir/gradle/java.gradle"

addTestSuiteForDir('latestDepTest', 'test')
addTestSuiteExtendingForDir('latestDepForkedTest', 'latestDepTest', 'test')

dependencies {
compileOnly group: 'com.amazonaws', name: 'aws-java-sdk-sqs', version: '1.11.0'
Expand All @@ -23,7 +24,7 @@ dependencies {
testImplementation project(':dd-java-agent:instrumentation:jms')

// SQS<->JMS testing:
testImplementation group: 'org.elasticmq', name: 'elasticmq-rest-sqs_2.13', version: '1.2.3'
testImplementation group: 'org.elasticmq', name: 'elasticmq-rest-sqs_2.13', version: '1.4.7'
testImplementation group: 'com.amazonaws', name: 'amazon-sqs-java-messaging-lib', version: '1.0.8'

latestDepTestImplementation group: 'com.amazonaws', name: 'aws-java-sdk-sqs', version: '+'
Expand Down
Loading

0 comments on commit 8f45302

Please sign in to comment.