mesosphere / marathon-lb

Marathon-lb is a service discovery & load balancing tool for DC/OS
Apache License 2.0
449 stars 300 forks source link

Ability to query the currently registered services #74

Closed Radek44 closed 8 years ago

Radek44 commented 8 years ago

Not sure if this capability already exists and i'm just missing it - if so please let me know how to use it. It would be great if marathon-lb exposed an api endpoint to query the current apps that are registered and obtain the assigned ports.

For example, assuming a marathon-lb-internal.marathon.mesos deployment, being able to:

curl http://marathon-lb-internal.marathon.mesos/v1/apps that would return as a minimum the list of known apps and their current marathon-lb service port

[{
    "id" : "backend-service", 
    "servicePort":10004, 
    "instancesInRotation": 4, 
    "algorithm": "roundrobin"
}]
brndnmtthws commented 8 years ago

You could try hitting the CSV endpoint, which may give you what you're looking for, provided you filter out the unwanted entries. Here's an example of something that does this programmatically: https://github.com/mesosphere/marathon-lb/blob/master/bluegreen_deploy.py#L147-L180

Radek44 commented 8 years ago

Thank you @brndnmtthws - to ask my question slightly differently - marathon-lb being a service-discovery and load balancing tool, I was wondering what is the best approach for the service-discovery part? Thanks!

brndnmtthws commented 8 years ago

To use it as an SD tool, you'd map services to ports (service ports). This only works for TCP-based services, and those which don't mind being tunneled through a proxy.

lloesche commented 8 years ago

Additionally for http based services (HAPROXY_0_MODE: http) there's a listener on tcp/9091 which parses a X-Marathon-App-Id header. This allows you to find the correct backends without requiring a domainname (HAPROXY_0_VHOST).

So if you have an app /myapp you can request

GET / HTTP/1.1
X-Marathon-App-Id: /myapp

and marathon-lb will route the request to the correct backends without the need for DNS changes.

Radek44 commented 8 years ago

Brilliant! Exactly what I was looking for @lloesche .