@@ -39,10 +39,6 @@ func TestRegisterConfigFile(t *testing.T) {
3939}
4040
4141func TestResolveConfig (t * testing.T ) {
42- allowedDir := []string {
43- "/etc/nginx" , "/usr/local/etc/nginx" , "/var/run/nginx" ,
44- "/usr/share/nginx/modules" , "/var/log/nginx" ,
45- }
4642 viperInstance = viper .NewWithOptions (viper .KeyDelimiter (KeyDelimiter ))
4743 err := loadPropertiesFromFile ("./testdata/nginx-agent.conf" )
4844 require .NoError (t , err )
@@ -57,50 +53,7 @@ func TestResolveConfig(t *testing.T) {
5753
5854 actual , err := ResolveConfig ()
5955 require .NoError (t , err )
60-
61- assert .Equal (t , "debug" , actual .Log .Level )
62- assert .Equal (t , "./" , actual .Log .Path )
63-
64- assert .Equal (t , 30 * time .Second , actual .DataPlaneConfig .Nginx .ReloadMonitoringPeriod )
65- assert .False (t , actual .DataPlaneConfig .Nginx .TreatWarningsAsErrors )
66- assert .Equal (t , []string {"/var/log/nginx/error.log" , "/var/log/nginx/access.log" },
67- actual .DataPlaneConfig .Nginx .ExcludeLogs )
68-
69- require .NotNil (t , actual .Collector )
70- assert .Equal (t , "/etc/nginx-agent/nginx-agent-otelcol.yaml" , actual .Collector .ConfigPath )
71- assert .NotEmpty (t , actual .Collector .Receivers )
72- assert .Equal (t , Processors {Batch : & Batch {}}, actual .Collector .Processors )
73- assert .NotEmpty (t , actual .Collector .Exporters )
74- assert .NotEmpty (t , actual .Collector .Extensions )
75-
76- // Client GRPC Settings
77- assert .Equal (t , 15 * time .Second , actual .Client .Grpc .KeepAlive .Timeout )
78- assert .Equal (t , 10 * time .Second , actual .Client .Grpc .KeepAlive .Time )
79- assert .False (t , actual .Client .Grpc .KeepAlive .PermitWithoutStream )
80- assert .Equal (t , 1048575 , actual .Client .Grpc .MaxMessageSize )
81- assert .Equal (t , 1048575 , actual .Client .Grpc .MaxMessageReceiveSize )
82- assert .Equal (t , 1048575 , actual .Client .Grpc .MaxMessageSendSize )
83-
84- // Client HTTP Settings
85- assert .Equal (t , 15 * time .Second , actual .Client .HTTP .Timeout )
86-
87- // Client Backoff Settings
88- assert .Equal (t , 200 * time .Millisecond , actual .Client .Backoff .InitialInterval )
89- assert .Equal (t , 10 * time .Second , actual .Client .Backoff .MaxInterval )
90- assert .Equal (t , 25 * time .Second , actual .Client .Backoff .MaxElapsedTime )
91- assert .InDelta (t , 1.5 , actual .Client .Backoff .RandomizationFactor , 0.01 )
92- assert .InDelta (t , 2.5 , actual .Client .Backoff .Multiplier , 0.01 )
93-
94- assert .Equal (t ,
95- allowedDir ,
96- actual .AllowedDirectories ,
97- )
98-
99- assert .Equal (t , allowedDir , actual .AllowedDirectories )
100-
101- assert .Equal (t , 5 * time .Second , actual .Watchers .InstanceWatcher .MonitoringFrequency )
102- assert .Equal (t , 5 * time .Second , actual .Watchers .InstanceHealthWatcher .MonitoringFrequency )
103- assert .Equal (t , 5 * time .Second , actual .Watchers .FileWatcher .MonitoringFrequency )
56+ assert .Equal (t , createConfig (), actual )
10457}
10558
10659func TestSetVersion (t * testing.T ) {
@@ -462,3 +415,206 @@ func getAgentConfig() *Config {
462415 },
463416 }
464417}
418+
419+ func createConfig () * Config {
420+ return & Config {
421+ Log : & Log {
422+ Level : "debug" ,
423+ Path : "./test-path" ,
424+ },
425+ Client : & Client {
426+ HTTP : & HTTP {
427+ Timeout : 15 * time .Second ,
428+ },
429+ Grpc : & GRPC {
430+ KeepAlive : & KeepAlive {
431+ Timeout : 15 * time .Second ,
432+ Time : 10 * time .Second ,
433+ PermitWithoutStream : false ,
434+ },
435+ MaxMessageSize : 1048575 ,
436+ MaxMessageReceiveSize : 1048575 ,
437+ MaxMessageSendSize : 1048575 ,
438+ },
439+ Backoff : & BackOff {
440+ InitialInterval : 200 * time .Millisecond ,
441+ MaxInterval : 10 * time .Second ,
442+ MaxElapsedTime : 25 * time .Second ,
443+ RandomizationFactor : 1.5 ,
444+ Multiplier : 2.5 ,
445+ },
446+ },
447+ AllowedDirectories : []string {
448+ "/etc/nginx" , "/usr/local/etc/nginx" , "/var/run/nginx" , "/usr/share/nginx/modules" , "/var/log/nginx" ,
449+ },
450+ DataPlaneConfig : & DataPlaneConfig {
451+ Nginx : & NginxDataPlaneConfig {
452+ ExcludeLogs : []string {"/var/log/nginx/error.log" , "/var/log/nginx/access.log" },
453+ ReloadMonitoringPeriod : 30 * time .Second ,
454+ TreatWarningsAsErrors : true ,
455+ },
456+ },
457+ Collector : & Collector {
458+ ConfigPath : "/etc/nginx-agent/nginx-agent-otelcol.yaml" ,
459+ Exporters : Exporters {
460+ OtlpExporters : []OtlpExporter {
461+ {
462+ Server : & ServerConfig {
463+ Host : "127.0.0.1" ,
464+ Port : 5643 ,
465+ Type : 0 ,
466+ },
467+ Authenticator : "test-saas-token" ,
468+ TLS : & TLSConfig {
469+ Cert : "/path/to/server-cert.pem" ,
470+ Key : "/path/to/server-key.pem" ,
471+ Ca : "/path/to/server-cert.pem" ,
472+ SkipVerify : false ,
473+ ServerName : "test-saas-server" ,
474+ },
475+ },
476+ },
477+ PrometheusExporter : & PrometheusExporter {
478+ Server : & ServerConfig {
479+ Host : "127.0.0.1" ,
480+ Port : 1235 ,
481+ Type : 0 ,
482+ },
483+ TLS : & TLSConfig {
484+ Cert : "/path/to/server-cert.pem" ,
485+ Key : "/path/to/server-key.pem" ,
486+ Ca : "/path/to/server-cert.pem" ,
487+ SkipVerify : false ,
488+ ServerName : "test-server" ,
489+ },
490+ },
491+ Debug : & DebugExporter {},
492+ },
493+ Processors : Processors {
494+ Batch : & Batch {
495+ SendBatchMaxSize : 1 ,
496+ SendBatchSize : 8199 ,
497+ Timeout : 30 * time .Second ,
498+ },
499+ Attribute : & Attribute {
500+ Actions : []Action {
501+ {
502+ Key : "test" ,
503+ Action : "insert" ,
504+ Value : "value" ,
505+ },
506+ },
507+ },
508+ },
509+ Receivers : Receivers {
510+ OtlpReceivers : []OtlpReceiver {
511+ {
512+ Server : & ServerConfig {
513+ Host : "127.0.0.1" ,
514+ Port : 4317 ,
515+ Type : 0 ,
516+ },
517+ Auth : & AuthConfig {
518+ Token : "secret-receiver-token" ,
519+ },
520+ OtlpTLSConfig : & OtlpTLSConfig {
521+ GenerateSelfSignedCert : false ,
522+ Cert : "/tmp/cert.pem" ,
523+ Key : "/tmp/key.pem" ,
524+ Ca : "/tmp/ca.pem" ,
525+ SkipVerify : true ,
526+ ServerName : "test-local-server" ,
527+ },
528+ },
529+ },
530+ NginxReceivers : []NginxReceiver {
531+ {
532+ InstanceID : "cd7b8911-c2c5-4daf-b311-dbead151d938" ,
533+ AccessLogs : []AccessLog {
534+ {
535+ LogFormat : "$remote_addr - $remote_user [$time_local] \" $request\" " +
536+ " $status $body_bytes_sent \" $http_referer\" \" $http_user_agent\" " +
537+ "\" $http_x_forwarded_for\" " ,
538+ FilePath : "/var/log/nginx/access-custom.conf" ,
539+ },
540+ },
541+ },
542+ },
543+ NginxPlusReceivers : []NginxPlusReceiver {
544+ {
545+ InstanceID : "cd7b8911-c2c5-4daf-b311-dbead151d939" ,
546+ },
547+ },
548+ HostMetrics : & HostMetrics {
549+ CollectionInterval : 10 * time .Second ,
550+ InitialDelay : 2 * time .Second ,
551+ Scrapers : & HostMetricsScrapers {
552+ CPU : & CPUScraper {},
553+ Disk : nil ,
554+ Filesystem : nil ,
555+ Memory : nil ,
556+ Network : nil ,
557+ },
558+ },
559+ },
560+ Extensions : Extensions {
561+ Health : & Health {
562+ Server : & ServerConfig {
563+ Host : "127.0.0.1" ,
564+ Port : 1337 ,
565+ Type : 0 ,
566+ },
567+ TLS : & TLSConfig {
568+ Cert : "/path/to/server-cert.pem" ,
569+ Key : "/path/to/server-key.pem" ,
570+ Ca : "/path/to/server-ca.pem" ,
571+ SkipVerify : false ,
572+ ServerName : "server-name" ,
573+ },
574+ Path : "/test" ,
575+ },
576+ HeadersSetter : & HeadersSetter {
577+ Headers : []Header {
578+ {
579+ Action : "action" ,
580+ Key : "key" ,
581+ Value : "value" ,
582+ },
583+ },
584+ },
585+ },
586+ Log : & Log {
587+ Level : "INFO" ,
588+ Path : "/var/log/nginx-agent/opentelemetry-collector-agent.log" ,
589+ },
590+ },
591+ Command : & Command {
592+ Server : & ServerConfig {
593+ Host : "127.0.0.1" ,
594+ Port : 8888 ,
595+ Type : Grpc ,
596+ },
597+ Auth : & AuthConfig {
598+ Token : "1234" ,
599+ },
600+ TLS : & TLSConfig {
601+ Cert : "some.cert" ,
602+ Key : "some.key" ,
603+ Ca : "some.ca" ,
604+ SkipVerify : false ,
605+ ServerName : "server-name" ,
606+ },
607+ },
608+ Watchers : & Watchers {
609+ InstanceWatcher : InstanceWatcher {
610+ MonitoringFrequency : 10 * time .Second ,
611+ },
612+ InstanceHealthWatcher : InstanceHealthWatcher {
613+ MonitoringFrequency : 10 * time .Second ,
614+ },
615+ FileWatcher : FileWatcher {
616+ MonitoringFrequency : 10 * time .Second ,
617+ },
618+ },
619+ }
620+ }
0 commit comments