diff --git a/pkg/helpers/aws.go b/pkg/helpers/aws.go index cf1cc7c05..a1c68784e 100644 --- a/pkg/helpers/aws.go +++ b/pkg/helpers/aws.go @@ -364,8 +364,10 @@ func CloudWatchLogsStream(ctx context.Context, cw cloudwatchlogsiface.CloudWatch var start int64 if opts.Since != nil { - start = time.Now().UTC().Add((*opts.Since)*-1).Unix() * int64(time.Microsecond) + start = time.Now().UTC().Add((*opts.Since) * -1).UnixMilli() req.StartTime = aws.Int64(start) + } else { + req.StartTime = aws.Int64(time.Now().UTC().Add(-1 * time.Hour).UnixMilli()) } if stream != "" { @@ -390,13 +392,21 @@ func CloudWatchLogsStream(ctx context.Context, cw cloudwatchlogsiface.CloudWatch if err != nil { switch AwsErrorCode(err) { case "ThrottlingException", "ResourceNotFoundException": - time.Sleep(1 * time.Second) + time.Sleep(3 * time.Second) continue default: return err } } + if res != nil { + if res.NextToken != nil { + time.Sleep(2 * time.Second) + } else if len(res.Events) == 0 { + time.Sleep(5 * time.Second) + } + } + es := []*cloudwatchlogs.FilteredLogEvent{} for _, e := range res.Events { diff --git a/provider/aws/apps_test.go b/provider/aws/apps_test.go index dbc9c60ee..734717b99 100644 --- a/provider/aws/apps_test.go +++ b/provider/aws/apps_test.go @@ -98,6 +98,7 @@ func TestAppLogs(t *testing.T) { Follow: options.Bool(false), Filter: options.String("test"), Prefix: options.Bool(true), + Since: options.Duration(time.Since(time.Date(2011, 1, 1, 0, 0, 0, 0, time.UTC))), }) io.Copy(buf, r) @@ -403,7 +404,8 @@ var cycleLogFilterLogEvents1 = awsutil.Cycle{ Body: `{ "filterPattern": "test", "interleaved": true, - "logGroupName": "convox-httpd-LogGroup-L4V203L35WRM" + "logGroupName": "convox-httpd-LogGroup-L4V203L35WRM", + "startTime": 1293840000000 }`, }, Response: awsutil.Response{ @@ -459,7 +461,8 @@ var cycleLogFilterLogEvents2 = awsutil.Cycle{ "filterPattern": "test", "interleaved": true, "logGroupName": "convox-httpd-LogGroup-L4V203L35WRM", - "nextToken": "ZNUEPl7FcQuXbIH4Swk9D9eFu2XBg-ijZIZlvzz4ea9zZRjw-MMtQtvcoMdmq4T29K7Q6Y1e_KvyfpcT_f_tUw" + "nextToken": "ZNUEPl7FcQuXbIH4Swk9D9eFu2XBg-ijZIZlvzz4ea9zZRjw-MMtQtvcoMdmq4T29K7Q6Y1e_KvyfpcT_f_tUw", + "startTime": 1293840000000 }`, }, Response: awsutil.Response{