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