@@ -232,7 +232,9 @@ func (oc *Collector) bootup(ctx context.Context) error {
232232 return
233233 }
234234
235- oc .setProxyIfNeeded (ctx )
235+ if oc .config .IsCommandServerProxyConfigured () {
236+ oc .setProxyIfNeeded (ctx )
237+ }
236238
237239 appErr := oc .service .Run (ctx )
238240 if appErr != nil {
@@ -392,7 +394,10 @@ func (oc *Collector) restartCollector(ctx context.Context) {
392394 if ! oc .tryCreateCollector (ctx ) {
393395 return
394396 }
395- oc .setProxyIfNeeded (ctx )
397+
398+ if oc .config .IsCommandServerProxyConfigured () {
399+ oc .setProxyIfNeeded (ctx )
400+ }
396401 var runCtx context.Context
397402 runCtx , oc .cancel = context .WithCancel (ctx )
398403 if ! oc .stopped {
@@ -778,29 +783,17 @@ func escapeString(input string) string {
778783}
779784
780785func (oc * Collector ) setExporterProxyEnvVars (ctx context.Context ) {
781- // Validate proxy fields
782- if oc .config .Command .Server .Proxy == nil {
783- slog .InfoContext (ctx , "Proxy configuration is not setup; skipping Proxy setup" )
784- return
785- }
786-
787786 proxy := oc .config .Command .Server .Proxy
788- if proxy .URL == "" {
789- slog .WarnContext (ctx , "Proxy URL is empty; skipping Proxy setup" )
790- return
791- }
792787 proxyURL := proxy .URL
793- u , err := url .Parse (proxyURL )
788+ parsedProxyURL , err := url .Parse (proxyURL )
794789 if err != nil {
795790 slog .ErrorContext (ctx , "Malformed proxy URL; skipping Proxy setup" , "url" , proxyURL , "error" , err )
796791 return
797792 }
798793
799794 auth := ""
800- if oc .config .Command .Server .Proxy .AuthMethod != "" &&
801- strings .TrimSpace (oc .config .Command .Server .Proxy .AuthMethod ) != "" {
802- auth = strings .TrimSpace (oc .config .Command .Server .Proxy .AuthMethod )
803- slog .DebugContext (ctx , "auth string" , "auth" , auth )
795+ if proxy .AuthMethod != "" && strings .TrimSpace (proxy .AuthMethod ) != "" {
796+ auth = strings .TrimSpace (proxy .AuthMethod )
804797 }
805798
806799 // Use the standalone setProxyWithBasicAuth function
@@ -809,9 +802,8 @@ func (oc *Collector) setExporterProxyEnvVars(ctx context.Context) {
809802 return
810803 }
811804 authLower := strings .ToLower (auth )
812- slog .DebugContext (ctx , "auth To Lower string" , "authlower" , authLower )
813805 if authLower == "basic" {
814- setProxyWithBasicAuth (ctx , proxy , u )
806+ setProxyWithBasicAuth (ctx , proxy , parsedProxyURL )
815807 } else {
816808 slog .ErrorContext (ctx , "Unknown auth type for proxy; Aborting Proxy Setup" , "auth" , auth , "url" , proxyURL )
817809 }
@@ -829,14 +821,14 @@ func setProxyEnvs(ctx context.Context, proxyEnvURL, msg string) {
829821}
830822
831823// setProxyWithBasicAuth sets the proxy environment variables with basic auth credentials.
832- func setProxyWithBasicAuth (ctx context.Context , proxy * config.Proxy , u * url.URL ) {
824+ func setProxyWithBasicAuth (ctx context.Context , proxy * config.Proxy , parsedProxyURL * url.URL ) {
833825 username := proxy .Username
834826 password := proxy .Password
835827 if username == "" || password == "" {
836828 slog .ErrorContext (ctx , "Username or password missing for basic auth" )
837829 return
838830 }
839- u .User = url .UserPassword (username , password )
840- proxyURL := u .String ()
831+ parsedProxyURL .User = url .UserPassword (username , password )
832+ proxyURL := parsedProxyURL .String ()
841833 setProxyEnvs (ctx , proxyURL , "Setting Proxy with basic auth" )
842834}
0 commit comments