Skip to content

Commit

Permalink
Plumb additional TLS configuration (#23)
Browse files Browse the repository at this point in the history
* Plumb additional TLS configuration

* Use upstream TLSClientSetting
  • Loading branch information
zalegrala authored Apr 29, 2024
1 parent 6b84dfd commit 721a4f4
Showing 1 changed file with 22 additions and 17 deletions.
39 changes: 22 additions & 17 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 @@ -143,9 +144,9 @@ func (ct *TracingModule) newTemplatedGenerator(g goja.ConstructorCall, rt *goja.
}

type ClientConfig struct {
Exporter exporterType `json:"type"`
Endpoint string `json:"url"`
Insecure bool `json:"insecure"`
Exporter exporterType `json:"type"`
Endpoint string `json:"url"`
TLS configtls.TLSClientSetting `json:"tls"`
Authentication struct {
User string `json:"user"`
Password string `json:"password"`
Expand All @@ -168,15 +169,23 @@ func NewClient(cfg *ClientConfig, vu modules.VU) (*Client, error) {
exporterCfg component.Config
)

tlsConfig := configtls.TLSClientSetting{
Insecure: cfg.TLS.Insecure,
ServerName: cfg.TLS.ServerName,
TLSSetting: configtls.TLSSetting{
CAFile: cfg.TLS.CAFile,
CertFile: cfg.TLS.CertFile,
KeyFile: cfg.TLS.KeyFile,
},
}

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 +194,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 +204,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 721a4f4

Please sign in to comment.