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

[Autodiscover] Check if runner is already running before starting again #18564

Merged
merged 9 commits into from
May 21, 2020
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
- Fix panic when assigning a key to a `nil` value in an event. {pull}18143[18143]
- Gives monitoring reporter hosts, if configured, total precedence over corresponding output hosts. {issue}17937[17937] {pull}17991[17991]
- Change `decode_json_fields` processor, to merge parsed json objects with existing objects in the event instead of fully replacing them. {pull}17958[17958]
- [Autodiscover] Check if runner is already running before starting again. {pull}18564[18564]

*Auditbeat*

Expand Down
6 changes: 5 additions & 1 deletion libbeat/cfgfile/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,11 @@ func (r *RunnerList) Reload(configs []*reload.ConfigWithMeta) error {
if _, ok := stopList[hash]; ok {
delete(stopList, hash)
} else {
startList[hash] = config
if _, ok := r.runners[hash]; !ok {
startList[hash] = config
} else {
r.logger.Debugf("Runner already running for this config hash: %s", hash)
}
}
}

Expand Down
21 changes: 21 additions & 0 deletions libbeat/cfgfile/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,27 @@ func TestReloadSameConfigs(t *testing.T) {
assert.Equal(t, state, list.copyRunnerList())
}

func TestReloadDuplicateConfig(t *testing.T) {
factory := &runnerFactory{}
list := NewRunnerList("", factory, nil)

list.Reload([]*reload.ConfigWithMeta{
createConfig(1),
})

state := list.copyRunnerList()
assert.Equal(t, len(state), 1)

// This can happen in Autodiscover when a container if getting restarted but the previous one is not clean yet.
list.Reload([]*reload.ConfigWithMeta{
createConfig(1),
createConfig(1),
})

// nothing changed
assert.Equal(t, state, list.copyRunnerList())
}

func TestReloadStopConfigs(t *testing.T) {
factory := &runnerFactory{}
list := NewRunnerList("", factory, nil)
Expand Down