@@ -467,6 +467,7 @@ func (p *pool) checkOut(ctx context.Context) (conn *connection, err error) {
467
467
})
468
468
}
469
469
470
+ start := time .Now ()
470
471
// Check the pool state while holding a stateMu read lock. If the pool state is not "ready",
471
472
// return an error. Do all of this while holding the stateMu read lock to prevent a state change between
472
473
// 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) {
477
478
case poolClosed :
478
479
p .stateMu .RUnlock ()
479
480
481
+ duration := time .Since (start )
480
482
if mustLogPoolMessage (p ) {
481
483
keysAndValues := logger.KeyValues {
484
+ logger .KeyDurationMS , duration .Milliseconds (),
482
485
logger .KeyReason , logger .ReasonConnCheckoutFailedPoolClosed ,
483
486
}
484
487
@@ -487,18 +490,21 @@ func (p *pool) checkOut(ctx context.Context) (conn *connection, err error) {
487
490
488
491
if p .monitor != nil {
489
492
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 ,
493
497
})
494
498
}
495
499
return nil , ErrPoolClosed
496
500
case poolPaused :
497
501
err := poolClearedError {err : p .lastClearErr , address : p .address }
498
502
p .stateMu .RUnlock ()
499
503
504
+ duration := time .Since (start )
500
505
if mustLogPoolMessage (p ) {
501
506
keysAndValues := logger.KeyValues {
507
+ logger .KeyDurationMS , duration .Milliseconds (),
502
508
logger .KeyReason , logger .ReasonConnCheckoutFailedError ,
503
509
}
504
510
@@ -507,10 +513,11 @@ func (p *pool) checkOut(ctx context.Context) (conn *connection, err error) {
507
513
508
514
if p .monitor != nil {
509
515
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 ,
514
521
})
515
522
}
516
523
return nil , err
@@ -539,9 +546,11 @@ func (p *pool) checkOut(ctx context.Context) (conn *connection, err error) {
539
546
// or an error, so unlock the stateMu lock here.
540
547
p .stateMu .RUnlock ()
541
548
549
+ duration := time .Since (start )
542
550
if w .err != nil {
543
551
if mustLogPoolMessage (p ) {
544
552
keysAndValues := logger.KeyValues {
553
+ logger .KeyDurationMS , duration .Milliseconds (),
545
554
logger .KeyReason , logger .ReasonConnCheckoutFailedError ,
546
555
}
547
556
@@ -550,18 +559,21 @@ func (p *pool) checkOut(ctx context.Context) (conn *connection, err error) {
550
559
551
560
if p .monitor != nil {
552
561
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 ,
557
567
})
558
568
}
559
569
return nil , w .err
560
570
}
561
571
572
+ duration = time .Since (start )
562
573
if mustLogPoolMessage (p ) {
563
574
keysAndValues := logger.KeyValues {
564
575
logger .KeyDriverConnectionID , w .conn .driverConnectionID ,
576
+ logger .KeyDurationMS , duration .Milliseconds (),
565
577
}
566
578
567
579
logPoolMessage (p , logger .ConnectionCheckedOut , keysAndValues ... )
@@ -572,6 +584,7 @@ func (p *pool) checkOut(ctx context.Context) (conn *connection, err error) {
572
584
Type : event .GetSucceeded ,
573
585
Address : p .address .String (),
574
586
ConnectionID : w .conn .driverConnectionID ,
587
+ Duration : duration ,
575
588
})
576
589
}
577
590
@@ -584,12 +597,14 @@ func (p *pool) checkOut(ctx context.Context) (conn *connection, err error) {
584
597
p .stateMu .RUnlock ()
585
598
586
599
// Wait for either the wantConn to be ready or for the Context to time out.
587
- start := time .Now ()
600
+ waitQueueStart := time .Now ()
588
601
select {
589
602
case <- w .ready :
590
603
if w .err != nil {
604
+ duration := time .Since (start )
591
605
if mustLogPoolMessage (p ) {
592
606
keysAndValues := logger.KeyValues {
607
+ logger .KeyDurationMS , duration .Milliseconds (),
593
608
logger .KeyReason , logger .ReasonConnCheckoutFailedError ,
594
609
logger .KeyError , w .err .Error (),
595
610
}
@@ -599,19 +614,22 @@ func (p *pool) checkOut(ctx context.Context) (conn *connection, err error) {
599
614
600
615
if p .monitor != nil {
601
616
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 ,
606
622
})
607
623
}
608
624
609
625
return nil , w .err
610
626
}
611
627
628
+ duration := time .Since (start )
612
629
if mustLogPoolMessage (p ) {
613
630
keysAndValues := logger.KeyValues {
614
631
logger .KeyDriverConnectionID , w .conn .driverConnectionID ,
632
+ logger .KeyDurationMS , duration .Milliseconds (),
615
633
}
616
634
617
635
logPoolMessage (p , logger .ConnectionCheckedOut , keysAndValues ... )
@@ -622,14 +640,17 @@ func (p *pool) checkOut(ctx context.Context) (conn *connection, err error) {
622
640
Type : event .GetSucceeded ,
623
641
Address : p .address .String (),
624
642
ConnectionID : w .conn .driverConnectionID ,
643
+ Duration : duration ,
625
644
})
626
645
}
627
646
return w .conn , nil
628
647
case <- ctx .Done ():
629
- duration := time .Since (start )
648
+ waitQueueDuration := time .Since (waitQueueStart )
630
649
650
+ duration := time .Since (start )
631
651
if mustLogPoolMessage (p ) {
632
652
keysAndValues := logger.KeyValues {
653
+ logger .KeyDurationMS , duration .Milliseconds (),
633
654
logger .KeyReason , logger .ReasonConnCheckoutFailedTimout ,
634
655
}
635
656
@@ -638,10 +659,11 @@ func (p *pool) checkOut(ctx context.Context) (conn *connection, err error) {
638
659
639
660
if p .monitor != nil {
640
661
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 (),
645
667
})
646
668
}
647
669
@@ -650,7 +672,7 @@ func (p *pool) checkOut(ctx context.Context) (conn *connection, err error) {
650
672
maxPoolSize : p .maxSize ,
651
673
totalConnections : p .totalConnectionCount (),
652
674
availableConnections : p .availableConnectionCount (),
653
- waitDuration : duration ,
675
+ waitDuration : waitQueueDuration ,
654
676
}
655
677
if p .loadBalanced {
656
678
err .pinnedConnections = & pinnedConnections {
@@ -1085,6 +1107,7 @@ func (p *pool) createConnections(ctx context.Context, wg *sync.WaitGroup) {
1085
1107
})
1086
1108
}
1087
1109
1110
+ start := time .Now ()
1088
1111
// Pass the createConnections context to connect to allow pool close to cancel connection
1089
1112
// establishment so shutdown doesn't block indefinitely if connectTimeout=0.
1090
1113
err := conn .connect (ctx )
@@ -1111,9 +1134,11 @@ func (p *pool) createConnections(ctx context.Context, wg *sync.WaitGroup) {
1111
1134
continue
1112
1135
}
1113
1136
1137
+ duration := time .Since (start )
1114
1138
if mustLogPoolMessage (p ) {
1115
1139
keysAndValues := logger.KeyValues {
1116
1140
logger .KeyDriverConnectionID , conn .driverConnectionID ,
1141
+ logger .KeyDurationMS , duration .Milliseconds (),
1117
1142
}
1118
1143
1119
1144
logPoolMessage (p , logger .ConnectionReady , keysAndValues ... )
@@ -1124,6 +1149,7 @@ func (p *pool) createConnections(ctx context.Context, wg *sync.WaitGroup) {
1124
1149
Type : event .ConnectionReady ,
1125
1150
Address : p .address .String (),
1126
1151
ConnectionID : conn .driverConnectionID ,
1152
+ Duration : duration ,
1127
1153
})
1128
1154
}
1129
1155
0 commit comments