Skip to content

Commit 24ef6fb

Browse files
authored
Field registry: Don't overwrite fields with same name (elastic#13914) (elastic#14037)
When fields are registered (fields.go, autogenerated), they are grouped by (Beatname, Name and Priority). Currently, if the same triplet is used more than once, the previous asset is overwritten. This is the case with Filebeat inputs and modules sharing the same name: module/netflow/fields.go: asset.SetFields("filebeat", "netflow", asset.ModuleFieldsPri, AssetNetflow) input/netflow/fields.go: asset.SetFields("filebeat", "netflow", asset.ModuleFieldsPri, AssetNetflow) Also this introduces an inconsistence as the order of registration can vary. Fixes elastic#13768 (cherry picked from commit 5fec6bc)
1 parent 6584e1d commit 24ef6fb

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

CHANGELOG.next.asciidoc

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
5151
- cisco asa and ftd filesets: Fix parsing of message 106001. {issue}13891[13891] {pull}13903[13903]
5252
- Fix merging of fields specified in global scope with fields specified under an input's scope. {issue}3628[3628] {pull}13909[13909]
5353
- Fix delay in enforcing close_renamed and close_removed options. {issue}13488[13488] {pull}13907[13907]
54+
- Fix missing netflow fields in index template. {issue}13768[13768] {pull}13914[13914]
5455

5556
*Heartbeat*
5657

libbeat/asset/registry.go

+12-10
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import (
2929
// As each entry is an array of bytes multiple fields.yml can be added under one path.
3030
// This can become useful as we don't have to generate anymore the fields.yml but can
3131
// package each local fields.yml from things like processors.
32-
var FieldsRegistry = map[string]map[int]map[string]string{}
32+
var FieldsRegistry = map[string]map[int]map[string][]string{}
3333

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

4040
if _, ok := FieldsRegistry[beat]; !ok {
41-
FieldsRegistry[beat] = map[int]map[string]string{}
41+
FieldsRegistry[beat] = map[int]map[string][]string{}
4242
}
4343

4444
if _, ok := FieldsRegistry[beat][priority]; !ok {
45-
FieldsRegistry[beat][priority] = map[string]string{}
45+
FieldsRegistry[beat][priority] = map[string][]string{}
4646
}
4747

48-
FieldsRegistry[beat][priority][name] = data
48+
FieldsRegistry[beat][priority][name] = append(FieldsRegistry[beat][priority][name], data)
4949

5050
return nil
5151
}
@@ -74,13 +74,15 @@ func GetFields(beat string) ([]byte, error) {
7474
sort.Strings(entries)
7575

7676
for _, entry := range entries {
77-
data := priorityRegistry[entry]
78-
output, err := DecodeData(data)
79-
if err != nil {
80-
return nil, err
77+
list := priorityRegistry[entry]
78+
for _, data := range list {
79+
output, err := DecodeData(data)
80+
if err != nil {
81+
return nil, err
82+
}
83+
84+
fields = append(fields, output...)
8185
}
82-
83-
fields = append(fields, output...)
8486
}
8587
}
8688
return fields, nil

0 commit comments

Comments
 (0)