-
Notifications
You must be signed in to change notification settings - Fork 217
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
Support multiple aggregate processors in local mode #4574
Merged
kkondaka
merged 2 commits into
opensearch-project:main
from
kkondaka:multiple-local-aggr
Jun 14, 2024
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
102 changes: 102 additions & 0 deletions
102
.../src/main/java/org/opensearch/dataprepper/peerforwarder/DefaultPeerForwarderProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.dataprepper.peerforwarder; | ||
|
||
import org.opensearch.dataprepper.metrics.PluginMetrics; | ||
import org.opensearch.dataprepper.model.event.Event; | ||
import org.opensearch.dataprepper.model.record.Record; | ||
import org.opensearch.dataprepper.model.processor.Processor; | ||
import org.opensearch.dataprepper.peerforwarder.client.PeerForwarderClient; | ||
import org.opensearch.dataprepper.peerforwarder.discovery.DiscoveryMode; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
public class DefaultPeerForwarderProvider implements PeerForwarderProvider { | ||
|
||
private final PeerForwarderClientFactory peerForwarderClientFactory; | ||
private final PeerForwarderClient peerForwarderClient; | ||
private final PeerForwarderConfiguration peerForwarderConfiguration; | ||
private final PluginMetrics pluginMetrics; | ||
private final Map<String, Map<String, PeerForwarderReceiveBuffer<Record<Event>>>> pipelinePeerForwarderReceiveBufferMap = new HashMap<>(); | ||
private HashRing hashRing; | ||
|
||
DefaultPeerForwarderProvider(final PeerForwarderClientFactory peerForwarderClientFactory, | ||
final PeerForwarderClient peerForwarderClient, | ||
final PeerForwarderConfiguration peerForwarderConfiguration, | ||
final PluginMetrics pluginMetrics) { | ||
this.peerForwarderClientFactory = peerForwarderClientFactory; | ||
this.peerForwarderClient = peerForwarderClient; | ||
this.peerForwarderConfiguration = peerForwarderConfiguration; | ||
this.pluginMetrics = pluginMetrics; | ||
} | ||
|
||
public PeerForwarder register(final String pipelineName, final Processor processor, final String pluginId, final Set<String> identificationKeys, | ||
final Integer pipelineWorkerThreads) { | ||
if (pipelinePeerForwarderReceiveBufferMap.containsKey(pipelineName) && | ||
pipelinePeerForwarderReceiveBufferMap.get(pipelineName).containsKey(pluginId)) { | ||
throw new RuntimeException("Data Prepper 2.0 will only support a single peer-forwarder per pipeline/plugin type"); | ||
} | ||
|
||
final PeerForwarderReceiveBuffer<Record<Event>> peerForwarderReceiveBuffer = createBufferPerPipelineProcessor(pipelineName, pluginId); | ||
|
||
if (isPeerForwardingRequired()) { | ||
if (hashRing == null) { | ||
hashRing = peerForwarderClientFactory.createHashRing(); | ||
} | ||
return new RemotePeerForwarder( | ||
peerForwarderClient, | ||
hashRing, | ||
peerForwarderReceiveBuffer, | ||
pipelineName, | ||
pluginId, | ||
identificationKeys, | ||
pluginMetrics, | ||
peerForwarderConfiguration.getBatchDelay(), | ||
peerForwarderConfiguration.getFailedForwardingRequestLocalWriteTimeout(), | ||
peerForwarderConfiguration.getForwardingBatchSize(), | ||
peerForwarderConfiguration.getForwardingBatchQueueDepth(), | ||
peerForwarderConfiguration.getForwardingBatchTimeout(), | ||
pipelineWorkerThreads | ||
); | ||
} | ||
else { | ||
return new LocalPeerForwarder(); | ||
} | ||
} | ||
|
||
private PeerForwarderReceiveBuffer<Record<Event>> createBufferPerPipelineProcessor(final String pipelineName, final String pluginId) { | ||
final PeerForwarderReceiveBuffer<Record<Event>> peerForwarderReceiveBuffer = new | ||
PeerForwarderReceiveBuffer<>(peerForwarderConfiguration.getBufferSize(), peerForwarderConfiguration.getBatchSize(), pipelineName, pluginId); | ||
|
||
final Map<String, PeerForwarderReceiveBuffer<Record<Event>>> pluginsBufferMap = | ||
pipelinePeerForwarderReceiveBufferMap.computeIfAbsent(pipelineName, k -> new HashMap<>()); | ||
|
||
pluginsBufferMap.put(pluginId, peerForwarderReceiveBuffer); | ||
|
||
return peerForwarderReceiveBuffer; | ||
} | ||
|
||
public boolean isPeerForwardingRequired() { | ||
return arePeersConfigured() && pipelinePeerForwarderReceiveBufferMap.size() > 0; | ||
} | ||
|
||
public boolean arePeersConfigured() { | ||
final DiscoveryMode discoveryMode = peerForwarderConfiguration.getDiscoveryMode(); | ||
if (discoveryMode.equals(DiscoveryMode.LOCAL_NODE)) { | ||
return false; | ||
} | ||
else if (discoveryMode.equals(DiscoveryMode.STATIC) && peerForwarderConfiguration.getStaticEndpoints().size() <= 1) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
public Map<String, Map<String, PeerForwarderReceiveBuffer<Record<Event>>>> getPipelinePeerForwarderReceiveBufferMap() { | ||
return pipelinePeerForwarderReceiveBufferMap; | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
...rc/main/java/org/opensearch/dataprepper/peerforwarder/LocalModePeerForwarderProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.dataprepper.peerforwarder; | ||
|
||
import org.opensearch.dataprepper.model.event.Event; | ||
import org.opensearch.dataprepper.model.record.Record; | ||
import org.opensearch.dataprepper.model.processor.Processor; | ||
import org.opensearch.dataprepper.model.peerforwarder.RequiresPeerForwarding; | ||
|
||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
public class LocalModePeerForwarderProvider implements PeerForwarderProvider { | ||
|
||
private final PeerForwarderProvider peerForwarderProvider; | ||
private boolean isRemotePeerForwarderRegistered; | ||
|
||
public LocalModePeerForwarderProvider(final PeerForwarderProvider peerForwarderProvider) { | ||
this.peerForwarderProvider = peerForwarderProvider; | ||
this.isRemotePeerForwarderRegistered = false; | ||
} | ||
|
||
@Override | ||
public PeerForwarder register(final String pipelineName, final Processor processor, final String pluginId, final Set<String> identificationKeys, final Integer pipelineWorkerThreads) { | ||
if (((RequiresPeerForwarding)processor).isForLocalProcessingOnly(null)) { | ||
return new LocalPeerForwarder(); | ||
} | ||
isRemotePeerForwarderRegistered = true; | ||
return peerForwarderProvider.register(pipelineName, processor, pluginId, identificationKeys, pipelineWorkerThreads); | ||
} | ||
|
||
@Override | ||
public boolean isPeerForwardingRequired() { | ||
return isRemotePeerForwarderRegistered; | ||
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. It is a little strange that there is no way to verify that |
||
} | ||
|
||
@Override | ||
public Map<String, Map<String, PeerForwarderReceiveBuffer<Record<Event>>>> getPipelinePeerForwarderReceiveBufferMap() { | ||
return (isRemotePeerForwarderRegistered) ? | ||
peerForwarderProvider.getPipelinePeerForwarderReceiveBufferMap() : | ||
Map.of(); | ||
} | ||
|
||
@Override | ||
public boolean arePeersConfigured() { | ||
return isRemotePeerForwarderRegistered ? peerForwarderProvider.arePeersConfigured() : false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Should this say Data Prepper 2.x?