Skip to content

Commit

Permalink
Plumb additional TLS configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
zalegrala committed Mar 15, 2024
1 parent e340ce8 commit 4f24bf7
Showing 1 changed file with 23 additions and 14 deletions.
37 changes: 23 additions & 14 deletions tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import (
"sync"

"github.com/dop251/goja"
"github.com/grafana/xk6-client-tracing/pkg/tracegen"
"github.com/grafana/xk6-client-tracing/pkg/util"
"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/jaegerexporter"
"github.com/pkg/errors"
"go.k6.io/k6/js/common"
Expand All @@ -27,6 +25,9 @@ import (
tracenoop "go.opentelemetry.io/otel/trace/noop"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"

"github.com/grafana/xk6-client-tracing/pkg/tracegen"
"github.com/grafana/xk6-client-tracing/pkg/util"
)

type exporterType string
Expand Down Expand Up @@ -146,6 +147,10 @@ type ClientConfig struct {
Exporter exporterType `json:"type"`
Endpoint string `json:"url"`
Insecure bool `json:"insecure"`
TLSServerName string `json:"tls_server_name"`
TLSCertFile string `json:"tls_cert_file"`
TLSKeyFile string `json:"tls_key_file"`
TLSCAFile string `json:"tls_ca_file"`
Authentication struct {
User string `json:"user"`
Password string `json:"password"`
Expand All @@ -168,15 +173,23 @@ func NewClient(cfg *ClientConfig, vu modules.VU) (*Client, error) {
exporterCfg component.Config
)

tlsConfig := configtls.TLSClientSetting{
Insecure: cfg.Insecure,
ServerName: cfg.TLSServerName,
TLSSetting: configtls.TLSSetting{
CAFile: cfg.TLSCAFile,
CertFile: cfg.TLSCertFile,
KeyFile: cfg.TLSKeyFile,
},
}

switch cfg.Exporter {
case exporterNone, exporterOTLP:
factory = otlpexporter.NewFactory()
exporterCfg = factory.CreateDefaultConfig()
exporterCfg.(*otlpexporter.Config).GRPCClientSettings = configgrpc.GRPCClientSettings{
Endpoint: cfg.Endpoint,
TLSSetting: configtls.TLSClientSetting{
Insecure: cfg.Insecure,
},
Endpoint: cfg.Endpoint,
TLSSetting: tlsConfig,
Headers: util.MergeMaps(map[string]configopaque.String{
"Authorization": authorizationHeader(cfg.Authentication.User, cfg.Authentication.Password),
}, cfg.Headers),
Expand All @@ -185,10 +198,8 @@ func NewClient(cfg *ClientConfig, vu modules.VU) (*Client, error) {
factory = jaegerexporter.NewFactory()
exporterCfg = factory.CreateDefaultConfig()
exporterCfg.(*jaegerexporter.Config).GRPCClientSettings = configgrpc.GRPCClientSettings{
Endpoint: cfg.Endpoint,
TLSSetting: configtls.TLSClientSetting{
Insecure: cfg.Insecure,
},
Endpoint: cfg.Endpoint,
TLSSetting: tlsConfig,
Headers: util.MergeMaps(map[string]configopaque.String{
"Authorization": authorizationHeader(cfg.Authentication.User, cfg.Authentication.Password),
}, cfg.Headers),
Expand All @@ -197,10 +208,8 @@ func NewClient(cfg *ClientConfig, vu modules.VU) (*Client, error) {
factory = otlphttpexporter.NewFactory()
exporterCfg = factory.CreateDefaultConfig()
exporterCfg.(*otlphttpexporter.Config).HTTPClientSettings = confighttp.HTTPClientSettings{
Endpoint: cfg.Endpoint,
TLSSetting: configtls.TLSClientSetting{
Insecure: cfg.Insecure,
},
Endpoint: cfg.Endpoint,
TLSSetting: tlsConfig,
Headers: util.MergeMaps(map[string]configopaque.String{
"Authorization": authorizationHeader(cfg.Authentication.User, cfg.Authentication.Password),
}, cfg.Headers),
Expand Down

0 comments on commit 4f24bf7

Please sign in to comment.