From 0b98ba9395ae99ef6d404d985ad2670241490be5 Mon Sep 17 00:00:00 2001 From: Alon Zivony Date: Tue, 7 May 2024 03:36:04 +0300 Subject: [PATCH] chore(events): decrease SO loader error log level to debug Errors from the SO loader are pretty frequent because of race conditions. As the user has nothing to do with it, the log level should be lowered from WARN. --- pkg/events/derive/symbols_collision.go | 12 +++++++++--- pkg/events/derive/symbols_loaded.go | 2 -- pkg/events/derive/symbols_loaded_test.go | 12 +++++------- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/pkg/events/derive/symbols_collision.go b/pkg/events/derive/symbols_collision.go index e7eb3216138b..ed65d837125f 100644 --- a/pkg/events/derive/symbols_collision.go +++ b/pkg/events/derive/symbols_collision.go @@ -1,6 +1,8 @@ package derive import ( + "errors" + "github.com/hashicorp/golang-lru/simplelru" "golang.org/x/exp/maps" @@ -182,15 +184,19 @@ func (gen *SymbolsCollisionArgsGenerator) findShObjsCollisions( // get exported symbols from the shared object BEING loaded loadingShObj.exportedSymbols, err = gen.soLoader.GetExportedSymbols(loadingShObj.ObjInfo) if err != nil { + // High level languages like Java might load non-ELF files + // There is no need to log errors for such cases + var notElfErr *sharedobjs.UnsupportedFileError + if errors.As(err, ¬ElfErr) { + return nil, nil + } // TODO: rate limit frequent errors for overloaded envs _, ok := gen.returnedErrorsMap[err.Error()] if !ok { gen.returnedErrorsMap[err.Error()] = true - logger.Warnw("symbols_loaded", "object loaded", loadingShObj.ObjInfo, "error", err.Error()) - } else { logger.Debugw("symbols_loaded", "object loaded", loadingShObj.ObjInfo, "error", err.Error()) } - return nil, errfmt.WrapError(err) + return nil, nil } loadingShObj.FilterSymbols(gen.symbolsBlacklistMap) // del symbols NOT in blacklist loadingShObj.FilterOutSymbols(gen.symbolsWhitelistMap) // del symbols IN the white list diff --git a/pkg/events/derive/symbols_loaded.go b/pkg/events/derive/symbols_loaded.go index 6afcf3ee2848..2a11e4054c57 100644 --- a/pkg/events/derive/symbols_loaded.go +++ b/pkg/events/derive/symbols_loaded.go @@ -144,8 +144,6 @@ func (symbsLoadedGen *symbolsLoadedEventGenerator) deriveArgs( _, ok := symbsLoadedGen.returnedErrors[err.Error()] if !ok { symbsLoadedGen.returnedErrors[err.Error()] = true - logger.Warnw("symbols_loaded", "object loaded", loadingObjectInfo, "error", err.Error()) - } else { logger.Debugw("symbols_loaded", "object loaded", loadingObjectInfo, "error", err.Error()) } return nil, nil diff --git a/pkg/events/derive/symbols_loaded_test.go b/pkg/events/derive/symbols_loaded_test.go index 09292c7223f5..33052b01f8f5 100644 --- a/pkg/events/derive/symbols_loaded_test.go +++ b/pkg/events/derive/symbols_loaded_test.go @@ -202,7 +202,7 @@ func TestDeriveSharedObjectExportWatchedSymbols(t *testing.T) { mockLoader := initLoaderMock(errors.New("loading error")) gen := initSymbolsLoadedEventGenerator(mockLoader, nil, nil) - // First error should be always returned + // First error should always be logged for debug eventArgs, err := gen.deriveArgs(generateSOLoadedEvent(pid, sharedobjs.ObjInfo{Id: sharedobjs.ObjID{Inode: 1}, Path: "1.so"})) assert.NoError(t, err) assert.Nil(t, eventArgs) @@ -210,11 +210,11 @@ func TestDeriveSharedObjectExportWatchedSymbols(t *testing.T) { <-errChan assert.Empty(t, errChan) - // Debug mode should return errors always + // Error should be suppressed eventArgs, err = gen.deriveArgs(generateSOLoadedEvent(pid, sharedobjs.ObjInfo{Id: sharedobjs.ObjID{Inode: 1}, Path: "1.so"})) assert.NoError(t, err) assert.Nil(t, eventArgs) - assert.NotEmpty(t, errChan) + assert.Empty(t, errChan) }) t.Run("No debug", func(t *testing.T) { errChan := setMockLogger(logger.WarnLevel) @@ -222,12 +222,10 @@ func TestDeriveSharedObjectExportWatchedSymbols(t *testing.T) { mockLoader := initLoaderMock(errors.New("loading error")) gen := initSymbolsLoadedEventGenerator(mockLoader, nil, nil) - // First error should create warning + // First error should create debug log, so we won't see it eventArgs, err := gen.deriveArgs(generateSOLoadedEvent(pid, sharedobjs.ObjInfo{Id: sharedobjs.ObjID{Inode: 1}, Path: "1.so"})) assert.NoError(t, err) assert.Nil(t, eventArgs) - assert.NotEmpty(t, errChan) - <-errChan assert.Empty(t, errChan) // Error should be suppressed @@ -236,7 +234,7 @@ func TestDeriveSharedObjectExportWatchedSymbols(t *testing.T) { assert.Nil(t, eventArgs) assert.Empty(t, errChan) }) - t.Run("Non-ELF", func(t *testing.T) { + t.Run("Non-ELF error", func(t *testing.T) { errChan := setMockLogger(logger.DebugLevel) defer logger.SetLogger(baseLogger) mockLoader := initLoaderMock(sharedobjs.InitUnsupportedFileError(nil))