Skip to content

Add QueryParameters option to AWS CloudMap-based peer discovery#1560

Merged
dlvenable merged 4 commits into
opensearch-project:mainfrom
engechas:main
Jul 7, 2022
Merged

Add QueryParameters option to AWS CloudMap-based peer discovery#1560
dlvenable merged 4 commits into
opensearch-project:mainfrom
engechas:main

Conversation

@engechas
Copy link
Copy Markdown
Collaborator

@engechas engechas commented Jul 1, 2022

Description

This PR adds awsCloudMapQueryParameters as an optional setting when using AWS CloudMap for peer discovery. The implementation accepts a Map<String, String> which is passed directly to the queryParameters field of the DiscoverInstancesRequest.

Documentation on this field: https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/services/servicediscovery/model/DiscoverInstancesRequest.Builder.html#queryParameters-java.util.Map-

Testing

AWS CloudMap service contents:

aws servicediscovery --region eu-west-1 discover-instances --namespace serv-disc --service serv-disc
{
    "Instances": [
        {
            "InstanceId": "a2ae948ed1244897bf8dfa404fc9593c",
            "NamespaceName": "serv-disc",
            "ServiceName": "serv-disc",
            "HealthStatus": "HEALTHY",
            "Attributes": {
                "AWS_INSTANCE_IPV4": "<redacted>",
                "REGION": "eu-west-1"
            }
        },
        {
            "InstanceId": "30e368d910bf421e98a246d7275987ba",
            "NamespaceName": "serv-disc",
            "ServiceName": "serv-disc",
            "HealthStatus": "HEALTHY",
            "Attributes": {
                "AWS_INSTANCE_IPV4": "<redacted>",
                "REGION": "eu-west-1",
                "test": "filter-params"
            }
        },
        {
            "InstanceId": "c18c00a21852483ebefbb020510bb910",
            "NamespaceName": "serv-disc",
            "ServiceName": "serv-disc",
            "HealthStatus": "HEALTHY",
            "Attributes": {
                "AWS_INSTANCE_IPV4": "<redacted>",
                "REGION": "eu-west-1"
            }
        }
    ]
}

Testing no filters

pipelines.yaml:

simple-sample-pipeline:
  workers: 2
  delay: "5000"
  source:
    random:
  processor:
    - peer_forwarder:
        discovery_mode: aws_cloud_map
        ssl: false
        awsCloudMapNamespaceName: serv-disc
        awsCloudMapServiceName: serv-disc
        awsRegion: eu-west-1
  sink:
    - stdout:

Logs:

2022-07-01T22:41:13,504 [sdk-async-response-0-0] INFO  com.amazon.dataprepper.plugins.prepper.peerforwarder.discovery.AwsCloudMapPeerListProvider$AwsCloudMapDynamicEndpointGroup - Discovered 3 instances.

Testing filter has match:

pipelines.yaml:

simple-sample-pipeline:
  workers: 2
  delay: "5000"
  source:
    random:
  processor:
    - peer_forwarder:
        discovery_mode: aws_cloud_map
        ssl: false
        awsCloudMapNamespaceName: serv-disc
        awsCloudMapServiceName: serv-disc
        awsRegion: eu-west-1
        awsCloudMapQueryParameters:
          test: filter-params
  sink:
    - stdout:

Logs:

2022-07-01T22:58:23,312 [sdk-async-response-0-0] INFO  com.amazon.dataprepper.plugins.prepper.peerforwarder.discovery.AwsCloudMapPeerListProvider$AwsCloudMapDynamicEndpointGroup - Discovered 1 instances.

Testing filter has no matches

pipelines.yaml:

simple-sample-pipeline:
  workers: 2
  delay: "5000"
  source:
    random:
  processor:
    - peer_forwarder:
        discovery_mode: aws_cloud_map
        ssl: false
        awsCloudMapNamespaceName: serv-disc
        awsCloudMapServiceName: serv-disc
        awsRegion: eu-west-1
        awsCloudMapQueryParameters:
          test: no-match
  sink:
    - stdout:

Logs:

2022-07-01T22:59:47,138 [sdk-async-response-0-0] INFO  com.amazon.dataprepper.plugins.prepper.peerforwarder.discovery.AwsCloudMapPeerListProvider$AwsCloudMapDynamicEndpointGroup - Discovered 0 instances.
2022-07-01T22:59:47,141 [sdk-async-response-0-0] INFO  com.amazon.dataprepper.plugins.prepper.peerforwarder.HashRing - Building hash ring with endpoints: []

