Comments (6)
I don't see any problem with adding the ability to get all services. The consul API allows you to do this with /v1/catalog/services/
(docs)
I think we should create a method called Diplomat::Service.all()
- I don't think we should create an :all parameter because as you can see in the docs above it returns different output. Alternatively, we could use /v1/catalog/services/
to build an enumerator and loop through getting the individual results, but I'm not convinced that's necessarily the job of this gem.
If you've got something you're using in production already, feel free to submit a pull request! 😄
from diplomat.
Whoops, just reread what I wrote. What I was referring to was the ability to return all instances of a service. For example calling the API directly when 2 instances of a service are available returns this JSON:
$ curl http://int-docker-01:8500/v1/catalog/service/dashingdev
[{"Node":"int-docker-02","Address":"10.51.10.216","ServiceID":"int-docker-02:dashingdev:8000","ServiceName":"dashingdev","ServiceTags":["v0.0.19"],"ServicePort":10034},{"Node":"int-docker-03","Address":"10.51.10.220","ServiceID":"int-docker-03:dashingdev:8000","ServiceName":"dashingdev","ServiceTags":["v0.0.19"],"ServicePort":10034}]
But when calling Diplomat::Service.get() only the following is returned:
irb(main):007:0> foo_service = Diplomat::Service.get('dashingdev')
I, [2014-10-29T13:52:30.722565 #3998] INFO -- : get http://localhost:8500/v1/catalog/service/dashingdev
D, [2014-10-29T13:52:30.722644 #3998] DEBUG -- request: User-Agent: "Faraday v0.9.0"
I, [2014-10-29T13:52:30.724377 #3998] INFO -- Status: 200
D, [2014-10-29T13:52:30.724439 #3998] DEBUG -- response: content-type: "application/json"
x-consul-index: "1900"
x-consul-knownleader: "true"
x-consul-lastcontact: "0"
date: "Wed, 29 Oct 2014 02:52:30 GMT"
content-length: "335"
connection: "close"
=> #<OpenStruct Node="int-docker-02", Address="10.51.10.216", ServiceID="int-docker-02:dashingdev:8000", ServiceName="dashingdev", ServiceTags=["v0.0.19"], ServicePort=10034>
due to the .first on https://github.com/WeAreFarmGeek/diplomat/blob/master/lib/diplomat/service.rb#L12
What I would love would be for some way to return all instances of a single service, sorry for the confusion in my original post.
What would you suggest as the best way to implement this?
from diplomat.
Gotcha!
Yep, I see the problem now:
Really we should have the API refactored as such:
- Have
Diplomat::Service.get("key")
return the first match for the key - Have
Diplomat::Service.get("key", :all)
return all services which match the key
I incorrectly assumed that the keys were unique, when that's obviously not the case.
from diplomat.
@ross-w FYI, Just pushed a change which gives you the :all
flag. Pushing a new release now. Thanks for using diplomat! 😄
from diplomat.
Legend, thanks @johnhamelink ! Sorry I've been so busy I haven't managed to get back to this. Thanks again for the fix.
from diplomat.
No worries! :)
Just released it as 0.2.0 (as its a backwards-compatible api change)
JH
—
Sent from Mailbox
On Thu, Nov 13, 2014 at 10:54 PM, ross-w [email protected] wrote:
Legend, thanks @johnhamelink ! Sorry I've been so busy I haven't managed to get back to this. Thanks again for the fix.
Reply to this email directly or view it on GitHub:
#5 (comment)
from diplomat.
Related Issues (20)
- /v1/catalog/register is broken after upgrade to v2.1.2 HOT 1
- Support Consul 1.4.0+ ACL system HOT 2
- Add support for Consul 1.5.x ACL tokens HOT 2
- Add support for Consul 1.5.x Auth Method and Binding Rule HTTP APIs HOT 2
- Improve error message in case of missing ACL
- 2.3.0: syntax error in file lib/diplomat/rest_client.rb:243 ? HOT 4
- It is unable to retrieve service configuration from consul HOT 2
- Add support for Operator Autopilot API HOT 5
- Due to faraday 1.1 release diplomat only works on ruby 2.4+
- Unable to use multiple tags when querying for services HOT 2
- Bump faraday requirement HOT 1
- Register HTTP checks HOT 3
- Add support for default datacenter HOT 3
- Broken link to API documentation HOT 3
- Register entities via agent
- Add blocking read support for service health endpoint HOT 3
- Faraday 2.0.0 breaks diplomat HOT 4
- Faraday 1.x can bypass Diplomat::QueryAlreadyExists HOT 1
- Can't get it to work with auth token given in config HOT 5
- Kv.put() method with Consul v1.10.1 results in KV entries that are visible via CLI/API, but not UI HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from diplomat.