@@ -469,11 +469,13 @@ func TestBackendSendAsyncMetrics(t *testing.T) {
469469func TestRetrySendMetrics (t * testing.T ) {
470470 t .Parallel ()
471471 for _ , tc := range []struct {
472- name string
473- numUntilSuccess int
474- maxRetries int
475- wantAttempts int
476- numErrs int
472+ name string
473+ numUntilSuccess int
474+ maxRetries int
475+ maxRequestElapseTime int
476+ wantAttempts int
477+ approxAttempts bool // because of randomness of the retry interval
478+ numErrs int
477479 }{
478480 {
479481 name : "should retry sending metrics if it fails for the first time" ,
@@ -503,6 +505,23 @@ func TestRetrySendMetrics(t *testing.T) {
503505 wantAttempts : 1 ,
504506 numErrs : 1 ,
505507 },
508+ {
509+ name : "should not retry if maxRetries reached" ,
510+ numUntilSuccess : 5 ,
511+ maxRetries : 3 ,
512+ maxRequestElapseTime : 100 ,
513+ wantAttempts : 4 ,
514+ numErrs : 1 ,
515+ },
516+ {
517+ name : "should stop retry if maxRequestElapseTime reached" ,
518+ numUntilSuccess : 5 ,
519+ maxRetries : 100 ,
520+ maxRequestElapseTime : 1 ,
521+ wantAttempts : 3 ,
522+ approxAttempts : true ,
523+ numErrs : 1 ,
524+ },
506525 } {
507526 t .Run (tc .name , func (t * testing.T ) {
508527 attempts := 0
@@ -520,6 +539,7 @@ func TestRetrySendMetrics(t *testing.T) {
520539 v .Set ("otlp.metrics_endpoint" , fmt .Sprintf ("%s/%s" , s .URL , "v1/metrics" ))
521540 v .Set ("otlp.logs_endpoint" , fmt .Sprintf ("%s/%s" , s .URL , "v1/logs" ))
522541 v .Set ("otlp.max_retries" , tc .maxRetries )
542+ v .Set ("otlp.max_request_elapsed_time" , tc .maxRequestElapseTime )
523543
524544 logger := fixtures .NewTestLogger (t )
525545
@@ -532,7 +552,12 @@ func TestRetrySendMetrics(t *testing.T) {
532552
533553 b .SendMetricsAsync (context .Background (), gostatsd .NewMetricMap (false ), func (errs []error ) {
534554 assert .Equal (t , tc .numErrs , len (errs ))
535- assert .Equal (t , tc .wantAttempts , attempts , "Must retry sending metrics" )
555+ if tc .approxAttempts {
556+ assert .InDelta (t , tc .wantAttempts , attempts , 1 , "Must retry sending metrics" )
557+ } else {
558+ assert .Equal (t , tc .wantAttempts , attempts , "Must retry sending metrics" )
559+ }
560+
536561 })
537562 })
538563 }
0 commit comments