@@ -467,6 +467,7 @@ func (p *pool) checkOut(ctx context.Context) (conn *connection, err error) {
467467 })
468468 }
469469
470+ start := time .Now ()
470471 // Check the pool state while holding a stateMu read lock. If the pool state is not "ready",
471472 // return an error. Do all of this while holding the stateMu read lock to prevent a state change between
472473 // checking the state and entering the wait queue. Not holding the stateMu read lock here may
@@ -477,8 +478,10 @@ func (p *pool) checkOut(ctx context.Context) (conn *connection, err error) {
477478 case poolClosed :
478479 p .stateMu .RUnlock ()
479480
481+ duration := time .Since (start )
480482 if mustLogPoolMessage (p ) {
481483 keysAndValues := logger.KeyValues {
484+ logger .KeyDurationMS , duration .Milliseconds (),
482485 logger .KeyReason , logger .ReasonConnCheckoutFailedPoolClosed ,
483486 }
484487
@@ -487,18 +490,21 @@ func (p *pool) checkOut(ctx context.Context) (conn *connection, err error) {
487490
488491 if p .monitor != nil {
489492 p .monitor .Event (& event.PoolEvent {
490- Type : event .GetFailed ,
491- Address : p .address .String (),
492- Reason : event .ReasonPoolClosed ,
493+ Type : event .GetFailed ,
494+ Address : p .address .String (),
495+ Duration : duration ,
496+ Reason : event .ReasonPoolClosed ,
493497 })
494498 }
495499 return nil , ErrPoolClosed
496500 case poolPaused :
497501 err := poolClearedError {err : p .lastClearErr , address : p .address }
498502 p .stateMu .RUnlock ()
499503
504+ duration := time .Since (start )
500505 if mustLogPoolMessage (p ) {
501506 keysAndValues := logger.KeyValues {
507+ logger .KeyDurationMS , duration .Milliseconds (),
502508 logger .KeyReason , logger .ReasonConnCheckoutFailedError ,
503509 }
504510
@@ -507,10 +513,11 @@ func (p *pool) checkOut(ctx context.Context) (conn *connection, err error) {
507513
508514 if p .monitor != nil {
509515 p .monitor .Event (& event.PoolEvent {
510- Type : event .GetFailed ,
511- Address : p .address .String (),
512- Reason : event .ReasonConnectionErrored ,
513- Error : err ,
516+ Type : event .GetFailed ,
517+ Address : p .address .String (),
518+ Duration : duration ,
519+ Reason : event .ReasonConnectionErrored ,
520+ Error : err ,
514521 })
515522 }
516523 return nil , err
@@ -539,9 +546,11 @@ func (p *pool) checkOut(ctx context.Context) (conn *connection, err error) {
539546 // or an error, so unlock the stateMu lock here.
540547 p .stateMu .RUnlock ()
541548
549+ duration := time .Since (start )
542550 if w .err != nil {
543551 if mustLogPoolMessage (p ) {
544552 keysAndValues := logger.KeyValues {
553+ logger .KeyDurationMS , duration .Milliseconds (),
545554 logger .KeyReason , logger .ReasonConnCheckoutFailedError ,
546555 }
547556
@@ -550,18 +559,21 @@ func (p *pool) checkOut(ctx context.Context) (conn *connection, err error) {
550559
551560 if p .monitor != nil {
552561 p .monitor .Event (& event.PoolEvent {
553- Type : event .GetFailed ,
554- Address : p .address .String (),
555- Reason : event .ReasonConnectionErrored ,
556- Error : w .err ,
562+ Type : event .GetFailed ,
563+ Address : p .address .String (),
564+ Duration : duration ,
565+ Reason : event .ReasonConnectionErrored ,
566+ Error : w .err ,
557567 })
558568 }
559569 return nil , w .err
560570 }
561571
572+ duration = time .Since (start )
562573 if mustLogPoolMessage (p ) {
563574 keysAndValues := logger.KeyValues {
564575 logger .KeyDriverConnectionID , w .conn .driverConnectionID ,
576+ logger .KeyDurationMS , duration .Milliseconds (),
565577 }
566578
567579 logPoolMessage (p , logger .ConnectionCheckedOut , keysAndValues ... )
@@ -572,6 +584,7 @@ func (p *pool) checkOut(ctx context.Context) (conn *connection, err error) {
572584 Type : event .GetSucceeded ,
573585 Address : p .address .String (),
574586 ConnectionID : w .conn .driverConnectionID ,
587+ Duration : duration ,
575588 })
576589 }
577590
@@ -584,12 +597,14 @@ func (p *pool) checkOut(ctx context.Context) (conn *connection, err error) {
584597 p .stateMu .RUnlock ()
585598
586599 // Wait for either the wantConn to be ready or for the Context to time out.
587- start := time .Now ()
600+ waitQueueStart := time .Now ()
588601 select {
589602 case <- w .ready :
590603 if w .err != nil {
604+ duration := time .Since (start )
591605 if mustLogPoolMessage (p ) {
592606 keysAndValues := logger.KeyValues {
607+ logger .KeyDurationMS , duration .Milliseconds (),
593608 logger .KeyReason , logger .ReasonConnCheckoutFailedError ,
594609 logger .KeyError , w .err .Error (),
595610 }
@@ -599,19 +614,22 @@ func (p *pool) checkOut(ctx context.Context) (conn *connection, err error) {
599614
600615 if p .monitor != nil {
601616 p .monitor .Event (& event.PoolEvent {
602- Type : event .GetFailed ,
603- Address : p .address .String (),
604- Reason : event .ReasonConnectionErrored ,
605- Error : w .err ,
617+ Type : event .GetFailed ,
618+ Address : p .address .String (),
619+ Duration : duration ,
620+ Reason : event .ReasonConnectionErrored ,
621+ Error : w .err ,
606622 })
607623 }
608624
609625 return nil , w .err
610626 }
611627
628+ duration := time .Since (start )
612629 if mustLogPoolMessage (p ) {
613630 keysAndValues := logger.KeyValues {
614631 logger .KeyDriverConnectionID , w .conn .driverConnectionID ,
632+ logger .KeyDurationMS , duration .Milliseconds (),
615633 }
616634
617635 logPoolMessage (p , logger .ConnectionCheckedOut , keysAndValues ... )
@@ -622,14 +640,17 @@ func (p *pool) checkOut(ctx context.Context) (conn *connection, err error) {
622640 Type : event .GetSucceeded ,
623641 Address : p .address .String (),
624642 ConnectionID : w .conn .driverConnectionID ,
643+ Duration : duration ,
625644 })
626645 }
627646 return w .conn , nil
628647 case <- ctx .Done ():
629- duration := time .Since (start )
648+ waitQueueDuration := time .Since (waitQueueStart )
630649
650+ duration := time .Since (start )
631651 if mustLogPoolMessage (p ) {
632652 keysAndValues := logger.KeyValues {
653+ logger .KeyDurationMS , duration .Milliseconds (),
633654 logger .KeyReason , logger .ReasonConnCheckoutFailedTimout ,
634655 }
635656
@@ -638,10 +659,11 @@ func (p *pool) checkOut(ctx context.Context) (conn *connection, err error) {
638659
639660 if p .monitor != nil {
640661 p .monitor .Event (& event.PoolEvent {
641- Type : event .GetFailed ,
642- Address : p .address .String (),
643- Reason : event .ReasonTimedOut ,
644- Error : ctx .Err (),
662+ Type : event .GetFailed ,
663+ Address : p .address .String (),
664+ Duration : duration ,
665+ Reason : event .ReasonTimedOut ,
666+ Error : ctx .Err (),
645667 })
646668 }
647669
@@ -650,7 +672,7 @@ func (p *pool) checkOut(ctx context.Context) (conn *connection, err error) {
650672 maxPoolSize : p .maxSize ,
651673 totalConnections : p .totalConnectionCount (),
652674 availableConnections : p .availableConnectionCount (),
653- waitDuration : duration ,
675+ waitDuration : waitQueueDuration ,
654676 }
655677 if p .loadBalanced {
656678 err .pinnedConnections = & pinnedConnections {
@@ -1085,6 +1107,7 @@ func (p *pool) createConnections(ctx context.Context, wg *sync.WaitGroup) {
10851107 })
10861108 }
10871109
1110+ start := time .Now ()
10881111 // Pass the createConnections context to connect to allow pool close to cancel connection
10891112 // establishment so shutdown doesn't block indefinitely if connectTimeout=0.
10901113 err := conn .connect (ctx )
@@ -1111,9 +1134,11 @@ func (p *pool) createConnections(ctx context.Context, wg *sync.WaitGroup) {
11111134 continue
11121135 }
11131136
1137+ duration := time .Since (start )
11141138 if mustLogPoolMessage (p ) {
11151139 keysAndValues := logger.KeyValues {
11161140 logger .KeyDriverConnectionID , conn .driverConnectionID ,
1141+ logger .KeyDurationMS , duration .Milliseconds (),
11171142 }
11181143
11191144 logPoolMessage (p , logger .ConnectionReady , keysAndValues ... )
@@ -1124,6 +1149,7 @@ func (p *pool) createConnections(ctx context.Context, wg *sync.WaitGroup) {
11241149 Type : event .ConnectionReady ,
11251150 Address : p .address .String (),
11261151 ConnectionID : conn .driverConnectionID ,
1152+ Duration : duration ,
11271153 })
11281154 }
11291155
0 commit comments