Skip to content

Commit 1e282bf

Browse files
authored
otel: Mark explictly option's default values (#5343)
1 parent 20b4ddd commit 1e282bf

File tree

2 files changed

+79
-79
lines changed

2 files changed

+79
-79
lines changed

internal/output/opentelemetry/config.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -120,21 +120,21 @@ func GetConsolidatedConfig(jsonRawConf json.RawMessage, env map[string]string) (
120120
// newDefaultConfig creates a new default config with default values
121121
func newDefaultConfig() Config {
122122
return Config{
123-
ServiceName: null.StringFrom("k6"),
124-
ServiceVersion: null.StringFrom(build.Version),
123+
ServiceName: null.NewString("k6", false),
124+
ServiceVersion: null.NewString(build.Version, false),
125125
ExporterProtocol: null.NewString(grpcExporterProtocol, false),
126126

127-
HTTPExporterInsecure: null.BoolFrom(false),
128-
HTTPExporterEndpoint: null.StringFrom("localhost:4318"),
129-
HTTPExporterURLPath: null.StringFrom("/v1/metrics"),
127+
HTTPExporterInsecure: null.NewBool(false, false),
128+
HTTPExporterEndpoint: null.NewString("localhost:4318", false),
129+
HTTPExporterURLPath: null.NewString("/v1/metrics", false),
130130

131-
GRPCExporterInsecure: null.BoolFrom(false),
132-
GRPCExporterEndpoint: null.StringFrom("localhost:4317"),
131+
GRPCExporterInsecure: null.NewBool(false, false),
132+
GRPCExporterEndpoint: null.NewString("localhost:4317", false),
133133

134-
ExportInterval: types.NullDurationFrom(10 * time.Second),
135-
FlushInterval: types.NullDurationFrom(1 * time.Second),
134+
ExportInterval: types.NewNullDuration(10*time.Second, false),
135+
FlushInterval: types.NewNullDuration(1*time.Second, false),
136136

137-
SingleCounterForRate: null.BoolFrom(true),
137+
SingleCounterForRate: null.NewBool(true, false),
138138
}
139139
}
140140

internal/output/opentelemetry/config_test.go

Lines changed: 69 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -23,34 +23,34 @@ func TestConfig(t *testing.T) {
2323
}{
2424
"default": {
2525
expectedConfig: Config{
26-
ServiceName: null.StringFrom("k6"),
27-
ServiceVersion: null.StringFrom(build.Version),
26+
ServiceName: null.NewString("k6", false),
27+
ServiceVersion: null.NewString(build.Version, false),
2828
ExporterProtocol: null.NewString(grpcExporterProtocol, false),
29-
HTTPExporterInsecure: null.BoolFrom(false),
30-
HTTPExporterEndpoint: null.StringFrom("localhost:4318"),
31-
HTTPExporterURLPath: null.StringFrom("/v1/metrics"),
32-
GRPCExporterInsecure: null.BoolFrom(false),
33-
GRPCExporterEndpoint: null.StringFrom("localhost:4317"),
34-
ExportInterval: types.NullDurationFrom(10 * time.Second),
35-
FlushInterval: types.NullDurationFrom(1 * time.Second),
36-
SingleCounterForRate: null.BoolFrom(true),
29+
HTTPExporterInsecure: null.NewBool(false, false),
30+
HTTPExporterEndpoint: null.NewString("localhost:4318", false),
31+
HTTPExporterURLPath: null.NewString("/v1/metrics", false),
32+
GRPCExporterInsecure: null.NewBool(false, false),
33+
GRPCExporterEndpoint: null.NewString("localhost:4317", false),
34+
ExportInterval: types.NewNullDuration(10*time.Second, false),
35+
FlushInterval: types.NewNullDuration(1*time.Second, false),
36+
SingleCounterForRate: null.NewBool(true, false),
3737
},
3838
},
3939

4040
"environment success merge": {
4141
env: map[string]string{"K6_OTEL_GRPC_EXPORTER_ENDPOINT": "else", "K6_OTEL_EXPORT_INTERVAL": "4ms"},
4242
expectedConfig: Config{
43-
ServiceName: null.StringFrom("k6"),
44-
ServiceVersion: null.StringFrom(build.Version),
43+
ServiceName: null.NewString("k6", false),
44+
ServiceVersion: null.NewString(build.Version, false),
4545
ExporterProtocol: null.NewString(grpcExporterProtocol, false),
46-
HTTPExporterInsecure: null.NewBool(false, true),
47-
HTTPExporterEndpoint: null.StringFrom("localhost:4318"),
48-
HTTPExporterURLPath: null.StringFrom("/v1/metrics"),
49-
GRPCExporterInsecure: null.NewBool(false, true),
50-
GRPCExporterEndpoint: null.StringFrom("else"),
51-
ExportInterval: types.NullDurationFrom(4 * time.Millisecond),
52-
FlushInterval: types.NullDurationFrom(1 * time.Second),
53-
SingleCounterForRate: null.BoolFrom(true),
46+
HTTPExporterInsecure: null.NewBool(false, false),
47+
HTTPExporterEndpoint: null.NewString("localhost:4318", false),
48+
HTTPExporterURLPath: null.NewString("/v1/metrics", false),
49+
GRPCExporterInsecure: null.NewBool(false, false),
50+
GRPCExporterEndpoint: null.NewString("else", true),
51+
ExportInterval: types.NewNullDuration(4*time.Millisecond, true),
52+
FlushInterval: types.NewNullDuration(1*time.Second, false),
53+
SingleCounterForRate: null.NewBool(true, false),
5454
},
5555
},
5656

@@ -75,23 +75,23 @@ func TestConfig(t *testing.T) {
7575
"K6_OTEL_SINGLE_COUNTER_FOR_RATE": "false",
7676
},
7777
expectedConfig: Config{
78-
ServiceName: null.StringFrom("foo"),
79-
ServiceVersion: null.StringFrom("v0.0.99"),
80-
ExporterType: null.StringFrom(httpExporterType),
81-
ExporterProtocol: null.StringFrom(httpExporterProtocol),
82-
ExportInterval: types.NullDurationFrom(4 * time.Millisecond),
78+
ServiceName: null.NewString("foo", true),
79+
ServiceVersion: null.NewString("v0.0.99", true),
80+
ExporterType: null.NewString(httpExporterType, true),
81+
ExporterProtocol: null.NewString(httpExporterProtocol, true),
82+
ExportInterval: types.NewNullDuration(4*time.Millisecond, true),
8383
HTTPExporterInsecure: null.NewBool(true, true),
84-
HTTPExporterEndpoint: null.StringFrom("localhost:5555"),
85-
HTTPExporterURLPath: null.StringFrom("/foo/bar"),
84+
HTTPExporterEndpoint: null.NewString("localhost:5555", true),
85+
HTTPExporterURLPath: null.NewString("/foo/bar", true),
8686
GRPCExporterInsecure: null.NewBool(true, true),
87-
GRPCExporterEndpoint: null.StringFrom("else"),
88-
FlushInterval: types.NullDurationFrom(13 * time.Second),
87+
GRPCExporterEndpoint: null.NewString("else", true),
88+
FlushInterval: types.NewNullDuration(13*time.Second, true),
8989
TLSInsecureSkipVerify: null.NewBool(true, true),
90-
TLSCertificate: null.StringFrom("cert_path"),
91-
TLSClientCertificate: null.StringFrom("client_cert_path"),
92-
TLSClientKey: null.StringFrom("client_key_path"),
93-
Headers: null.StringFrom("key1=value1,key2=value2"),
94-
SingleCounterForRate: null.BoolFrom(false),
90+
TLSCertificate: null.NewString("cert_path", true),
91+
TLSClientCertificate: null.NewString("client_cert_path", true),
92+
TLSClientKey: null.NewString("client_key_path", true),
93+
Headers: null.NewString("key1=value1,key2=value2", true),
94+
SingleCounterForRate: null.NewBool(false, true),
9595
},
9696
},
9797

@@ -100,17 +100,17 @@ func TestConfig(t *testing.T) {
100100
"OTEL_SERVICE_NAME": "otel-service",
101101
},
102102
expectedConfig: Config{
103-
ServiceName: null.StringFrom("otel-service"),
104-
ServiceVersion: null.StringFrom(build.Version),
103+
ServiceName: null.NewString("otel-service", true),
104+
ServiceVersion: null.NewString(build.Version, false),
105105
ExporterProtocol: null.NewString(grpcExporterProtocol, false),
106-
HTTPExporterInsecure: null.NewBool(false, true),
107-
HTTPExporterEndpoint: null.StringFrom("localhost:4318"),
108-
HTTPExporterURLPath: null.StringFrom("/v1/metrics"),
109-
GRPCExporterInsecure: null.NewBool(false, true),
110-
GRPCExporterEndpoint: null.StringFrom("localhost:4317"),
111-
ExportInterval: types.NullDurationFrom(10 * time.Second),
112-
FlushInterval: types.NullDurationFrom(1 * time.Second),
113-
SingleCounterForRate: null.BoolFrom(true),
106+
HTTPExporterInsecure: null.NewBool(false, false),
107+
HTTPExporterEndpoint: null.NewString("localhost:4318", false),
108+
HTTPExporterURLPath: null.NewString("/v1/metrics", false),
109+
GRPCExporterInsecure: null.NewBool(false, false),
110+
GRPCExporterEndpoint: null.NewString("localhost:4317", false),
111+
ExportInterval: types.NewNullDuration(10*time.Second, false),
112+
FlushInterval: types.NewNullDuration(1*time.Second, false),
113+
SingleCounterForRate: null.NewBool(true, false),
114114
},
115115
},
116116

