From 5d17a5228315b3445d38d24e3ca414a131507f15 Mon Sep 17 00:00:00 2001 From: daniele Date: Wed, 4 Mar 2015 15:44:36 +0000 Subject: [PATCH] SRV support for dns watcher Accepts an optional "srv" field in the servers definition. The port will be fetched from the srv record, with fallback on the "port" field in case of failure/empty value --- lib/synapse/service_watcher/dns.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/synapse/service_watcher/dns.rb b/lib/synapse/service_watcher/dns.rb index d59c6971..a5716922 100644 --- a/lib/synapse/service_watcher/dns.rb +++ b/lib/synapse/service_watcher/dns.rb @@ -63,7 +63,8 @@ def resolve_servers resolver.tap do |dns| resolution = discovery_servers.map do |server| addresses = dns.getaddresses(server['host']).map(&:to_s) - [server, addresses.sort] + port = dns.getresource(server['srv'],Resolv::DNS::Resource::IN::SRV).port if server['srv'] + [server, addresses.sort, port] end return resolution @@ -79,11 +80,12 @@ def resolver end def configure_backends(servers) - new_backends = servers.flat_map do |(server, addresses)| + new_backends = servers.flat_map do |(server, addresses, port)| + custom_port = port || server['port'] addresses.map do |address| { 'host' => address, - 'port' => server['port'], + 'port' => custom_port, 'name' => server['name'], } end