Skip to content

Add support to skip remote peer forwarding based on configuration#5127

Merged
kkondaka merged 3 commits intoopensearch-project:mainfrom
kkondaka:optional-peer-forwarding
Oct 30, 2024
Merged

Add support to skip remote peer forwarding based on configuration#5127
kkondaka merged 3 commits intoopensearch-project:mainfrom
kkondaka:optional-peer-forwarding

Conversation

@kkondaka
Copy link
Copy Markdown
Collaborator

Description

Add support to not do remote peer forwarding optionally for certain identification keys.

If this config option is used, any processors using the same identification keys as specified in the config, do not do remote peer forwarding. All those events are locally processed.

Issues Resolved

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

Check List

  • 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.

final PeerForwarderProvider peerForwarderProvider,
final String pipelineName,
final String pluginId,
final List<String> noPeerForwardingKeys,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Let's take this in as a Collection<Collection<String>> to indicate that the order does not matter. In fact we use it as a set.

Also, note my changes above for why it is a nested collection.

@JsonAlias("serverPort")
final String serverPort,
@JsonProperty("no_peer_forwarding_keys")
final List<String> noPeerForwardingKeys,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This logic is setup to exclude a key. I think that is not exactly the solution. It should exclude identification_keys.

So a couple of changes here:

  1. Rename this to exclude_identification_keys
  2. Change to a list of list of string.
exclude_identification_keys:
- ['traceId']
- ['someId1', 'someId2']

The peer forwarder should still forward for a processor with identificationKeys of traceId, someOtherValue.

private static boolean isPeerForwardingDisabled(Processor processor, List<String> noPeerForwardingKeys) {
if (processor instanceof RequiresPeerForwarding && noPeerForwardingKeys != null && noPeerForwardingKeys.size() > 0) {
Set<String> noPeerForwardKeys = new HashSet<>(noPeerForwardingKeys);
for (final String identificationKey: ((RequiresPeerForwarding) processor).getIdentificationKeys()) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

With the changes I suggested above, this should become something like the following:

Collection<String> identificationKeys = ((RequiresPeerForwarding) processor).getIdentificationKeys());
for(Set<String> excludedIdentificationKeys : allExcludedIdentificationKeys) {
  if(excludedIdentificationKeys.equals(identificationKeys)) {
    return false;
  }
}

@kkondaka kkondaka force-pushed the optional-peer-forwarding branch from 04dbc0a to bc2393a Compare October 29, 2024 18:57
Set<String> notMatchingIdentificationKeys = Set.of("key1", "key3");
when(requiresPeerForwarding.getIdentificationKeys()).thenReturn(identificationKeys);
final List<Processor> processors = createObjectUnderTestDecoratedProcessorsWithExcludeIdentificationKeys(Collections.singletonList((Processor) requiresPeerForwarding), List.of(notMatchingIdentificationKeys));
for (final Processor processor: processors) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please assert the number of processors before this loop. Otherwise, this could result in no verification.

assertThat(processors, hasSize(2));

Set<String> identificationKeys = Set.of("key1", "key2");
when(requiresPeerForwarding.getIdentificationKeys()).thenReturn(identificationKeys);
final List<Processor> processors = createObjectUnderTestDecoratedProcessorsWithExcludeIdentificationKeys(Collections.singletonList((Processor) requiresPeerForwarding), List.of(identificationKeys));
for (final Processor processor: processors) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please assert the number of processors before this loop. Otherwise, this could result in no verification.

assertThat(processors, hasSize(2));

@JsonAlias("privateKeyPassword")
final String privateKeyPassword,
@JsonProperty("exclude_identification_keys")
final List<List<String>> excludeIdentificationKeys,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
final List<List<String>> excludeIdentificationKeys,
final List<Set<String>> excludeIdentificationKeys,

Signed-off-by: Krishna Kondaka <krishkdk@dev-dsk-krishkdk-2c-b72a134e.us-west-2.amazon.com>
Signed-off-by: Krishna Kondaka <krishkdk@amazon.com>
Signed-off-by: Krishna Kondaka <krishkdk@amazon.com>
@kkondaka kkondaka force-pushed the optional-peer-forwarding branch from 241da36 to 286e822 Compare October 29, 2024 20:23
dlvenable
dlvenable previously approved these changes Oct 29, 2024
Signed-off-by: Krishna Kondaka <krishkdk@amazon.com>
@kkondaka kkondaka merged commit 25a3224 into opensearch-project:main Oct 30, 2024
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.

3 participants