@@ -22,12 +22,12 @@ func TestK8sHintsBuilderMetrics(t *testing.T) {
22
22
err := id .UnmarshalText ([]byte ("redis/pod-2-UID_6379" ))
23
23
assert .NoError (t , err )
24
24
25
- var config = `
25
+ config : = `
26
26
collection_interval: "20s"
27
27
timeout: "30s"
28
28
username: "username"
29
29
password: "changeme"`
30
- var configRedis = `
30
+ configRedis : = `
31
31
collection_interval: "20s"
32
32
timeout: "130s"
33
33
username: "username"
@@ -53,8 +53,10 @@ password: "changeme"`
53
53
otelMetricsHints + "/enabled" : "true" ,
54
54
otelMetricsHints + "/scraper" : "redis" ,
55
55
otelMetricsHints + "/config" : config ,
56
- }},
57
- Port : 6379 },
56
+ },
57
+ },
58
+ Port : 6379 ,
59
+ },
58
60
},
59
61
expectedReceiver : receiverTemplate {
60
62
receiverConfig : receiverConfig {
@@ -78,8 +80,10 @@ password: "changeme"`
78
80
otelMetricsHints + "/enabled" : "true" ,
79
81
otelMetricsHints + "/scraper" : "redis" ,
80
82
otelMetricsHints + "/config" : config ,
81
- }},
82
- Port : 6379 },
83
+ },
84
+ },
85
+ Port : 6379 ,
86
+ },
83
87
},
84
88
expectedReceiver : receiverTemplate {},
85
89
wantError : false ,
@@ -97,8 +101,10 @@ password: "changeme"`
97
101
Annotations : map [string ]string {
98
102
otelMetricsHints + "/enabled" : "true" ,
99
103
otelMetricsHints + "/scraper" : "redis" ,
100
- }},
101
- Port : 6379 },
104
+ },
105
+ },
106
+ Port : 6379 ,
107
+ },
102
108
},
103
109
expectedReceiver : receiverTemplate {
104
110
receiverConfig : receiverConfig {
@@ -122,8 +128,10 @@ password: "changeme"`
122
128
otelMetricsHints + ".6379/enabled" : "true" ,
123
129
otelMetricsHints + ".6379/scraper" : "redis" ,
124
130
otelMetricsHints + ".6379/config" : config ,
125
- }},
126
- Port : 6379 },
131
+ },
132
+ },
133
+ Port : 6379 ,
134
+ },
127
135
},
128
136
expectedReceiver : receiverTemplate {
129
137
receiverConfig : receiverConfig {
@@ -148,8 +156,10 @@ password: "changeme"`
148
156
otelMetricsHints + ".6379/scraper" : "redis" ,
149
157
otelMetricsHints + "/config" : config ,
150
158
otelMetricsHints + ".6379/config" : configRedis ,
151
- }},
152
- Port : 6379 },
159
+ },
160
+ },
161
+ Port : 6379 ,
162
+ },
153
163
},
154
164
expectedReceiver : receiverTemplate {
155
165
receiverConfig : receiverConfig {
@@ -173,7 +183,9 @@ password: "changeme"`
173
183
otelMetricsHints + "/enabled" : "true" ,
174
184
otelMetricsHints + "/scraper" : "redis" ,
175
185
otelMetricsHints + "/config" : config ,
176
- }}},
186
+ },
187
+ },
188
+ },
177
189
},
178
190
expectedReceiver : receiverTemplate {},
179
191
wantError : true ,
@@ -204,14 +216,14 @@ password: "changeme"`
204
216
}
205
217
206
218
func TestGetConfFromAnnotations (t * testing.T ) {
207
- var config = `
219
+ config : = `
208
220
endpoint: "0.0.0.0:8080"
209
221
collection_interval: "20s"
210
222
initial_delay: "20s"
211
223
read_buffer_size: "10"
212
224
nested_example:
213
225
foo: bar`
214
- var configNoEndpoint = `
226
+ configNoEndpoint : = `
215
227
collection_interval: "20s"
216
228
initial_delay: "20s"
217
229
read_buffer_size: "10"
@@ -223,51 +235,52 @@ nested_example:
223
235
defaultEndpoint string
224
236
scopeSuffix string
225
237
expectError bool
226
- }{"simple_annotation_case" : {
227
- hintsAnn : map [string ]string {
228
- "io.opentelemetry.discovery.metrics/enabled" : "true" ,
229
- "io.opentelemetry.discovery.metrics/config" : config ,
230
- }, expectedConf : userConfigMap {
231
- "collection_interval" : "20s" ,
232
- "endpoint" : "0.0.0.0:8080" ,
233
- "initial_delay" : "20s" ,
234
- "read_buffer_size" : "10" ,
235
- "nested_example" : userConfigMap {"foo" : "bar" },
236
- }, defaultEndpoint : "0.0.0.0:8080" ,
237
- scopeSuffix : "" ,
238
- }, "simple_annotation_case_default_endpoint" : {
239
- hintsAnn : map [string ]string {
240
- "io.opentelemetry.discovery.metrics/enabled" : "true" ,
241
- "io.opentelemetry.discovery.metrics/config" : configNoEndpoint ,
242
- }, expectedConf : userConfigMap {
243
- "collection_interval" : "20s" ,
244
- "endpoint" : "1.1.1.1:8080" ,
245
- "initial_delay" : "20s" ,
246
- "read_buffer_size" : "10" ,
247
- "nested_example" : userConfigMap {"foo" : "bar" },
248
- }, defaultEndpoint : "1.1.1.1:8080" ,
249
- scopeSuffix : "" ,
250
- }, "simple_annotation_case_scoped" : {
251
- hintsAnn : map [string ]string {
252
- "io.opentelemetry.discovery.metrics.8080/enabled" : "true" ,
253
- "io.opentelemetry.discovery.metrics.8080/config" : config ,
254
- }, expectedConf : userConfigMap {
255
- "collection_interval" : "20s" ,
256
- "endpoint" : "0.0.0.0:8080" ,
257
- "initial_delay" : "20s" ,
258
- "read_buffer_size" : "10" ,
259
- "nested_example" : userConfigMap {"foo" : "bar" },
260
- }, defaultEndpoint : "0.0.0.0:8080" ,
261
- scopeSuffix : "8080" ,
262
- }, "simple_annotation_case_with_invalid_endpoint" : {
263
- hintsAnn : map [string ]string {
264
- "io.opentelemetry.discovery.metrics/enabled" : "true" ,
265
- "io.opentelemetry.discovery.metrics/config" : config ,
266
- }, expectedConf : userConfigMap {},
267
- defaultEndpoint : "1.2.3.4:8080" ,
268
- scopeSuffix : "" ,
269
- expectError : true ,
270
- },
238
+ }{
239
+ "simple_annotation_case" : {
240
+ hintsAnn : map [string ]string {
241
+ "io.opentelemetry.discovery.metrics/enabled" : "true" ,
242
+ "io.opentelemetry.discovery.metrics/config" : config ,
243
+ }, expectedConf : userConfigMap {
244
+ "collection_interval" : "20s" ,
245
+ "endpoint" : "0.0.0.0:8080" ,
246
+ "initial_delay" : "20s" ,
247
+ "read_buffer_size" : "10" ,
248
+ "nested_example" : userConfigMap {"foo" : "bar" },
249
+ }, defaultEndpoint : "0.0.0.0:8080" ,
250
+ scopeSuffix : "" ,
251
+ }, "simple_annotation_case_default_endpoint" : {
252
+ hintsAnn : map [string ]string {
253
+ "io.opentelemetry.discovery.metrics/enabled" : "true" ,
254
+ "io.opentelemetry.discovery.metrics/config" : configNoEndpoint ,
255
+ }, expectedConf : userConfigMap {
256
+ "collection_interval" : "20s" ,
257
+ "endpoint" : "1.1.1.1:8080" ,
258
+ "initial_delay" : "20s" ,
259
+ "read_buffer_size" : "10" ,
260
+ "nested_example" : userConfigMap {"foo" : "bar" },
261
+ }, defaultEndpoint : "1.1.1.1:8080" ,
262
+ scopeSuffix : "" ,
263
+ }, "simple_annotation_case_scoped" : {
264
+ hintsAnn : map [string ]string {
265
+ "io.opentelemetry.discovery.metrics.8080/enabled" : "true" ,
266
+ "io.opentelemetry.discovery.metrics.8080/config" : config ,
267
+ }, expectedConf : userConfigMap {
268
+ "collection_interval" : "20s" ,
269
+ "endpoint" : "0.0.0.0:8080" ,
270
+ "initial_delay" : "20s" ,
271
+ "read_buffer_size" : "10" ,
272
+ "nested_example" : userConfigMap {"foo" : "bar" },
273
+ }, defaultEndpoint : "0.0.0.0:8080" ,
274
+ scopeSuffix : "8080" ,
275
+ }, "simple_annotation_case_with_invalid_endpoint" : {
276
+ hintsAnn : map [string ]string {
277
+ "io.opentelemetry.discovery.metrics/enabled" : "true" ,
278
+ "io.opentelemetry.discovery.metrics/config" : config ,
279
+ }, expectedConf : userConfigMap {},
280
+ defaultEndpoint : "1.2.3.4:8080" ,
281
+ scopeSuffix : "" ,
282
+ expectError : true ,
283
+ },
271
284
}
272
285
273
286
for name , test := range tests {
@@ -287,7 +300,7 @@ nested_example:
287
300
}
288
301
289
302
func TestDiscoveryMetricsEnabled (t * testing.T ) {
290
- var config = `
303
+ config : = `
291
304
endpoint: "0.0.0.0:8080"`
292
305
tests := map [string ]struct {
293
306
hintsAnn map [string ]string
@@ -346,6 +359,11 @@ func TestValidateEndpoint(t *testing.T) {
346
359
defaultEndpoint : "1.2.3.4:8080" ,
347
360
expectError : false ,
348
361
},
362
+ "test_invalid" : {
363
+ endpoint : "http://0.0.0.0:8080/some?foo=1.2.3.4:8080" ,
364
+ defaultEndpoint : "1.2.3.4:8080" ,
365
+ expectError : true ,
366
+ },
349
367
"test_valid_no_scheme" : {
350
368
endpoint : "1.2.3.4:8080/stats" ,
351
369
defaultEndpoint : "1.2.3.4:8080" ,
0 commit comments