52
52
http2Enabled : true ,
53
53
// 5 minutes is typically above the maximum sane scrape interval. So we can
54
54
// use keepalive for all configurations.
55
- idleConnTimeout : 5 * time .Minute ,
55
+ idleConnTimeout : 5 * time .Minute ,
56
+ newTLSConfigFunc : NewTLSConfigWithContext ,
56
57
}
57
58
)
58
59
@@ -452,8 +453,12 @@ func (a *BasicAuth) UnmarshalYAML(unmarshal func(interface{}) error) error {
452
453
// by net.Dialer.
453
454
type DialContextFunc func (context.Context , string , string ) (net.Conn , error )
454
455
456
+ // NewTLSConfigFunc returns tls.Config.
457
+ type NewTLSConfigFunc func (context.Context , * TLSConfig , ... TLSConfigOption ) (* tls.Config , error )
458
+
455
459
type httpClientOptions struct {
456
460
dialContextFunc DialContextFunc
461
+ newTLSConfigFunc NewTLSConfigFunc
457
462
keepAlivesEnabled bool
458
463
http2Enabled bool
459
464
idleConnTimeout time.Duration
@@ -473,13 +478,23 @@ func (f httpClientOptionFunc) applyToHTTPClientOptions(options *httpClientOption
473
478
f (options )
474
479
}
475
480
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`.
477
483
func WithDialContextFunc (fn DialContextFunc ) HTTPClientOption {
478
484
return httpClientOptionFunc (func (opts * httpClientOptions ) {
479
485
opts .dialContextFunc = fn
480
486
})
481
487
}
482
488
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
+
483
498
// WithKeepAlivesDisabled allows to disable HTTP keepalive.
484
499
func WithKeepAlivesDisabled () HTTPClientOption {
485
500
return httpClientOptionFunc (func (opts * httpClientOptions ) {
@@ -670,7 +685,7 @@ func NewRoundTripperFromConfigWithContext(ctx context.Context, cfg HTTPClientCon
670
685
return rt , nil
671
686
}
672
687
673
- tlsConfig , err := NewTLSConfig ( & cfg .TLSConfig , WithSecretManager (opts .secretManager ))
688
+ tlsConfig , err := opts . newTLSConfigFunc ( ctx , & cfg .TLSConfig , WithSecretManager (opts .secretManager ))
674
689
if err != nil {
675
690
return nil , err
676
691
}
@@ -679,6 +694,7 @@ func NewRoundTripperFromConfigWithContext(ctx context.Context, cfg HTTPClientCon
679
694
if err != nil {
680
695
return nil , err
681
696
}
697
+
682
698
if tlsSettings .immutable () {
683
699
// No need for a RoundTripper that reloads the files automatically.
684
700
return newRT (tlsConfig )
0 commit comments