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

Add acknowledgement support to aggregate processor #5139

Merged
merged 7 commits into from
Dec 20, 2024

Conversation

kkondaka
Copy link
Collaborator

@kkondaka kkondaka commented Oct 31, 2024

Description

Add acknowledgement support to aggregate processor
Unaggregated events are not passed to the next processor in chain. For such events, DataPrepper core (in ProcessWorker) would send acknowledgements. It is possible for some aggregate actions (like TailSampler) to "hold" un-aggregated events. holdsEvents() processor API indicates that and DataPrepper code wouldn't send acks for such events.

Issues Resolved

Resolves #[Issue number to be closed when this PR is merged]

Check List

  • [X ] New functionality includes testing.
  • New functionality has a documentation issue. Please link to it in this PR.
    • New functionality has javadoc added
  • [X ] Commits are signed with a real name per the DCO

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.

@@ -62,6 +82,7 @@ boolean shouldConcludeGroup(final Duration groupDuration) {

void resetGroup() {
groupStart = Instant.now();
this.eventHandle = new AggregateEventHandle(groupStart);
Copy link
Member

Choose a reason for hiding this comment

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

Should this do something with the old eventHandle? Release it? Something else?

Copy link
Collaborator Author

@kkondaka kkondaka Dec 12, 2024

Choose a reason for hiding this comment

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

No. The previous event handle was sent with the concluded event and will be released after the event is sent to Sink. Every "aggregate duration" ONE aggregated event is created and one aggregate event handle is created. The aggregate event handle is attached to the aggregated event and the group will create a new handle for the new duration. If the event handle is not attached to any event, then it will be freed (by garbage collector) when a new event handle is created in resetGroup.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for the explanation. This is clear. To be sure, are there any paths that could lead to resetting a group where we do need to handle the aggregate event?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It doesn't look like it. It looks like resetGroup() is called only in closeGroup() which is called only when the group is concluded.

@@ -26,6 +26,14 @@ public interface Processor<InputRecord extends Record<?>, OutputRecord extends R
*/
Collection<OutputRecord> execute(Collection<InputRecord> records);

/**
* indicates if the processor holds the events or not
Copy link
Member

Choose a reason for hiding this comment

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

Update this to be a little clear on what it means to hold events.

@dlvenable dlvenable marked this pull request as ready for review December 13, 2024 19:21
Copy link
Member

@dlvenable dlvenable left a comment

Choose a reason for hiding this comment

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

This looks good overall. I'm good once you make a few small tweaks such as documentation improvements and add tests.

Signed-off-by: Krishna Kondaka <krishkdk@amazon.com>
Signed-off-by: Krishna Kondaka <krishkdk@amazon.com>
Signed-off-by: Krishna Kondaka <krishkdk@amazon.com>
@kkondaka kkondaka dismissed dlvenable’s stale review December 18, 2024 17:28

David has approved changes before the test cases are added

graytaylor0
graytaylor0 previously approved these changes Dec 18, 2024
@@ -125,6 +125,7 @@ public Collection<Record<Event>> doExecute(Collection<Record<Event>> records) {
}
final IdentificationKeysHasher.IdentificationKeysMap identificationKeysMap = identificationKeysHasher.createIdentificationKeysMapFromEvent(event);
final AggregateGroup aggregateGroupForEvent = aggregateGroupManager.getAggregateGroup(identificationKeysMap);
aggregateGroupForEvent.attachToEventAcknowledgementSet(event);
Copy link
Member

Choose a reason for hiding this comment

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

So the solution is to create a new event handle to represent the aggregate group? Makes sense but what is happening exactly to the original event's event handle. Those don't have to be released?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

They are released by ProcessWorker. In the following code

 records = processor.execute(records);
                if (inputEvents != null) {
                    processAcknowledgements(inputEvents, records);
                }

where every event that's not passed to the next processor is acknowledged

Signed-off-by: Krishna Kondaka <krishkdk@amazon.com>
graytaylor0
graytaylor0 previously approved these changes Dec 19, 2024
@@ -125,6 +125,7 @@ public Collection<Record<Event>> doExecute(Collection<Record<Event>> records) {
}
final IdentificationKeysHasher.IdentificationKeysMap identificationKeysMap = identificationKeysHasher.createIdentificationKeysMapFromEvent(event);
final AggregateGroup aggregateGroupForEvent = aggregateGroupManager.getAggregateGroup(identificationKeysMap);
Copy link
Member

Choose a reason for hiding this comment

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

Consider automating the attachment of an event to the AggregateGroup during object creation so that it's encapsulated within the AggregateGroupManager

public AggregateGroup getAggregateGroup(Map<Object, Object> identificationKeysMap, Event event) {
        AggregateGroup aggregateGroup = getOrCreateAggregateGroup(identificationKeysMap);
        ...
        aggregateGroup.attachToEventAcknowledgementSet(event);
        return aggregateGroup;
    }

Comment on lines 51 to 59
public AggregateActionOutput concludeGroup(final AggregateActionInput aggregateActionInput) {
if (aggregateActionInput != null) {
EventHandle eventHandle = aggregateActionInput.getEventHandle();
if (eventHandle != null) {
eventHandle.release(true);
}
}
return new AggregateActionOutput(Collections.emptyList());
}
Copy link
Member

@dinujoh dinujoh Dec 19, 2024

Choose a reason for hiding this comment

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

Can this be default implementation in the interface ? I see the same logic for multiple implementation.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That's a good suggestion.

Signed-off-by: Krishna Kondaka <krishkdk@amazon.com>
graytaylor0
graytaylor0 previously approved these changes Dec 19, 2024
@@ -26,6 +27,12 @@ AggregateGroup getAggregateGroup(final IdentificationKeysHasher.IdentificationKe
return allGroups.computeIfAbsent(identificationKeysMap, (hash) -> new AggregateGroup(identificationKeysMap.getKeyMap()));
}

AggregateGroup getAggregateGroupForEvent(final IdentificationKeysHasher.IdentificationKeysMap identificationKeysMap, final Event event) {
AggregateGroup aggregateGroup = getAggregateGroup(identificationKeysMap);
aggregateGroup.attachToEventAcknowledgementSet(event);
Copy link
Member

Choose a reason for hiding this comment

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

we are repeating this in both AggregateGroupManager and AggregateProcessor line 98

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Forgot to remove this.

Signed-off-by: Krishna Kondaka <krishkdk@amazon.com>
Signed-off-by: Krishna Kondaka <krishkdk@amazon.com>
@kkondaka kkondaka merged commit 708843c into opensearch-project:main Dec 20, 2024
47 checks passed
dlvenable pushed a commit that referenced this pull request Jan 3, 2025
* Addressed review comments

Signed-off-by: Krishna Kondaka <krishkdk@amazon.com>

* Addressed review comments and added tests

Signed-off-by: Krishna Kondaka <krishkdk@amazon.com>

* Fixed checkstyle errors

Signed-off-by: Krishna Kondaka <krishkdk@amazon.com>

* Fixed test errors by adding await

Signed-off-by: Krishna Kondaka <krishkdk@amazon.com>

* Addressed review comments

Signed-off-by: Krishna Kondaka <krishkdk@amazon.com>

* Removed unnecessary API

Signed-off-by: Krishna Kondaka <krishkdk@amazon.com>

* Fixed checkstyle error

Signed-off-by: Krishna Kondaka <krishkdk@amazon.com>

---------

Signed-off-by: Krishna Kondaka <krishkdk@amazon.com>
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.

4 participants