Skip to content

Commit d03ccf3

Browse files
pasha-codefreshnitishfyCefBoud
authored
fix: disable automaxprocs logging (#20069) - cherry-pick 2.13 (#20718)
* fix: disable automaxprocs logging (#20069) * disable automaxprocs logging Signed-off-by: nitishfy <[email protected]> fix lint checks Signed-off-by: nitishfy <[email protected]> move maxprocs to main.go Signed-off-by: nitishfy <[email protected]> move set auto max procs to a function Signed-off-by: nitishfy <[email protected]> add info log Signed-off-by: nitishfy <[email protected]> * add info log Signed-off-by: nitishfy <[email protected]> * fix lint checks Signed-off-by: nitishfy <[email protected]> * fix lint checks Signed-off-by: nitishfy <[email protected]> * add unit test Signed-off-by: nitishfy <[email protected]> * fix lint issues Signed-off-by: nitishfy <[email protected]> --------- Signed-off-by: nitishfy <[email protected]> (cherry picked from commit cfa1c89) * fix(ci): ignore temporary files when checking for out of bound symlinks (#20527) Signed-off-by: cef <[email protected]> --------- Signed-off-by: cef <[email protected]> Co-authored-by: Nitish Kumar <[email protected]> Co-authored-by: ABBOUD Moncef <[email protected]>
1 parent 7f45c9e commit d03ccf3

File tree

4 files changed

+57
-3
lines changed

4 files changed

+57
-3
lines changed

cmd/main.go

+10-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import (
44
"os"
55
"path/filepath"
66

7-
"github.com/spf13/cobra"
7+
"github.com/argoproj/argo-cd/v2/cmd/util"
88

9-
_ "go.uber.org/automaxprocs"
9+
"github.com/spf13/cobra"
1010

1111
appcontroller "github.com/argoproj/argo-cd/v2/cmd/argocd-application-controller/commands"
1212
applicationset "github.com/argoproj/argo-cd/v2/cmd/argocd-applicationset-controller/commands"
@@ -31,9 +31,12 @@ func main() {
3131
if val := os.Getenv(binaryNameEnv); val != "" {
3232
binaryName = val
3333
}
34+
35+
isCLI := false
3436
switch binaryName {
3537
case "argocd", "argocd-linux-amd64", "argocd-darwin-amd64", "argocd-windows-amd64.exe":
3638
command = cli.NewCommand()
39+
isCLI = true
3740
case "argocd-server":
3841
command = apiserver.NewCommand()
3942
case "argocd-application-controller":
@@ -42,19 +45,24 @@ func main() {
4245
command = reposerver.NewCommand()
4346
case "argocd-cmp-server":
4447
command = cmpserver.NewCommand()
48+
isCLI = true
4549
case "argocd-dex":
4650
command = dex.NewCommand()
4751
case "argocd-notifications":
4852
command = notification.NewCommand()
4953
case "argocd-git-ask-pass":
5054
command = gitaskpass.NewCommand()
55+
isCLI = true
5156
case "argocd-applicationset-controller":
5257
command = applicationset.NewCommand()
5358
case "argocd-k8s-auth":
5459
command = k8sauth.NewCommand()
60+
isCLI = true
5561
default:
5662
command = cli.NewCommand()
63+
isCLI = true
5764
}
65+
util.SetAutoMaxProcs(isCLI)
5866

5967
if err := command.Execute(); err != nil {
6068
os.Exit(1)

cmd/util/app.go

+15
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import (
99
"strings"
1010
"time"
1111

12+
"go.uber.org/automaxprocs/maxprocs"
13+
1214
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
1315

1416
"github.com/argoproj/gitops-engine/pkg/utils/kube"
@@ -88,6 +90,19 @@ type AppOptions struct {
8890
ref string
8991
}
9092

93+
// SetAutoMaxProcs sets the GOMAXPROCS value based on the binary name.
94+
// It suppresses logs for CLI binaries and logs the setting for services.
95+
func SetAutoMaxProcs(isCLI bool) {
96+
if isCLI {
97+
_, _ = maxprocs.Set() // Intentionally ignore errors for CLI binaries
98+
} else {
99+
_, err := maxprocs.Set(maxprocs.Logger(log.Infof))
100+
if err != nil {
101+
log.Errorf("Error setting GOMAXPROCS: %v", err)
102+
}
103+
}
104+
}
105+
91106
func AddAppFlags(command *cobra.Command, opts *AppOptions) {
92107
command.Flags().StringVar(&opts.repoURL, "repo", "", "Repository URL, ignored if a file is set")
93108
command.Flags().StringVar(&opts.appPath, "path", "", "Path in repository to the app directory, ignored if a file is set")

cmd/util/app_test.go

+26-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
package util
22

33
import (
4+
"bytes"
5+
"log"
46
"os"
57
"testing"
68

7-
log "github.com/sirupsen/logrus"
89
"github.com/spf13/cobra"
910
"github.com/stretchr/testify/assert"
1011
"github.com/stretchr/testify/require"
@@ -529,3 +530,27 @@ func TestFilterResources(t *testing.T) {
529530
assert.Nil(t, filteredResources)
530531
})
531532
}
533+
534+
func TestSetAutoMaxProcs(t *testing.T) {
535+
t.Run("CLI mode ignores errors", func(t *testing.T) {
536+
logBuffer := &bytes.Buffer{}
537+
oldLogger := log.Default()
538+
log.SetOutput(logBuffer)
539+
defer log.SetOutput(oldLogger.Writer())
540+
541+
SetAutoMaxProcs(true)
542+
543+
assert.Empty(t, logBuffer.String(), "Expected no log output when isCLI is true")
544+
})
545+
546+
t.Run("Non-CLI mode logs error on failure", func(t *testing.T) {
547+
logBuffer := &bytes.Buffer{}
548+
oldLogger := log.Default()
549+
log.SetOutput(logBuffer)
550+
defer log.SetOutput(oldLogger.Writer())
551+
552+
SetAutoMaxProcs(false)
553+
554+
assert.NotContains(t, logBuffer.String(), "Error setting GOMAXPROCS", "Unexpected log output detected")
555+
})
556+
}

util/app/path/path.go

+6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package path
22

33
import (
4+
"errors"
45
"fmt"
56
"os"
67
"path/filepath"
@@ -51,6 +52,11 @@ func CheckOutOfBoundsSymlinks(basePath string) error {
5152
}
5253
return filepath.Walk(absBasePath, func(path string, info os.FileInfo, err error) error {
5354
if err != nil {
55+
// Ignore "no such file or directory" errors than can happen with
56+
// temporary files such as .git/*.lock
57+
if errors.Is(err, os.ErrNotExist) {
58+
return nil
59+
}
5460
return fmt.Errorf("failed to walk for symlinks in %s: %w", absBasePath, err)
5561
}
5662
if files.IsSymlink(info) {

0 commit comments

Comments
 (0)