consul: Provide logger to yamux

This commit is contained in:
Armon Dadgar 2014-05-28 16:32:10 -07:00
parent 6331a717ed
commit 22f548c338
4 changed files with 16 additions and 5 deletions

View File

@ -99,7 +99,7 @@ func NewClient(config *Config) (*Client, error) {
// Create server // Create server
c := &Client{ c := &Client{
config: config, config: config,
connPool: NewPool(clientRPCCache, clientMaxStreams, tlsConfig), connPool: NewPool(config.LogOutput, clientRPCCache, clientMaxStreams, tlsConfig),
eventCh: make(chan serf.Event, 256), eventCh: make(chan serf.Event, 256),
logger: logger, logger: logger,
shutdownCh: make(chan struct{}), shutdownCh: make(chan struct{}),

View File

@ -7,6 +7,7 @@ import (
"github.com/hashicorp/yamux" "github.com/hashicorp/yamux"
"github.com/inconshreveable/muxado" "github.com/inconshreveable/muxado"
"github.com/ugorji/go/codec" "github.com/ugorji/go/codec"
"io"
"net" "net"
"net/rpc" "net/rpc"
"sync" "sync"
@ -110,6 +111,9 @@ func (c *Conn) returnClient(client *StreamClient) {
type ConnPool struct { type ConnPool struct {
sync.Mutex sync.Mutex
// LogOutput is used to control logging
logOutput io.Writer
// The maximum time to keep a connection open // The maximum time to keep a connection open
maxTime time.Duration maxTime time.Duration
@ -132,8 +136,9 @@ type ConnPool struct {
// Set maxTime to 0 to disable reaping. maxStreams is used to control // Set maxTime to 0 to disable reaping. maxStreams is used to control
// the number of idle streams allowed. // the number of idle streams allowed.
// If TLS settings are provided outgoing connections use TLS. // If TLS settings are provided outgoing connections use TLS.
func NewPool(maxTime time.Duration, maxStreams int, tlsConfig *tls.Config) *ConnPool { func NewPool(logOutput io.Writer, maxTime time.Duration, maxStreams int, tlsConfig *tls.Config) *ConnPool {
pool := &ConnPool{ pool := &ConnPool{
logOutput: logOutput,
maxTime: maxTime, maxTime: maxTime,
maxStreams: maxStreams, maxStreams: maxStreams,
pool: make(map[string]*Conn), pool: make(map[string]*Conn),
@ -235,8 +240,12 @@ func (p *ConnPool) getNewConn(addr net.Addr, version int) (*Conn, error) {
return nil, err return nil, err
} }
// Setup the logger
conf := yamux.DefaultConfig()
conf.LogOutput = nil
// Create a multiplexed session // Create a multiplexed session
session, _ = yamux.Client(conn, nil) session, _ = yamux.Client(conn, conf)
} }
// Wrap the connection // Wrap the connection

View File

@ -130,7 +130,9 @@ func (s *Server) handleMultiplex(conn net.Conn) {
// using the Yamux multiplexer // using the Yamux multiplexer
func (s *Server) handleMultiplexV2(conn net.Conn) { func (s *Server) handleMultiplexV2(conn net.Conn) {
defer conn.Close() defer conn.Close()
server, _ := yamux.Server(conn, nil) conf := yamux.DefaultConfig()
conf.LogOutput = s.config.LogOutput
server, _ := yamux.Server(conn, conf)
for { for {
sub, err := server.Accept() sub, err := server.Accept()
if err != nil { if err != nil {

View File

@ -163,7 +163,7 @@ func NewServer(config *Config) (*Server, error) {
// Create server // Create server
s := &Server{ s := &Server{
config: config, config: config,
connPool: NewPool(serverRPCCache, serverMaxStreams, tlsConfig), connPool: NewPool(config.LogOutput, serverRPCCache, serverMaxStreams, tlsConfig),
eventChLAN: make(chan serf.Event, 256), eventChLAN: make(chan serf.Event, 256),
eventChWAN: make(chan serf.Event, 256), eventChWAN: make(chan serf.Event, 256),
localConsuls: make(map[string]*serverParts), localConsuls: make(map[string]*serverParts),