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

Return ConsumedCapacityUnits from DynamoDB Enhanced GetItem calls #4372

Closed
1 of 2 tasks
psnilesh opened this issue Aug 30, 2023 · 5 comments
Closed
1 of 2 tasks

Return ConsumedCapacityUnits from DynamoDB Enhanced GetItem calls #4372

psnilesh opened this issue Aug 30, 2023 · 5 comments
Labels
dynamodb-enhanced feature-request A feature should be added or improved. p2 This is a standard priority issue

Comments

@psnilesh
Copy link
Contributor

psnilesh commented Aug 30, 2023

Describe the feature

DynamoDB can return capacity units consumed by GetItem call if requested, but it is not supported by DynamoDbTable interface. Following are all the methods for loading data,

 interface DynamoDbTable<T> {
    ...
    T getItem(GetItemEnhancedRequest request);
    T getItem(Consumer<GetItemEnhancedRequest.Builder> requestConsumer);
    T getItem(Key key);
    T getItem(T keyItem);
}

However, this is already supported by Put, Update and Delete methods,

 interface DynamoDbTable<T> {
  ...
  PutItemEnhancedResponse<T> putItemWithResponse(PutItemEnhancedRequest<T> request)
  DeleteItemEnhancedResponse<T> deleteItemWithResponse(DeleteItemEnhancedRequest request)
  UpdateItemEnhancedResponse<T> updateItemWithResponse(UpdateItemEnhancedRequest<T> request)
}

// https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/enhanced/dynamodb/model/UpdateItemEnhancedResponse.html
class UpdateItemEnhancedResponse<T> {
    private final T attributes;
    private final ConsumedCapacity consumedCapacity;
    private final ItemCollectionMetrics itemCollectionMetrics;
}

// https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/enhanced/dynamodb/model/PutItemEnhancedResponse.html
class PutItemEnhancedResponse<T> {
    private final T attributes;
    private final ConsumedCapacity consumedCapacity;
    private final ItemCollectionMetrics itemCollectionMetrics;
}

// https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/enhanced/dynamodb/model/DeleteItemEnhancedResponse.html
class DeleteItemEnhancedResponse<T> {
    private final T attributes;
    private final ConsumedCapacity consumedCapacity;
    private final ItemCollectionMetrics itemCollectionMetrics;
}


I propose we add ConsumedCapacity and ItemCollectionMetrics to for read operations as well in a backwards compatible manner.

Related to #1918

Use Case

We have a requirement where we need to accurately calculate capacity consumed by multiple DynamoDB requests made in succession. Having the metrics from DynamoDB would greatly simplify this work.

Proposed Solution

(Better names are welcome)

I propose we add and implement following new methods, similar to how Put, Update and Delete is implemented.

 interface DynamoDbTable<T> {
    // TODO: withResponse may not be the best suffix. It was alright for Put, Update and Delete since
    // their sibling methods are returning void. 
    GetItemEnhancedResponse<T> getItemWithResponse(T keyItem);
    GetItemEnhancedResponse<T> getItemWithResponse(Key key);
    ...
}

class GetItemEnhancedResponse<T> {
    private final T attributes;
    private final ConsumedCapacity consumedCapacity;
}

Other Information

No response

Acknowledgements

  • I may be able to implement this feature request
  • This feature might incur a breaking change

AWS Java SDK version used

2.x

JDK version used

Java8 or newer

Operating System and version

ALL

@psnilesh psnilesh added feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. labels Aug 30, 2023
@psnilesh
Copy link
Contributor Author

If accepted, I can raise a pull request with required changes.

@debora-ito
Copy link
Member

@psnilesh PRs are welcome!

@debora-ito debora-ito added dynamodb-enhanced feature-request A feature should be added or improved. p2 This is a standard priority issue and removed feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. labels Aug 30, 2023
@psnilesh
Copy link
Contributor Author

Submitted PR #4375

davidh44 pushed a commit that referenced this issue Sep 12, 2023
* feat: add GetItemEnhancedResponse with consumedCapacity units to DynamoDb enhanced client

This addressing feature request #4372

* Fix dependency error in DynamoDB Enhanced Client

Related to issue #4372

* More unit and functional tests for DynamoDbTable#getItemWithResponse() api

* Add unit tests for DynamoDB GetItemEnhancedResponse

---------

Co-authored-by: Nilesh <[email protected]>
@psnilesh
Copy link
Contributor Author

Changes for retrieving read units consumed by GetItem and BatchGetItem operations have been merged and will be available in the next minor version release.

@github-actions
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dynamodb-enhanced feature-request A feature should be added or improved. p2 This is a standard priority issue
Projects
None yet
Development

No branches or pull requests

2 participants