WeAreFarmGeek / diplomat

A HTTP Ruby API for Consul
BSD 3-Clause "New" or "Revised" License
370 stars 116 forks source link

It is unable to retrieve service configuration from consul #205

Closed kinnalru closed 4 years ago

kinnalru commented 4 years ago

Diplomat::Service.get uses "/v1/catalog/service/#{key}" path which returns not service configuration but nodes providing a service in a given datacenter. See here: https://www.consul.io/api/catalog.html#list-nodes-for-service

So there is no method in Diplomat::Service to retrieve configuratiom registered with Diplomat::Service.register by unique service ID.

Do you intrested in implementation of such method? https://www.consul.io/api/agent/service.html#get-service-configuration

pierresouchay commented 4 years ago

Hello @kinnalru ,

The endpoint already implemented in diplomat: https://github.com/WeAreFarmGeek/diplomat/blob/master/lib/diplomat/agent.rb#L31

It of course works only for a single agent (aka it find agent only for a single Consul Agent). For me, it has little usage as it is not really unique (it is unique ONLY per agent, not within cluster).

Still, the serviceID is available for the whole cluster as well in Diplomat::Service.get.

So, if I understand clearly, it means that what you want it:

# Return nil or the service having given ID for Consul agent we are configured with
def agent_service_from_id(id_to_lookup)
  Diplomat::Agent.services.select{|i,s| s['ID'] == serviceid_to_look_at}.first
end

Can we close the issue or did I miss something?

kinnalru commented 4 years ago

Yep. Thanx.