// doActiveHealthCheck performs a health check to host which
// can be reached at address hostAddr. The health status of
// the host will be updated according to whether it passes
// the health check. An error is returned only if the health
// check fails to occur or if marking the host's health status
// fails.
doActiveHealthCheck performs a health check to host which
can be reached at address hostAddr. The health status of
the host will be updated according to whether it passes
the health check. An error is returned only if the health
check fails to occur or if marking the host's health status
fails.
// doActiveHealthCheck performs a health check to host which // can be reached at address hostAddr . The health status of // the host will be updated according to whether it passes // the health check . An error is returned only if the health // check fails to occur or if marking the host ' s health status // fails .
func (h *Handler) doActiveHealthCheck(p *peer) error {
	addr := p.address
	if h.HealthChecks.Active.Port > 0 {
		addr.StartPort = uint(h.HealthChecks.Active.Port)
		addr.EndPort = addr.StartPort
	}
	hostPort := addr.JoinHostPort(0)
	timeout := time.Duration(h.HealthChecks.Active.Timeout)
	conn, err := net.DialTimeout(addr.Network, hostPort, timeout)
	if err != nil {
		h.HealthChecks.Active.logger.Info("host is down",
			zap.String("address", addr.String()),
			zap.Duration("timeout", timeout),
			zap.Error(err))
		_, err2 := p.setHealthy(false)
		if err2 != nil {
			return fmt.Errorf("marking unhealthy: %v (original error: %v)", err2, err)
		}
		return nil
	}
	conn.Close()
	swapped, err := p.setHealthy(true)
	if swapped {
		h.HealthChecks.Active.logger.Info("host is up", zap.String("address", addr.String()))
	}
	if err != nil {
		return fmt.Errorf("marking healthy: %v", err)
	}
	return nil
}
func ( h * Handler ) doActiveHealthCheck ( p * peer ) error { addr := p . address if h . HealthChecks . Active . Port > 0 { addr . StartPort = uint ( h . HealthChecks . Active . Port ) addr . EndPort = addr . StartPort } hostPort := addr . JoinHostPort ( 0 ) timeout := time . Duration ( h . HealthChecks . Active . Timeout ) conn , err := net . DialTimeout ( addr . Network , hostPort , timeout ) if err != nil { h . HealthChecks . Active . logger . Info ( " " , zap . String ( " " , addr . String ( ) ) , zap . Duration ( " " , timeout ) , zap . Error ( err ) ) _ , err2 := p . setHealthy ( false ) if err2 != nil { return fmt . Errorf ( " " , err2 , err ) } return nil } conn . Close ( ) swapped , err := p . setHealthy ( true ) if swapped { h . HealthChecks . Active . logger . Info ( " " , zap . String ( " " , addr . String ( ) ) ) } if err != nil { return fmt . Errorf ( " " , err ) } return nil }
doActiveHealthCheck performs a health check to host which
can be reached at address hostAddr.
doActiveHealthCheck performs a health check to host which can be reached at address hostAddr .
// adjust the port, if configured to be different // connection succeeded, so mark as healthy