Skip to content

Commit

Permalink
Remove runner creation from every reload check (#5141)
Browse files Browse the repository at this point in the history
  • Loading branch information
vjsamuel authored and ruflin committed Sep 12, 2017
1 parent c2d7b13 commit b247e88
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 19 deletions.
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{}{}
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

0 comments on commit b247e88

Please sign in to comment.