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

Fix duplication of dynamic fields on reconnect #7352

Merged
merged 2 commits into from
Jun 26, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -71,6 +71,7 @@ https://github.com/elastic/beats/compare/v6.2.3...master[Check the HEAD diff]
- Do not emit Kubernetes autodiscover events for Pods without IP address. {pull}7235[7235]
- Allow to override the `ignore_above` option when defining new field with the type keyword. {pull}7238[7238]
- Allow index-pattern only setup when setup.dashboards.only_index=true. {pull}7285[7285]
- Fix duplicating dynamic_fields in template when overwriting the template. {pull}7352[7352]

*Auditbeat*

Expand Down
3 changes: 3 additions & 0 deletions libbeat/template/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ func New(beatVersion string, beatName string, esVersion string, config TemplateC

func (t *Template) load(fields common.Fields) (common.MapStr, error) {

dynamicTemplates = nil
Copy link
Member

@andrewkroh andrewkroh Jun 20, 2018

Choose a reason for hiding this comment

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

With this function being called each time that a client connects to Elasticsearch I would expect that this could lead to data races (especially if the number of workers is greater than 1). So because these are globals I think a mutex is required for reads and writes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added a lock directly above for the load method. All access to dynamicTemplates and defaultFields happens inside the processor and generator which both are triggered here. Generate could also be called from outside but in this case it's one of the Cobra commands so will not overlap with the running beat and only happening once.

defaultFields = nil

var err error
if len(t.config.AppendFields) > 0 {
cfgwarn.Experimental("append_fields is used.")
Expand Down