hashicorp / consul

Consul is a distributed, highly available, and data center aware solution to connect and configure applications across dynamic, distributed infrastructure.
https://www.consul.io
Other
28.25k stars 4.41k forks source link

Service address does not default to the IP address of the agent #2076

Open joshuaspence opened 8 years ago

joshuaspence commented 8 years ago

I have the following service definition:

{
    "service": {
        "checks": [
            {
                "interval": "5s",
                "tcp": "0.0.0.0:6081"
            }
        ],
        "id": "varnish_cache",
        "name": "varnish_cache",
        "port": 6081,
        "tags": []
    }
}

According to the documentation, the Address field should be optional:

The address field can be used to specify a service-specific IP address. By default, the IP address of the agent is used, and this does not need to be provided. The port field can be used as well to make a service-oriented architecture simpler to configure; this way, the address and port of a service can be discovered.

However, the field doesn't seem to be correctly populated when querying the API:

> curl http://127.0.0.1:8500/v1/catalog/service/varnish_cache?pretty=true
[
    {
        "Node": "REDACTED",
        "Address": "REDACTED",
        "ServiceID": "varnish_cache",
        "ServiceName": "varnish_cache",
        "ServiceTags": [],
        "ServiceAddress": "",
        "ServicePort": 6081,
        "ServiceEnableTagOverride": false,
        "CreateIndex": 1474983,
        "ModifyIndex": 1475619
    }
]

> curl http://127.0.0.1:8500/v1/health/service/varnish_cache?pretty=true
[
    {
        "Node": {
            "Node": "REDACTED",
            "Address": "REDACTED",
            "TaggedAddresses": {
                "wan": "REDACTED"
            },
            "CreateIndex": 1474982,
            "ModifyIndex": 1638580
        },
        "Service": {
            "ID": "varnish_cache",
            "Service": "varnish_cache",
            "Tags": [],
            "Address": "",
            "Port": 6081,
            "EnableTagOverride": false,
            "CreateIndex": 1474983,
            "ModifyIndex": 1475619
        },
        "Checks": [
            {
                "Node": "REDACTED",
                "CheckID": "serfHealth",
                "Name": "Serf Health Status",
                "Status": "passing",
                "Notes": "",
                "Output": "Agent alive and reachable",
                "ServiceID": "",
                "ServiceName": "",
                "CreateIndex": 1474982,
                "ModifyIndex": 1638570
            },
            {
                "Node": "REDACTED",
                "CheckID": "service:varnish_cache",
                "Name": "Service 'varnish_cache' check",
                "Status": "passing",
                "Notes": "",
                "Output": "TCP connect 0.0.0.0:6081: Success",
                "ServiceID": "varnish_cache",
                "ServiceName": "varnish_cache",
                "CreateIndex": 1474983,
                "ModifyIndex": 1475619
            }
        ]
    }
]
slackpad commented 8 years ago

Hi @joshuaspence thanks for opening an issue. Right now, clients have to realize that the address is empty and look up the node's address in the other part of the structure (that's what Consul does internally for DNS, for example). We should consider filling this in to make this API easier to consume.

Implementation note - we will need to be a little careful how this is done (probably in the agent) because the servers will have a pointer into the state store, so we can't just loop and tweak them.