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

[WIP] Introduce local fields generation #9507

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from 6 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() {
ruflin marked this conversation as resolved.
Show resolved Hide resolved
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
4 changes: 4 additions & 0 deletions dev-tools/mage/clean.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ var DefaultCleanPaths = []string{
"_meta/kibana.generated",
"_meta/kibana/6/index-pattern/{{.BeatName}}.json",
"_meta/kibana/7/index-pattern/{{.BeatName}}.json",
"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.

13 changes: 13 additions & 0 deletions filebeat/inputsource/udp/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package udp
import (
"time"

<<<<<<< HEAD:filebeat/inputsource/udp/config.go

Choose a reason for hiding this comment

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

expected 'STRING', found '<<' (and 6 more errors)

"github.com/elastic/beats/libbeat/common/cfgtype"
)

Expand All @@ -28,4 +29,16 @@ type Config struct {
Host string `config:"host"`
MaxMessageSize cfgtype.ByteSize `config:"max_message_size" validate:"positive,nonzero"`
Timeout time.Duration `config:"timeout"`
=======
func init() {
if err := asset.SetFields("packetbeat", "Udp", asset.ModuleFieldsPri, AssetUdp); err != nil {
panic(err)
}
}

// AssetUdp returns asset data.
// This is the base64 encoded gzipped contents of protos/udp.
func AssetUdp() string {
return "eJwBAAD//wAAAAE="
>>>>>>> Introduce local fields generation:packetbeat/protos/udp/fields.go
}
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 filebeat/module/apache2/fields.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/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