Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

service/kinesis: Add support for retrying service specific API errors #2751

Merged
merged 3 commits into from
Aug 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG_PENDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
* `AWS IoT Events`'s `IotEventsAction` with `Action`. The previously deleted `Action` is available as `ActionData`.

### SDK Enhancements
* `service/kinesis`: Add support for retrying service specific API errors ([#2751](https://github.com/aws/aws-sdk-go/pull/2751)
* Adds support for retrying the Kinesis API error, LimitExceededException.
* Fixes [#1376](https://github.com/aws/aws-sdk-go/issues/1376)

### SDK Bugs
* `private/model/api`: Fix broken shape stutter rename during generation ([#2747](https://github.com/aws/aws-sdk-go/pull/2747))
Expand Down
18 changes: 9 additions & 9 deletions service/kinesis/customizations.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ import (
var readDuration = 5 * time.Second

func init() {
ops := []string{
opGetRecords,
}
initRequest = func(r *request.Request) {
for _, operation := range ops {
if r.Operation.Name == operation {
r.ApplyOptions(request.WithResponseReadTimeout(readDuration))
}
}
initRequest = customizeRequest
}

func customizeRequest(r *request.Request) {
if r.Operation.Name == opGetRecords {
r.ApplyOptions(request.WithResponseReadTimeout(readDuration))
}

// Service specific error codes. Github(aws/aws-sdk-go#1376)
r.RetryErrorCodes = append(r.RetryErrorCodes, ErrCodeLimitExceededException)
}
46 changes: 46 additions & 0 deletions service/kinesis/customizations_test.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package kinesis

import (
"bytes"
"fmt"
"io"
"io/ioutil"
"net/http"
"testing"
"time"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/aws/corehandlers"
"github.com/aws/aws-sdk-go/aws/request"
"github.com/aws/aws-sdk-go/awstesting/unit"
)
Expand Down Expand Up @@ -87,3 +91,45 @@ func TestKinesisGetRecordsNoTimeout(t *testing.T) {
t.Errorf("Expected no error, but received %v", err)
}
}

func TestKinesisCustomRetryErrorCodes(t *testing.T) {
svc := New(unit.Session, &aws.Config{
MaxRetries: aws.Int(1),
LogLevel: aws.LogLevel(aws.LogDebugWithHTTPBody),
})
svc.Handlers.Validate.Clear()

const jsonErr = `{"__type":%q, "message":"some error message"}`
var reqCount int
resps := []*http.Response{
{
StatusCode: 400,
Header: http.Header{},
Body: ioutil.NopCloser(bytes.NewReader(
[]byte(fmt.Sprintf(jsonErr, ErrCodeLimitExceededException)),
)),
},
{
StatusCode: 200,
Header: http.Header{},
Body: ioutil.NopCloser(bytes.NewReader([]byte{})),
},
}

req, _ := svc.GetRecordsRequest(&GetRecordsInput{})
req.Handlers.Send.Swap(corehandlers.SendHandler.Name, request.NamedHandler{
Name: "custom send handler",
Fn: func(r *request.Request) {
r.HTTPResponse = resps[reqCount]
reqCount++
},
})

if err := req.Send(); err != nil {
t.Fatalf("expect no error, got %v", err)
}

if e, a := 2, reqCount; e != a {
t.Errorf("expect %v requests, got %v", e, a)
}
}