Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix TLS struct keys and adjust field tags to match field names #27

Merged
merged 9 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading