Skip to content

Commit c1d910a

Browse files
committed
Optimize CloudWatch log pagination logic
Updated paginator options to stop on duplicate tokens and set a maximum limit, removing redundant lastToken comparison. This simplifies the code and ensures more efficient log retrieval.
1 parent 572c84f commit c1d910a

File tree

1 file changed

+3
-8
lines changed

1 file changed

+3
-8
lines changed

plugins/aws/main.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -250,22 +250,17 @@ func (p *AWSProcessor) getLogs(startTime, endTime time.Time) ([]string, error) {
250250
StartTime: aws.Int64(startTime.Unix() * 1000),
251251
EndTime: aws.Int64(endTime.Unix() * 1000),
252252
StartFromHead: aws.Bool(true),
253+
}, func(options *cloudwatchlogs.GetLogEventsPaginatorOptions) {
254+
options.StopOnDuplicateToken = true
255+
options.Limit = 10000
253256
})
254257

255-
var lastToken string
256-
257258
for paginator.HasMorePages() {
258259
page, err := paginator.NextPage(ctx)
259260
if err != nil {
260261
return nil, catcher.Error("cannot get logs", err, nil)
261262
}
262263

263-
if lastToken == *page.NextForwardToken {
264-
break
265-
}
266-
267-
lastToken = *page.NextForwardToken
268-
269264
for _, event := range page.Events {
270265
transformedLogs = append(transformedLogs, *event.Message)
271266
}

0 commit comments

Comments
 (0)