common icon indicating copy to clipboard operation
common copied to clipboard

Add `WithDialTLSContextFunc` option

Open LeviHarrison opened this issue 3 years ago • 8 comments

This PR adds needed functionality to implement https://github.com/prometheus/prometheus/issues/4827, in the form of the WithDialTLSContextFunc option and __server_name__ label.

(slightly incorrect) Example implementation:

fn := func(ctx context.Context, network, addr string) (net.Conn, error) {
	tls := cfg.ScrapeConfig.HTTPClientConfig.TLSConfig
	tls.ServerName = ctx.Value(model.ServerNameLabel)

	dialer := &tls.Dialer{
		Config: tls,
	}
	return dialer.DialContext(ctx, network, addr)
}

NewClientFromConfig(cfg, "", WithDialTLSContextFunc(fn))

LeviHarrison avatar Sep 12 '21 20:09 LeviHarrison

Unfortunately, the DialTLSContext options was only introduced in 1.14, so this patch doesn't support 1.13.

LeviHarrison avatar Sep 12 '21 20:09 LeviHarrison

cc @roidelapluie

LeviHarrison avatar Sep 12 '21 20:09 LeviHarrison

Do we need to do the same with DialTLSContextFunc as we do with DialContextFunc?

https://github.com/prometheus/common/blob/d9fc5f48ec67a29d8ad182d5e695df46b713678d/config/http_config.go#L369-L378

LeviHarrison avatar Sep 14 '21 13:09 LeviHarrison

No.

roidelapluie avatar Sep 14 '21 14:09 roidelapluie

To remove go 1.13, we would need to see with client_golang.

Otherwise, I'd suggest that you go get this commit in your fork so we can assess of the feature would work.

roidelapluie avatar Sep 14 '21 14:09 roidelapluie

Build tags with version constraints could also be an option.

LeviHarrison avatar Sep 14 '21 14:09 LeviHarrison

Can you please rebase this so we can continue working on this?

roidelapluie avatar Dec 08 '22 12:12 roidelapluie

Sure, but if I remember correctly what was holding this up was the usage of this new function: https://github.com/prometheus/prometheus/pull/9482#issuecomment-978047587.

LeviHarrison avatar Dec 21 '22 13:12 LeviHarrison