common
common copied to clipboard
Add `WithDialTLSContextFunc` option
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))
Unfortunately, the DialTLSContext
options was only introduced in 1.14, so this patch doesn't support 1.13.
cc @roidelapluie
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
No.
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.
Build tags with version constraints could also be an option.
Can you please rebase this so we can continue working on this?
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.