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

aws/ec2metadata: Reduces timeout and number of max retries for EC2Metadata client #3066

Merged
merged 1 commit into from
Jan 7, 2020
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 @@ -3,3 +3,6 @@
### SDK Enhancements

### SDK Bugs
* `aws/ec2metadata` : Reduces request timeout for EC2Metadata client along with maximum number of retries ([#3066](https://github.com/aws/aws-sdk-go/pull/3066))
* Reduces latency while fetching response from EC2Metadata client running in a container to around 3 seconds
* Fixes [#2972](https://github.com/aws/aws-sdk-go/issues/2972)
13 changes: 10 additions & 3 deletions aws/ec2metadata/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -997,9 +997,12 @@ func TestRequestTimeOut(t *testing.T) {

c.Handlers.Complete.PushBack(op.addToOperationPerformedList)

start := time.Now()
resp, err := c.GetMetadata("/some/path")

expectedOperationsPerformed := []string{"GetToken", "GetMetadata"}
if e, a := 1*time.Second, time.Since(start); e < a {
t.Fatalf("expected duration of test to be less than %v, got %v", e, a)
}

if e, a := "IMDSProfileForSDKGo", resp; e != a {
t.Fatalf("Expected %v, got %v", e, a)
Expand All @@ -1009,13 +1012,16 @@ func TestRequestTimeOut(t *testing.T) {
t.Fatalf("Expected no error, got %v", err)
}

expectedOperationsPerformed := []string{"GetToken", "GetMetadata"}
if e, a := expectedOperationsPerformed, op.operationsPerformed; !reflect.DeepEqual(e, a) {
t.Fatalf("expect %v operations, got %v", e, a)
}

start = time.Now()
resp, err = c.GetMetadata("/some/path")

expectedOperationsPerformed = []string{"GetToken", "GetMetadata", "GetMetadata"}
if e, a := 1*time.Second, time.Since(start); e < a {
t.Fatalf("expected duration of test to be less than %v, got %v", e, a)
}

if e, a := "IMDSProfileForSDKGo", resp; e != a {
t.Fatalf("Expected %v, got %v", e, a)
Expand All @@ -1025,6 +1031,7 @@ func TestRequestTimeOut(t *testing.T) {
t.Fatalf("Expected no error, got %v", err)
}

expectedOperationsPerformed = []string{"GetToken", "GetMetadata", "GetMetadata"}
if e, a := expectedOperationsPerformed, op.operationsPerformed; !reflect.DeepEqual(e, a) {
t.Fatalf("expect %v operations, got %v", e, a)
}
Expand Down
4 changes: 3 additions & 1 deletion aws/ec2metadata/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,10 @@ func NewClient(cfg aws.Config, handlers request.Handlers, endpoint, signingRegio
// use a shorter timeout than default because the metadata
// service is local if it is running, and to fail faster
// if not running on an ec2 instance.
Timeout: 5 * time.Second,
Timeout: 1 * time.Second,
}
// max number of retries on the client operation
cfg.MaxRetries = aws.Int(2)
}

svc := &EC2Metadata{
Expand Down
2 changes: 1 addition & 1 deletion aws/ec2metadata/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func TestClientOverrideDefaultHTTPClientTimeout(t *testing.T) {
t.Errorf("expect %v, not to equal %v", e, a)
}

if e, a := 5*time.Second, svc.Config.HTTPClient.Timeout; e != a {
if e, a := 1*time.Second, svc.Config.HTTPClient.Timeout; e != a {
t.Errorf("expect %v to be %v", e, a)
}
}
Expand Down