diff --git a/conn.go b/conn.go index edcf5d7b8..22e0c8144 100644 --- a/conn.go +++ b/conn.go @@ -159,8 +159,34 @@ type Conn struct { timeouts int64 } -// Connect establishes a connection to a Cassandra node. -func (s *Session) dial(host *HostInfo, cfg *ConnConfig, errorHandler ConnErrorHandler) (*Conn, error) { +// connect establishes a connection to a Cassandra node using session's connection config. +func (s *Session) connect(host *HostInfo, errorHandler ConnErrorHandler) (*Conn, error) { + return s.dial(host, s.connCfg, errorHandler) +} + +// dial establishes a connection to a Cassandra node and notifies the session's connectObserver. +func (s *Session) dial(host *HostInfo, connConfig *ConnConfig, errorHandler ConnErrorHandler) (*Conn, error) { + var obs ObservedConnect + if s.connectObserver != nil { + obs.Host = host + obs.Start = time.Now() + } + + conn, err := s.dialWithoutObserver(host, connConfig, errorHandler) + + if s.connectObserver != nil { + obs.End = time.Now() + obs.Err = err + s.connectObserver.ObserveConnect(obs) + } + + return conn, err +} + +// dialWithoutObserver establishes connection to a Cassandra node. +// +// dialWithoutObserver does not notify the connection observer, so you most probably want to call dial() instead. +func (s *Session) dialWithoutObserver(host *HostInfo, cfg *ConnConfig, errorHandler ConnErrorHandler) (*Conn, error) { ip := host.ConnectAddress() port := host.port diff --git a/session.go b/session.go index b28a54d18..92261cc62 100644 --- a/session.go +++ b/session.go @@ -656,21 +656,6 @@ func (s *Session) MapExecuteBatchCAS(batch *Batch, dest map[string]interface{}) return applied, iter, iter.err } -func (s *Session) connect(host *HostInfo, errorHandler ConnErrorHandler) (*Conn, error) { - if s.connectObserver != nil { - obs := ObservedConnect{ - Host: host, - Start: time.Now(), - } - conn, err := s.dial(host, s.connCfg, errorHandler) - obs.End = time.Now() - obs.Err = err - s.connectObserver.ObserveConnect(obs) - return conn, err - } - return s.dial(host, s.connCfg, errorHandler) -} - type hostMetrics struct { Attempts int TotalLatency int64