bobrik / marathoner

Service discovery for marathon
26 stars 5 forks source link

Marathon API service ports #7

Open rdigiorgio opened 9 years ago

rdigiorgio commented 9 years ago

Hi,

I have been playing around with Marathoner today, and I must admit I really like it. But I feel like something is wrong in the way you are using ports returned by Marathon API. Also, sorry I can not just make a pull request, as I am not able to code using Go...

Here is my Marathon app:

{
    "id": "elasticsearch",
    "container": {
        "type": "DOCKER",
        "docker": {
            "image": "img/elasticsearch",
            "network": "BRIDGE",
            "portMappings": [
                { "containerPort": 9200, "servicePort": 9200 }
            ]
        }
    },
    "labels": {
        "marathoner_haproxy_enabled": "true"
    },
    "ports": [0]
}

AFAIK, Marathon will "generate" a random and unbound port for each instance of this application. Let's say I run an instance on a slave which IP is 192.168.1.1, and the generated ports are 10000.

The result I expected when using Marathoner for HAProxy would have been as follow: Proxy 127.0.0.1:9200 to 192.168.1.1:10000

Your code makes it clear that it does not handle auto-generated ports:

// servicePort for docker can be set, but ports still can be [0]
// it's better to skip such apps for now
foundEmptyPort := false
for _, p := range a.Ports {
    if p == 0 {
        foundEmptyPort = true
        break
    }
}

Why did you put such a limit there ? Being a recent user of Marathon, I may also be mistaken. :) Thanks for the support !

rdigiorgio commented 9 years ago

By the way, I saw in the changelogs that you got away from using /tasks endpoint to /apps. Why ?

The /tasks endpoint seems to do the work for you:

elasticsearch   9200    192.168.1.1:10000   192.168.1.2:10000