@@ -50,18 +50,18 @@ _async_connected (mongoc_async_cmd_t *acmd);
50
50
static void
51
51
_async_success (mongoc_async_cmd_t * acmd ,
52
52
const bson_t * ismaster_response ,
53
- int64_t rtt_msec );
53
+ int64_t duration_usec );
54
54
55
55
static void
56
56
_async_error_or_timeout (mongoc_async_cmd_t * acmd ,
57
- int64_t rtt_msec ,
57
+ int64_t duration_usec ,
58
58
const char * default_err_msg );
59
59
60
60
static void
61
61
_async_handler (mongoc_async_cmd_t * acmd ,
62
62
mongoc_async_cmd_result_t async_status ,
63
63
const bson_t * ismaster_response ,
64
- int64_t rtt_msec );
64
+ int64_t duration_usec );
65
65
66
66
static void
67
67
_mongoc_topology_scanner_monitor_heartbeat_started (
@@ -71,13 +71,15 @@ static void
71
71
_mongoc_topology_scanner_monitor_heartbeat_succeeded (
72
72
const mongoc_topology_scanner_t * ts ,
73
73
const mongoc_host_list_t * host ,
74
- const bson_t * reply );
74
+ const bson_t * reply ,
75
+ int64_t duration_usec );
75
76
76
77
static void
77
78
_mongoc_topology_scanner_monitor_heartbeat_failed (
78
79
const mongoc_topology_scanner_t * ts ,
79
80
const mongoc_host_list_t * host ,
80
- const bson_error_t * error );
81
+ const bson_error_t * error ,
82
+ int64_t duration_usec );
81
83
82
84
83
85
/* reset "retired" nodes that failed or were removed in the previous scan */
@@ -433,7 +435,7 @@ _async_connected (mongoc_async_cmd_t *acmd)
433
435
static void
434
436
_async_success (mongoc_async_cmd_t * acmd ,
435
437
const bson_t * ismaster_response ,
436
- int64_t rtt_msec )
438
+ int64_t duration_usec )
437
439
{
438
440
void * data = acmd -> data ;
439
441
mongoc_topology_scanner_node_t * node =
@@ -452,7 +454,7 @@ _async_success (mongoc_async_cmd_t *acmd,
452
454
node -> last_failed = -1 ;
453
455
454
456
_mongoc_topology_scanner_monitor_heartbeat_succeeded (
455
- ts , & node -> host , ismaster_response );
457
+ ts , & node -> host , ismaster_response , duration_usec );
456
458
457
459
/* set our successful stream. */
458
460
BSON_ASSERT (!node -> stream );
@@ -464,12 +466,17 @@ _async_success (mongoc_async_cmd_t *acmd,
464
466
ismaster_response , & node -> sasl_supported_mechs );
465
467
}
466
468
467
- ts -> cb (node -> id , ismaster_response , rtt_msec , ts -> cb_data , & acmd -> error );
469
+ /* mongoc_topology_scanner_cb_t takes rtt_msec, not usec */
470
+ ts -> cb (node -> id ,
471
+ ismaster_response ,
472
+ duration_usec / 1000 ,
473
+ ts -> cb_data ,
474
+ & acmd -> error );
468
475
}
469
476
470
477
static void
471
478
_async_error_or_timeout (mongoc_async_cmd_t * acmd ,
472
- int64_t rtt_msec ,
479
+ int64_t duration_usec ,
473
480
const char * default_err_msg )
474
481
{
475
482
void * data = acmd -> data ;
@@ -516,10 +523,11 @@ _async_error_or_timeout (mongoc_async_cmd_t *acmd,
516
523
node -> host .host_and_port );
517
524
518
525
_mongoc_topology_scanner_monitor_heartbeat_failed (
519
- ts , & node -> host , & node -> last_error );
526
+ ts , & node -> host , & node -> last_error , duration_usec );
520
527
521
- /* call the topology scanner callback. cannot connect to this node. */
522
- ts -> cb (node -> id , NULL , rtt_msec , ts -> cb_data , error );
528
+ /* call the topology scanner callback. cannot connect to this node.
529
+ * callback takes rtt_msec, not usec. */
530
+ ts -> cb (node -> id , NULL , duration_usec / 1000 , ts -> cb_data , error );
523
531
} else {
524
532
/* there are still more commands left for this node or it succeeded
525
533
* with another stream. skip the topology scanner callback. */
@@ -540,7 +548,7 @@ static void
540
548
_async_handler (mongoc_async_cmd_t * acmd ,
541
549
mongoc_async_cmd_result_t async_status ,
542
550
const bson_t * ismaster_response ,
543
- int64_t rtt_msec )
551
+ int64_t duration_usec )
544
552
{
545
553
BSON_ASSERT (acmd -> data );
546
554
@@ -549,13 +557,13 @@ _async_handler (mongoc_async_cmd_t *acmd,
549
557
_async_connected (acmd );
550
558
return ;
551
559
case MONGOC_ASYNC_CMD_SUCCESS :
552
- _async_success (acmd , ismaster_response , rtt_msec );
560
+ _async_success (acmd , ismaster_response , duration_usec );
553
561
return ;
554
562
case MONGOC_ASYNC_CMD_TIMEOUT :
555
- _async_error_or_timeout (acmd , rtt_msec , "connection timeout" );
563
+ _async_error_or_timeout (acmd , duration_usec , "connection timeout" );
556
564
return ;
557
565
case MONGOC_ASYNC_CMD_ERROR :
558
- _async_error_or_timeout (acmd , rtt_msec , "connection error" );
566
+ _async_error_or_timeout (acmd , duration_usec , "connection error" );
559
567
return ;
560
568
case MONGOC_ASYNC_CMD_IN_PROGRESS :
561
569
default :
@@ -773,8 +781,10 @@ mongoc_topology_scanner_node_setup (mongoc_topology_scanner_node_t *node,
773
781
{
774
782
bool success = false;
775
783
mongoc_stream_t * stream ;
784
+ int64_t start ;
776
785
777
786
_mongoc_topology_scanner_monitor_heartbeat_started (node -> ts , & node -> host );
787
+ start = bson_get_monotonic_time ();
778
788
779
789
/* if there is already a working stream, push it back to be re-scanned. */
780
790
if (node -> stream ) {
@@ -803,7 +813,10 @@ mongoc_topology_scanner_node_setup (mongoc_topology_scanner_node_t *node,
803
813
804
814
if (!success ) {
805
815
_mongoc_topology_scanner_monitor_heartbeat_failed (
806
- node -> ts , & node -> host , error );
816
+ node -> ts ,
817
+ & node -> host ,
818
+ error ,
819
+ (bson_get_monotonic_time () - start ) / 1000 );
807
820
808
821
node -> ts -> setup_err_cb (node -> id , node -> ts -> cb_data , error );
809
822
return ;
@@ -1053,13 +1066,15 @@ static void
1053
1066
_mongoc_topology_scanner_monitor_heartbeat_succeeded (
1054
1067
const mongoc_topology_scanner_t * ts ,
1055
1068
const mongoc_host_list_t * host ,
1056
- const bson_t * reply )
1069
+ const bson_t * reply ,
1070
+ int64_t duration_usec )
1057
1071
{
1058
1072
if (ts -> apm_callbacks .server_heartbeat_succeeded ) {
1059
1073
mongoc_apm_server_heartbeat_succeeded_t event ;
1060
1074
event .host = host ;
1061
1075
event .context = ts -> apm_context ;
1062
1076
event .reply = reply ;
1077
+ event .duration_usec = duration_usec ;
1063
1078
ts -> apm_callbacks .server_heartbeat_succeeded (& event );
1064
1079
}
1065
1080
}
@@ -1069,13 +1084,15 @@ static void
1069
1084
_mongoc_topology_scanner_monitor_heartbeat_failed (
1070
1085
const mongoc_topology_scanner_t * ts ,
1071
1086
const mongoc_host_list_t * host ,
1072
- const bson_error_t * error )
1087
+ const bson_error_t * error ,
1088
+ int64_t duration_usec )
1073
1089
{
1074
1090
if (ts -> apm_callbacks .server_heartbeat_failed ) {
1075
1091
mongoc_apm_server_heartbeat_failed_t event ;
1076
1092
event .host = host ;
1077
1093
event .context = ts -> apm_context ;
1078
1094
event .error = error ;
1095
+ event .duration_usec = duration_usec ;
1079
1096
ts -> apm_callbacks .server_heartbeat_failed (& event );
1080
1097
}
1081
1098
}
0 commit comments