Skip to content

Commit 8ff01e3

Browse files
authored
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.
1 parent afe14b9 commit 8ff01e3

File tree

2 files changed

+8
-17
lines changed

2 files changed

+8
-17
lines changed

internal/pkg/api/handleCheckin.go

+4-5
Original file line numberDiff line numberDiff line change
@@ -1005,14 +1005,13 @@ func parseComponents(zlog zerolog.Logger, agent *model.Agent, req *CheckinReques
10051005
// Compare the deserialized meta structures and return the bytes to update if different
10061006
if !reflect.DeepEqual(reqComponents, agent.Components) {
10071007

1008+
reqComponentsJSON, _ := json.Marshal(*req.Components)
10081009
zlog.Trace().
1009-
RawJSON("oldComponents", agentComponentsJSON).
1010-
RawJSON("newComponents", *req.Components).
1010+
Str("oldComponents", string(agentComponentsJSON)).
1011+
Str("req.Components", string(reqComponentsJSON)).
10111012
Msg("local components data is not equal")
10121013

1013-
zlog.Info().
1014-
RawJSON("req.Components", *req.Components).
1015-
Msg("applying new components data")
1014+
zlog.Info().Msg("applying new components data")
10161015

10171016
outComponents = *req.Components
10181017
compUnhealthyReason := calcUnhealthyReason(reqComponents)

internal/pkg/server/fleet.go

+4-12
Original file line numberDiff line numberDiff line change
@@ -254,25 +254,17 @@ func configCacheChanged(curCfg, newCfg *config.Config) bool {
254254
return curCfg.Inputs[0].Cache != newCfg.Inputs[0].Cache
255255
}
256256

257-
func configChangedServer(log zerolog.Logger, curCfg, newCfg *config.Config) bool {
258-
zlog := log.With().Interface("new", newCfg.Redact()).Logger()
259-
257+
func configChangedServer(zlog zerolog.Logger, curCfg, newCfg *config.Config) bool {
260258
changed := true
261259
switch {
262260
case curCfg == nil:
263261
zlog.Info().Msg("initial server configuration")
264262
case !reflect.DeepEqual(curCfg.Fleet.CopyNoLogging(), newCfg.Fleet.CopyNoLogging()):
265-
zlog.Info().
266-
Interface("old", curCfg.Redact()).
267-
Msg("fleet configuration has changed")
263+
zlog.Info().Msg("fleet configuration has changed")
268264
case !reflect.DeepEqual(curCfg.Output, newCfg.Output):
269-
zlog.Info().
270-
Interface("old", curCfg.Redact()).
271-
Msg("output configuration has changed")
265+
zlog.Info().Msg("output configuration has changed")
272266
case !reflect.DeepEqual(curCfg.Inputs[0].Server, newCfg.Inputs[0].Server):
273-
zlog.Info().
274-
Interface("old", curCfg.Redact()).
275-
Msg("server configuration has changed")
267+
zlog.Info().Msg("server configuration has changed")
276268
default:
277269
changed = false
278270
}

0 commit comments

Comments
 (0)