Skip to content

Commit

Permalink
Resolve endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
sabmeua committed Aug 30, 2018
1 parent e94088d commit dcb10eb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions build_config.rb
Expand Up @@ -62,6 +62,7 @@
conf.gem :github => 'mattn/mruby-thread'
conf.gem :github => 'mattn/mruby-json'
conf.gem :github => 'sabmeua/mruby-aws-cloudwatch'
conf.gem :github => 'iij/mruby-socket'

end

Expand Down
6 changes: 5 additions & 1 deletion healthcheck.rb
Expand Up @@ -33,7 +33,11 @@
metrics.each do |e|
servers[e['Label']]['lag'] = e['Values'].first
end
redis.set 'upstreams', JSON::stringify(servers.select{|k,h| h['lag'] < 30}.values.map{|e| e['endpoint']})
redis.set 'upstreams', JSON::stringify(servers.select{|k,h| h['lag'] < 30}.values.map{ |e|
(host,port) = e['endpoint'].split ':'
a = Addrinfo.getaddrinfo(host, port, nil, Socket::SOCK_STREAM, Socket::IPPROTO_TCP)
"#{a[0].ip_address}:#{a[0].ip_port}"
})
else
puts 'Error: Health check failed'
end
Expand Down

0 comments on commit dcb10eb

Please sign in to comment.