Skip to content

Commit 1d11205

Browse files
committed
fix ListTagsForResource ARN and harden autodiscover tag test
DescribeLogGroups returns two ARN fields for each log group. The Arn field carries the log-stream wildcard suffix ":*", while LogGroupArn is documented by the AWS SDK as the value to use for tagging APIs. ListTagsForResource rejects the ":*" form with a ValidationException, so tag-based autodiscovery fails at runtime against real AWS despite the unit test passing with a non-realistic mock ARN. Switch to lg.LogGroupArn, update the test mock to include both fields, and tighten the assertion so a log group whose tags do not match is verified to be excluded from FilterLogEvents rather than only checking that some record flowed. Rename the chloggen entry to match the surrounding naming convention.
1 parent d1a6a92 commit 1d11205

3 files changed

Lines changed: 11 additions & 4 deletions

File tree

.chloggen/main.yaml renamed to .chloggen/awscloudwatch-tag-filter-46237.yaml

File renamed without changes.

receiver/awscloudwatchreceiver/logs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ func (l *logsReceiver) discoverGroups(ctx context.Context, auto *AutodiscoverCon
462462

463463
if auto.Tags != nil {
464464
tags, err := l.client.ListTagsForResource(ctx, &cloudwatchlogs.ListTagsForResourceInput{
465-
ResourceArn: aws.String(*lg.Arn),
465+
ResourceArn: lg.LogGroupArn,
466466
})
467467
if err != nil {
468468
l.settings.Logger.Error("unable to list tags for resource", zap.Error(err))

receiver/awscloudwatchreceiver/logs_test.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,11 +1003,13 @@ func TestAutodiscoverTags(t *testing.T) {
10031003
}), mock.Anything).Return(&cloudwatchlogs.DescribeLogGroupsOutput{
10041004
LogGroups: []types.LogGroup{
10051005
{
1006-
Arn: aws.String("arn:aws:logs:us-west-1:123456789012:log-group:/aws/working-group"),
1006+
Arn: aws.String("arn:aws:logs:us-west-1:123456789012:log-group:/aws/working-group:*"),
1007+
LogGroupArn: aws.String("arn:aws:logs:us-west-1:123456789012:log-group:/aws/working-group"),
10071008
LogGroupName: aws.String("/aws/working-group"),
10081009
},
10091010
{
1010-
Arn: aws.String("arn:aws:logs:us-west-1:123456789012:log-group:/aws/not-in-tags-group"),
1011+
Arn: aws.String("arn:aws:logs:us-west-1:123456789012:log-group:/aws/not-in-tags-group:*"),
1012+
LogGroupArn: aws.String("arn:aws:logs:us-west-1:123456789012:log-group:/aws/not-in-tags-group"),
10111013
LogGroupName: aws.String("/aws/not-in-tags-group"),
10121014
},
10131015
},
@@ -1047,11 +1049,16 @@ func TestAutodiscoverTags(t *testing.T) {
10471049
require.NoError(t, err)
10481050

10491051
require.Eventually(t, func() bool {
1050-
return sink.LogRecordCount() > 0
1052+
return sink.LogRecordCount() >= 1
10511053
}, 2*time.Second, 10*time.Millisecond)
10521054

10531055
err = logsRcvr.Shutdown(t.Context())
10541056
require.NoError(t, err)
1057+
1058+
require.Equal(t, 1, sink.LogRecordCount(), "log group whose tags do not match should be excluded")
1059+
mc.AssertNotCalled(t, "FilterLogEvents", mock.Anything, mock.MatchedBy(func(input *cloudwatchlogs.FilterLogEventsInput) bool {
1060+
return input.LogGroupName != nil && *input.LogGroupName == "/aws/not-in-tags-group"
1061+
}), mock.Anything)
10551062
}
10561063

10571064
func defaultMockClient() client {

0 commit comments

Comments
 (0)