Prepared queries: treat empty-string tags as no tags at all #2151
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Skipping tag filtering in prepared queries might fail as match() produces an empty-string tag.
When using standard DNS interface, it is easy to - optionally - filter by tag, just adding it in front of the service name.
Take the "web" service from the Consul intro as an example:
First, a non-tagged query:
Then, with tag prepended:
A problem arises, if one would like to mimic this behaviour using prepared queries:
This works for queries with a tag specified:
But with the tag ommited - HIL
match()
function returns an empty string, and as such - one ends up with an "empty string" tag:This is not equal to no tag filtering at all, and such queries will not return an answer:
As a further confirmation - adding a ""-tag to the service definition would let it match:
A potential solution would be to flatten or compact the tags list, omitting empty strings, and returning null instead of a list when no non-empty tags remain:
Seems to fix the problem mentioned, hope it does not break other things.