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

Remove runner creation from every reload check #5141

Merged
merged 1 commit into from
Sep 12, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ https://github.com/elastic/beats/compare/v6.0.0-beta2...master[Check the HEAD di
- Combine `fields.yml` properties when they are defined in different sources. {issue}5075[5075]
- Keep Docker & Kubernetes pod metadata after container dies while they are needed by processors. {pull}5084[5084]
- Fix `fields.yml` lookup when using `export template` with a custom `path.config` param. {issue}5089[5089]
- Remove runner creation from every reload check {pull}5141[5141]

*Auditbeat*

Expand Down
44 changes: 25 additions & 19 deletions libbeat/cfgfile/reload.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"time"

"github.com/joeshaw/multierror"
"github.com/mitchellh/hashstructure"
"github.com/pkg/errors"

"github.com/elastic/beats/libbeat/common"
Expand Down Expand Up @@ -134,7 +135,7 @@ func (rl *Reloader) Run(runnerFactory RunnerFactory) {
rl.config.Reload.Period = 0
}

overwriteUpate := true
overwriteUpdate := true

for {
select {
Expand All @@ -154,8 +155,8 @@ func (rl *Reloader) Run(runnerFactory RunnerFactory) {
}

// no file changes
if !updated && !overwriteUpate {
overwriteUpate = false
if !updated && !overwriteUpdate {
overwriteUpdate = false
continue
}

Expand All @@ -174,29 +175,34 @@ func (rl *Reloader) Run(runnerFactory RunnerFactory) {
continue
}

runner, err := runnerFactory.Create(c)
rawCfg := map[string]interface{}{}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not 100% sure anymore, but I think there is a difference between this and ID(). In the case of ID() the following to configs are the same:

a: b
c: d

and

c: d
a: b

That means the order does not matter, but with the above it does. But not 100% sure anymore if that was the reason I ended up with ID() but there was an issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

func main () {
	a := map[string]interface{}{
		"a": "b",
		"c": "d",
	}


	b := map[string]interface{}{
		"c": "d",
		"a": "b",
	}

	fmt.Println(hashstructure.Hash(a, nil))
	fmt.Println(hashstructure.Hash(b, nil))
}

output:

8710980024335696864 <nil>
8710980024335696864 <nil>

err := c.Unpack(rawCfg)

if err != nil {
logp.Err("Unable to unpack config file due to error: %v", err)
continue
}

hash, err := hashstructure.Hash(rawCfg, nil)
if err != nil {
// Make sure the next run also updates because some runners were not properly loaded
overwriteUpate = true

// In case prospector already is running, do not stop it
if runner != nil && rl.registry.Has(runner.ID()) {
debugf("Remove module from stoplist: %v", runner.ID())
delete(stopList, runner.ID())
} else {
logp.Err("Error creating module: %s", err)
}
overwriteUpdate = true
debugf("Unable to generate hash for config file %v due to error: %v", c, err)
continue
}

debugf("Remove module from stoplist: %v", runner.ID())
delete(stopList, runner.ID())
debugf("Remove module from stoplist: %v", hash)
delete(stopList, hash)

// As module already exist, it must be removed from the stop list and not started
if !rl.registry.Has(runner.ID()) {
debugf("Add module to startlist: %v", runner.ID())
startList[runner.ID()] = runner
continue
if !rl.registry.Has(hash) {
debugf("Add module to startlist: %v", hash)
runner, err := runnerFactory.Create(c)
if err != nil {
logp.Err("Unable to create runner due to error: %v", err)
continue
}
startList[hash] = runner
}
}

Expand Down