diff --git a/extension/entitystore/extension.go b/extension/entitystore/extension.go index bd27012a3c..ec3a3e4d1d 100644 --- a/extension/entitystore/extension.go +++ b/extension/entitystore/extension.go @@ -144,9 +144,7 @@ func (e *EntityStore) CreateLogFileEntity(logFileGlob LogFileGlob, logGroupName keyAttributes := e.createServiceKeyAttributes(serviceAttr) attributeMap := e.createAttributeMap() addNonEmptyToMap(attributeMap, ServiceNameSourceKey, serviceAttr.ServiceNameSource) - if _, ok := keyAttributes[entityattributes.AwsAccountId]; !ok { - return nil - } + return &cloudwatchlogs.Entity{ KeyAttributes: keyAttributes, Attributes: attributeMap, @@ -226,7 +224,6 @@ func (e *EntityStore) createServiceKeyAttributes(serviceAttr ServiceAttribute) m } addNonEmptyToMap(serviceKeyAttr, entityattributes.ServiceName, serviceAttr.ServiceName) addNonEmptyToMap(serviceKeyAttr, entityattributes.DeploymentEnvironment, serviceAttr.Environment) - addNonEmptyToMap(serviceKeyAttr, entityattributes.AwsAccountId, e.ec2Info.GetAccountID()) return serviceKeyAttr } diff --git a/extension/entitystore/extension_test.go b/extension/entitystore/extension_test.go index fea148847a..c4d44c006d 100644 --- a/extension/entitystore/extension_test.go +++ b/extension/entitystore/extension_test.go @@ -310,7 +310,6 @@ func TestEntityStore_createServiceKeyAttributes(t *testing.T) { func TestEntityStore_createLogFileRID(t *testing.T) { instanceId := "i-abcd1234" - accountId := "123456789012" glob := LogFileGlob("glob") group := LogGroupName("group") serviceAttr := ServiceAttribute{ @@ -322,7 +321,7 @@ func TestEntityStore_createLogFileRID(t *testing.T) { sp.On("logFileServiceAttribute", glob, group).Return(serviceAttr) e := EntityStore{ mode: config.ModeEC2, - ec2Info: EC2Info{InstanceID: instanceId, AccountID: accountId}, + ec2Info: EC2Info{InstanceID: instanceId}, serviceprovider: sp, nativeCredential: &session.Session{}, } @@ -334,7 +333,6 @@ func TestEntityStore_createLogFileRID(t *testing.T) { entityattributes.DeploymentEnvironment: aws.String("test-environment"), entityattributes.ServiceName: aws.String("test-service"), entityattributes.EntityType: aws.String(Service), - entityattributes.AwsAccountId: aws.String(accountId), }, Attributes: map[string]*string{ InstanceIDKey: aws.String(instanceId), diff --git a/plugins/outputs/cloudwatchlogs/pusher_test.go b/plugins/outputs/cloudwatchlogs/pusher_test.go index fc3957e5cc..f97b9f22ec 100644 --- a/plugins/outputs/cloudwatchlogs/pusher_test.go +++ b/plugins/outputs/cloudwatchlogs/pusher_test.go @@ -27,26 +27,20 @@ import ( type mockLogSrc struct { logs.LogSrc - returnEmpty bool } func (m *mockLogSrc) Entity() *cloudwatchlogs.Entity { - entity := &cloudwatchlogs.Entity{ + return &cloudwatchlogs.Entity{ Attributes: map[string]*string{ "PlatformType": aws.String("AWS::EC2"), "EC2.InstanceId": aws.String("i-123456789"), "EC2.AutoScalingGroup": aws.String("test-group"), }, KeyAttributes: map[string]*string{ - "Name": aws.String("myService"), - "Environment": aws.String("myEnvironment"), - "AwsAccountId": aws.String("123456789"), + "Name": aws.String("myService"), + "Environment": aws.String("myEnvironment"), }, } - if m.returnEmpty { - return nil - } - return entity } var wg sync.WaitGroup @@ -109,7 +103,7 @@ func (e evtMock) Done() { } } -func TestAddSingleEvent_WithAccountId(t *testing.T) { +func TestAddSingleEvent(t *testing.T) { var s svcMock called := false nst := "NEXT_SEQ_TOKEN" @@ -120,9 +114,8 @@ func TestAddSingleEvent_WithAccountId(t *testing.T) { "EC2.AutoScalingGroup": aws.String("test-group"), }, KeyAttributes: map[string]*string{ - "Name": aws.String("myService"), - "Environment": aws.String("myEnvironment"), - "AwsAccountId": aws.String("123456789"), + "Name": aws.String("myService"), + "Environment": aws.String("myEnvironment"), }, } @@ -162,48 +155,6 @@ func TestAddSingleEvent_WithAccountId(t *testing.T) { wg.Wait() } -func TestAddSingleEvent_WithoutAccountId(t *testing.T) { - var s svcMock - called := false - nst := "NEXT_SEQ_TOKEN" - - s.ple = func(in *cloudwatchlogs.PutLogEventsInput) (*cloudwatchlogs.PutLogEventsOutput, error) { - called = true - - if in.SequenceToken != nil { - t.Errorf("PutLogEvents called with wrong sequenceToken, first call should not provide any token") - } - - if *in.LogGroupName != "G" || *in.LogStreamName != "S" { - t.Errorf("PutLogEvents called with wrong group and stream: %v/%v", *in.LogGroupName, *in.LogStreamName) - } - - if len(in.LogEvents) != 1 || *in.LogEvents[0].Message != "MSG" { - t.Errorf("PutLogEvents called with incorrect message, got: '%v'", *in.LogEvents[0].Message) - } - require.Nil(t, in.Entity) - return &cloudwatchlogs.PutLogEventsOutput{ - NextSequenceToken: &nst, - }, nil - } - - stop, p := testPreparation(-1, &s, 1*time.Hour, maxRetryTimeout) - p.logSrc = &mockLogSrc{returnEmpty: true} - - p.AddEvent(evtMock{"MSG", time.Now(), nil}) - require.False(t, called, "PutLogEvents has been called too fast, it should wait until FlushTimeout.") - - p.FlushTimeout = 10 * time.Millisecond - p.resetFlushTimer() - - time.Sleep(3 * time.Second) - require.True(t, called, "PutLogEvents has not been called after FlushTimeout has been reached.") - require.NotNil(t, nst, *p.sequenceToken, "Pusher did not capture the NextSequenceToken") - - close(stop) - wg.Wait() -} - func TestStopPusherWouldDoFinalSend(t *testing.T) { var s svcMock called := false