Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds support for instrumenting the AWS SDK for Java V2 #56

Merged
merged 3 commits into from
Jan 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions aws-xray-recorder-sdk-aws-sdk-core/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>aws-xray-recorder-sdk-pom</artifactId>
<groupId>com.amazonaws</groupId>
<version>2.1.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>aws-xray-recorder-sdk-aws-sdk-core</artifactId>
<version>2.1.0</version>
<name>AWS X-Ray Recorder SDK for Java - AWS SDK Core</name>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>8</source>
<target>8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.10.4</version>
<configuration>
<javadocDirectory>${basedir}/docs</javadocDirectory>
<docfilessubdirs>true</docfilessubdirs>
<overview>${basedir}/docs/overview.html</overview>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-xray-recorder-sdk-core</artifactId>
<version>${awsxrayrecordersdk.version}</version>
</dependency>
<!-- Test -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.10.19</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.amazonaws.xray.handlers.config;

import com.fasterxml.jackson.annotation.JsonProperty;

import java.util.HashMap;
import java.util.HashSet;

import com.fasterxml.jackson.annotation.JsonProperty;

public class AWSOperationHandler {
@JsonProperty
private HashMap<String, AWSOperationHandlerRequestDescriptor> requestDescriptors;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.amazonaws.xray.handlers.config;

import java.util.Map;

import com.fasterxml.jackson.annotation.JsonProperty;

import java.util.Map;

public class AWSOperationHandlerManifest {
@JsonProperty
private Map<String, AWSOperationHandler> operations;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.amazonaws.xray.handlers.config;

import java.util.Map;

import com.fasterxml.jackson.annotation.JsonProperty;

import java.util.Map;

public class AWSServiceHandler {
@JsonProperty
private Map<String, AWSOperationHandler> operations;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.amazonaws.xray.handlers.config;

import java.util.Map;

import com.fasterxml.jackson.annotation.JsonProperty;

import java.util.Map;

public class AWSServiceHandlerManifest {
@JsonProperty
private Map<String, AWSOperationHandlerManifest> services;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.amazonaws.xray.utils;

public class StringTransform {
private static final String REGEX = "([a-z])([A-Z]+)";
private static final String REPLACE = "$1_$2";

public static String toSnakeCase(String camelCase) {
return camelCase.replaceAll(REGEX, REPLACE).toLowerCase();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package com.amazonaws.xray.handlers.config;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.PropertyNamingStrategy;
import org.junit.Assert;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.MethodSorters;
import org.mockito.runners.MockitoJUnitRunner;

import java.net.URL;
import java.util.HashSet;

@FixMethodOrder(MethodSorters.JVM)
@RunWith(MockitoJUnitRunner.class)
public class AWSServiceHandlerManifestTest {
private static URL testParameterWhitelist = AWSServiceHandlerManifestTest.class.getResource("/com/amazonaws/xray/handlers/config/OperationParameterWhitelist.json");

private ObjectMapper mapper = new ObjectMapper()
.setPropertyNamingStrategy(PropertyNamingStrategy.CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES)
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
.configure(JsonParser.Feature.ALLOW_COMMENTS, true);

@Test
public void testOperationRequestDescriptors() throws Exception {
AWSServiceHandlerManifest serviceManifest = mapper.readValue(testParameterWhitelist, AWSServiceHandlerManifest.class);
AWSOperationHandlerManifest operationManifest = serviceManifest.getOperationHandlerManifest("DynamoDb");
AWSOperationHandler operationHandler = operationManifest.getOperationHandler("BatchGetItem");
AWSOperationHandlerRequestDescriptor descriptor = operationHandler.getRequestDescriptors().get("RequestItems");

Assert.assertEquals(true, descriptor.isMap());
Assert.assertEquals(false, descriptor.isList());
Assert.assertEquals(true, descriptor.shouldGetKeys());
Assert.assertEquals(false, descriptor.shouldGetCount());
Assert.assertEquals("table_names", descriptor.getRenameTo());
}

@Test
public void testOperationRequestParameters() throws Exception {
AWSServiceHandlerManifest serviceManifest = mapper.readValue(testParameterWhitelist, AWSServiceHandlerManifest.class);
AWSOperationHandlerManifest operationManifest = serviceManifest.getOperationHandlerManifest("DynamoDb");
AWSOperationHandler operationHandler = operationManifest.getOperationHandler("CreateTable");
HashSet<String> parameters = operationHandler.getRequestParameters();

Assert.assertEquals(true, parameters.contains("GlobalSecondaryIndexes"));
Assert.assertEquals(true, parameters.contains("LocalSecondaryIndexes"));
Assert.assertEquals(true, parameters.contains("ProvisionedThroughput"));
Assert.assertEquals(true, parameters.contains("TableName"));
}

@Test
public void testOperationResponseDescriptors() throws Exception {
AWSServiceHandlerManifest serviceManifest = mapper.readValue(testParameterWhitelist, AWSServiceHandlerManifest.class);
AWSOperationHandlerManifest operationManifest = serviceManifest.getOperationHandlerManifest("DynamoDb");
AWSOperationHandler operationHandler = operationManifest.getOperationHandler("ListTables");
AWSOperationHandlerResponseDescriptor descriptor = operationHandler.getResponseDescriptors().get("TableNames");

Assert.assertEquals(false, descriptor.isMap());
Assert.assertEquals(true, descriptor.isList());
Assert.assertEquals(false, descriptor.shouldGetKeys());
Assert.assertEquals(true, descriptor.shouldGetCount());
Assert.assertEquals("table_count", descriptor.getRenameTo());
}

@Test
public void testOperationResponseParameters() throws Exception {
AWSServiceHandlerManifest serviceManifest = mapper.readValue(testParameterWhitelist, AWSServiceHandlerManifest.class);
AWSOperationHandlerManifest operationManifest = serviceManifest.getOperationHandlerManifest("DynamoDb");
AWSOperationHandler operationHandler = operationManifest.getOperationHandler("DeleteItem");
HashSet<String> parameters = operationHandler.getResponseParameters();

Assert.assertEquals(true, parameters.contains("ConsumedCapacity"));
Assert.assertEquals(true, parameters.contains("ItemCollectionMetrics"));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.amazonaws.xray.utils;

import org.junit.Assert;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runners.MethodSorters;

@FixMethodOrder(MethodSorters.JVM)
public class StringTransformTest {

@Test
public void testToSnakeCase() {
Assert.assertEquals("table_name", StringTransform.toSnakeCase("tableName"));
Assert.assertEquals("consumed_capacity", StringTransform.toSnakeCase("ConsumedCapacity"));
Assert.assertEquals("item_collection_metrics", StringTransform.toSnakeCase("ItemCollectionMetrics"));
}

@Test
public void testToSnakeCaseNoExtraUnderscores() {
Assert.assertEquals("table_name", StringTransform.toSnakeCase("table_name"));
}
}
Loading