Skip to content

Commit

Permalink
Fix TLS struct keys and adjust field tags to match field names (#27)
Browse files Browse the repository at this point in the history
* Update TLS configuration to control json field names

* Update docker examples after TLS updates

* Include additional struct field

* Clean up struct keys

* Update examples/param/param.js

* Update examples/template/template.js

* Describe TLS config in README

---------

Co-authored-by: A. Stoewer <[email protected]>
  • Loading branch information
zalegrala and stoewer authored May 23, 2024
1 parent 721a4f4 commit 1f223eb
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 15 deletions.
21 changes: 17 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,25 @@ The configuration is an object with the following schema:
endpoint: string,
// The exporter protocol used for sending the traces: tracing.EXPORTER_OTLP or tracing.EXPORTER_JAEGER
exporter: string,
// Whether insecure connections are allowed (optional, default: false)
insecure: bool,
// Credentials used for authentication
// Credentials used for authentication (optional)
authentication: { user: string, password: string },
// Additional headers sent by the client
// Additional headers sent by the client (optional)
headers: { string : string }
// TLS configuration
tls: {
// Whether insecure connections are allowed (optional, default: false)
insecure: boolean,
// Enable TLS but skip verification (optional, default: false)
insecure_skip_verify: boolean,
// The server name requested by the client (optional)
server_name: string,
// The path to the CA certificate file (optional)
ca_file: string,
// The path to the certificate file (optional)
cert_file: string,
// The path to the key file (optional)
key_file: string,
},
}
```

Expand Down
6 changes: 4 additions & 2 deletions examples/param/param.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ const endpoint = __ENV.ENDPOINT || "otel-collector:4317"
const client = new tracing.Client({
endpoint,
exporter: tracing.EXPORTER_OTLP,
insecure: true,
tls: {
insecure: true,
}
});

export default function () {
Expand Down Expand Up @@ -45,4 +47,4 @@ export default function () {

export function teardown() {
client.shutdown();
}
}
4 changes: 3 additions & 1 deletion examples/template/template.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ const orgid = __ENV.TEMPO_X_SCOPE_ORGID || "k6-test"
const client = new tracing.Client({
endpoint,
exporter: tracing.EXPORTER_OTLP,
insecure: true,
tls: {
insecure: true,
},
headers: {
"X-Scope-Orgid": orgid
}
Expand Down
26 changes: 18 additions & 8 deletions tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,15 +143,24 @@ func (ct *TracingModule) newTemplatedGenerator(g goja.ConstructorCall, rt *goja.
return rt.ToValue(generator).ToObject(rt)
}

type TLSClientConfig struct {
Insecure bool `js:"insecure"`
InsecureSkipVerify bool `js:"insecure_skip_verify"`
ServerName string `js:"server_name"`
CAFile string `js:"ca_file"`
CertFile string `js:"cert_file"`
KeyFile string `js:"key_file"`
}

type ClientConfig struct {
Exporter exporterType `json:"type"`
Endpoint string `json:"url"`
TLS configtls.TLSClientSetting `json:"tls"`
Exporter exporterType `js:"exporter"`
Endpoint string `js:"endpoint"`
TLS TLSClientConfig `js:"tls"`
Authentication struct {
User string `json:"user"`
Password string `json:"password"`
User string `js:"user"`
Password string `js:"password"`
}
Headers map[string]configopaque.String `json:"headers"`
Headers map[string]configopaque.String `js:"headers"`
}

type Client struct {
Expand All @@ -170,8 +179,9 @@ func NewClient(cfg *ClientConfig, vu modules.VU) (*Client, error) {
)

tlsConfig := configtls.TLSClientSetting{
Insecure: cfg.TLS.Insecure,
ServerName: cfg.TLS.ServerName,
Insecure: cfg.TLS.Insecure,
InsecureSkipVerify: cfg.TLS.InsecureSkipVerify,
ServerName: cfg.TLS.ServerName,
TLSSetting: configtls.TLSSetting{
CAFile: cfg.TLS.CAFile,
CertFile: cfg.TLS.CertFile,
Expand Down

0 comments on commit 1f223eb

Please sign in to comment.