@@ -137,41 +137,41 @@ func TestConfig(t *testing.T) {
137137
`}`,
138138
),
139139
expectedConfig: Config{
140-
ServiceName: null.StringFrom("bar"),
141-
ServiceVersion: null.StringFrom("v2.0.99"),
142-
ExporterType: null.StringFrom(httpExporterType),
143-
ExporterProtocol: null.StringFrom(httpExporterProtocol),
144-
ExportInterval: types.NullDurationFrom(15 * time.Millisecond),
140+
ServiceName: null.NewString("bar", true),
141+
ServiceVersion: null.NewString("v2.0.99", true),
142+
ExporterType: null.NewString(httpExporterType, true),
143+
ExporterProtocol: null.NewString(httpExporterProtocol, true),
144+
ExportInterval: types.NewNullDuration(15*time.Millisecond, true),
145145
HTTPExporterInsecure: null.NewBool(true, true),
146-
HTTPExporterEndpoint: null.StringFrom("localhost:5555"),
147-
HTTPExporterURLPath: null.StringFrom("/foo/bar"),
146+
HTTPExporterEndpoint: null.NewString("localhost:5555", true),
147+
HTTPExporterURLPath: null.NewString("/foo/bar", true),
148148
GRPCExporterInsecure: null.NewBool(true, true),
149-
GRPCExporterEndpoint: null.StringFrom("else"),
150-
FlushInterval: types.NullDurationFrom(13 * time.Second),
149+
GRPCExporterEndpoint: null.NewString("else", true),
150+
FlushInterval: types.NewNullDuration(13*time.Second, true),
151151
TLSInsecureSkipVerify: null.NewBool(true, true),
152-
TLSCertificate: null.StringFrom("cert_path"),
153-
TLSClientCertificate: null.StringFrom("client_cert_path"),
154-
TLSClientKey: null.StringFrom("client_key_path"),
155-
Headers: null.StringFrom("key1=value1,key2=value2"),
156-
SingleCounterForRate: null.BoolFrom(false),
152+
TLSCertificate: null.NewString("cert_path", true),
153+
TLSClientCertificate: null.NewString("client_cert_path", true),
154+
TLSClientKey: null.NewString("client_key_path", true),
155+
Headers: null.NewString("key1=value1,key2=value2", true),
156+
SingleCounterForRate: null.NewBool(false, true),
157157
},
158158
},
159159

