-
Notifications
You must be signed in to change notification settings - Fork 211
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
Changes from 3 commits
3f2d59f
2ac8584
98d0644
7cb44d2
2af6722
47ada91
d78769d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.dataprepper.model.processor; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import static org.hamcrest.CoreMatchers.equalTo; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
public class ProcessorTest { | ||
|
||
@Test | ||
public void testDefault() { | ||
Processor processor = mock(Processor.class); | ||
when(processor.holdsEvents()).thenCallRealMethod(); | ||
assertThat(processor.holdsEvents(), equalTo(false)); | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. They are released by ProcessWorker. In the following code
where every event that's not passed to the next processor is acknowledged |
||
|
||
final AggregateActionResponse handleEventResponse = aggregateActionSynchronizer.handleEventForGroup(event, identificationKeysMap, aggregateGroupForEvent); | ||
|
||
|
@@ -149,6 +150,11 @@ public Collection<Record<Event>> doExecute(Collection<Record<Event>> records) { | |
return recordsOut; | ||
} | ||
|
||
@Override | ||
public boolean holdsEvents() { | ||
return aggregateAction.holdsEvents(); | ||
} | ||
|
||
public static long getTimeNanos(final Instant time) { | ||
final long NANO_MULTIPLIER = 1_000 * 1_000 * 1_000; | ||
long currentTimeNanos = time.getEpochSecond() * NANO_MULTIPLIER + time.getNano(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,12 +8,16 @@ | |
import org.opensearch.dataprepper.model.annotations.DataPrepperPlugin; | ||
import org.opensearch.dataprepper.model.annotations.DataPrepperPluginConstructor; | ||
import org.opensearch.dataprepper.model.event.Event; | ||
import org.opensearch.dataprepper.model.event.EventHandle; | ||
import org.opensearch.dataprepper.plugins.processor.aggregate.AggregateAction; | ||
import org.opensearch.dataprepper.plugins.processor.aggregate.AggregateActionInput; | ||
import org.opensearch.dataprepper.plugins.processor.aggregate.AggregateActionOutput; | ||
import org.opensearch.dataprepper.plugins.processor.aggregate.AggregateActionResponse; | ||
|
||
import com.google.common.util.concurrent.RateLimiter; | ||
|
||
import java.util.Collections; | ||
|
||
/** | ||
* An AggregateAction that combines multiple Events into a single Event. This action | ||
* | ||
|
@@ -42,4 +46,15 @@ public AggregateActionResponse handleEvent(final Event event, final AggregateAct | |
} | ||
return new AggregateActionResponse(event); | ||
} | ||
|
||
@Override | ||
public AggregateActionOutput concludeGroup(final AggregateActionInput aggregateActionInput) { | ||
if (aggregateActionInput != null) { | ||
EventHandle eventHandle = aggregateActionInput.getEventHandle(); | ||
if (eventHandle != null) { | ||
eventHandle.release(true); | ||
} | ||
} | ||
return new AggregateActionOutput(Collections.emptyList()); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's a good suggestion. |
||
} |
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.
Consider automating the attachment of an event to the AggregateGroup during object creation so that it's encapsulated within the AggregateGroupManager