Skip to content

Commit 280b0e7

Browse files
authored
http_config: Allow customizing TLS config and settings. (#748)
* http_config: Allow customizing TLS config and settings. Signed-off-by: bwplotka <bwplotka@gmail.com> * Switched to newTLSConfigFunc Signed-off-by: bwplotka <bwplotka@gmail.com> * Addressed comments. Signed-off-by: bwplotka <bwplotka@gmail.com> --------- Signed-off-by: bwplotka <bwplotka@gmail.com>
1 parent aea8919 commit 280b0e7

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

config/http_config.go

+19-3
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ var (
5252
http2Enabled: true,
5353
// 5 minutes is typically above the maximum sane scrape interval. So we can
5454
// use keepalive for all configurations.
55-
idleConnTimeout: 5 * time.Minute,
55+
idleConnTimeout: 5 * time.Minute,
56+
newTLSConfigFunc: NewTLSConfigWithContext,
5657
}
5758
)
5859

@@ -452,8 +453,12 @@ func (a *BasicAuth) UnmarshalYAML(unmarshal func(interface{}) error) error {
452453
// by net.Dialer.
453454
type DialContextFunc func(context.Context, string, string) (net.Conn, error)
454455

456+
// NewTLSConfigFunc returns tls.Config.
457+
type NewTLSConfigFunc func(context.Context, *TLSConfig, ...TLSConfigOption) (*tls.Config, error)
458+
455459
type httpClientOptions struct {
456460
dialContextFunc DialContextFunc
461+
newTLSConfigFunc NewTLSConfigFunc
457462
keepAlivesEnabled bool
458463
http2Enabled bool
459464
idleConnTimeout time.Duration
@@ -473,13 +478,23 @@ func (f httpClientOptionFunc) applyToHTTPClientOptions(options *httpClientOption
473478
f(options)
474479
}
475480

476-
// WithDialContextFunc allows you to override func gets used for the actual dialing. The default is `net.Dialer.DialContext`.
481+
// WithDialContextFunc allows you to override the func gets used for the dialing.
482+
// The default is `net.Dialer.DialContext`.
477483
func WithDialContextFunc(fn DialContextFunc) HTTPClientOption {
478484
return httpClientOptionFunc(func(opts *httpClientOptions) {
479485
opts.dialContextFunc = fn
480486
})
481487
}
482488

489+
// WithNewTLSConfigFunc allows you to override the func that creates the TLS config
490+
// from the prometheus http config.
491+
// The default is `NewTLSConfigWithContext`.
492+
func WithNewTLSConfigFunc(newTLSConfigFunc NewTLSConfigFunc) HTTPClientOption {
493+
return httpClientOptionFunc(func(opts *httpClientOptions) {
494+
opts.newTLSConfigFunc = newTLSConfigFunc
495+
})
496+
}
497+
483498
// WithKeepAlivesDisabled allows to disable HTTP keepalive.
484499
func WithKeepAlivesDisabled() HTTPClientOption {
485500
return httpClientOptionFunc(func(opts *httpClientOptions) {
@@ -670,7 +685,7 @@ func NewRoundTripperFromConfigWithContext(ctx context.Context, cfg HTTPClientCon
670685
return rt, nil
671686
}
672687

673-
tlsConfig, err := NewTLSConfig(&cfg.TLSConfig, WithSecretManager(opts.secretManager))
688+
tlsConfig, err := opts.newTLSConfigFunc(ctx, &cfg.TLSConfig, WithSecretManager(opts.secretManager))
674689
if err != nil {
675690
return nil, err
676691
}
@@ -679,6 +694,7 @@ func NewRoundTripperFromConfigWithContext(ctx context.Context, cfg HTTPClientCon
679694
if err != nil {
680695
return nil, err
681696
}
697+
682698
if tlsSettings.immutable() {
683699
// No need for a RoundTripper that reloads the files automatically.
684700
return newRT(tlsConfig)

0 commit comments

Comments
 (0)