-
Notifications
You must be signed in to change notification settings - Fork 191
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
Adding ttl_delete parameter to metadata for DynamoDB #4982
base: main
Are you sure you want to change the base?
Adding ttl_delete parameter to metadata for DynamoDB #4982
Conversation
Signed-off-by: Lee Hannigan <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for making this contribution! Made some minor comments that would be nice to address but overall does look good.
* @throws Exception Exception if failed to write to buffer. | ||
*/ | ||
public void addToBuffer(final AcknowledgementSet acknowledgementSet, | ||
final Map<String, Object> data, | ||
final Map<String, Object> keys, | ||
final long eventCreationTimeMillis, | ||
final long eventVersionNumber, | ||
final String eventName) throws Exception { | ||
final String eventName, | ||
final Boolean userIdentity) throws Exception { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This boolean should named according to whether it's a TTL delete. Alternatively, it may make sense to make this a String and do the boolean conversion to TTL delete in this method
@@ -102,6 +105,7 @@ public void addToBuffer(final AcknowledgementSet acknowledgementSet, | |||
eventMetadata.setAttribute(DDB_STREAM_EVENT_NAME_METADATA_ATTRIBUTE, eventName); | |||
eventMetadata.setAttribute(EVENT_NAME_BULK_ACTION_METADATA_ATTRIBUTE, mapStreamEventNameToBulkAction(eventName)); | |||
eventMetadata.setAttribute(EVENT_VERSION_FROM_TIMESTAMP, eventVersionNumber); | |||
eventMetadata.setAttribute(DDB_STREAM_EVENT_USER_IDENTITY, userIdentity); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might make sense to only add this metadata attribute when it is a TTL delete. That way in the configuration later on for routes and things of that sort, users can just do a simple check on
getMetadata("ttl_delete") != null
rather than having to check explicitly for a true value with getMetadata("ttl_delete") == true
. I am fine with it either way though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using a simple boolean (true/false) rather than three options (null/false/true) is easier to deal with.
If anything, I'd change this from capital Boolean
which allows null
to lowercase boolean
which as a primitive can only be true or false.
@@ -80,6 +80,7 @@ public void writeToBuffer(final AcknowledgementSet acknowledgementSet, List<Reco | |||
int eventCount = 0; | |||
for (Record record : records) { | |||
final long bytes = record.dynamodb().sizeBytes(); | |||
final Boolean userIdentity = record.userIdentity() != null && "dynamodb.amazonaws.com".equals(record.userIdentity().principalId()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This variable should be named isTtlDelete
, or the userIdentity could be passed to addToBuffer
directly as a String like my comment above.
Also, would be good to have "dynamodb.amazonaws.com" as a private static variable whenever it is used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, these would be good improvements to the readability.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I moved the logic to addToBuffer
but instead of passing a String, I was forced to pass the Identity as it also contains Type
which was suggested for checking.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @LeeroyHannigan for this nice feature! I have a few comments, many also shared by @graytaylor0 .
@@ -102,6 +105,7 @@ public void addToBuffer(final AcknowledgementSet acknowledgementSet, | |||
eventMetadata.setAttribute(DDB_STREAM_EVENT_NAME_METADATA_ATTRIBUTE, eventName); | |||
eventMetadata.setAttribute(EVENT_NAME_BULK_ACTION_METADATA_ATTRIBUTE, mapStreamEventNameToBulkAction(eventName)); | |||
eventMetadata.setAttribute(EVENT_VERSION_FROM_TIMESTAMP, eventVersionNumber); | |||
eventMetadata.setAttribute(DDB_STREAM_EVENT_USER_IDENTITY, userIdentity); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using a simple boolean (true/false) rather than three options (null/false/true) is easier to deal with.
If anything, I'd change this from capital Boolean
which allows null
to lowercase boolean
which as a primitive can only be true or false.
@@ -80,6 +80,7 @@ public void writeToBuffer(final AcknowledgementSet acknowledgementSet, List<Reco | |||
int eventCount = 0; | |||
for (Record record : records) { | |||
final long bytes = record.dynamodb().sizeBytes(); | |||
final Boolean userIdentity = record.userIdentity() != null && "dynamodb.amazonaws.com".equals(record.userIdentity().principalId()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, these would be good improvements to the readability.
@@ -21,4 +21,5 @@ public class MetadataKeyAttributes { | |||
static final String DDB_STREAM_EVENT_NAME_METADATA_ATTRIBUTE = "dynamodb_event_name"; | |||
|
|||
static final String EVENT_TABLE_NAME_METADATA_ATTRIBUTE = "table_name"; | |||
static final String DDB_STREAM_EVENT_USER_IDENTITY = "ttl_delete"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
static final String DDB_STREAM_EVENT_USER_IDENTITY = "ttl_delete"; | |
static final String DDB_STREAM_EVENT_IS_TTL_DELETE = "ttl_delete"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renamed static variable
when(streamConfig.getStreamViewForRemoves()).thenReturn(StreamViewType.OLD_IMAGE); | ||
|
||
final Identity userIdentity = Identity.builder() | ||
.principalId("dynamodb.amazonaws.com") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please include a test case where the userIdentity is not null, but the principal is something other than this known principle.
It would cover the case of && "dynamodb.amazonaws.com".equals(record.userIdentity().principalId())
.
...java/org/opensearch/dataprepper/plugins/source/dynamodb/converter/StreamRecordConverter.java
Outdated
Show resolved
Hide resolved
Signed-off-by: Lee Hannigan <[email protected]>
Thank you both for review. Incorporated both your feedback, let me know if the current version is acceptable. |
Description
This change allows users to identify the source of a REMOVE event from DynamoDB streams, if it was a manual delete or a TTL delete.
Issues Resolved
Resolves #4560
Check List
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.