Return error from PingConsulServer

In order to report why a Ping failed, change the signature of PingConsulServers to include an error message.
pull/1880/head
Sean Chittenden 9 years ago
parent 28dc6451d9
commit c9afc16d96

@ -287,8 +287,9 @@ func TestClient_RPC_ConsulServerPing(t *testing.T) {
for range servers {
time.Sleep(1 * time.Second)
s := c.serverMgr.FindServer()
if !c.connPool.PingConsulServer(s) {
t.Errorf("Unable to ping server %v", s.String())
ok, err := c.connPool.PingConsulServer(s)
if !ok {
t.Errorf("Unable to ping server %v: %s", s.String(), err)
}
pingCount += 1
}

@ -408,11 +408,11 @@ func (p *ConnPool) RPC(dc string, addr net.Addr, version int, method string, arg
// PingConsulServer sends a Status.Ping message to the specified server and
// returns true if healthy, false if an error occurred
func (p *ConnPool) PingConsulServer(s *server_details.ServerDetails) bool {
func (p *ConnPool) PingConsulServer(s *server_details.ServerDetails) (bool, error) {
// Get a usable client
conn, sc, err := p.getClient(s.Datacenter, s.Addr, s.Version)
if err != nil {
return false
return false, err
}
// Make the RPC call
@ -421,13 +421,13 @@ func (p *ConnPool) PingConsulServer(s *server_details.ServerDetails) bool {
if err != nil {
sc.Close()
p.releaseConn(conn)
return false
return false, err
}
// Done with the connection
conn.returnClient(sc)
p.releaseConn(conn)
return true
return true, nil
}
// Reap is used to close conns open over maxTime

@ -56,7 +56,7 @@ type ConsulClusterInfo interface {
// ConnPoolTester is an interface wrapping client.ConnPool to prevent a
// cyclic import dependency
type ConnPoolPinger interface {
PingConsulServer(server *server_details.ServerDetails) bool
PingConsulServer(server *server_details.ServerDetails) (bool, error)
}
// serverConfig is the thread-safe configuration struct used to maintain the
@ -306,11 +306,13 @@ FAILED_SERVER_DURING_REBALANCE:
selectedServer := sc.servers[0]
// sm.logger.Printf("[INFO] server manager: Preemptively testing server %s before rebalance", selectedServer.String())
ok := sm.connPoolPinger.PingConsulServer(selectedServer)
ok, err := sm.connPoolPinger.PingConsulServer(selectedServer)
if ok {
foundHealthyServer = true
break
}
sm.logger.Printf("[DEBUG] server manager: pinging server %s failed: %s", selectedServer.String(), err)
sc.cycleServer()
}

@ -28,8 +28,8 @@ func GetBufferedLogger() *log.Logger {
type fauxConnPool struct {
}
func (s *fauxConnPool) PingConsulServer(server *server_details.ServerDetails) bool {
return true
func (s *fauxConnPool) PingConsulServer(server *server_details.ServerDetails) (bool, error) {
return true, nil
}
type fauxSerf struct {

@ -29,8 +29,8 @@ func GetBufferedLogger() *log.Logger {
type fauxConnPool struct {
}
func (s *fauxConnPool) PingConsulServer(server *server_details.ServerDetails) bool {
return true
func (s *fauxConnPool) PingConsulServer(server *server_details.ServerDetails) (bool, error) {
return true, nil
}
type fauxSerf struct {

Loading…
Cancel
Save