diff --git a/plugins/outputs/cloudwatchlogs/internal/pusher/batch.go b/plugins/outputs/cloudwatchlogs/internal/pusher/batch.go index e8a7cb8f2a..ce14d42490 100644 --- a/plugins/outputs/cloudwatchlogs/internal/pusher/batch.go +++ b/plugins/outputs/cloudwatchlogs/internal/pusher/batch.go @@ -22,7 +22,7 @@ const ( // The maximum number of log events in a batch. reqEventsLimit = 10000 // The bytes required for metadata for each log event. - perEventHeaderBytes = 26 + perEventHeaderBytes = 200 // A batch of log events in a single request cannot span more than 24 hours. Otherwise, the operation fails. batchTimeRangeLimit = 24 * time.Hour ) diff --git a/plugins/outputs/cloudwatchlogs/internal/pusher/batch_test.go b/plugins/outputs/cloudwatchlogs/internal/pusher/batch_test.go index cc7051bdbb..5a06414284 100644 --- a/plugins/outputs/cloudwatchlogs/internal/pusher/batch_test.go +++ b/plugins/outputs/cloudwatchlogs/internal/pusher/batch_test.go @@ -70,20 +70,20 @@ func TestLogEventBatch(t *testing.T) { t.Run("HasSpace", func(t *testing.T) { batch := newLogEventBatch(Target{Group: "G", Stream: "S"}, nil) + event := newLogEvent(time.Now(), "Test message", nil) + maxEvents := reqSizeLimit / event.eventBytes + // Add events until close to the limit - for i := 0; i < reqEventsLimit-1; i++ { - event := newLogEvent(time.Now(), "Test message", nil) + for i := 0; i < maxEvents-1; i++ { batch.append(event) } - assert.True(t, batch.hasSpace(100), "Batch should have space for one more small event") - assert.False(t, batch.hasSpace(reqSizeLimit), "Batch should not have space for an event that exceeds the size limit") + assert.True(t, batch.hasSpace(event.eventBytes)) // Add one more event to reach the limit - event := newLogEvent(time.Now(), "Last message", nil) batch.append(event) - assert.False(t, batch.hasSpace(1), "Batch should not have space after reaching event limit") + assert.False(t, batch.hasSpace(event.eventBytes)) }) t.Run("Build", func(t *testing.T) {