Simplify paging FilterLogEvents
@@ -138,25 +138,20 @@ func (p *awsConnection) getLogsForLogGroupsConcurrently(names []string, logGroup
// Run FilterLogEvents for each log group in parallel
for _, logGroup := range logGroups {
go func(logGroup string) {
- var nextToken *string
var ret []*cloudwatchlogs.FilteredLogEvent
- for {
- resp, err := p.logSvc.FilterLogEvents(&cloudwatchlogs.FilterLogEventsInput{
+ err := p.logSvc.FilterLogEventsPages(&cloudwatchlogs.FilterLogEventsInput{
LogGroupName: aws.String(logGroup),
StartTime: startMilli,
EndTime: endMilli,
- NextToken: nextToken,
- })
- if err != nil {
- glog.V(5).Infof("[getLogs] Error getting logs: %v %v\n", logGroup, err)
- }
+ }, func(resp *cloudwatchlogs.FilterLogEventsOutput, lastPage bool) bool {
ret = append(ret, resp.Events...)
- nextToken = resp.NextToken
- if resp.NextToken == nil {
- break
- } else {
+ if !lastPage {
fmt.Printf("Getting more logs for %v...\n", logGroup)
}
+ return true
+ })
+ if err != nil {
+ glog.V(5).Infof("[getLogs] Error getting logs: %v %v\n", logGroup, err)
}
ch <- ret
}(logGroup)
