Skip to content

Introducing DynamoDB interception via SDK client class replacement#1495

Open
aschenzle wants to merge 8 commits intoWebFuzzing:masterfrom
aschenzle:pr/dynamodb-interception
Open

Introducing DynamoDB interception via SDK client class replacement#1495
aschenzle wants to merge 8 commits intoWebFuzzing:masterfrom
aschenzle:pr/dynamodb-interception

Conversation

@aschenzle
Copy link
Copy Markdown
Contributor

Intercepting main operations (Query, Scan, GetItem, BatchGetItems, PutItem, UpdateItem and Delete Item) for both sync and async DynamoDB SDK clients. The interception happens at the SDK level and I've verified it works via an integration test using Docker. There was a dependency conflict while bringing the AWS SDK through Maven, Netty versions would get mixed up for Redis end to end tests so I've made the decision to exclude Netty from Lettuce package and use the Netty version packaged on AWS SDK. All e2e tests are passing.

As this is my first PR I'm looking for exhaustive feedback to quickly learn any conventions I've might missed.


protected static Object handle(ThirdPartyMethodReplacementClass singleton, Object client, String id, Object request, String operationName) {
long start = System.currentTimeMillis();
boolean isAsync = client.getClass().getName().contains("Async");
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't we habe a handleAsync() and handleSync() and we call each method replacement differently?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was trying to optimize for code reuse as there will be 8 lines of repeated code if we split the methods. I'm ok changing if that fits better with project conventions. Please confirm you want this change and I'll do it.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please change it

return Collections.singletonList(tableName);
}
} catch (NoSuchMethodException ignored) {
// no-op
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this ignored?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing a really important comment. The following comment will replace that no-op: "// Ignored in the case we are calling for a batch request, it will be handled below in the next section" Let me know if that's clear enough. Or you also want to split the logic for singleTable calls vs batch requests.

Collections.sort(tableNames);
return tableNames;
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
return Collections.emptyList();
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is is defaulted to empty?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seemed like the best option, as we don't want the interception to throw exceptions and retuning null requires handling it. We are just getting less metadata about the interception for this particular request if for some weird reason it fails (Only case I can think this failing would be a dependency problem with another version of the SDK breaking API compatibility, not expected from AWS).

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't you encapsulate this and throw a RuntimeException?

<groupId>io.lettuce</groupId>
<artifactId>lettuce-core</artifactId>
<version>${io.lettuce.core.version}</version>
<!-- Need to exclude Netty from this package to avoid a clash of versions with AWS SDK -->
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you improve the comment why this exclusion is needed?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about "Need to exclude Netty from this package to avoid a conflict of versions with the Netty dependency introduced by AWS SDK, the AWS SDK version of Netty is newer and all e2e tests pass with it."?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>netty-nio-client</artifactId>
<version>${software.amazon.awssdk.dynamodb.version}</version>
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't the scope of this dependency be also test?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants