-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Port fields.yml collector to Golang #6911
Port fields.yml collector to Golang #6911
Conversation
"github.com/elastic/beats/filebeat/generator" | ||
) | ||
|
||
func Generate(module, fileset, modulesPath, beatsPath string) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exported function Generate should have comment or be unexported
filebeat/generator/module/module.go
Outdated
"github.com/elastic/beats/filebeat/generator" | ||
) | ||
|
||
func Generate(module, modulesPath, beatsPath string) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exported function Generate should have comment or be unexported
"path/filepath" | ||
) | ||
|
||
func CollectModuleFiles(root string) ([]*YmlFile, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exported function CollectModuleFiles should have comment or be unexported
"path/filepath" | ||
) | ||
|
||
func CollectFiles(root string) ([]*YmlFile, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exported function CollectFiles should have comment or be unexported
libbeat/generator/fields/fields.go
Outdated
return bytes.Join([][]byte{newline, content}, empty) | ||
} | ||
|
||
func Generate(beatsPath, beatName string, files []*YmlFile) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exported function Generate should have comment or be unexported
filebeat/generator/fields/fields.go
Outdated
return nil | ||
} | ||
|
||
func Generate(moduleName, filesetName, beatsPath string, noDoc bool) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exported function Generate should have comment or be unexported
filebeat/cmd/generate.go
Outdated
|
||
err := fields.Generate(moduleName, filesetName, beatsPath, noDoc) | ||
if err != nil { | ||
return fmt.Errorf("cannot generate fields.yml for %s/%s: %v\n", moduleName, filesetName, err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
error strings should not be capitalized or end with punctuation or a newline
filebeat/cmd/generate.go
Outdated
|
||
err := fileset.Generate(moduleName, filesetName, modulesPath, beatsPath) | ||
if err != nil { | ||
return fmt.Errorf("cannot generate fileset: %v\n", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
error strings should not be capitalized or end with punctuation or a newline
filebeat/cmd/generate.go
Outdated
|
||
modulePath := path.Join(modulesPath, "module", moduleName) | ||
if !generator.DirExists(modulePath) { | ||
fmt.Errorf("cannot generate fileset: module not exists, please create module first by create-module command\n") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
error strings should not be capitalized or end with punctuation or a newline
filebeat/cmd/generate.go
Outdated
|
||
err := module.Generate(name, modulesPath, beatsPath) | ||
if err != nil { | ||
return fmt.Errorf("cannot generate module: %v\n", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
error strings should not be capitalized or end with punctuation or a newline
Could this PR be split up in 2 parts:
This should make reviewing easier and will separate the two different concerns. |
2530189
to
21922fd
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for splitting up in 2 PR's. Review is probably to early but left some notes.
This is really great as soon all the fields.yml collection is directly in golang.
filebeat/beater/filebeat.go
Outdated
@@ -132,6 +133,10 @@ func New(b *beat.Beat, rawConfig *common.Config) (beat.Beater, error) { | |||
return nil, err | |||
} | |||
|
|||
b.CollectFieldsYmlCallback = func() ([]*fields.YmlFile, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Leftover from the other PR?
@@ -5,6 +5,8 @@ SYSTEM_TESTS?=true | |||
TEST_ENVIRONMENT?=true | |||
GOX_FLAGS=-arch="amd64 386 arm ppc64 ppc64le" | |||
ES_BEATS?=.. | |||
FIELDS_FILE_PATH=module |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this only support one path? I could see especially in libbeat or filebeat that a module, processor and inputs have fields.yml.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but it can be changed easily to support lists.
heartbeat/beater/heartbeat.go
Outdated
@@ -49,6 +51,12 @@ func New(b *beat.Beat, cfg *common.Config) (beat.Beater, error) { | |||
scheduler: sched, | |||
manager: manager, | |||
} | |||
|
|||
pathToFields := filepath.Join("monitors", "active") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Leftover?
libbeat/cmd/instance/beat.go
Outdated
@@ -418,6 +419,38 @@ func (b *Beat) Setup(bt beat.Creator, template, dashboards, machineLearning, pip | |||
}()) | |||
} | |||
|
|||
// Setup registers ES index template and kibana dashboards | |||
func (b *Beat) GenerateGlobalFields(bt beat.Creator, beatsPath string) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably also part of the other PR?
21922fd
to
05cb292
Compare
I removed the leftovers from the other PR and added tests. However, I have a Winlogbeat issue I am still investigating. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As this is a breaking change for all our community beats, this should be documented on the CHANGELOG-developer with a note on how to migrate.
libbeat/generator/fields/fields.go
Outdated
}, | ||
} | ||
|
||
//processors := collectProcessorsFields(beatsPath) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be uncommented or removed? Same next line.
libbeat/generator/fields/fields.go
Outdated
content = bytes.Replace(content, newline, c, -1) | ||
content = bytes.TrimRight(content, " ") | ||
|
||
return bytes.Join([][]byte{newline, content}, empty) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we also add a newline after to make sure it ends with a newline?
libbeat/generator/fields/fields.go
Outdated
func Generate(beatsPath, beatName string, files []*YmlFile) error { | ||
files = collectBeatFiles(beatsPath, beatName, files) | ||
|
||
err := os.MkdirAll(filepath.Join(beatsPath, beatName, "_meta"), 0644) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't the global fields.yml
end up outside the _meta
directory?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In Makefiles of Beats the generated file ends up under _meta
. See for example Metricbeat: https://github.com/elastic/beats/blob/master/metricbeat/Makefile#L28
return files, nil | ||
} | ||
|
||
func collect(module os.FileInfo, files []*YmlFile, modulesPath string) []*YmlFile { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we call this collectModule
as this is quite specific to modules?
libbeat/generator/fields/fields.go
Outdated
const ( | ||
generatedFieldsYml = "_meta/fields.generated.yml" | ||
commonFieldsYml = "libbeat/_meta/fields.common.yml" | ||
libbeatFields = "libbeat/processors/*/_meta/fields.yml" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this used somewhere except for the tests? Should this be moved to the tests?
05cb292
to
92e2e85
Compare
libbeat/generator/fields/fields.go
Outdated
generatedFieldsYml = "_meta/fields.generated.yml" | ||
) | ||
|
||
type YmlFile struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exported type YmlFile should have comment or be unexported
I tried the code locally by run
|
An other thing I spotted when testing is that the indentation of |
Yes, I started to refactor the code, so things got messed up and a few things are not working properly. I will ping you when it's ready for a next round of review. |
11f5363
to
f59fd4b
Compare
@ruflin I fixed the problems in the code. It should be ready to be reviewed. |
@kvch Could you have a look at the generator tests? The change seems to break it. |
2c5415d
to
133509e
Compare
91794a4
to
e982a79
Compare
per elastic/beats#6911 set FIELDS_FILE_PATH accordingly.
* use beats provided fields target per elastic/beats#6911 set FIELDS_FILE_PATH accordingly. * Update beats framework to 245b3e1 * removes fields target from top-level Makefile * vendors github.com/elastic/beats/libbeat/generator/fields * cleans up github.com/ericchiang/k8s/...
Existing Python and shell code is ported to Golang. The previous Beat specific field collection is is generalized and moved to the
Makefile
oflibbeat
. A new variable is added to makefiles:FIELDS_FILE_PATH
. This specifies wherefields.yml
are.Misc
fields_base.yml
is renamed tofields.common.yml
to be the same as in other BeatsBreaking change for community Beats
If your Beat has partial
fields.yml
files which need to be collected bymake update
, please fill in theFIELDS_FILE_PATH
variable in yourMakefile
with the root directory of your fields files.If you need a custom collector function you can implement it
module_fields_collector.go
with the following type signature: