GithubHelp home page GithubHelp logo

Comments (6)

johnhamelink avatar johnhamelink commented on May 28, 2024

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.

ross-w avatar ross-w commented on May 28, 2024

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.

johnhamelink avatar johnhamelink commented on May 28, 2024

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.

johnhamelink avatar johnhamelink commented on May 28, 2024

@ross-w FYI, Just pushed a change which gives you the :all flag. Pushing a new release now. Thanks for using diplomat! 😄

from diplomat.

ross-w avatar ross-w commented on May 28, 2024

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.

johnhamelink avatar johnhamelink commented on May 28, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.