Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Near argument for prepared queries doesn't work #2327

Closed
MagicMicky opened this issue Sep 6, 2016 · 2 comments
Closed

Near argument for prepared queries doesn't work #2327

MagicMicky opened this issue Sep 6, 2016 · 2 comments

Comments

@MagicMicky
Copy link

MagicMicky commented Sep 6, 2016

I'm trying touse the dns API to retrieve the ip of a service (i.e.: nginx), using a prepared query that would let me use the Near argument.
When I setup my query using the following

curl -X POST -d '{ "Name": "failover",  "Near": "7e46dd932a84", "Service": { "Service": "nginx",, "Failover": { "NearestN": 3 } } }' 'localhost:8500/v1/query'

The query seems to work, but when I try to dig or execute the request, the results are random. I tried to use the explain endpoint, the "Near" field doesn't seem to be saved.

{
    "Query": {
        "ID": "579af1f5-d7ea-412f-0c19-3bd9a40f1097",
        "Name": "failover",
        "Session": "",
        "Token": "",
        "Template": {
            "Type": "",
            "Regexp": ""
        },
        "Service": {
            "Service": "nginx",
            "Failover": {
                "NearestN": 3,
                "Datacenters": null
            },
            "OnlyPassing": false,
            "Tags": null
        },
        "DNS": {
            "TTL": ""
        },
        "CreateIndex": 6555,
        "ModifyIndex": 6555
    },
    "Index": 0,
    "LastContact": 0,
    "KnownLeader": true
}

From the sources, it seems that the Near argument should be in the Service definition. Tried that but it didn't work too.

To reproduce :

docker run --name nginx_2 -d nginx
docker run --name nginx_1 -d nginx
docker run -d --name=dev-consul -p 8500:8500 -p 8600:8600 consul agent -server -client=0.0.0.0 -dev
docker run -d -v /home/sysadmin/service1.conf:/cslcfg/nginx.json --name=dev-consul-2 -p 8501:8500 -p 8601:8600 consul agent -client=0.0.0.0 -dev -retry-join 172.17.0.2 -config-dir /cslcfg
docker run -d -v /home/sysadmin/service2.conf:/cslcfg/nginx.json --name=dev-consul-3 -p 8502:8500 -p 8602:8600 consul agent -client=0.0.0.0 -dev -retry-join 172.17.0.2 -config-dir /cslcfg
curl -X POST -d '{ "Name": "failover",  "Near": "7e46dd932a84", "Service": { "Service": "nginx",, "Failover": { "NearestN": 3 } } }' 'localhost:8500/v1/query' # Near argument is the hostname of dev-consul-2

The service1 & service2.conf looks the following, jst the ips changing :

{
  "service": {
   "name": "nginx",
    "tags": ["master"],
    "address": "172.17.0.3",
    "port": 80,
    "checks": [
      {
        "script": "ping -c 1 172.17.0.3",
        "interval": "10s"
      }
    ]
  }
}

Version :

# docker exec -ti dev-consul consul version
Consul v0.6.4
Consul Protocol: 3 (Understands back to: 1)
@MagicMicky
Copy link
Author

MagicMicky commented Sep 6, 2016

Ok, as from the changelog from your master branch, it seems that this will only be supported when the 0.7.0 will be released :

Prepared queries support baking in the Near sorting parameter. [GH-2137]

Might be a good idea to notice it somewhere in the documentation

@slackpad
Copy link
Contributor

slackpad commented Sep 6, 2016

Hi @MagicMicky sorry for the confusion. I added a note in 0a34741 about the 0.7 version requirements.

@slackpad slackpad closed this as completed Sep 6, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants