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

Conversation

ruflin
Copy link
Contributor

@ruflin ruflin commented Jun 18, 2018

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.

@ruflin ruflin added bug review libbeat needs_backport PR is waiting to be backported to other branches. labels Jun 18, 2018
@@ -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}[]
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added

Copy link
Contributor

@tsg tsg left a 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.
@ruflin ruflin force-pushed the fix-dynamic-fields-duplicates branch from 3f3c6fa to 649d0b6 Compare June 18, 2018 11:17
@ruflin
Copy link
Contributor Author

ruflin commented Jun 20, 2018

jenkins, test this

1 similar comment
@ruflin
Copy link
Contributor Author

ruflin commented Jun 20, 2018

jenkins, test this

@@ -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.

@ruflin ruflin force-pushed the fix-dynamic-fields-duplicates branch from 262b13a to 67e65a7 Compare June 25, 2018 10:52
@exekias exekias merged commit df74c26 into elastic:master Jun 26, 2018
@ruflin ruflin deleted the fix-dynamic-fields-duplicates branch June 26, 2018 08:47
ruflin added a commit to ruflin/beats that referenced this pull request Jun 26, 2018
* 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)
@ruflin ruflin added v6.3.1 and removed needs_backport PR is waiting to be backported to other branches. labels Jun 26, 2018
exekias pushed a commit that referenced this pull request Jun 27, 2018
* 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)
leweafan pushed a commit to leweafan/beats that referenced this pull request Apr 28, 2023
…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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants