Skip to content

Commit

Permalink
Prevent mapping explosion on logs (#4181)
Browse files Browse the repository at this point in the history
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 8ff01e3)
  • Loading branch information
belimawr authored and mergify[bot] committed Dec 11, 2024
1 parent 1579e65 commit dd36d84
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 17 deletions.
9 changes: 4 additions & 5 deletions internal/pkg/api/handleCheckin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
16 changes: 4 additions & 12 deletions internal/pkg/server/fleet.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit dd36d84

Please sign in to comment.