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

ServiceMultipleTags API is not working when passing services with multiple tags. #17223

Open bigdatasourav opened 1 year ago

bigdatasourav commented 1 year ago

Overview of the Issue

The ServiceMultipleTags API is not rendering results if we pass services with multiple tags. Example -> Service name - nomad tags - [rpc serf http] when all tags are passed, the API is not rendering results, but if I pass a single tag, the API is working.


Reproduction Steps

Execute the API with any service which has multiple tags

Consul info for both Client and Server

Client info ``` Output from client 'consul info' command here ``` ``` Client agent HCL config ```
Server info ``` Output from server 'consul info' command here ``` ``` Server agent HCL config ```

Operating system and Environment details

Log Fragments

huikang commented 1 year ago

@bigdatasourav , thanks for reporting the issue. To help us reproduce the behavior, could you provide

  1. the version of Consul you use
  2. An example API command to trigger the issue

Looking forward to your reply!

bigdatasourav commented 1 year ago

@huikang I am using the consul version - 1.15.2 Here is a sample API command -> curl -H "Authorization: Bearer token" "http://address/v1/catalog/service/nomad?tag=rpc&tag=serf&tag=http"

jkirschner-hashicorp commented 1 year ago

Hi @bigdatasourav,

We'd have to look into the tag query parameter. In the meantime, can you try the equivalent using the filter query parameter?

It should look something like:

curl --get -H "Authorization: Bearer token" http://address/v1/catalog/service/nomad --data-urlencode 'filter="rpc" in ServiceTags and "serf" in ServiceTags and "http" in ServiceTags'

For reference, this is the docs page on filtering: https://developer.hashicorp.com/consul/api-docs/features/filtering

bigdatasourav commented 1 year ago

Hey @jkirschner-hashicorp, I tried the method you suggested above, but unfortunately, it doesn't seem to be working with multiple tags. I was able to get it to work with a single tag in the filter using (http in ServiceTags).

huikang commented 1 year ago

@bigdatasourav , I couldn't reproduce the problem with the following steps.

  1. Start a consul agent v1.15.2
==> Starting Consul agent...
              Version: '1.15.2'
           Build Date: '2023-03-30 17:51:19 +0000 UTC'
              Node ID: 'edabf396-b86c-bb42-78f9-6d1766f8825f'
            Node name: 'server-1'
  1. Register a service named, say counting with 3 tags — "rpc", "serf", "http".

  2. Query service without tag

curl --location --request GET '127.0.0.1:8500/v1/catalog/service/counting' | jq 

    "ServiceName": "counting",
    "ServiceTags": [
      "rpc",
      "serf",
      "http"
    ],
    "ServiceAddress": "",
  1. Query service with tag
curl --location --request GET '127.0.0.1:8500/v1/catalog/service/counting?tag=serf&tag=rpc&tag=http' | jq .

    "ServiceTags": [
      "rpc",
      "serf",
      "http"
    ],
    "ServiceAddress": "",

As you can see, the result is the same as query without any tag.

Please let me know if I miss anything your steps.