thanos icon indicating copy to clipboard operation
thanos copied to clipboard

Refactoring: move all http.Transport configuration parameter parsing into one place

Open GiedriusS opened this issue 4 years ago • 9 comments

These are all functions/structs for configuring the same thing:

https://github.com/thanos-io/thanos/blob/5bda2d48b9ef0bf138af6132641eb20102223edb/pkg/objstore/azure/helpers.go#L121 https://github.com/thanos-io/thanos/blob/46ac4d590e783368fc4ec7676f29ff97cd0bd630/pkg/objstore/cos/cos.go#L95 https://github.com/thanos-io/thanos/blob/bf963237e0b95402aeea4093dce465abde055675/pkg/objstore/s3/s3.go#L124

Another place being added: https://github.com/thanos-io/thanos/pull/4623

Move them into one struct. This probably belongs in exthttp.

GiedriusS avatar Sep 01 '21 14:09 GiedriusS

@GiedriusS I would like to fix this issue. Please guide me how can I get started , I am new to this project.

heysujal avatar Sep 01 '21 14:09 heysujal

All of these functions and structs can be joined into one and we can use them everywhere consistently. Please let me know if you have any specific questions.

GiedriusS avatar Sep 02 '21 07:09 GiedriusS

So will replacing the NewTransport() function in exhttp with something like this help?

func NewTransport(config HTTPConfig) *http.Transport {
	return &http.Transport{
		Proxy: http.ProxyFromEnvironment,
		DialContext: (&net.Dialer{
			Timeout:   30 * time.Second,
			KeepAlive: 30 * time.Second,
			DualStack: true,
		}).DialContext,

		MaxIdleConns:          config.MaxIdleConns,
		MaxIdleConnsPerHost:   config.MaxIdleConnsPerHost,
		IdleConnTimeout:       time.Duration(config.IdleConnTimeout),
		MaxConnsPerHost:       config.MaxConnsPerHost,
		TLSHandshakeTimeout:   time.Duration(config.TLSHandshakeTimeout),
		ExpectContinueTimeout: time.Duration(config.ExpectContinueTimeout),
		ResponseHeaderTimeout: time.Duration(config.ResponseHeaderTimeout),
		DisableCompression:	config.DisableCompression,
		TLSClientConfig:	&tls.Config{InsecureSkipVerify: config.InsecureSkipVerify},
	}
}

4molybdenum2 avatar Sep 04 '21 11:09 4molybdenum2

So will replacing the NewTransport() function in exhttp with something like this help?

@4molybdenum2 I think replacing NewTransport() would not be helpful as it serves a different purpose, rather you can try creating a new func DefaultTransport() in exhttp, may be with the same return values as you proposed above, in the comment :)

Namanl2001 avatar Sep 10 '21 17:09 Namanl2001

Ok, will check this out, maybe make a PR...

4molybdenum2 avatar Sep 11 '21 07:09 4molybdenum2

Hello 👋 Looks like there was no activity on this issue for the last two months. Do you mind updating us on the status? Is this still reproducible or needed? If yes, just comment on this PR or push a commit. Thanks! 🤗 If there will be no activity in the next two weeks, this issue will be closed (we can always reopen an issue if we need!). Alternatively, use remind command if you wish to be reminded at some point in future.

stale[bot] avatar Apr 17 '22 04:04 stale[bot]

AC:

  • There is only single HTTPConfig struct that can be unmarshalled from YAML in the consistent way.
  • There is only single reused helper for creating Transport from this HTTPConfig
  • We don't break Cortex deps

bwplotka avatar Jun 16 '22 08:06 bwplotka

I am working on this issue🙌

SrushtiSapkale avatar Jun 16 '22 09:06 SrushtiSapkale

Hey @saswatamcode,This issue can be closed with reference to the above merged PR.

NishantBansal2003 avatar Jul 22 '24 13:07 NishantBansal2003