160160
"JSON success merge": {
161161
jsonRaw: json.RawMessage(`{"exporterType":"http","httpExporterEndpoint":"localhost:5566","httpExporterURLPath":"/lorem/ipsum","exportInterval":"15ms"}`),
162162
expectedConfig: Config{
163-
ServiceName: null.StringFrom("k6"),
164-
ServiceVersion: null.StringFrom(build.Version),
165-
ExporterType: null.StringFrom(httpExporterType),
163+
ServiceName: null.NewString("k6", false),
164+
ServiceVersion: null.NewString(build.Version, false),
165+
ExporterType: null.NewString(httpExporterType, true),
166166
ExporterProtocol: null.NewString(grpcExporterType, false),
167-
HTTPExporterInsecure: null.NewBool(false, true),
168-
HTTPExporterEndpoint: null.StringFrom("localhost:5566"),
169-
HTTPExporterURLPath: null.StringFrom("/lorem/ipsum"),
170-
GRPCExporterInsecure: null.NewBool(false, true), // default
171-
GRPCExporterEndpoint: null.StringFrom("localhost:4317"), // default
172-
ExportInterval: types.NullDurationFrom(15 * time.Millisecond),
173-
FlushInterval: types.NullDurationFrom(1 * time.Second),
174-
SingleCounterForRate: null.BoolFrom(true),
167+
HTTPExporterInsecure: null.NewBool(false, false),
168+
HTTPExporterEndpoint: null.NewString("localhost:5566", true),
169+
HTTPExporterURLPath: null.NewString("/lorem/ipsum", true),
170+
GRPCExporterInsecure: null.NewBool(false, false), // default
171+
GRPCExporterEndpoint: null.NewString("localhost:4317", false), // default
172+
ExportInterval: types.NewNullDuration(15*time.Millisecond, true),
173+
FlushInterval: types.NewNullDuration(1*time.Second, false),
174+
SingleCounterForRate: null.NewBool(true, false),
175175
},
176176
},
177177
"no scheme in http exporter protocol": {

0 commit comments

Comments
 (0)