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

enable module fields overrides from custom beats #10060

Merged
merged 6 commits into from
Jan 18, 2019
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion auditbeat/include/fields.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion filebeat/include/fields.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion heartbeat/include/fields.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion journalbeat/include/fields.go

Large diffs are not rendered by default.

50 changes: 28 additions & 22 deletions libbeat/generator/fields/fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,39 +52,45 @@ func NewYmlFile(path string, indent int) (*YmlFile, error) {
}, nil
}

func collectCommonFiles(esBeatsPath, beatPath string, fieldFiles []*YmlFile) ([]*YmlFile, error) {
var libbeatFieldFiles []*YmlFile
var err error
commonFields := []string{filepath.Join(esBeatsPath, "libbeat/_meta/fields.ecs.yml")}
if !isLibbeat(beatPath) {
commonFields = append(commonFields,
filepath.Join(esBeatsPath, "libbeat/_meta/fields.common.yml"),
)
libbeatModulesPath := filepath.Join(esBeatsPath, "libbeat/processors")
libbeatFieldFiles, err = CollectModuleFiles(libbeatModulesPath)
if err != nil {
func makeYml(indent int, paths ...string) ([]*YmlFile, error) {
Copy link
Member

Choose a reason for hiding this comment

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

+1 on extracting this.

var files []*YmlFile
for _, path := range paths {
if ymlFile, err := NewYmlFile(path, indent); err != nil {
return nil, err
} else if ymlFile != nil {
files = append(files, ymlFile)
}
}
return files, nil
}

// Fields for custom beats last, to enable overriding more generically defined fields
commonFields = append(commonFields,
filepath.Join(beatPath, "_meta/fields.common.yml"),
filepath.Join(beatPath, "_meta/fields.yml"),
)

func collectCommonFiles(esBeatsPath, beatPath string, fieldFiles []*YmlFile) ([]*YmlFile, error) {
var files []*YmlFile
for _, cf := range commonFields {
ymlFile, err := NewYmlFile(cf, 0)
var ymls []*YmlFile
var err error
if ymls, err = makeYml(0, filepath.Join(esBeatsPath, "libbeat/_meta/fields.ecs.yml")); err != nil {
return nil, err
}
files = append(files, ymls...)

if !isLibbeat(beatPath) {
if ymls, err = makeYml(0, filepath.Join(esBeatsPath, "libbeat/_meta/fields.common.yml")); err != nil {
return nil, err
}
files = append(files, ymls...)
libbeatModulesPath := filepath.Join(esBeatsPath, "libbeat/processors")
libbeatFieldFiles, err := CollectModuleFiles(libbeatModulesPath)
if err != nil {
return nil, err
} else if ymlFile != nil {
files = append(files, ymlFile)
}
files = append(files, libbeatFieldFiles...)
}

files = append(files, libbeatFieldFiles...)
// Fields for custom beats last, to enable overriding more generically defined fields
if ymls, err = makeYml(0, filepath.Join(beatPath, "_meta/fields.common.yml"), filepath.Join(beatPath, "_meta/fields.yml")); err != nil {
return nil, err
}
files = append(files, ymls...)

return append(files, fieldFiles...), nil
}
Expand Down
19 changes: 7 additions & 12 deletions libbeat/generator/fields/module_fields_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,13 @@ func CollectModuleFiles(modulesDir string) ([]*YmlFile, error) {
// CollectFiles collects all files for the given module including filesets
func CollectFiles(module string, modulesPath string) ([]*YmlFile, error) {
var files []*YmlFile
var ymls []*YmlFile
var err error

fieldsYmlPath := filepath.Join(modulesPath, module, "_meta/fields.yml")
ymlFile, err := NewYmlFile(fieldsYmlPath, 0)

if err != nil {
if ymls, err = makeYml(0, filepath.Join(modulesPath, module, "_meta/fields.yml")); err != nil {
return nil, err
} else if ymlFile != nil {
files = append(files, ymlFile)
}
files = append(files, ymls...)

modulesRoot := filepath.Base(modulesPath)
sets, err := ioutil.ReadDir(filepath.Join(modulesPath, module))
Expand All @@ -90,14 +88,11 @@ func CollectFiles(module string, modulesPath string) ([]*YmlFile, error) {
continue
}

fieldsYmlPath = filepath.Join(modulesPath, module, s.Name(), "_meta/fields.yml")
ymlFile, err := NewYmlFile(fieldsYmlPath, indentByModule[modulesRoot])

if err != nil {
fieldsYmlPath := filepath.Join(modulesPath, module, s.Name(), "_meta/fields.yml")
if ymls, err = makeYml(indentByModule[modulesRoot], fieldsYmlPath); err != nil {
return nil, err
} else if ymlFile != nil {
files = append(files, ymlFile)
}
files = append(files, ymls...)
}
return files, nil
}
2 changes: 1 addition & 1 deletion metricbeat/include/fields/fields.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packetbeat/include/fields.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion winlogbeat/include/fields.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion x-pack/functionbeat/include/fields.go

Large diffs are not rendered by default.