Skip to content

Commit 6e76d60

Browse files
committed
Remove configurable maxRetryTimeout in favor of default hardcoded value
1 parent b463872 commit 6e76d60

11 files changed

Lines changed: 66 additions & 119 deletions

File tree

plugins/outputs/cloudwatchlogs/cloudwatchlogs.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ const (
3737
LogEntryField = "value"
3838

3939
defaultFlushTimeout = 5 * time.Second
40-
41-
maxRetryTimeout = 14*24*time.Hour + 10*time.Minute
4240
)
4341

4442
var (
@@ -166,7 +164,7 @@ func (c *CloudWatchLogs) getDest(t pusher.Target, logSrc logs.LogSrc) *cwDest {
166164
}
167165
c.targetManager = pusher.NewTargetManager(c.Log, client)
168166
})
169-
p := pusher.NewPusher(c.Log, t, client, c.targetManager, logSrc, c.workerPool, c.ForceFlushInterval.Duration, maxRetryTimeout, &c.pusherWaitGroup, c.Concurrency, c.retryHeap)
167+
p := pusher.NewPusher(c.Log, t, client, c.targetManager, logSrc, c.workerPool, c.ForceFlushInterval.Duration, &c.pusherWaitGroup, c.Concurrency, c.retryHeap)
170168
cwd := &cwDest{
171169
pusher: p,
172170
retryer: logThrottleRetryer,

plugins/outputs/cloudwatchlogs/internal/pusher/batch.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,12 @@ import (
1515
"github.com/aws/amazon-cloudwatch-agent/sdk/service/cloudwatchlogs"
1616
)
1717

18-
// CloudWatch Logs PutLogEvents API limits
19-
// Taken from https://docs.aws.amazon.com/AmazonCloudWatchLogs/latest/APIReference/API_PutLogEvents.html
2018
const (
19+
// maxRetryTimeout is the default retry timeout for CloudWatch Logs operations
20+
maxRetryTimeout = 14*24*time.Hour + 10*time.Minute
21+
22+
// CloudWatch Logs PutLogEvents API limits
23+
// Taken from https://docs.aws.amazon.com/AmazonCloudWatchLogs/latest/APIReference/API_PutLogEvents.html
2124
// The maximum batch size in bytes. This size is calculated as the sum of all event messages in UTF-8,
2225
// plus 26 bytes for each log event.
2326
reqSizeLimit = 1024 * 1024
@@ -253,11 +256,11 @@ func (t byTimestamp) Less(i, j int) bool {
253256
}
254257

255258
// initializeStartTime sets the start time and expiration time if not already set.
256-
func (b *logEventBatch) initializeStartTime(retryDuration time.Duration) {
259+
func (b *logEventBatch) initializeStartTime() {
257260
if b.startTime.IsZero() {
258261
b.startTime = time.Now()
259262
}
260-
b.expireAfter = b.startTime.Add(retryDuration)
263+
b.expireAfter = b.startTime.Add(maxRetryTimeout)
261264
}
262265

263266
// updateRetryMetadata updates the retry metadata after a failed send attempt.

plugins/outputs/cloudwatchlogs/internal/pusher/batch_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ func TestBatchRetryMetadata(t *testing.T) {
414414
assert.False(t, batch.isExpired())
415415

416416
// Test initializeStartTime
417-
batch.initializeStartTime(time.Hour)
417+
batch.initializeStartTime()
418418
assert.False(t, batch.startTime.IsZero())
419419

420420
// Test updateRetryMetadata

plugins/outputs/cloudwatchlogs/internal/pusher/pool.go

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ package pusher
66
import (
77
"sync"
88
"sync/atomic"
9-
"time"
109
)
1110

1211
type WorkerPool interface {
@@ -113,13 +112,3 @@ func (s *senderPool) Stop() {
113112
// workerpool is stopped by the plugin
114113
s.sender.Stop()
115114
}
116-
117-
// SetRetryDuration sets the retry duration on the wrapped Sender.
118-
func (s *senderPool) SetRetryDuration(duration time.Duration) {
119-
s.sender.SetRetryDuration(duration)
120-
}
121-
122-
// RetryDuration returns the retry duration of the wrapped Sender.
123-
func (s *senderPool) RetryDuration() time.Duration {
124-
return s.sender.RetryDuration()
125-
}

plugins/outputs/cloudwatchlogs/internal/pusher/pool_test.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,11 @@ func TestSenderPool(t *testing.T) {
107107
logger := testutil.NewNopLogger()
108108
mockService := new(mockLogsService)
109109
mockService.On("PutLogEvents", mock.Anything).Return(&cloudwatchlogs.PutLogEventsOutput{}, nil)
110-
s := newSender(logger, mockService, nil, time.Second, nil)
110+
s := newSender(logger, mockService, nil, nil)
111111
p := NewWorkerPool(12)
112112
sp := newSenderPool(p, s)
113113

114-
assert.Equal(t, time.Second, sp.RetryDuration())
115-
sp.SetRetryDuration(time.Minute)
116-
assert.Equal(t, time.Minute, sp.RetryDuration())
114+
// Retry duration methods removed - just test basic functionality
117115

118116
var completed atomic.Int32
119117
var evts []*logEvent
@@ -144,7 +142,7 @@ func TestSenderPoolRetryHeap(t *testing.T) {
144142
retryHeap := NewRetryHeap(10)
145143
defer retryHeap.Stop()
146144

147-
s := newSender(logger, mockService, nil, time.Second, retryHeap)
145+
s := newSender(logger, mockService, nil, retryHeap)
148146
p := NewWorkerPool(12)
149147
defer p.Stop()
150148

plugins/outputs/cloudwatchlogs/internal/pusher/pusher.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,11 @@ func NewPusher(
3232
entityProvider logs.LogEntityProvider,
3333
workerPool WorkerPool,
3434
flushTimeout time.Duration,
35-
retryDuration time.Duration,
3635
wg *sync.WaitGroup,
3736
concurrency int,
3837
retryHeap RetryHeap,
3938
) *Pusher {
40-
s := createSender(logger, service, targetManager, workerPool, retryDuration, retryHeap)
39+
s := createSender(logger, service, targetManager, workerPool, retryHeap)
4140

4241
q := newQueue(logger, target, flushTimeout, entityProvider, s, wg)
4342
targetManager.PutRetentionPolicy(target)
@@ -62,10 +61,9 @@ func createSender(
6261
service cloudWatchLogsService,
6362
targetManager TargetManager,
6463
workerPool WorkerPool,
65-
retryDuration time.Duration,
6664
retryHeap RetryHeap,
6765
) Sender {
68-
s := newSender(logger, service, targetManager, retryDuration, retryHeap)
66+
s := newSender(logger, service, targetManager, retryHeap)
6967
if workerPool == nil {
7068
return s
7169
}

plugins/outputs/cloudwatchlogs/internal/pusher/pusher_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@ func setupPusher(t *testing.T, workerPool WorkerPool, wg *sync.WaitGroup) *Pushe
111111
nil,
112112
workerPool,
113113
time.Second,
114-
time.Minute,
115114
wg,
116115
1, // concurrency
117116
nil, // retryHeap
@@ -149,7 +148,6 @@ func TestPusherRetryHeap(t *testing.T) {
149148
nil,
150149
workerPool,
151150
time.Second,
152-
time.Minute,
153151
&wg,
154152
2, // concurrency > 1
155153
retryHeap,

plugins/outputs/cloudwatchlogs/internal/pusher/queue_test.go

Lines changed: 16 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,6 @@ func (m *mockSender) Send(batch *logEventBatch) {
7777
m.Called(batch)
7878
}
7979

80-
func (m *mockSender) SetRetryDuration(d time.Duration) {
81-
m.Called(d)
82-
}
83-
84-
func (m *mockSender) RetryDuration() time.Duration {
85-
args := m.Called()
86-
return args.Get(0).(time.Duration)
87-
}
88-
8980
func (m *mockSender) Stop() {
9081
m.Called()
9182
}
@@ -123,7 +114,7 @@ func TestAddSingleEvent_WithAccountId(t *testing.T) {
123114
}
124115

125116
ep := newMockEntityProvider(expectedEntity)
126-
q, sender := testPreparation(t, -1, &s, 1*time.Hour, 2*time.Hour, ep, &wg)
117+
q, sender := testPreparation(t, -1, &s, 1*time.Hour, ep, &wg)
127118
q.AddEvent(newStubLogEvent("MSG", time.Now()))
128119
require.False(t, called.Load(), "PutLogEvents has been called too fast, it should wait until FlushTimeout.")
129120

@@ -160,7 +151,7 @@ func TestAddSingleEvent_WithoutAccountId(t *testing.T) {
160151
}
161152

162153
ep := newMockEntityProvider(nil)
163-
q, sender := testPreparation(t, -1, &s, 1*time.Hour, 2*time.Hour, ep, &wg)
154+
q, sender := testPreparation(t, -1, &s, 1*time.Hour, ep, &wg)
164155
q.AddEvent(newStubLogEvent("MSG", time.Now()))
165156
require.False(t, called.Load(), "PutLogEvents has been called too fast, it should wait until FlushTimeout.")
166157

@@ -190,7 +181,7 @@ func TestStopQueueWouldDoFinalSend(t *testing.T) {
190181
return &cloudwatchlogs.PutLogEventsOutput{}, nil
191182
}
192183

193-
q, sender := testPreparation(t, -1, &s, 1*time.Hour, 2*time.Hour, nil, &wg)
184+
q, sender := testPreparation(t, -1, &s, 1*time.Hour, nil, &wg)
194185
q.AddEvent(newStubLogEvent("MSG", time.Now()))
195186

196187
time.Sleep(10 * time.Millisecond)
@@ -214,7 +205,7 @@ func TestStopPusherWouldStopRetries(t *testing.T) {
214205
}
215206

216207
logSink := testutil.NewLogSink()
217-
q, sender := testPreparationWithLogger(t, logSink, -1, &s, 1*time.Hour, 2*time.Hour, nil, &wg)
208+
q, sender := testPreparationWithLogger(t, logSink, -1, &s, 1*time.Hour, nil, &wg)
218209
q.AddEvent(newStubLogEvent("MSG", time.Now()))
219210
time.Sleep(10 * time.Millisecond)
220211

@@ -256,7 +247,7 @@ func TestLongMessageHandling(t *testing.T) {
256247
return &cloudwatchlogs.PutLogEventsOutput{}, nil
257248
}
258249

259-
q, sender := testPreparation(t, -1, &s, 1*time.Hour, 2*time.Hour, nil, &wg)
250+
q, sender := testPreparation(t, -1, &s, 1*time.Hour, nil, &wg)
260251
q.AddEvent(newStubLogEvent(longMsg, time.Now()))
261252

262253
triggerSend(t, q)
@@ -285,7 +276,7 @@ func TestRequestIsLessThan1MB(t *testing.T) {
285276
return &cloudwatchlogs.PutLogEventsOutput{}, nil
286277
}
287278

288-
q, sender := testPreparation(t, -1, &s, 1*time.Hour, 2*time.Hour, nil, &wg)
279+
q, sender := testPreparation(t, -1, &s, 1*time.Hour, nil, &wg)
289280
for i := 0; i < 8; i++ {
290281
q.AddEvent(newStubLogEvent(longMsg, time.Now()))
291282
}
@@ -311,7 +302,7 @@ func TestRequestIsLessThan10kEvents(t *testing.T) {
311302
return &cloudwatchlogs.PutLogEventsOutput{}, nil
312303
}
313304

314-
q, sender := testPreparation(t, -1, &s, 1*time.Hour, 2*time.Hour, nil, &wg)
305+
q, sender := testPreparation(t, -1, &s, 1*time.Hour, nil, &wg)
315306
for i := 0; i < 30000; i++ {
316307
q.AddEvent(newStubLogEvent(msg, time.Now()))
317308
}
@@ -337,7 +328,7 @@ func TestTimestampPopulation(t *testing.T) {
337328
return &cloudwatchlogs.PutLogEventsOutput{}, nil
338329
}
339330

340-
q, sender := testPreparation(t, -1, &s, 1*time.Hour, 2*time.Hour, nil, &wg)
331+
q, sender := testPreparation(t, -1, &s, 1*time.Hour, nil, &wg)
341332
for i := 0; i < 3; i++ {
342333
q.AddEvent(newStubLogEvent("msg", time.Time{}))
343334
}
@@ -361,7 +352,7 @@ func TestIgnoreOutOfTimeRangeEvent(t *testing.T) {
361352
}
362353

363354
logSink := testutil.NewLogSink()
364-
q, sender := testPreparationWithLogger(t, logSink, -1, &s, 10*time.Millisecond, 2*time.Hour, nil, &wg)
355+
q, sender := testPreparationWithLogger(t, logSink, -1, &s, 10*time.Millisecond, nil, &wg)
365356
q.AddEvent(newStubLogEvent("MSG", time.Now().Add(-15*24*time.Hour)))
366357
q.AddEventNonBlocking(newStubLogEvent("MSG", time.Now().Add(2*time.Hour+1*time.Minute)))
367358

@@ -414,7 +405,7 @@ func TestAddMultipleEvents(t *testing.T) {
414405
))
415406
}
416407
evts[10], evts[90] = evts[90], evts[10] // make events out of order
417-
q, sender := testPreparation(t, -1, &s, 1*time.Hour, 2*time.Hour, nil, &wg)
408+
q, sender := testPreparation(t, -1, &s, 1*time.Hour, nil, &wg)
418409
for _, e := range evts {
419410
q.AddEvent(e)
420411
}
@@ -466,7 +457,7 @@ func TestSendReqWhenEventsSpanMoreThan24Hrs(t *testing.T) {
466457
return nil, nil
467458
}
468459

469-
q, sender := testPreparation(t, -1, &s, 1*time.Hour, 2*time.Hour, nil, &wg)
460+
q, sender := testPreparation(t, -1, &s, 1*time.Hour, nil, &wg)
470461
q.AddEvent(newStubLogEvent("MSG 25hrs ago", time.Now().Add(-25*time.Hour)))
471462
q.AddEvent(newStubLogEvent("MSG 24hrs ago", time.Now().Add(-24*time.Hour)))
472463
q.AddEvent(newStubLogEvent("MSG 23hrs ago", time.Now().Add(-23*time.Hour)))
@@ -496,7 +487,7 @@ func TestUnhandledErrorWouldNotResend(t *testing.T) {
496487
}
497488

498489
logSink := testutil.NewLogSink()
499-
q, sender := testPreparationWithLogger(t, logSink, -1, &s, 10*time.Millisecond, 2*time.Hour, nil, &wg)
490+
q, sender := testPreparationWithLogger(t, logSink, -1, &s, 10*time.Millisecond, nil, &wg)
500491
q.AddEvent(newStubLogEvent("msg", time.Now()))
501492
time.Sleep(2 * time.Second)
502493

@@ -542,7 +533,7 @@ func TestCreateLogGroupAndLogStreamWhenNotFound(t *testing.T) {
542533
}
543534

544535
logSink := testutil.NewLogSink()
545-
q, sender := testPreparationWithLogger(t, logSink, -1, &s, 1*time.Hour, 2*time.Hour, nil, &wg)
536+
q, sender := testPreparationWithLogger(t, logSink, -1, &s, 1*time.Hour, nil, &wg)
546537
var eventWG sync.WaitGroup
547538
eventWG.Add(1)
548539
q.AddEvent(&stubLogEvent{message: "msg", timestamp: time.Now(), done: eventWG.Done})
@@ -580,7 +571,7 @@ func TestLogRejectedLogEntryInfo(t *testing.T) {
580571
}
581572

582573
logSink := testutil.NewLogSink()
583-
q, sender := testPreparationWithLogger(t, logSink, -1, &s, 1*time.Hour, 2*time.Hour, nil, &wg)
574+
q, sender := testPreparationWithLogger(t, logSink, -1, &s, 1*time.Hour, nil, &wg)
584575
var eventWG sync.WaitGroup
585576
eventWG.Add(1)
586577
q.AddEvent(&stubLogEvent{message: "msg", timestamp: time.Now(), done: eventWG.Done})
@@ -630,7 +621,7 @@ func TestAddEventNonBlocking(t *testing.T) {
630621
start.Add(time.Duration(i)*time.Millisecond),
631622
))
632623
}
633-
q, sender := testPreparation(t, -1, &s, 1*time.Hour, 2*time.Hour, nil, &wg)
624+
q, sender := testPreparation(t, -1, &s, 1*time.Hour, nil, &wg)
634625
time.Sleep(200 * time.Millisecond) // Wait until pusher started, merge channel is blocked
635626

636627
for _, e := range evts {
@@ -646,32 +637,6 @@ func TestAddEventNonBlocking(t *testing.T) {
646637
wg.Wait()
647638
}
648639

649-
func TestResendWouldStopAfterExhaustedRetries(t *testing.T) {
650-
t.Parallel()
651-
var wg sync.WaitGroup
652-
var s stubLogsService
653-
var cnt atomic.Int32
654-
655-
s.ple = func(*cloudwatchlogs.PutLogEventsInput) (*cloudwatchlogs.PutLogEventsOutput, error) {
656-
cnt.Add(1)
657-
return nil, &cloudwatchlogs.ServiceUnavailableException{}
658-
}
659-
660-
logSink := testutil.NewLogSink()
661-
q, sender := testPreparationWithLogger(t, logSink, -1, &s, 10*time.Millisecond, time.Second, nil, &wg)
662-
q.AddEvent(newStubLogEvent("msg", time.Now()))
663-
time.Sleep(2 * time.Second)
664-
665-
logLines := logSink.Lines()
666-
lastLine := logLines[len(logLines)-1]
667-
expected := fmt.Sprintf("All %v retries to G/S failed for PutLogEvents, request dropped.", cnt.Load()-1)
668-
require.True(t, strings.HasSuffix(lastLine, expected), fmt.Sprintf("Expecting error log to end with request dropped, but received '%s' in the log", logSink.String()))
669-
670-
q.Stop()
671-
sender.Stop()
672-
wg.Wait()
673-
}
674-
675640
// Cannot call q.send() directly as it would cause a race condition. Reset last sent time and trigger flush.
676641
func triggerSend(t *testing.T, q *queue) {
677642
t.Helper()
@@ -684,7 +649,6 @@ func testPreparation(
684649
retention int,
685650
service cloudWatchLogsService,
686651
flushTimeout time.Duration,
687-
retryDuration time.Duration,
688652
entityProvider logs.LogEntityProvider,
689653
wg *sync.WaitGroup,
690654
) (*queue, Sender) {
@@ -694,7 +658,6 @@ func testPreparation(
694658
retention,
695659
service,
696660
flushTimeout,
697-
retryDuration,
698661
entityProvider,
699662
wg,
700663
)
@@ -706,13 +669,12 @@ func testPreparationWithLogger(
706669
retention int,
707670
service cloudWatchLogsService,
708671
flushTimeout time.Duration,
709-
retryDuration time.Duration,
710672
entityProvider logs.LogEntityProvider,
711673
wg *sync.WaitGroup,
712674
) (*queue, Sender) {
713675
t.Helper()
714676
tm := NewTargetManager(logger, service)
715-
s := newSender(logger, service, tm, retryDuration, nil)
677+
s := newSender(logger, service, tm, nil)
716678
q := newQueue(
717679
logger,
718680
Target{"G", "S", util.StandardLogGroupClass, retention},

plugins/outputs/cloudwatchlogs/internal/pusher/retryheap.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,8 @@ type RetryHeapProcessor struct {
127127
func NewRetryHeapProcessor(retryHeap RetryHeap, workerPool WorkerPool, service cloudWatchLogsService, targetManager TargetManager, logger telegraf.Logger) *RetryHeapProcessor {
128128
// Create processor's own sender and senderPool
129129
// Pass retryHeap so failed batches go back to RetryHeap instead of blocking on sync retry
130-
// Use the same maxRetryTimeout that main pusher uses for consistency
131-
sender := newSender(logger, service, targetManager, 14*24*time.Hour+10*time.Minute, retryHeap)
130+
// Use the same default retry timeout that main pusher uses for consistency
131+
sender := newSender(logger, service, targetManager, retryHeap)
132132
senderPool := newSenderPool(workerPool, sender)
133133

134134
return &RetryHeapProcessor{

0 commit comments

Comments
 (0)