go-resty / resty

Simple HTTP and REST client library for Go
MIT License
10.02k stars 706 forks source link

Service Discovery option for clients #430

Open smadarasmi opened 3 years ago

smadarasmi commented 3 years ago

Current Behavior

Resty seems to support two ways of looking up address

  1. Specifying host information as part of url parameter which will be taken as-is if SRVRecord is not provided
  2. Use net.LookupSRV if SRVRecord is provided

Proposal

Allow for other types of service discovery.

Some projects use Consul or K8s APIs to discover the available addresses of service and does client-side round robin. It's true that one could use Consul DNS or K8s Service to avoid client-side round robin, but I'm not sure if we need to restrict this usage.

Other use cases may want to specify a list of hosts to do some weighted round robin on the client side as well.

Could we provide some Option that supports other types of addresses lookup other than net.LookupSRV? Currently, if address is specified directly to url parameter, this means that all retries will also go to the same address.

If we think that this is something useful to support, perhaps I can draw out a short spec for how we can add this functionality/option. Then I can contribute accordingly if we are in agreement.

jeevatkm commented 3 years ago

@smadarasmi I think, this is where Resty Request Middleware shines, resty could write a middleware process with their discovery service and set the request-host URL.

jeevatkm commented 1 year ago

I will add an interface to extend the Resty user's discovery process on v3.0.0.

jeevatkm commented 1 week ago

This feature aims to introduce the interface for getting the base host URL or DNS from it.

So that Resty users could implement many possibilities based on the interface and share it with the community.