-
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
Add the option to generate the template into a file #4323
Conversation
Perhaps we should discuss again with after
Or assuming -S is implies
|
|
||
// XXX: Should we kill the Beat here or just continue? | ||
return fmt.Errorf("Stopping after successfully writing the template to the file.") |
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.
[golint] reported by reviewdog 🐶
error strings should not be capitalized or end with punctuation or a newline
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 this case, dear reviewdog, we know that the error is final, so the punctuation looks better to the user.
libbeat/template/load.go
Outdated
@@ -80,6 +82,41 @@ func (l *Loader) Load() error { | |||
return nil | |||
} | |||
|
|||
func (l *Loader) Generate() 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.
[golint] reported by reviewdog 🐶
exported method Loader.Generate should have comment or be unexported
@ruflin Yeah, I guess we should review the whole I have the feeling we can't get a nice solution as part of this PR, so the question is what do we want for the time being? IMO stopping is much nicer in this case, but it's inconsistent with |
Agree that we can't find a good solution as part of this PR. +1 on stopping as if you want to manually load the template, you don't want to already send data. |
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.
I left a few comments which we should handle in a follow up. Will merge it for now as this is a big step forward.
@@ -469,8 +469,30 @@ func (b *Beat) registerTemplateLoading() error { | |||
} | |||
} | |||
|
|||
esConfig := b.Config.Output["elasticsearch"] | |||
// Check if outputting to file is enabled, and output to file if it is |
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.
This comment confused me at first because the check for the file only happens later, but I see you meant it for the "complete" block
Settings templateSettings `config:"settings"` | ||
OutputToFile OutputToFile `config:"output_to_file"` |
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.
Not too much of a fan of the config name, but well :-)
@@ -80,6 +82,43 @@ func (l *Loader) Load() error { | |||
return nil | |||
} | |||
|
|||
// Generate generates the template and writes it to a file based on the configuration | |||
// from `output_to_file`. | |||
func (l *Loader) Generate() 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.
We could probably now use this function also in https://github.com/elastic/beats/blob/master/dev-tools/cmd/index_template/index_template.go
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.
Oh, I didn't realize we have that utility already.
@@ -9,4 +9,11 @@ def setUpClass(self): | |||
self.beat_name = "mockbeat" | |||
self.beat_path = os.path.abspath(os.path.join(os.path.dirname(__file__), "../../")) | |||
self.test_binary = self.beat_path + "/libbeat.test" | |||
self.beats = [ | |||
"filebeat", |
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.
Looks like a beats specifics dependency in libbeat.
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.
Yeah, only needed for those skipped tets for now, I can delete them.
beats = ["metricbeat", "packetbeat", "filebeat", "winlogbeat"] | ||
|
||
for beat in beats: | ||
for beat in self.beats: |
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.
be aware that these tests are currently skipped.
Part of #3654.
This adds two settings:
setup.template.output_to_file.path
andsetup.template.output_to_file.version
. The version refers to the ES version and is optional, we'll use the Beats version if not specified. I put it underoutput_to_file
to make it clear that it only applies when outputting to a file:To generate a config, one can do:
In the current version, the Beat automatically stops after generating the template, but the output might be slightly confusing:
IMO this is better than the alternative of leaving it running.
To generate the template for the 2.x version, one can do:
Remaining TODOs: