@@ -460,14 +460,57 @@ func TestDescribeLogGroupsBatching(t *testing.T) {
460460 batch := make (map [string ]Target )
461461 batch ["group-1" ] = Target {Group : "group-1" , Stream : "stream" , Retention : 7 }
462462 batch ["group-2" ] = Target {Group : "group-2" , Stream : "stream" , Retention : 7 }
463- tm .updateTargetBatch (batch )
463+ tm .updateTargets (batch )
464464
465465 // Wait for ticker to fire (slightly longer than 5 seconds)
466466 time .Sleep (5100 * time .Millisecond )
467467
468468 mockService .AssertNotCalled (t , "PutRetentionPolicy" )
469469 })
470470
471+ t .Run ("FallbackToPrefix" , func (t * testing.T ) {
472+ mockService := new (mockLogsService )
473+
474+ // First call with identifiers fails with unsupported error
475+ mockService .On ("DescribeLogGroups" , mock .MatchedBy (func (input * cloudwatchlogs.DescribeLogGroupsInput ) bool {
476+ return len (input .LogGroupIdentifiers ) > 0
477+ })).Return (& cloudwatchlogs.DescribeLogGroupsOutput {},
478+ awserr .New (cloudwatchlogs .ErrCodeInvalidParameterException , errMessageLogGroupIdentifierNotSupported , nil )).Once ()
479+
480+ // Fallback calls with prefix for each group
481+ mockService .On ("DescribeLogGroups" , mock .MatchedBy (func (input * cloudwatchlogs.DescribeLogGroupsInput ) bool {
482+ return input .LogGroupNamePrefix != nil && * input .LogGroupNamePrefix == "group-1"
483+ })).Return (& cloudwatchlogs.DescribeLogGroupsOutput {
484+ LogGroups : []* cloudwatchlogs.LogGroup {
485+ {LogGroupName : aws .String ("group-1" ), RetentionInDays : aws .Int64 (1 )},
486+ },
487+ }, nil ).Once ()
488+
489+ mockService .On ("DescribeLogGroups" , mock .MatchedBy (func (input * cloudwatchlogs.DescribeLogGroupsInput ) bool {
490+ return input .LogGroupNamePrefix != nil && * input .LogGroupNamePrefix == "group-2"
491+ })).Return (& cloudwatchlogs.DescribeLogGroupsOutput {
492+ LogGroups : []* cloudwatchlogs.LogGroup {
493+ {LogGroupName : aws .String ("group-2" ), RetentionInDays : aws .Int64 (7 )},
494+ },
495+ }, nil ).Once ()
496+
497+ mockService .On ("PutRetentionPolicy" , mock .MatchedBy (func (input * cloudwatchlogs.PutRetentionPolicyInput ) bool {
498+ return * input .LogGroupName == "group-1" && * input .RetentionInDays == 7
499+ })).Return (& cloudwatchlogs.PutRetentionPolicyOutput {}, nil ).Once ()
500+
501+ manager := NewTargetManager (logger , mockService )
502+ tm := manager .(* targetManager )
503+
504+ batch := make (map [string ]Target )
505+ batch ["group-1" ] = Target {Group : "group-1" , Stream : "stream" , Retention : 7 }
506+ batch ["group-2" ] = Target {Group : "group-2" , Stream : "stream" , Retention : 7 }
507+
508+ tm .updateTargets (batch )
509+ time .Sleep (100 * time .Millisecond )
510+
511+ mockService .AssertExpectations (t )
512+ })
513+
471514 t .Run ("RetentionPolicyUpdate" , func (t * testing.T ) {
472515 mockService := new (mockLogsService )
473516
@@ -497,7 +540,7 @@ func TestDescribeLogGroupsBatching(t *testing.T) {
497540 batch ["group-1" ] = Target {Group : "group-1" , Stream : "stream" , Retention : 7 }
498541 batch ["group-2" ] = Target {Group : "group-2" , Stream : "stream" , Retention : 7 }
499542
500- tm .updateTargetBatch (batch )
543+ tm .updateTargets (batch )
501544 time .Sleep (100 * time .Millisecond )
502545
503546 mockService .AssertExpectations (t )
@@ -523,13 +566,38 @@ func TestDescribeLogGroupsBatching(t *testing.T) {
523566 batch := make (map [string ]Target )
524567 batch ["group-1" ] = Target {Group : "group-1" , Stream : "stream" , Retention : 7 }
525568
526- tm .updateTargetBatch (batch )
569+ tm .updateTargets (batch )
527570 // Sleep enough for retry
528571 time .Sleep (2 * time .Second )
529572
530573 mockService .AssertExpectations (t )
531574 })
532575
576+ t .Run ("FallbackToPrefix/OtherError" , func (t * testing.T ) {
577+ mockService := new (mockLogsService )
578+
579+ // First call with identifiers fails with different error (should not fallback)
580+ mockService .On ("DescribeLogGroups" , mock .MatchedBy (func (input * cloudwatchlogs.DescribeLogGroupsInput ) bool {
581+ return len (input .LogGroupIdentifiers ) > 0
582+ })).Return (& cloudwatchlogs.DescribeLogGroupsOutput {},
583+ awserr .New (cloudwatchlogs .ErrCodeInvalidParameterException , "Different error message" , nil )).Times (numBackoffRetries )
584+
585+ manager := NewTargetManager (logger , mockService )
586+ tm := manager .(* targetManager )
587+
588+ batch := make (map [string ]Target )
589+ batch ["group-1" ] = Target {Group : "group-1" , Stream : "stream" , Retention : 7 }
590+
591+ tm .updateTargets (batch )
592+ time .Sleep (2 * time .Second )
593+
594+ mockService .AssertExpectations (t )
595+ // Should not call prefix-based DescribeLogGroups
596+ mockService .AssertNotCalled (t , "DescribeLogGroups" , mock .MatchedBy (func (input * cloudwatchlogs.DescribeLogGroupsInput ) bool {
597+ return input .LogGroupNamePrefix != nil
598+ }))
599+ })
600+
533601}
534602
535603func TestCalculateBackoff (t * testing.T ) {
0 commit comments