Added retry logic with exponential backoff to s3Upload for uploading logs
cr
@@ -97,11 +97,18 @@ func (u *AmazonS3Util) S3Upload(log log.T, bucketName string, objectKey string,
ContentType: aws.String("text/plain"),
ACL: aws.String("bucket-owner-full-control"),
}
- if result, err := u.myUploader.Upload(params); err == nil {
+
+ for attempt := 1; attempt <= 4; attempt++ {
+ var result *s3manager.UploadOutput
+ if result, err = u.myUploader.Upload(params); err == nil {
log.Infof("Successfully uploaded file to ", result.Location)
+ break
} else {
- log.Errorf("Failed uploading %v to s3://%v/%v err:%v", filePath, bucketName, objectKey, err)
+ log.Errorf("Attempt %s: Failed uploading %v to s3://%v/%v err:%v ", attempt, filePath, bucketName, objectKey, err)
+ time.Sleep(time.Duration(math.Pow(2, float64(attempt))*100) * time.Millisecond)
+ }
}
+
return err
}
