Skip to content
This repository has been archived by the owner on Jan 19, 2022. It is now read-only.

WIP Cloud Map Service Discovery #551

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft

Conversation

fitzoh
Copy link

@fitzoh fitzoh commented May 2, 2020

Super janky minimal implementation of an AWS Cloud Map based Service Discovery client (#398).
Currently meant as more of a conversation starter than something ready for a full review.

Note that @darylrobbins has a more fleshed out version of this parked in a branch, but I didn't feel comfortable opening a PR with his code.

// TODO filter on health?
return aws.listInstances(listInstancesRequest).getInstances().stream()
.map(summary -> getInstance(serviceId, summary.getId()))
.collect(Collectors.toList());
Copy link
Author

Choose a reason for hiding this comment

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

Currently making a bunch of sequential HTTP requests, any suggested alternatives?
Is it reasonable to pull in reactor here?

Copy link
Contributor

Choose a reason for hiding this comment

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

potentially, there's also ReactiveDiscoveryClient

Copy link
Author

Choose a reason for hiding this comment

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

Added a reactive client in fdffdf1.

@Override
public List<ServiceInstance> getInstances(String serviceId) {
ListInstancesRequest listInstancesRequest = new ListInstancesRequest()
.withServiceId(serviceId);
Copy link
Author

Choose a reason for hiding this comment

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

Should we always be filtering for healthy instances only, or is that generally a configurable option?

Copy link
Contributor

Choose a reason for hiding this comment

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

Could be an option or also could go in a filter for instance in ribbon or spring cloud loadbalancer

Copy link
Author

Choose a reason for hiding this comment

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

ServiceInstance doesn't appear to have a health property, would that mean it would just need to look it up as a string via getMetadata?

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label May 2, 2020
@fitzoh
Copy link
Author

fitzoh commented May 2, 2020

Any particular implementations I should take a look at for testing inspiration?

Copy link
Contributor

@spencergibb spencergibb left a comment

Choose a reason for hiding this comment

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

Looks interesting, needs to provide ReactiveDiscoveryClient

// TODO filter on health?
return aws.listInstances(listInstancesRequest).getInstances().stream()
.map(summary -> getInstance(serviceId, summary.getId()))
.collect(Collectors.toList());
Copy link
Contributor

Choose a reason for hiding this comment

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

potentially, there's also ReactiveDiscoveryClient

@Override
public List<ServiceInstance> getInstances(String serviceId) {
ListInstancesRequest listInstancesRequest = new ListInstancesRequest()
.withServiceId(serviceId);
Copy link
Contributor

Choose a reason for hiding this comment

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

Could be an option or also could go in a filter for instance in ribbon or spring cloud loadbalancer


@Override
public boolean isSecure() {
return getPort() == 443;
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this always the case?

Copy link
Author

Choose a reason for hiding this comment

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

That's more of a best guess at the moment:

$ aws servicediscovery list-instances --service-id=srv-blah
{
    "Instances": [
        {
            "Id": "fitz-test-instance",
            "Attributes": {
                "AWS_INSTANCE_IPV4": "blah",
                "AWS_INSTANCE_IPV6": "blah blah blah",
                "AWS_INSTANCE_PORT": "8080"
            }
        }
    ]
}

@fitzoh
Copy link
Author

fitzoh commented May 10, 2020

Got some of the configuration boilerplate knocked out, not sure what's next/what kind of testing makes sense for this

Comment on lines +47 to +52
ListInstancesRequest listInstancesRequest = new ListInstancesRequest().withServiceId(serviceId);
// TODO pagination
// TODO parallel requests?
// TODO filter on health?
return aws.listInstances(listInstancesRequest).getInstances().stream()
.map(summary -> getInstance(serviceId, summary.getId())).collect(Collectors.toList());

Choose a reason for hiding this comment

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

I'd recommend using the DiscoverInstances API that is built for this use-case.

  • No need for pagination
  • Filter on the health status is included out of the box

https://docs.aws.amazon.com/cloud-map/latest/api/API_DiscoverInstances.html

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status: waiting-for-triage An issue we've not yet triaged
Development

Successfully merging this pull request may close these issues.

4 participants