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
kvch
left a comment
There was a problem hiding this comment.
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/*.tmplfollowedby 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.asciidocorCHANGELOG-developer.next.asciidoc.Author's Checklist
How to test this PR locally
make updateDeveloper Docs
Any magefile.go that used
devtools.ConfigFileParamsmust switch to usingdevtools.DefaultConfigFileParams(). The append their config file template glob to the list ofTemplates. Conventionally this is_meta/config/*.tmpl.