Skip to content

Commit

Permalink
Reduces timeout and number of max retries for EC2Metadata client
Browse files Browse the repository at this point in the history
  • Loading branch information
skotambkar committed Jan 6, 2020
1 parent 6a08738 commit c78d1b0
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
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 ([#3028](https://github.com/aws/aws-sdk-go/pull/3028))
* 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

0 comments on commit c78d1b0

Please sign in to comment.