Unverified Commit 544807ba authored by Danielle Lancashire's avatar Danielle Lancashire
Browse files

env_aws: Disable Retries and set Session cfg

Previously, Nomad used hand rolled HTTP requests to interact with the
EC2 metadata API. Recently however, we switched to using the AWS SDK for
this fingerprinting.

The default behaviour of the AWS SDK is to perform retries with
exponential backoff when a request fails. This is problematic for Nomad,
because interacting with the EC2 API is in our client start path.

Here we revert to our pre-existing behaviour of not performing retries
in the fast path, as if the metadata service is unavailable, it's likely
that nomad is not running in AWS.
parent 7700d384
No related merge requests found
Showing with 12 additions and 4 deletions
+12 -4
......@@ -75,7 +75,10 @@ func (f *EnvAWSFingerprint) Fingerprint(request *FingerprintRequest, response *F
timeout = 1 * time.Millisecond
}
ec2meta := ec2MetaClient(f.endpoint, timeout)
ec2meta, err := ec2MetaClient(f.endpoint, timeout)
if err != nil {
return fmt.Errorf("failed to setup ec2 client: %v", err)
}
if !ec2meta.Available() {
return nil
......@@ -191,15 +194,20 @@ func (f *EnvAWSFingerprint) linkSpeed(ec2meta *ec2metadata.EC2Metadata) int {
return netSpeed
}
func ec2MetaClient(endpoint string, timeout time.Duration) *ec2metadata.EC2Metadata {
func ec2MetaClient(endpoint string, timeout time.Duration) (*ec2metadata.EC2Metadata, error) {
client := &http.Client{
Timeout: timeout,
Transport: cleanhttp.DefaultTransport(),
}
c := aws.NewConfig().WithHTTPClient(client)
c := aws.NewConfig().WithHTTPClient(client).WithMaxRetries(0)
if endpoint != "" {
c = c.WithEndpoint(endpoint)
}
return ec2metadata.New(session.New(), c)
session, err := session.NewSession(c)
if err != nil {
return nil, err
}
return ec2metadata.New(session, c), nil
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment