Skip to content

Commit

Permalink
filebeat: make deep copy before notifying of config change (#42992)
Browse files Browse the repository at this point in the history
This prevents concurrent read & write map access.

Unrelated, but I've escalated one log line to Info to allow for easier verifying that ES store is being used from agent logs.

Fixes #42815

(cherry picked from commit f1e42fc)
  • Loading branch information
orestisfl authored and mergify[bot] committed Mar 6, 2025
1 parent cadba94 commit 82ff0c1
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
10 changes: 9 additions & 1 deletion filebeat/beater/filebeat.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,15 @@ func (fb *Filebeat) Run(b *beat.Beat) error {
return nil
}

stateStore.notifier.Notify(outCfg.Config())
// Create a new config with the output configuration. Since r.Config is a pointer, a copy is required to
// avoid concurrent map read and write.
// See https://github.com/elastic/beats/issues/42815
configCopy, err := conf.NewConfigFrom(outCfg.Config())
if err != nil {
logp.Err("Failed to create a new config from the output config: %v", err)
return nil
}
stateStore.notifier.Notify(configCopy)
return nil
})
}
Expand Down
2 changes: 1 addition & 1 deletion libbeat/statestore/backend/es/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ func (s *store) Each(fn func(string, backend.ValueDecoder) (bool, error)) error
}

func (s *store) configure(ctx context.Context, c *conf.C) {
s.log.Debugf("Configure ES store")
s.log.Info("Configuring ES store")
s.mx.Lock()
defer s.mx.Unlock()

Expand Down
2 changes: 1 addition & 1 deletion x-pack/filebeat/tests/integration/managerV2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -930,7 +930,7 @@ func TestHTTPJSONInputReloadUnderElasticAgentWithElasticStateStore(t *testing.T)
)

for _, contains := range []string{
"Configure ES store",
"Configuring ES store",
"input-cursor::openStore: prefix: httpjson inputID: " + inputID,
"input-cursor store read 0 keys", // first, no previous data exists
"input-cursor store read 1 keys", // after the restart, previous key is read
Expand Down

0 comments on commit 82ff0c1

Please sign in to comment.