@@ -40,10 +40,6 @@ func TestRegisterConfigFile(t *testing.T) {
4040}
4141
4242func TestResolveConfig (t * testing.T ) {
43- allowedDir := []string {
44- "/etc/nginx" , "/usr/local/etc/nginx" , "/var/run/nginx" ,
45- "/usr/share/nginx/modules" , "/var/log/nginx" ,
46- }
4743 viperInstance = viper .NewWithOptions (viper .KeyDelimiter (KeyDelimiter ))
4844 err := loadPropertiesFromFile ("./testdata/nginx-agent.conf" )
4945 require .NoError (t , err )
@@ -58,50 +54,7 @@ func TestResolveConfig(t *testing.T) {
5854
5955 actual , err := ResolveConfig ()
6056 require .NoError (t , err )
61-
62- assert .Equal (t , "debug" , actual .Log .Level )
63- assert .Equal (t , "./" , actual .Log .Path )
64-
65- assert .Equal (t , 30 * time .Second , actual .DataPlaneConfig .Nginx .ReloadMonitoringPeriod )
66- assert .False (t , actual .DataPlaneConfig .Nginx .TreatWarningsAsErrors )
67- assert .Equal (t , []string {"/var/log/nginx/error.log" , "/var/log/nginx/access.log" },
68- actual .DataPlaneConfig .Nginx .ExcludeLogs )
69-
70- require .NotNil (t , actual .Collector )
71- assert .Equal (t , "/etc/nginx-agent/nginx-agent-otelcol.yaml" , actual .Collector .ConfigPath )
72- assert .NotEmpty (t , actual .Collector .Receivers )
73- assert .Equal (t , Processors {Batch : & Batch {}}, actual .Collector .Processors )
74- assert .NotEmpty (t , actual .Collector .Exporters )
75- assert .NotEmpty (t , actual .Collector .Extensions )
76-
77- // Client GRPC Settings
78- assert .Equal (t , 15 * time .Second , actual .Client .Grpc .KeepAlive .Timeout )
79- assert .Equal (t , 10 * time .Second , actual .Client .Grpc .KeepAlive .Time )
80- assert .False (t , actual .Client .Grpc .KeepAlive .PermitWithoutStream )
81- assert .Equal (t , 1048575 , actual .Client .Grpc .MaxMessageSize )
82- assert .Equal (t , 1048575 , actual .Client .Grpc .MaxMessageReceiveSize )
83- assert .Equal (t , 1048575 , actual .Client .Grpc .MaxMessageSendSize )
84-
85- // Client HTTP Settings
86- assert .Equal (t , 15 * time .Second , actual .Client .HTTP .Timeout )
87-
88- // Client Backoff Settings
89- assert .Equal (t , 200 * time .Millisecond , actual .Client .Backoff .InitialInterval )
90- assert .Equal (t , 10 * time .Second , actual .Client .Backoff .MaxInterval )
91- assert .Equal (t , 25 * time .Second , actual .Client .Backoff .MaxElapsedTime )
92- assert .InDelta (t , 1.5 , actual .Client .Backoff .RandomizationFactor , 0.01 )
93- assert .InDelta (t , 2.5 , actual .Client .Backoff .Multiplier , 0.01 )
94-
95- assert .Equal (t ,
96- allowedDir ,
97- actual .AllowedDirectories ,
98- )
99-
100- assert .Equal (t , allowedDir , actual .AllowedDirectories )
101-
102- assert .Equal (t , 5 * time .Second , actual .Watchers .InstanceWatcher .MonitoringFrequency )
103- assert .Equal (t , 5 * time .Second , actual .Watchers .InstanceHealthWatcher .MonitoringFrequency )
104- assert .Equal (t , 5 * time .Second , actual .Watchers .FileWatcher .MonitoringFrequency )
57+ assert .Equal (t , createConfig (), actual )
10558}
10659
10760func TestSetVersion (t * testing.T ) {
@@ -179,7 +132,7 @@ func TestLoadPropertiesFromFile(t *testing.T) {
179132 require .NoError (t , err )
180133
181134 assert .Equal (t , "debug" , viperInstance .GetString (LogLevelKey ))
182- assert .Equal (t , "./" , viperInstance .GetString (LogPathKey ))
135+ assert .Equal (t , "./test-path " , viperInstance .GetString (LogPathKey ))
183136
184137 assert .Equal (t , 15 * time .Second , viperInstance .GetDuration (ClientKeepAliveTimeoutKey ))
185138
@@ -772,3 +725,207 @@ func getAgentConfig() *Config {
772725 Labels : make (map [string ]any ),
773726 }
774727}
728+
729+ func createConfig () * Config {
730+ return & Config {
731+ Log : & Log {
732+ Level : "debug" ,
733+ Path : "./test-path" ,
734+ },
735+ Client : & Client {
736+ HTTP : & HTTP {
737+ Timeout : 15 * time .Second ,
738+ },
739+ Grpc : & GRPC {
740+ KeepAlive : & KeepAlive {
741+ Timeout : 15 * time .Second ,
742+ Time : 10 * time .Second ,
743+ PermitWithoutStream : false ,
744+ },
745+ MaxMessageSize : 1048575 ,
746+ MaxMessageReceiveSize : 1048575 ,
747+ MaxMessageSendSize : 1048575 ,
748+ },
749+ Backoff : & BackOff {
750+ InitialInterval : 200 * time .Millisecond ,
751+ MaxInterval : 10 * time .Second ,
752+ MaxElapsedTime : 25 * time .Second ,
753+ RandomizationFactor : 1.5 ,
754+ Multiplier : 2.5 ,
755+ },
756+ },
757+ AllowedDirectories : []string {
758+ "/etc/nginx" , "/usr/local/etc/nginx" , "/var/run/nginx" , "/usr/share/nginx/modules" , "/var/log/nginx" ,
759+ },
760+ DataPlaneConfig : & DataPlaneConfig {
761+ Nginx : & NginxDataPlaneConfig {
762+ ExcludeLogs : []string {"/var/log/nginx/error.log" , "/var/log/nginx/access.log" },
763+ ReloadMonitoringPeriod : 30 * time .Second ,
764+ TreatWarningsAsErrors : true ,
765+ },
766+ },
767+ Collector : & Collector {
768+ ConfigPath : "/etc/nginx-agent/nginx-agent-otelcol.yaml" ,
769+ Exporters : Exporters {
770+ OtlpExporters : []OtlpExporter {
771+ {
772+ Server : & ServerConfig {
773+ Host : "127.0.0.1" ,
774+ Port : 5643 ,
775+ },
776+ Authenticator : "test-saas-token" ,
777+ TLS : & TLSConfig {
778+ Cert : "/path/to/server-cert.pem" ,
779+ Key : "/path/to/server-key.pem" ,
780+ Ca : "/path/to/server-cert.pem" ,
781+ SkipVerify : false ,
782+ ServerName : "test-saas-server" ,
783+ },
784+ },
785+ },
786+ PrometheusExporter : & PrometheusExporter {
787+ Server : & ServerConfig {
788+ Host : "127.0.0.1" ,
789+ Port : 1235 ,
790+ },
791+ TLS : & TLSConfig {
792+ Cert : "/path/to/server-cert.pem" ,
793+ Key : "/path/to/server-key.pem" ,
794+ Ca : "/path/to/server-cert.pem" ,
795+ SkipVerify : false ,
796+ ServerName : "test-server" ,
797+ },
798+ },
799+ Debug : & DebugExporter {},
800+ },
801+ Processors : Processors {
802+ Batch : & Batch {
803+ SendBatchMaxSize : 1 ,
804+ SendBatchSize : 8199 ,
805+ Timeout : 30 * time .Second ,
806+ },
807+ Attribute : & Attribute {
808+ Actions : []Action {
809+ {
810+ Key : "test" ,
811+ Action : "insert" ,
812+ Value : "value" ,
813+ },
814+ },
815+ },
816+ },
817+ Receivers : Receivers {
818+ OtlpReceivers : []OtlpReceiver {
819+ {
820+ Server : & ServerConfig {
821+ Host : "127.0.0.1" ,
822+ Port : 4317 ,
823+ },
824+ Auth : & AuthConfig {
825+ Token : "secret-receiver-token" ,
826+ },
827+ OtlpTLSConfig : & OtlpTLSConfig {
828+ GenerateSelfSignedCert : false ,
829+ Cert : "/tmp/cert.pem" ,
830+ Key : "/tmp/key.pem" ,
831+ Ca : "/tmp/ca.pem" ,
832+ SkipVerify : true ,
833+ ServerName : "test-local-server" ,
834+ },
835+ },
836+ },
837+ NginxReceivers : []NginxReceiver {
838+ {
839+ InstanceID : "cd7b8911-c2c5-4daf-b311-dbead151d938" ,
840+ AccessLogs : []AccessLog {
841+ {
842+ LogFormat : "$remote_addr - $remote_user [$time_local] \" $request\" " +
843+ " $status $body_bytes_sent \" $http_referer\" \" $http_user_agent\" " +
844+ "\" $http_x_forwarded_for\" " ,
845+ FilePath : "/var/log/nginx/access-custom.conf" ,
846+ },
847+ },
848+ },
849+ },
850+ NginxPlusReceivers : []NginxPlusReceiver {
851+ {
852+ InstanceID : "cd7b8911-c2c5-4daf-b311-dbead151d939" ,
853+ },
854+ },
855+ HostMetrics : & HostMetrics {
856+ CollectionInterval : 10 * time .Second ,
857+ InitialDelay : 2 * time .Second ,
858+ Scrapers : & HostMetricsScrapers {
859+ CPU : & CPUScraper {},
860+ Disk : nil ,
861+ Filesystem : nil ,
862+ Memory : nil ,
863+ Network : nil ,
864+ },
865+ },
866+ },
867+ Extensions : Extensions {
868+ Health : & Health {
869+ Server : & ServerConfig {
870+ Host : "127.0.0.1" ,
871+ Port : 1337 ,
872+ },
873+ TLS : & TLSConfig {
874+ Cert : "/path/to/server-cert.pem" ,
875+ Key : "/path/to/server-key.pem" ,
876+ Ca : "/path/to/server-ca.pem" ,
877+ SkipVerify : false ,
878+ ServerName : "server-name" ,
879+ },
880+ Path : "/test" ,
881+ },
882+ HeadersSetter : & HeadersSetter {
883+ Headers : []Header {
884+ {
885+ Action : "action" ,
886+ Key : "key" ,
887+ Value : "value" ,
888+ },
889+ },
890+ },
891+ },
892+ Log : & Log {
893+ Level : "INFO" ,
894+ Path : "/var/log/nginx-agent/opentelemetry-collector-agent.log" ,
895+ },
896+ },
897+ Command : & Command {
898+ Server : & ServerConfig {
899+ Host : "127.0.0.1" ,
900+ Port : 8888 ,
901+ Type : Grpc ,
902+ },
903+ Auth : & AuthConfig {
904+ Token : "1234" ,
905+ },
906+ TLS : & TLSConfig {
907+ Cert : "some.cert" ,
908+ Key : "some.key" ,
909+ Ca : "some.ca" ,
910+ SkipVerify : false ,
911+ ServerName : "server-name" ,
912+ },
913+ },
914+ Watchers : & Watchers {
915+ InstanceWatcher : InstanceWatcher {
916+ MonitoringFrequency : 10 * time .Second ,
917+ },
918+ InstanceHealthWatcher : InstanceHealthWatcher {
919+ MonitoringFrequency : 10 * time .Second ,
920+ },
921+ FileWatcher : FileWatcher {
922+ MonitoringFrequency : 10 * time .Second ,
923+ },
924+ },
925+ Labels : map [string ]any {
926+ "label1" : "label 1" ,
927+ "label2" : "new-value" ,
928+ "label3" : 123 ,
929+ },
930+ }
931+ }
0 commit comments