Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

filebeat: make deep copy before notifying of config change #42992

Merged
merged 10 commits into from
Mar 6, 2025
10 changes: 9 additions & 1 deletion filebeat/beater/filebeat.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,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
Loading