diplomat icon indicating copy to clipboard operation
diplomat copied to clipboard

add option to search all nodes and services filtering by metadata

Open rockpapergoat opened this issue 6 years ago • 10 comments

These small changes add options to the node and service get_all methods to allow including metadata filters in the URL passed to the consul API. I updated the spec tests and docs to reflect this change, but let me know if you need anything else here. Thanks!

rockpapergoat avatar Jan 27 '18 00:01 rockpapergoat

well, this is disappointing. i thought this worked. the query url gets constructed correctly, but it looks like faraday eats the nested query parameters. i'm not sure how to get faraday to accept these params but am looking.

so the url gets constructed like so:

nodes = Diplomat::Node.get_all(meta: {role: 'foo', az: 'us-east-1d'})
"/v1/catalog/nodes?node-meta=role:foo&node-meta=az:us-east-1d"

but then the consul log shows just the last node-meta param:

2018/02/08 15:47:39 [DEBUG] http: Request GET /v1/catalog/nodes?node-meta=az%3Aus-east-1d (131.244µs) from=127.0.0.1:56308

rockpapergoat avatar Feb 08 '18 21:02 rockpapergoat

lgtm

kamaradclimber avatar May 25 '18 07:05 kamaradclimber

@rockpapergoat Did you succeeded into faraday accepting multiple filters?

pierresouchay avatar May 25 '18 07:05 pierresouchay

i got diverted from this at work for a bit and haven't revisited it, but i believe it's still an issue. the changes i made most likely won't work as expected until sorting out the faraday portion.

rockpapergoat avatar May 25 '18 18:05 rockpapergoat

looks like this will do it. i'll try to test this sometime soon.

https://github.com/lostisland/faraday#changing-how-parameters-are-serialized

rockpapergoat avatar May 30 '18 19:05 rockpapergoat

yeah, that option works. i'll add something to docs to show how to use it.

rockpapergoat avatar May 31 '18 17:05 rockpapergoat

Great! Send the patch, we'll merge it

pierresouchay avatar May 31 '18 18:05 pierresouchay

i updated the code. tests fail for a few ruby versions, though it looks like some of them are linting issues. do we need to fix those first? tests pass on ruby 2.5.1 here for me.

rockpapergoat avatar Jun 01 '18 20:06 rockpapergoat

@rockpapergoat rebase and I'll merge it

pierresouchay avatar Feb 28 '19 20:02 pierresouchay

@rockpapergoat Can you rebase this PR? Thanks)

Jesterovskiy avatar Jul 07 '22 10:07 Jesterovskiy