-
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
Build config files with Go text/template #18148
Build config files with Go text/template #18148
Conversation
0befef4
to
1321ab8
Compare
💔 Build FailedExpand to view the summary
Build stats
Test stats 🧪
Test errorsExpand to view the tests failures
--------------------- >> end captured stdout << ---------------------- Steps errorsExpand to view the steps failures
Log outputExpand to view the last 100 lines of log output
|
1321ab8
to
e1227d0
Compare
Pinging @elastic/siem (Team:SIEM) |
cf7876e
to
d433aa7
Compare
Rather than relying on file concatenation followed by Go text/template we'll just use Go text/template. This makes is easier to customize a template without having to modify libbeat since you can just overwrite a template section (like inject your own processors section). This works by loading all of the templates from `libbeat/_meta/config/*.tmpl` followed by templates from `$mybeat/_meta/config/*.tmpl`. Files loaded last take precedence (it uses go text/template ParseGlob). Finally each template is created from `libbeat/_meta/config/default{., reference, docker}.yml.tmpl` (which can be changed if needed, see elastic/agent).
d433aa7
to
af7be22
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.
Great timing! :D I wanted to add similar functionality to add information about the advanced settings of modules in Filebeat to the reference and modules configuration.
…ols/config-go-text-template # Conflicts: # libbeat/_meta/config.yml.tmpl # winlogbeat/_meta/beat.yml.tmpl # winlogbeat/_meta/config/header.yml.tmpl # winlogbeat/scripts/mage/config.go # winlogbeat/winlogbeat.reference.yml # winlogbeat/winlogbeat.yml # x-pack/winlogbeat/_meta/config/winlogbeat.event_logs.yml.tmpl # x-pack/winlogbeat/winlogbeat.yml
…ols/config-go-text-template # Conflicts: # libbeat/_meta/config.reference.yml.tmpl
…ols/config-go-text-template
Rather than relying on file concatenation followed by Go text/template we'll just use Go text/template. This makes is easier to customize a template without having to modify libbeat since you can just overwrite a template section (like inject your own processors section). This works by loading all of the templates from `libbeat/_meta/config/*.tmpl` followed by templates from `$mybeat/_meta/config/*.tmpl`. Files loaded last take precedence (it uses go text/template ParseGlob). Finally each template is created from `libbeat/_meta/config/default{., reference, docker}.yml.tmpl` (which can be changed if needed, see elastic/agent). (cherry picked from commit c81adcc)
…18212) Rather than relying on file concatenation followed by Go text/template we'll just use Go text/template. This makes is easier to customize a template without having to modify libbeat since you can just overwrite a template section (like inject your own processors section). This works by loading all of the templates from `libbeat/_meta/config/*.tmpl` followed by templates from `$mybeat/_meta/config/*.tmpl`. Files loaded last take precedence (it uses go text/template ParseGlob). Finally each template is created from `libbeat/_meta/config/default{., reference, docker}.yml.tmpl` (which can be changed if needed, see elastic/agent). (cherry picked from commit c81adcc)
What does this PR do?
Rather than relying on file concatenation followed by Go text/template we'll just
use Go text/template. This makes is easier to customize a template without having
to modify libbeat since you can just overwrite a template section (like inject your own
processors section).
This works by loading all of the templates from
libbeat/_meta/config/*.tmpl
followedby templates from
$mybeat/_meta/config/*.tmpl
. Files loaded last take precedence(it uses go text/template ParseGlob). Finally each template is created from
libbeat/_meta/config/default{., reference, docker}.yml.tmpl
(which can be changedif needed, see elastic-agent as an example).
Why is it important?
I need to customize the default processors in the Winlogbeat configuration file and I don't want to add some special logic to the libbeat config files (see an example in https://github.com/elastic/beats/pull/18153/files#diff-5a4f08fe070667029d82636401b2aaf9R95). So with this change a Beat can more easily tailor the config to its needs.
Checklist
- [x] I have made corresponding changes to the documentation- [ ] I have added tests that prove my fix is effective or that my feature worksCHANGELOG.next.asciidoc
orCHANGELOG-developer.next.asciidoc
.Author's Checklist
How to test this PR locally
make update
Developer Docs
Any magefile.go that used
devtools.ConfigFileParams
must switch to usingdevtools.DefaultConfigFileParams()
. The append their config file template glob to the list ofTemplates
. Conventionally this is_meta/config/*.tmpl
.