Skip to content

Commit

Permalink
disable automaxprocs logging
Browse files Browse the repository at this point in the history
Signed-off-by: nitishfy <justnitish06@gmail.com>

fix lint checks

Signed-off-by: nitishfy <justnitish06@gmail.com>

move maxprocs to main.go

Signed-off-by: nitishfy <justnitish06@gmail.com>

move set auto max procs to a function

Signed-off-by: nitishfy <justnitish06@gmail.com>

add info log

Signed-off-by: nitishfy <justnitish06@gmail.com>
  • Loading branch information
nitishfy committed Oct 3, 2024
1 parent fe67cd5 commit a592ca2
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions cmd/main.go
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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()
Expand Down Expand Up @@ -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)
}
}
}

0 comments on commit a592ca2

Please sign in to comment.