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

Add capability to set timeout for ec2metadata's http client #4280

Conversation

pyaesone17
Copy link

@pyaesone17 pyaesone17 commented Feb 17, 2022

Currently if we use custom http client, it will take quite a long time for ec2metadata timeout ##2972. We could not able to use workaround for increasing hop as there is infra limit :) for that issue.
This PR will allow us flexibility to have custom http client and custom timeout for ec2metadata at the same time.

Using custom http client is important for us to make high throughput and low latency for our services. https://docs.aws.amazon.com/sdk-for-go/v1/developer-guide/custom-http.html

@pyaesone17 pyaesone17 changed the title Add capability to set custom http client timeout for ec2metadata Add capability to set timeout for ec2metadata's http client Feb 17, 2022
@mimol91
Copy link

mimol91 commented May 25, 2022

@pyaesone17
You can pass own RoundTrip where you can adjust timeout. (In this way it just fail quickly)

const imdsv2Path = "/latest/api/token"

type disableIMDSRoundTripper struct{}

func (disableIMDSRoundTripper) RoundTrip(req *http.Request) (*http.Response, error) {
	if req.Method == "PUT" && req.URL != nil && req.URL.Path == imdsv2Path {
		return nil, fmt.Error("disabled imdsv2")
	}
	return http.DefaultTransport.RoundTrip(req)
}

func NewDisableIMDSRoundTrip() http.RoundTripper {
	return disableIMDSRoundTripper{}
}
HTTPClient: &http.Client{
	Transport: NewDisableIMDSRoundTrip(),
},

@github-actions
Copy link

We have noticed this issue has not received attention in 1 year. We will close this issue for now. If you think this is in error, please feel free to comment and reopen the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants