Skip to content
Closed
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
36 changes: 36 additions & 0 deletions auditbeat/include/beat.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 3 additions & 9 deletions auditbeat/magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,17 +107,11 @@ func Config() error {

// Fields generates fields.yml and fields.go files for the Beat.
func Fields() {
mg.Deps(libbeatAndAuditbeatCommonFieldsGo, moduleFieldsGo)
mg.Deps(fieldsYML)
mg.Deps(beatFieldsGo, moduleFieldsGo, fieldsYML)
}

// libbeatAndAuditbeatCommonFieldsGo generates a fields.go containing both
// libbeat and auditbeat's common fields.
func libbeatAndAuditbeatCommonFieldsGo() error {
if err := mage.GenerateFieldsYAML(); err != nil {
return err
}
return mage.GenerateAllInOneFieldsGo()
func beatFieldsGo() error {
return mage.GenerateFieldsGo("beat")
}

// moduleFieldsGo generates a fields.go for each module.
Expand Down
5 changes: 5 additions & 0 deletions dev-tools/mage/clean.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ var DefaultCleanPaths = []string{
"_meta/kibana.generated",
"_meta/kibana/6/index-pattern/{{.BeatName}}.json",
"_meta/kibana/7/index-pattern/{{.BeatName}}.json",
// Generated fields files
"include/fields.go",
"include/module.go",
"include/beat.go",
"include/libbeat.go",
}

// Clean clean generated build artifacts.
Expand Down
17 changes: 7 additions & 10 deletions dev-tools/mage/fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package mage

import (
"path/filepath"
"strings"

"github.com/pkg/errors"

Expand Down Expand Up @@ -60,13 +61,8 @@ func generateFieldsYAML(baseDir, output string, moduleDirs ...string) error {
return globalFieldsCmd(moduleDirs...)
}

// GenerateAllInOneFieldsGo generates an all-in-one fields.go file.
func GenerateAllInOneFieldsGo() error {
return GenerateFieldsGo("fields.yml", "include/fields.go")
}

// GenerateFieldsGo generates a .go file containing the fields.yml data.
func GenerateFieldsGo(fieldsYML, out string) error {
// GenerateFieldsGo generates a *.go file from the related *.yml file in the build directory.
func GenerateFieldsGo(name string) error {
const assetCmdPath = "dev-tools/cmd/asset/asset.go"

beatsDir, err := ElasticBeatsDir()
Expand All @@ -76,10 +72,11 @@ func GenerateFieldsGo(fieldsYML, out string) error {

assetCmd := sh.RunCmd("go", "run",
filepath.Join(beatsDir, assetCmdPath),
"-pkg", "include",
"-in", fieldsYML,
"-out", createDir(out),
"-license", toLibbeatLicenseName(BeatLicense),
"-pkg", "include",
"-in", "./build/fields/"+name+".yml",
"-out", "include/"+name+".go",
"-name", strings.Title(name),
BeatName,
)

Expand Down
36 changes: 36 additions & 0 deletions filebeat/include/beat.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 2 additions & 10 deletions filebeat/magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,19 +117,11 @@ func includeList() error {

// Fields generates fields.yml and fields.go files for the Beat.
func Fields() {
mg.Deps(libbeatAndFilebeatCommonFieldsGo, moduleFieldsGo)
mg.Deps(moduleFieldsGo)
mage.GenerateFieldsGo("beat")
mg.Deps(fieldsYML)
}

// libbeatAndFilebeatCommonFieldsGo generates a fields.go containing both
// libbeat and filebeat's common fields.
func libbeatAndFilebeatCommonFieldsGo() error {
if err := mage.GenerateFieldsYAML(); err != nil {
return err
}
return mage.GenerateAllInOneFieldsGo()
}

// moduleFieldsGo generates a fields.go for each module.
func moduleFieldsGo() error {
return mage.GenerateModuleFieldsGo("module")
Expand Down
36 changes: 36 additions & 0 deletions heartbeat/include/beat.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 36 additions & 0 deletions heartbeat/include/module.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions heartbeat/magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ func Update() error {

// Fields generates a fields.yml for the Beat.
func Fields() error {
mage.GenerateFieldsGo("beat")
mage.GenerateFieldsGo("module")
return mage.GenerateFieldsYAML("monitors/active")
}

Expand Down
36 changes: 36 additions & 0 deletions journalbeat/include/beat.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions journalbeat/magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ func Update() error {

// Fields generates a fields.yml for the Beat.
func Fields() error {
mage.GenerateFieldsGo("beat")

return mage.GenerateFieldsYAML()
}

Expand Down
3 changes: 3 additions & 0 deletions libbeat/beat/beat.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ package beat
import (
"github.com/elastic/beats/libbeat/common"
"github.com/elastic/beats/libbeat/management"

// Include basic fields
_ "github.com/elastic/beats/libbeat/include"
)

// Creator initializes and configures a new Beater instance used to execute
Expand Down
8 changes: 8 additions & 0 deletions libbeat/cmd/instance/beat.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,19 @@ func NewBeat(name, indexPrefix, v string) (*Beat, error) {
return nil, err
}

// All Beat need the libbeat fields
libbeatFields, err := asset.GetFields("libbeat")
if err != nil {
return nil, err
}

fields, err := asset.GetFields(name)
if err != nil {
return nil, err
}

fields = append(libbeatFields[:], fields[:]...)

id, err := uuid.NewV4()
if err != nil {
return nil, err
Expand Down
Loading