From dd36d8413dcd1ed8a8457e5e2aed20130f45585b Mon Sep 17 00:00:00 2001 From: Tiago Queiroz Date: Wed, 11 Dec 2024 08:44:25 -0500 Subject: [PATCH] Prevent mapping explosion on logs (#4181) This commit remove some JSON objects that were added to the logs, thus preventing mapping explosion when those logs are ingested into Elasticsearch. Some entries are converted to strings, others are fully removed to keep the log within a reasonable size and some are kept as string at trace level. (cherry picked from commit 8ff01e35a155abde455443039616c5069848c488) --- internal/pkg/api/handleCheckin.go | 9 ++++----- internal/pkg/server/fleet.go | 16 ++++------------ 2 files changed, 8 insertions(+), 17 deletions(-) diff --git a/internal/pkg/api/handleCheckin.go b/internal/pkg/api/handleCheckin.go index 9adbc4791..d643b556e 100644 --- a/internal/pkg/api/handleCheckin.go +++ b/internal/pkg/api/handleCheckin.go @@ -999,14 +999,13 @@ func parseComponents(zlog zerolog.Logger, agent *model.Agent, req *CheckinReques // Compare the deserialized meta structures and return the bytes to update if different if !reflect.DeepEqual(reqComponents, agent.Components) { + reqComponentsJSON, _ := json.Marshal(*req.Components) zlog.Trace(). - RawJSON("oldComponents", agentComponentsJSON). - RawJSON("newComponents", *req.Components). + Str("oldComponents", string(agentComponentsJSON)). + Str("req.Components", string(reqComponentsJSON)). Msg("local components data is not equal") - zlog.Info(). - RawJSON("req.Components", *req.Components). - Msg("applying new components data") + zlog.Info().Msg("applying new components data") outComponents = *req.Components compUnhealthyReason := calcUnhealthyReason(reqComponents) diff --git a/internal/pkg/server/fleet.go b/internal/pkg/server/fleet.go index 677c8027a..7a3c11d45 100644 --- a/internal/pkg/server/fleet.go +++ b/internal/pkg/server/fleet.go @@ -251,25 +251,17 @@ func configCacheChanged(curCfg, newCfg *config.Config) bool { return curCfg.Inputs[0].Cache != newCfg.Inputs[0].Cache } -func configChangedServer(log zerolog.Logger, curCfg, newCfg *config.Config) bool { - zlog := log.With().Interface("new", newCfg.Redact()).Logger() - +func configChangedServer(zlog zerolog.Logger, curCfg, newCfg *config.Config) bool { changed := true switch { case curCfg == nil: zlog.Info().Msg("initial server configuration") case !reflect.DeepEqual(curCfg.Fleet.CopyNoLogging(), newCfg.Fleet.CopyNoLogging()): - zlog.Info(). - Interface("old", curCfg.Redact()). - Msg("fleet configuration has changed") + zlog.Info().Msg("fleet configuration has changed") case !reflect.DeepEqual(curCfg.Output, newCfg.Output): - zlog.Info(). - Interface("old", curCfg.Redact()). - Msg("output configuration has changed") + zlog.Info().Msg("output configuration has changed") case !reflect.DeepEqual(curCfg.Inputs[0].Server, newCfg.Inputs[0].Server): - zlog.Info(). - Interface("old", curCfg.Redact()). - Msg("server configuration has changed") + zlog.Info().Msg("server configuration has changed") default: changed = false }