You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently with Nomad Service Discovery, it is possible to list all of the Nomad services using the nomadService keyword. This is nice for something like a load balancer config.
It would be nice if you could select a single service from the list of Nomad Services. Ideally this could be semi-randomly selected for each allocation and not result in tons of restarts when Nomad service instances are added (or removed) from the list.
After speaking with the Consul team, they would like this on Consul services as well.
I think ideally we could name it hrwSelect or something like that (highest random weight), and also have another function that will select N services, not just one. In addition to hrwSelect an alias called something more generic/human friendly like pickOne or chooseOne might be nice.
Use-cases
This would allow writing an address/port to a config file for simple "load-balanced" service discovery without a load balancer.
Attempted Solutions
This WIP PR in Consul Template implements a simple chooseOne function that could achieve this (though there's a bug in real use).
Other Thoughts
Sometimes when dealing with lists in Template, you have to do a guard clause that checks if there are any items in the list before you then use that list. In my initial POC of this feature, I had to do something like this:
{{ $allocId := env "NOMAD_ALLOC_ID"}}
{{ $serviceList := nomadService "api" }}
{{ with $serviceList }}
{{ with chooseOne $allocId . }}
CURL_ADDR="http://{{.Address}}:{{.Port}}"
{{ end }}
{{ end }}
Which isn't a great UX. If we have to make a special function that has an empty-guard in it, I think that is better. I.E.
{{ $allocId := env "NOMAD_ALLOC_ID"}}
{{ $service := hrwNomadService "api" $allocId }}
{{ if $service }}
CURL_ADDR="http://{{$service.Address}}:{{$service.Port}}"
{{ end }}
{{ end }}
The text was updated successfully, but these errors were encountered:
I'm going to lock this issue because it has been closed for 120 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.
Proposal
Currently with Nomad Service Discovery, it is possible to list all of the Nomad services using the
nomadService
keyword. This is nice for something like a load balancer config.It would be nice if you could select a single service from the list of Nomad Services. Ideally this could be semi-randomly selected for each allocation and not result in tons of restarts when Nomad service instances are added (or removed) from the list.
After speaking with the Consul team, they would like this on Consul services as well.
I think ideally we could name it
hrwSelect
or something like that (highest random weight), and also have another function that will select N services, not just one. In addition tohrwSelect
an alias called something more generic/human friendly likepickOne
orchooseOne
might be nice.Use-cases
This would allow writing an address/port to a config file for simple "load-balanced" service discovery without a load balancer.
Attempted Solutions
This WIP PR in Consul Template implements a simple chooseOne function that could achieve this (though there's a bug in real use).
Other Thoughts
Sometimes when dealing with lists in Template, you have to do a guard clause that checks if there are any items in the list before you then use that list. In my initial POC of this feature, I had to do something like this:
Which isn't a great UX. If we have to make a special function that has an empty-guard in it, I think that is better. I.E.
The text was updated successfully, but these errors were encountered: