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.37k stars 4.42k forks source link

Consul filter /catalog/nodes not working #11471

Open Lord-Y opened 3 years ago

Lord-Y commented 3 years ago

Hello guys,

I'm running consul 1.10.3 with ACL enabled etc. So far everything is working perfectly. The only problem that I have so far is on the filtering management on /catalog/nodes.

Following the documentation here https://www.consul.io/api-docs/features/filtering and here https://www.consul.io/api-docs/catalog#list-nodes it doesn't works.

Exemple: curl -H "X-Consul-Token: $CONSUL_HTTP_TOKEN" --request GET "${CONSUL_HTTP_ADDR}/v1/catalog/nodes" --data-urlencode 'filter=Node == "gke-xxxx"' This command return all list of nodes instead of the specific one.

Am I doing something wrong?

jkirschner-hashicorp commented 2 years ago

Hi @Lord-Y,

Try replacing --request GET with -G (or --get) and let me know whether that fixes your problem.

Consul is expecting the filter to be included as a query parameter (which happens if you use -G), not in the body of the request (which happens if you use --request GET). This tripped me up also when I tried to reproduce what you were seeing.

Let me know if you have any suggestions for how to help avoid this confusion for others in the future.

For example, there may be an improvement we can make to the docs here. The docs you linked do show using --get (rather than --request GET), but I wonder whether we should call out that --request won't do what you need here.

Lord-Y commented 2 years ago

@jkirschner-hashicorp my bad. Yes it's working. The documentation is right. Maybe adding a warning saying to do not use --request will be helpful but I'm sure. Thx for the help, I'll close this issue.

jkirschner-hashicorp commented 2 years ago

Reopening as a reminder to consider adding a relevant message on this to the docs.

jkirschner-hashicorp commented 2 years ago

@Lord-Y: out of curiosity, what did you do to try to investigate what was going wrong here? (e.g., did you look at Consul log output at all?)

I'm wondering whether there's something Consul itself could have done here to help (separate from refining the documentation page).