@@ -60,6 +60,7 @@ func TestLoadConfig(t *testing.T) {
60
60
61
61
expectedDimensionClients := []string {"nop/one" , "nop/two" }
62
62
require .Equal (t , & Config {
63
+ MonitorType : "haproxy" ,
63
64
DimensionClients : expectedDimensionClients ,
64
65
monitorConfig : & haproxy.Config {
65
66
MonitorConfig : saconfig.MonitorConfig {
@@ -83,6 +84,7 @@ func TestLoadConfig(t *testing.T) {
83
84
require .NoError (t , cm .Unmarshal (& redisCfg ))
84
85
85
86
require .Equal (t , & Config {
87
+ MonitorType : "collectd/redis" ,
86
88
DimensionClients : []string {},
87
89
monitorConfig : & redis.Config {
88
90
MonitorConfig : saconfig.MonitorConfig {
@@ -103,6 +105,7 @@ func TestLoadConfig(t *testing.T) {
103
105
require .NoError (t , cm .Unmarshal (& hadoopCfg ))
104
106
105
107
require .Equal (t , & Config {
108
+ MonitorType : "collectd/hadoop" ,
106
109
monitorConfig : & hadoop.Config {
107
110
MonitorConfig : saconfig.MonitorConfig {
108
111
Type : "collectd/hadoop" ,
@@ -123,6 +126,7 @@ func TestLoadConfig(t *testing.T) {
123
126
require .NoError (t , cm .Unmarshal (& etcdCfg ))
124
127
125
128
require .Equal (t , & Config {
129
+ MonitorType : "etcd" ,
126
130
monitorConfig : & prometheusexporter.Config {
127
131
MonitorConfig : saconfig.MonitorConfig {
128
132
Type : "etcd" ,
@@ -147,6 +151,7 @@ func TestLoadConfig(t *testing.T) {
147
151
ntpqCfg := CreateDefaultConfig ().(* Config )
148
152
require .NoError (t , cm .Unmarshal (& ntpqCfg ))
149
153
require .Equal (t , & Config {
154
+ MonitorType : "telegraf/ntpq" ,
150
155
monitorConfig : & ntpq.Config {
151
156
MonitorConfig : saconfig.MonitorConfig {
152
157
Type : "telegraf/ntpq" ,
@@ -167,6 +172,8 @@ func TestLoadInvalidConfigWithoutType(t *testing.T) {
167
172
require .NoError (t , err )
168
173
withoutType := CreateDefaultConfig ().(* Config )
169
174
err = cm .Unmarshal (& withoutType )
175
+ require .NoError (t , err )
176
+ err = withoutType .validate ()
170
177
require .Error (t , err )
171
178
require .ErrorContains (t , err ,
172
179
`you must specify a "type" for a smartagent receiver` )
@@ -208,6 +215,7 @@ func TestLoadInvalidConfigs(t *testing.T) {
208
215
negativeIntervalCfg := CreateDefaultConfig ().(* Config )
209
216
require .NoError (t , cm .Unmarshal (& negativeIntervalCfg ))
210
217
require .Equal (t , & Config {
218
+ MonitorType : "collectd/redis" ,
211
219
monitorConfig : & redis.Config {
212
220
MonitorConfig : saconfig.MonitorConfig {
213
221
Type : "collectd/redis" ,
@@ -226,6 +234,7 @@ func TestLoadInvalidConfigs(t *testing.T) {
226
234
missingRequiredCfg := CreateDefaultConfig ().(* Config )
227
235
require .NoError (t , cm .Unmarshal (& missingRequiredCfg ))
228
236
require .Equal (t , & Config {
237
+ MonitorType : "collectd/consul" ,
229
238
monitorConfig : & consul.Config {
230
239
MonitorConfig : saconfig.MonitorConfig {
231
240
Type : "collectd/consul" ,
@@ -256,7 +265,8 @@ func TestLoadConfigWithEndpoints(t *testing.T) {
256
265
haproxyCfg := CreateDefaultConfig ().(* Config )
257
266
require .NoError (t , cm .Unmarshal (& haproxyCfg ))
258
267
require .Equal (t , & Config {
259
- Endpoint : "[fe80::20c:29ff:fe59:9446]:2345" ,
268
+ MonitorType : "haproxy" ,
269
+ Endpoint : "[fe80::20c:29ff:fe59:9446]:2345" ,
260
270
monitorConfig : & haproxy.Config {
261
271
MonitorConfig : saconfig.MonitorConfig {
262
272
Type : "haproxy" ,
@@ -280,7 +290,8 @@ func TestLoadConfigWithEndpoints(t *testing.T) {
280
290
redisCfg := CreateDefaultConfig ().(* Config )
281
291
require .NoError (t , cm .Unmarshal (& redisCfg ))
282
292
require .Equal (t , & Config {
283
- Endpoint : "redishost" ,
293
+ MonitorType : "collectd/redis" ,
294
+ Endpoint : "redishost" ,
284
295
monitorConfig : & redis.Config {
285
296
MonitorConfig : saconfig.MonitorConfig {
286
297
Type : "collectd/redis" ,
@@ -299,7 +310,8 @@ func TestLoadConfigWithEndpoints(t *testing.T) {
299
310
hadoopCfg := CreateDefaultConfig ().(* Config )
300
311
require .NoError (t , cm .Unmarshal (& hadoopCfg ))
301
312
require .Equal (t , & Config {
302
- Endpoint : "[::]:12345" ,
313
+ MonitorType : "collectd/hadoop" ,
314
+ Endpoint : "[::]:12345" ,
303
315
monitorConfig : & hadoop.Config {
304
316
MonitorConfig : saconfig.MonitorConfig {
305
317
Type : "collectd/hadoop" ,
@@ -319,7 +331,8 @@ func TestLoadConfigWithEndpoints(t *testing.T) {
319
331
etcdCfg := CreateDefaultConfig ().(* Config )
320
332
require .NoError (t , cm .Unmarshal (& etcdCfg ))
321
333
require .Equal (t , & Config {
322
- Endpoint : "etcdhost:5555" ,
334
+ MonitorType : "etcd" ,
335
+ Endpoint : "etcdhost:5555" ,
323
336
monitorConfig : & prometheusexporter.Config {
324
337
MonitorConfig : saconfig.MonitorConfig {
325
338
Type : "etcd" ,
@@ -344,7 +357,8 @@ func TestLoadConfigWithEndpoints(t *testing.T) {
344
357
require .NoError (t , cm .Unmarshal (& elasticCfg ))
345
358
tru := true
346
359
require .Equal (t , & Config {
347
- Endpoint : "elastic:567" ,
360
+ MonitorType : "elasticsearch" ,
361
+ Endpoint : "elastic:567" ,
348
362
monitorConfig : & stats.Config {
349
363
MonitorConfig : saconfig.MonitorConfig {
350
364
Type : "elasticsearch" ,
@@ -373,7 +387,8 @@ func TestLoadConfigWithEndpoints(t *testing.T) {
373
387
kubeletCfg := CreateDefaultConfig ().(* Config )
374
388
require .NoError (t , cm .Unmarshal (& kubeletCfg ))
375
389
require .Equal (t , & Config {
376
- Endpoint : "disregarded:678" ,
390
+ MonitorType : "kubelet-stats" ,
391
+ Endpoint : "disregarded:678" ,
377
392
monitorConfig : & cadvisor.KubeletStatsConfig {
378
393
MonitorConfig : saconfig.MonitorConfig {
379
394
Type : "kubelet-stats" ,
@@ -415,7 +430,8 @@ func TestLoadConfigWithUnsupportedEndpoint(t *testing.T) {
415
430
require .NoError (t , cm .Unmarshal (& nagiosCfg ))
416
431
417
432
require .Equal (t , & Config {
418
- Endpoint : "localhost:12345" ,
433
+ MonitorType : "nagios" ,
434
+ Endpoint : "localhost:12345" ,
419
435
monitorConfig : & nagios.Config {
420
436
MonitorConfig : saconfig.MonitorConfig {
421
437
Type : "nagios" ,
@@ -437,9 +453,24 @@ func TestLoadInvalidConfigWithNonArrayDimensionClients(t *testing.T) {
437
453
require .NoError (t , err )
438
454
haproxyCfg := CreateDefaultConfig ().(* Config )
439
455
err = cm .Unmarshal (& haproxyCfg )
440
- require .Error (t , err )
441
- require .ErrorContains (t , err ,
442
- `dimensionClients must be an array of compatible exporter names` )
456
+ require .NoError (t , err )
457
+ require .Equal (t , & Config {
458
+ MonitorType : "haproxy" ,
459
+ DimensionClients : []string {"notanarray" },
460
+ monitorConfig : & haproxy.Config {
461
+ MonitorConfig : saconfig.MonitorConfig {
462
+ Type : "haproxy" ,
463
+ DatapointsToExclude : []saconfig.MetricFilter {},
464
+ IntervalSeconds : 123 ,
465
+ },
466
+ Username : "SomeUser" ,
467
+ Password : "secret" ,
468
+ Path : "stats?stats;csv" ,
469
+ SSLVerify : true ,
470
+ Timeout : 5000000000 ,
471
+ },
472
+ acceptsEndpoints : true ,
473
+ }, haproxyCfg )
443
474
}
444
475
445
476
func TestLoadInvalidConfigWithNonStringArrayDimensionClients (t * testing.T ) {
@@ -450,8 +481,7 @@ func TestLoadInvalidConfigWithNonStringArrayDimensionClients(t *testing.T) {
450
481
haproxyCfg := CreateDefaultConfig ().(* Config )
451
482
err = cm .Unmarshal (& haproxyCfg )
452
483
require .Error (t , err )
453
- require .ErrorContains (t , err ,
454
- `dimensionClients must be an array of compatible exporter names` )
484
+ require .ErrorContains (t , err , `expected type 'string'` )
455
485
}
456
486
457
487
func TestFilteringConfig (t * testing.T ) {
@@ -465,6 +495,7 @@ func TestFilteringConfig(t *testing.T) {
465
495
require .NoError (t , cm .Unmarshal (& fsCfg ))
466
496
467
497
require .Equal (t , & Config {
498
+ MonitorType : "filesystems" ,
468
499
monitorConfig : & filesystems.Config {
469
500
MonitorConfig : saconfig.MonitorConfig {
470
501
Type : "filesystems" ,
@@ -495,6 +526,7 @@ func TestInvalidFilteringConfig(t *testing.T) {
495
526
fsCfg := CreateDefaultConfig ().(* Config )
496
527
require .NoError (t , cm .Unmarshal (& fsCfg ))
497
528
require .Equal (t , & Config {
529
+ MonitorType : "filesystems" ,
498
530
monitorConfig : & filesystems.Config {
499
531
MonitorConfig : saconfig.MonitorConfig {
500
532
Type : "filesystems" ,
@@ -525,6 +557,7 @@ func TestLoadConfigWithNestedMonitorConfig(t *testing.T) {
525
557
telegrafExecCfg := CreateDefaultConfig ().(* Config )
526
558
require .NoError (t , cm .Unmarshal (& telegrafExecCfg ))
527
559
require .Equal (t , & Config {
560
+ MonitorType : "telegraf/exec" ,
528
561
monitorConfig : & exec.Config {
529
562
MonitorConfig : saconfig.MonitorConfig {
530
563
Type : "telegraf/exec" ,
@@ -547,6 +580,7 @@ func TestLoadConfigWithNestedMonitorConfig(t *testing.T) {
547
580
require .NoError (t , cm .Unmarshal (& k8sVolumesCfg ))
548
581
tru := true
549
582
require .Equal (t , & Config {
583
+ MonitorType : "kubernetes-volumes" ,
550
584
monitorConfig : & volumes.Config {
551
585
MonitorConfig : saconfig.MonitorConfig {
552
586
Type : "kubernetes-volumes" ,
0 commit comments