consul icon indicating copy to clipboard operation
consul copied to clipboard

queries for multiple tags

Open carlivar opened this issue 12 years ago • 42 comments

We would like the ability to query multiple tags via DNS and HTTP.

An example of this would be using environment name as a tag, but also needing additional tag functionality such as master/slave. For example to get the master mysql server in the qa environment, we'd like the service to publish both those tags and allow a DNS query such as:

dig @127.0.0.1 -p 8600 master.qa.mysql.service.consul. ANY

Or for HTTP:

curl 'http://localhost:8500/v1/catalog/service/mysql?tag=master&tag=qa

Or whatever HTTP param syntax is sensible (I suppose multiple params named the same would not work. Perhaps an array syntax is needed).

For DNS, I'm not sure how easy it would be to support multiple tags in the format I suggested, so a delimiter could also work. Perhaps master_qa.mysql.service.consul using underscore as a delimiter. Although this would remove the ability to put underscore in tags.

This is somewhat related to #290 since it solves the multiple environments problem for those that are willing to use tags. After much internal discussion, we are.

carlivar avatar Aug 20 '14 01:08 carlivar

+1 -- tag intersections should be supported, at least for the HTTP API. DNS is another matter: not really sure how one could implement it given its hierarchical design.

mfischer-zd avatar Nov 18 '14 18:11 mfischer-zd

+1 ... if multiple tag= args could form an implicit AND / intersection, that would help a lot.

ecweaver avatar Nov 18 '14 18:11 ecweaver

+1 - this would be very useful.

broberts-zd avatar Nov 18 '14 19:11 broberts-zd

:+1: having multiple hosts + different services -> we need different tags

for dns maybe double-underscore as delimiter

grosser avatar Nov 18 '14 19:11 grosser

:+1:

grobie avatar Nov 18 '14 19:11 grobie

:+1: Though simple and/not/or/grouping syntax would quickly become desirable. For DNS could it be as simple as dig ... '(foo&bar)|!baz).mysvc.service.consul.'

babbottscott avatar Nov 18 '14 19:11 babbottscott

Those aren't legal characters in DNS, @babbottscott

mfischer-zd avatar Nov 18 '14 19:11 mfischer-zd

Not for hostnames, but for queries, this should be fine.

babbottscott avatar Nov 18 '14 19:11 babbottscott

Many forwarding resolvers will return errors before the queries ever get to Consul's DNS server. So it's not really practical.

mfischer-zd avatar Nov 18 '14 19:11 mfischer-zd

I can certainly see it working in HTTP, DNS will require more thought to avoid breaking backwards compatibility

armon avatar Nov 18 '14 19:11 armon

:+1: In most architectures having the possibility to query based on more than one tag would be a great feature.

mphoratiu avatar Nov 19 '14 13:11 mphoratiu

isn't possible to use dots as tag delimiter in DNS?

hanshasselberg avatar Nov 19 '14 14:11 hanshasselberg

@i0rek The problem is a tag could be "foo.bar", which is hard to disambiguate from "foo" and "bar" or just "foo.bar".

armon avatar Nov 19 '14 17:11 armon

@armon it already is a problem, no? service "foo.bar" VS service "bar" and tag "foo".

hanshasselberg avatar Nov 19 '14 20:11 hanshasselberg

Yes, currently any additional dots are considered to be part of the tag. So if your service name contains a period you cannot resolve it via DNS.

armon avatar Nov 19 '14 22:11 armon

We should probably forbid that.. (separate issue though)

mfischer-zd avatar Nov 19 '14 22:11 mfischer-zd

I think if dots are forbidden in service names the same should apply to tag names. Then we can have dots as tag delimiter and the lookup should be easy too.

hanshasselberg avatar Nov 20 '14 06:11 hanshasselberg

+1 for consistency amongst reserved characters. Since DNS is one of the primary APIs for consul it seems reasonable to reserve . as a delimiter across the board.

wolfspyre avatar Nov 20 '14 15:11 wolfspyre

:+1:

xakraz avatar Jan 21 '15 13:01 xakraz

:+1:

mdhelgen avatar Feb 03 '15 23:02 mdhelgen