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

Cherry-pick #13914 to 7.4: Field registry: Don't overwrite fields with same name #14037

Merged
merged 1 commit into from
Oct 14, 2019
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.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
- cisco asa and ftd filesets: Fix parsing of message 106001. {issue}13891[13891] {pull}13903[13903]
- Fix merging of fields specified in global scope with fields specified under an input's scope. {issue}3628[3628] {pull}13909[13909]
- Fix delay in enforcing close_renamed and close_removed options. {issue}13488[13488] {pull}13907[13907]
- Fix missing netflow fields in index template. {issue}13768[13768] {pull}13914[13914]

*Heartbeat*

Expand Down
22 changes: 12 additions & 10 deletions libbeat/asset/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
// As each entry is an array of bytes multiple fields.yml can be added under one path.
// This can become useful as we don't have to generate anymore the fields.yml but can
// package each local fields.yml from things like processors.
var FieldsRegistry = map[string]map[int]map[string]string{}
var FieldsRegistry = map[string]map[int]map[string][]string{}

// SetFields sets the fields for a given beat and asset name
func SetFields(beat, name string, p Priority, asset func() string) error {
Expand All @@ -38,14 +38,14 @@ func SetFields(beat, name string, p Priority, asset func() string) error {
priority := int(p)

if _, ok := FieldsRegistry[beat]; !ok {
FieldsRegistry[beat] = map[int]map[string]string{}
FieldsRegistry[beat] = map[int]map[string][]string{}
}

if _, ok := FieldsRegistry[beat][priority]; !ok {
FieldsRegistry[beat][priority] = map[string]string{}
FieldsRegistry[beat][priority] = map[string][]string{}
}

FieldsRegistry[beat][priority][name] = data
FieldsRegistry[beat][priority][name] = append(FieldsRegistry[beat][priority][name], data)

return nil
}
Expand Down Expand Up @@ -74,13 +74,15 @@ func GetFields(beat string) ([]byte, error) {
sort.Strings(entries)

for _, entry := range entries {
data := priorityRegistry[entry]
output, err := DecodeData(data)
if err != nil {
return nil, err
list := priorityRegistry[entry]
for _, data := range list {
output, err := DecodeData(data)
if err != nil {
return nil, err
}

fields = append(fields, output...)
}

fields = append(fields, output...)
}
}
return fields, nil
Expand Down