Return error from PingConsulServer

In order to report why a Ping failed, change the signature of PingConsulServers to include an error message.
This commit is contained in:
Sean Chittenden 2016-03-28 13:38:58 -07:00
parent 28dc6451d9
commit c9afc16d96
5 changed files with 15 additions and 12 deletions

View File

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

View File

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

View File

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

View File

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

View File

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