@@ -2303,6 +2303,8 @@ func TestPublishConnLatencyMetric(t *testing.T) {
2303
2303
getHistogramOptionsForIOLatency (AuthGSSConnLatency , time .Hour )),
2304
2304
AuthScramConnLatency : metric .NewHistogram (
2305
2305
getHistogramOptionsForIOLatency (AuthScramConnLatency , time .Hour )),
2306
+ AuthLDAPConnLatencyInternal : metric .NewHistogram (
2307
+ getHistogramOptionsForIOLatency (AuthLDAPConnLatencyInternal , time .Hour )),
2306
2308
},
2307
2309
}
2308
2310
@@ -2402,3 +2404,53 @@ func TestPublishConnLatencyMetric(t *testing.T) {
2402
2404
require .Equal (t , int64 (2 ), count )
2403
2405
require .Equal (t , float64 (9 ), sum )
2404
2406
}
2407
+
2408
+ // write unit tests for the function publishConnLatencyInternalMetric
2409
+ func TestPublishConnLatencyInternalMetric (t * testing.T ) {
2410
+ defer leaktest .AfterTest (t )()
2411
+
2412
+ c := conn {
2413
+ metrics : & tenantSpecificMetrics {
2414
+ AuthLDAPConnLatency : metric .NewHistogram (
2415
+ getHistogramOptionsForIOLatency (AuthLDAPConnLatency , time .Hour )),
2416
+ AuthLDAPConnLatencyInternal : metric .NewHistogram (
2417
+ getHistogramOptionsForIOLatency (AuthLDAPConnLatencyInternal , time .Hour )),
2418
+ },
2419
+ }
2420
+
2421
+ // LDAP
2422
+ ldapDuration := int64 (5 )
2423
+ ldapInternalDuration := int64 (4 )
2424
+ c .publishConnLatencyMetric (ldapDuration , ldapHBAEntry .string ())
2425
+ c .publishConnLatencyInternalMetric (ldapInternalDuration , ldapHBAEntry .string ())
2426
+ w := c .metrics .AuthLDAPConnLatency .WindowedSnapshot ()
2427
+ count , sum := w .Total ()
2428
+ require .Equal (t , int64 (1 ), count )
2429
+ require .Equal (t , float64 (5 ), sum )
2430
+
2431
+ wI := c .metrics .AuthLDAPConnLatencyInternal .WindowedSnapshot ()
2432
+ countI , sumI := wI .Total ()
2433
+ require .Equal (t , int64 (1 ), countI )
2434
+ require .Equal (t , float64 (4 ), sumI )
2435
+
2436
+ // internal latency must be less than total latency.
2437
+ require .Less (t , sumI , sum )
2438
+
2439
+ // republish on LDAP
2440
+ ldapDuration = int64 (2 )
2441
+ ldapInternalDuration = int64 (1 )
2442
+ c .publishConnLatencyMetric (ldapDuration , ldapHBAEntry .string ())
2443
+ c .publishConnLatencyInternalMetric (ldapInternalDuration , ldapHBAEntry .string ())
2444
+ w = c .metrics .AuthLDAPConnLatency .WindowedSnapshot ()
2445
+ count , sum = w .Total ()
2446
+ require .Equal (t , int64 (2 ), count )
2447
+ require .Equal (t , float64 (7 ), sum )
2448
+
2449
+ wI = c .metrics .AuthLDAPConnLatencyInternal .WindowedSnapshot ()
2450
+ countI , sumI = wI .Total ()
2451
+ require .Equal (t , int64 (2 ), countI )
2452
+ require .Equal (t , float64 (5 ), sumI )
2453
+
2454
+ // internal latency must be less than total latency.
2455
+ require .Less (t , sumI , sum )
2456
+ }
0 commit comments