Testing blank entry

pipelines.yaml:

simple-sample-pipeline:
  workers: 2
  delay: "5000"
  source:
    random:
  processor:
    - peer_forwarder:
        discovery_mode: aws_cloud_map
        ssl: false
        awsCloudMapNamespaceName: serv-disc
        awsCloudMapServiceName: serv-disc
        awsRegion: eu-west-1
        awsCloudMapQueryParameters:
  sink:
    - stdout:

Logs:

2022-07-01T23:02:33,129 [sdk-async-response-0-0] INFO  com.amazon.dataprepper.plugins.prepper.peerforwarder.discovery.AwsCloudMapPeerListProvider$AwsCloudMapDynamicEndpointGroup - Discovered 3 instances.

Check List

  • New functionality includes testing.
  • New functionality has been documented.
    • [N/A] New functionality has javadoc added
  • 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.

engechas added 3 commits July 1, 2022 17:30
…er discovery

Signed-off-by: Chase Engelbrecht <engechas@amazon.com>
…E wording to be a bit more specific

Signed-off-by: Chase Engelbrecht <engechas@amazon.com>
Signed-off-by: Chase Engelbrecht <engechas@amazon.com>
@engechas engechas requested a review from a team as a code owner July 1, 2022 23:12
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Jul 1, 2022

Codecov Report

Merging #1560 (af6aeda) into main (5febd6e) will not change coverage.
The diff coverage is n/a.

@@            Coverage Diff            @@
##               main    #1560   +/-   ##
=========================================
  Coverage     94.18%   94.18%           
  Complexity     1181     1181           
=========================================
  Files           165      165           
  Lines          3386     3386           
  Branches        277      277           
=========================================
  Hits           3189     3189           
  Misses          141      141           
  Partials         56       56           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5febd6e...af6aeda. Read the comment docs.

cmanning09
cmanning09 previously approved these changes Jul 5, 2022
private static Map<String, String> getOptionalSettingMap(final PluginSetting pluginSetting, final String propertyName) {
final Map<String, String> propertyValue = pluginSetting.getTypedMap(propertyName, String.class, String.class);

if (propertyValue == null) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Out of scope for PR: We should eliminate null checks by enforcing a default value in the PluginSettings or allow calling classes to specify the default. Raising: #1563

…case for QueryParameters missing from PluginSetting in AwsCloudMapPeerListProvider_CreateTest

Signed-off-by: Chase Engelbrecht <engechas@amazon.com>
void createPeerListProvider_with_missing_optional_map_property(final String propertyToRemove) {
pluginSetting.getSettings().remove(propertyToRemove);

final PeerListProvider result = AwsCloudMapPeerListProvider.createPeerListProvider(pluginSetting, pluginMetrics);
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.

Thanks! This is the bit of code that I was hoping to test.

The only missing part is to verify that a subsequent call to the AWS SDK has an empty map.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

The ServiceDiscoveryAsyncClient is created as a local variable in the createPeerListProvider so there's not a good way to mock it in this flow without introducing PowerMock as a new dependency or a decent chunk of refactoring.

I will drop the private scope from the getOptionalSettingMap to test the various scenarios while keeping this PR minimal.

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.

OK. I'm fine with keeping this as it is for now.

@dlvenable dlvenable modified the milestone: v2.0 Jul 6, 2022
@dlvenable dlvenable merged commit 2f91aa7 into opensearch-project:main Jul 7, 2022
finnroblin pushed a commit to finnroblin/data-prepper that referenced this pull request Jul 11, 2022
…search-project#1560)

* Implement QueryParameters filter option for AWS CloudMap peer forwarder discovery

Signed-off-by: Chase Engelbrecht <engechas@amazon.com>

* Small fixes related to import statements and unit tests. Update README wording to be a bit more specific

Signed-off-by: Chase Engelbrecht <engechas@amazon.com>

* Adding some asserts to unit tests

Signed-off-by: Chase Engelbrecht <engechas@amazon.com>

* Randomize map generation in AwsCloudMapPeerListProvider and add test case for QueryParameters missing from PluginSetting in AwsCloudMapPeerListProvider_CreateTest

Signed-off-by: Chase Engelbrecht <engechas@amazon.com>
Signed-off-by: Finn Roblin <finnrobl@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