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.
  • Loading branch information
belimawr authored Dec 11, 2024
1 parent afe14b9 commit 8ff01e3
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 @@ -1005,14 +1005,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 @@ -254,25 +254,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 8ff01e3

Please sign in to comment.