From a592ca2767d943e020d3b65e6df0c1b1df8ebb99 Mon Sep 17 00:00:00 2001 From: nitishfy Date: Tue, 24 Sep 2024 11:20:48 +0530 Subject: [PATCH] disable automaxprocs logging Signed-off-by: nitishfy fix lint checks Signed-off-by: nitishfy move maxprocs to main.go Signed-off-by: nitishfy move set auto max procs to a function Signed-off-by: nitishfy add info log Signed-off-by: nitishfy --- cmd/main.go | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/cmd/main.go b/cmd/main.go index e6c94c40f7c85..2618ec92d902f 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -1,13 +1,13 @@ package main import ( + log "github.com/sirupsen/logrus" + "go.uber.org/automaxprocs/maxprocs" "os" "path/filepath" "github.com/spf13/cobra" - _ "go.uber.org/automaxprocs" - appcontroller "github.com/argoproj/argo-cd/v2/cmd/argocd-application-controller/commands" applicationset "github.com/argoproj/argo-cd/v2/cmd/argocd-applicationset-controller/commands" cmpserver "github.com/argoproj/argo-cd/v2/cmd/argocd-cmp-server/commands" @@ -31,6 +31,8 @@ func main() { if val := os.Getenv(binaryNameEnv); val != "" { binaryName = val } + setAutoMaxProcs(binaryName) + switch binaryName { case "argocd", "argocd-linux-amd64", "argocd-darwin-amd64", "argocd-windows-amd64.exe": command = cli.NewCommand() @@ -60,3 +62,21 @@ func main() { os.Exit(1) } } + +// setAutoMaxProcs sets the GOMAXPROCS value based on the binary name. +// It suppresses logs for CLI binaries and logs the setting for services. +func setAutoMaxProcs(binaryName string) { + isCLI := binaryName == "argocd" || + binaryName == "argocd-linux-amd64" || + binaryName == "argocd-darwin-amd64" || + binaryName == "argocd-windows-amd64.exe" + + if isCLI { + _, _ = maxprocs.Set() // Intentionally ignore errors for CLI binaries + } else { + _, err := maxprocs.Set(maxprocs.Logger(log.Debugf)) + if err != nil { + log.Infof("Error setting GOMAXPROCS: %v", err) + } + } +}