diff --git a/pkg/prometheus/config/config.go b/pkg/prometheus/config/config.go index c16989253bd..0c8c21baf07 100644 --- a/pkg/prometheus/config/config.go +++ b/pkg/prometheus/config/config.go @@ -7,15 +7,14 @@ import ( "time" "github.com/asaskevich/govalidator" - - "github.com/jaegertracing/jaeger/pkg/config/tlscfg" + "go.opentelemetry.io/collector/config/configtls" ) // Configuration describes the options to customize the storage behavior. type Configuration struct { ServerURL string `valid:"required" mapstructure:"endpoint"` ConnectTimeout time.Duration `mapstructure:"connect_timeout"` - TLS tlscfg.Options + TLS configtls.ClientConfig TokenFilePath string `mapstructure:"token_file_path"` TokenOverrideFromContext bool `mapstructure:"token_override_from_context"` diff --git a/plugin/metrics/prometheus/metricsstore/reader.go b/plugin/metrics/prometheus/metricsstore/reader.go index df9fddd6f23..a44ce33d51a 100644 --- a/plugin/metrics/prometheus/metricsstore/reader.go +++ b/plugin/metrics/prometheus/metricsstore/reader.go @@ -5,7 +5,6 @@ package metricsstore import ( "context" - "crypto/tls" "fmt" "net" "net/http" @@ -315,12 +314,10 @@ func logErrorToSpan(span trace.Span, err error) { span.SetStatus(codes.Error, err.Error()) } -func getHTTPRoundTripper(c *config.Configuration, logger *zap.Logger) (rt http.RoundTripper, err error) { - var ctlsConfig *tls.Config - if c.TLS.Enabled { - if ctlsConfig, err = c.TLS.Config(logger); err != nil { - return nil, err - } +func getHTTPRoundTripper(c *config.Configuration, _ *zap.Logger) (rt http.RoundTripper, err error) { + ctlsConfig, err := c.TLS.LoadTLSConfig(context.Background()) + if err != nil { + return nil, err } // KeepAlive and TLSHandshake timeouts are kept to existing Prometheus client's // DefaultRoundTripper to simplify user configuration and may be made configurable when required. diff --git a/plugin/metrics/prometheus/metricsstore/reader_test.go b/plugin/metrics/prometheus/metricsstore/reader_test.go index 4aa9ba1ca21..207070b44c6 100644 --- a/plugin/metrics/prometheus/metricsstore/reader_test.go +++ b/plugin/metrics/prometheus/metricsstore/reader_test.go @@ -18,6 +18,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "go.opentelemetry.io/collector/config/configtls" "go.opentelemetry.io/otel/codes" sdktrace "go.opentelemetry.io/otel/sdk/trace" "go.opentelemetry.io/otel/sdk/trace/tracetest" @@ -25,7 +26,6 @@ import ( "go.uber.org/zap" "github.com/jaegertracing/jaeger/pkg/bearertoken" - "github.com/jaegertracing/jaeger/pkg/config/tlscfg" "github.com/jaegertracing/jaeger/pkg/prometheus/config" "github.com/jaegertracing/jaeger/pkg/testutils" "github.com/jaegertracing/jaeger/proto-gen/api_v2/metrics" @@ -739,13 +739,10 @@ func TestGetRoundTripperTLSConfig(t *testing.T) { t.Run(tc.name, func(t *testing.T) { logger := zap.NewNop() config := &config.Configuration{ - ConnectTimeout: 9 * time.Millisecond, - TLS: tlscfg.Options{ - Enabled: tc.tlsEnabled, - }, + ConnectTimeout: 9 * time.Millisecond, + TLS: configtls.ClientConfig{}, TokenOverrideFromContext: true, } - defer config.TLS.Close() rt, err := getHTTPRoundTripper(config, logger) require.NoError(t, err) @@ -856,9 +853,10 @@ func TestInvalidCertFile(t *testing.T) { reader, err := NewMetricsReader(config.Configuration{ ServerURL: "https://localhost:1234", ConnectTimeout: defaultTimeout, - TLS: tlscfg.Options{ - Enabled: true, - CAPath: "foo", + TLS: configtls.ClientConfig{ + Config: configtls.Config{ + CAFile: "foo", + }, }, }, logger, tracer) require.Error(t, err) diff --git a/plugin/metrics/prometheus/options.go b/plugin/metrics/prometheus/options.go index ad259a0b196..7f400b4842f 100644 --- a/plugin/metrics/prometheus/options.go +++ b/plugin/metrics/prometheus/options.go @@ -44,6 +44,8 @@ type Options struct { config.Configuration `mapstructure:",squash"` } +var tlsFlagsCfg = tlscfg.ClientFlagsConfig{Prefix: prefix} + func DefaultConfig() config.Configuration { return config.Configuration{ ServerURL: defaultServerURL, @@ -64,7 +66,7 @@ func NewOptions() *Options { } // AddFlags from this storage to the CLI. -func (opt *Options) AddFlags(flagSet *flag.FlagSet) { +func (*Options) AddFlags(flagSet *flag.FlagSet) { flagSet.String(prefix+suffixServerURL, defaultServerURL, "The Prometheus server's URL, must include the protocol scheme e.g. http://localhost:9090") flagSet.Duration(prefix+suffixConnectTimeout, defaultConnectTimeout, @@ -92,7 +94,7 @@ func (opt *Options) AddFlags(flagSet *flag.FlagSet) { `For example: `+ `"duration_bucket" (not normalized) -> "duration_milliseconds_bucket (normalized)"`) - opt.getTLSFlagsConfig().AddFlags(flagSet) + tlsFlagsCfg.AddFlags(flagSet) } // InitFromViper initializes the options struct with values from Viper. @@ -113,19 +115,14 @@ func (opt *Options) InitFromViper(v *viper.Viper) error { } var err error - opt.TLS, err = opt.getTLSFlagsConfig().InitFromViper(v) + tlsOpts, err := tlsFlagsCfg.InitFromViper(v) if err != nil { return fmt.Errorf("failed to process Prometheus TLS options: %w", err) } + opt.TLS = tlsOpts.ToOtelClientConfig() return nil } -func (*Options) getTLSFlagsConfig() tlscfg.ClientFlagsConfig { - return tlscfg.ClientFlagsConfig{ - Prefix: prefix, - } -} - // stripWhiteSpace removes all whitespace characters from a string. func stripWhiteSpace(str string) string { return strings.ReplaceAll(str, " ", "")