-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Conversation
CHANGELOG.asciidoc
Outdated
@@ -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}[] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add the PR number.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
If `setup.template.overwrite: true` is set the template is overwritten each time the Beat reconnects. The `dynamicTemplates` are a global variable that keeps state. This had the side effect that each time the template was generated for loading, the dynamic fields were append again. The logic in the code is changed now that each time when the template is generated first the dynamicFields array is reset. This also works with the new `append_fields` config option because it is read during the load process to also potentially add dynamic fields. The same applies to the default fields which are global. Also this array is reset. As default_fields were only used for Elasticsearch 7.0 is does not need an entry in the changelog. If possible in the future both variables should be part of the template object instead of being global. Unfortunately this would required major changes.
3f3c6fa
to
649d0b6
Compare
jenkins, test this |
1 similar comment
jenkins, test this |
libbeat/template/template.go
Outdated
@@ -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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
262b13a
to
67e65a7
Compare
* Fix duplication of dynamic fields on reconnect If `setup.template.overwrite: true` is set the template is overwritten each time the Beat reconnects. The `dynamicTemplates` are a global variable that keeps state. This had the side effect that each time the template was generated for loading, the dynamic fields were append again. The logic in the code is changed now that each time when the template is generated first the dynamicFields array is reset. This also works with the new `append_fields` config option because it is read during the load process to also potentially add dynamic fields. The same applies to the default fields which are global. Also this array is reset. As default_fields were only used for Elasticsearch 7.0 is does not need an entry in the changelog. If possible in the future both variables should be part of the template object instead of being global. Unfortunately this would required major changes. (cherry picked from commit df74c26)
* Fix duplication of dynamic fields on reconnect If `setup.template.overwrite: true` is set the template is overwritten each time the Beat reconnects. The `dynamicTemplates` are a global variable that keeps state. This had the side effect that each time the template was generated for loading, the dynamic fields were append again. The logic in the code is changed now that each time when the template is generated first the dynamicFields array is reset. This also works with the new `append_fields` config option because it is read during the load process to also potentially add dynamic fields. The same applies to the default fields which are global. Also this array is reset. As default_fields were only used for Elasticsearch 7.0 is does not need an entry in the changelog. If possible in the future both variables should be part of the template object instead of being global. Unfortunately this would required major changes. (cherry picked from commit df74c26)
…c#7417) * Fix duplication of dynamic fields on reconnect If `setup.template.overwrite: true` is set the template is overwritten each time the Beat reconnects. The `dynamicTemplates` are a global variable that keeps state. This had the side effect that each time the template was generated for loading, the dynamic fields were append again. The logic in the code is changed now that each time when the template is generated first the dynamicFields array is reset. This also works with the new `append_fields` config option because it is read during the load process to also potentially add dynamic fields. The same applies to the default fields which are global. Also this array is reset. As default_fields were only used for Elasticsearch 7.0 is does not need an entry in the changelog. If possible in the future both variables should be part of the template object instead of being global. Unfortunately this would required major changes. (cherry picked from commit b0a52be)
If
setup.template.overwrite: true
is set the template is overwritten each time the Beat reconnects. ThedynamicTemplates
are a global variable that keeps state. This had the side effect that each time the template was generated for loading, the dynamic fields were append again. The logic in the code is changed now that each time when the template is generated first the dynamicFields array is reset.This also works with the new
append_fields
config option because it is read during the load process to also potentially add dynamic fields.The same applies to the default fields which are global. Also this array is reset. As default_fields were only used for Elasticsearch 7.0 is does not need an entry in the changelog.
If possible in the future both variables should be part of the template object instead of being global. Unfortunately this would required major changes.