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

Build config files with Go text/template #18148

Conversation

andrewkroh
Copy link
Member

@andrewkroh andrewkroh commented May 1, 2020

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 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 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

  • My code follows the style guidelines of this project
  • I have commented my code, particularly in hard-to-understand areas
    - [x] I have made corresponding changes to the documentation
  • I have made corresponding change to the default configuration files
    - [ ] I have added tests that prove my fix is effective or that my feature works
  • I have added an entry in CHANGELOG.next.asciidoc or CHANGELOG-developer.next.asciidoc.

Author's Checklist

  • Review the generate config files. The only changes should be spacing and headings.

How to test this PR locally

make update

Developer Docs

Any magefile.go that used devtools.ConfigFileParams must switch to using devtools.DefaultConfigFileParams(). The append their config file template glob to the list of Templates. Conventionally this is _meta/config/*.tmpl.

@andrewkroh andrewkroh requested review from a team as code owners May 1, 2020 18:54
@botelastic botelastic bot added the needs_team Indicates that the issue/PR needs a Team:* label label May 1, 2020
@andrewkroh andrewkroh force-pushed the feature/dev-tools/config-go-text-template branch 2 times, most recently from 0befef4 to 1321ab8 Compare May 1, 2020 18:55
@elasticmachine
Copy link
Collaborator

elasticmachine commented May 1, 2020

💔 Build Failed

Pipeline View Test View Changes Artifacts preview stats

Expand to view the summary

Build stats

Test stats 🧪

Test Results
Failed 1
Passed 7687
Skipped 1210
Total 8898

Test errors

Expand to view the tests failures

  • Name: Build and Test / Filebeat Windows / test_clean_removed_with_clean_inactive – test_registrar.Test
    • Status: FAILED
    • Age: 1
    • Duration: 0.656
    • Error Details:
      -------------------- >> begin captured stdout << ---------------------
      registry size: 2
      registry size after remove: 0

--------------------- >> end captured stdout << ----------------------

Steps errors

Expand to view the steps failures

  • Name: Mage build unitTest

    • Description: mage build unitTest

    • Result: FAILURE

    • Duration: 9 min 25 sec<

    • Start Time: 2020-05-04T14:57:48.598+0000

  • Name: Make -C generator/_templates/metricbeat test

    • Description: make -C generator/_templates/metricbeat test

    • Result: FAILURE

    • Duration: 1 min 57 sec<

    • Start Time: 2020-05-04T14:57:11.770+0000

  • Name: Make -C generator/_templates/beat test

    • Description: make -C generator/_templates/beat test

    • Result: FAILURE

    • Duration: 1 min 53 sec<

    • Start Time: 2020-05-04T14:59:39.628+0000

  • Name: Make -C generator/_templates/metricbeat test

    • Description: make -C generator/_templates/metricbeat test

    • Result: FAILURE

    • Duration: 1 min 16 sec<

    • Start Time: 2020-05-04T15:14:33.974+0000

  • Name: Make -C generator/_templates/beat test

    • Description: make -C generator/_templates/beat test

    • Result: FAILURE

    • Duration: 2 min 39 sec<

    • Start Time: 2020-05-04T15:31:22.980+0000

Log output

Expand to view the last 100 lines of log output

[2020-05-04T15:56:23.686Z] [success] 67.12% test_base.Test.test_export_function: 0.2376s
[2020-05-04T15:56:23.686Z] [success] 32.88% test_base.Test.test_export_function_invalid_conf: 0.1164s
[2020-05-04T15:56:23.686Z] ----------------------------------------------------------------------
[2020-05-04T15:56:23.686Z] Ran 3 tests in 0.355s
[2020-05-04T15:56:23.686Z] 
[2020-05-04T15:56:23.686Z] OK (SKIP=1)
[2020-05-04T15:56:23.686Z] >> python test: Unit Testing Complete
[2020-05-04T15:56:23.752Z] Recording test results
[2020-05-04T15:56:29.968Z] Stashed 2 file(s)
[2020-05-04T15:56:29.980Z] Archiving artifacts
[2020-05-04T15:56:32.444Z] Running in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-18148/src/github.com/elastic/beats
[2020-05-04T15:56:32.759Z] + find . -type f -name TEST*.xml -path */build/* -delete
[2020-05-04T15:56:32.776Z] Running in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-18148/src/github.com/elastic/beats/Lint
[2020-05-04T15:56:32.865Z] Running in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-18148/src/github.com/elastic/beats/Elastic-Agent-Mac-OS-X
[2020-05-04T15:56:32.966Z] Running in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-18148/src/github.com/elastic/beats/Elastic-Agent-x-pack
[2020-05-04T15:56:33.061Z] Running in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-18148/src/github.com/elastic/beats/Winlogbeat-oss
[2020-05-04T15:56:33.143Z] Running in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-18148/src/github.com/elastic/beats/Generators-Metricbeat-Linux
[2020-05-04T15:56:33.224Z] Running in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-18148/src/github.com/elastic/beats/Journalbeat-oss
[2020-05-04T15:56:33.307Z] Running in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-18148/src/github.com/elastic/beats/Dockerlogbeat
[2020-05-04T15:56:33.378Z] Running in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-18148/src/github.com/elastic/beats/Generators-Beat-Linux
[2020-05-04T15:56:33.452Z] Running in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-18148/src/github.com/elastic/beats/Elastic-Agent-x-pack-Windows
[2020-05-04T15:56:33.535Z] Running in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-18148/src/github.com/elastic/beats/Filebeat-Mac-OS-X
[2020-05-04T15:56:33.614Z] Running in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-18148/src/github.com/elastic/beats/Functionbeat-x-pack
[2020-05-04T15:56:33.703Z] Running in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-18148/src/github.com/elastic/beats/Metricbeat-Mac-OS-X
[2020-05-04T15:56:33.771Z] Running in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-18148/src/github.com/elastic/beats/Metricbeat-crosscompile
[2020-05-04T15:56:33.842Z] Running in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-18148/src/github.com/elastic/beats/Metricbeat-OSS-Unit-tests
[2020-05-04T15:56:33.922Z] Running in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-18148/src/github.com/elastic/beats/Heartbeat-oss
[2020-05-04T15:56:34.002Z] Running in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-18148/src/github.com/elastic/beats/Filebeat-Windows
[2020-05-04T15:56:34.075Z] Running in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-18148/src/github.com/elastic/beats/Winlogbeat-Windows-x-pack
[2020-05-04T15:56:34.142Z] Running in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-18148/src/github.com/elastic/beats/Auditbeat-x-pack
[2020-05-04T15:56:34.214Z] Running in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-18148/src/github.com/elastic/beats/Libbeat-x-pack
[2020-05-04T15:56:34.279Z] Running in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-18148/src/github.com/elastic/beats/Packetbeat-oss
[2020-05-04T15:56:34.340Z] Running in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-18148/src/github.com/elastic/beats/Auditbeat-Linux
[2020-05-04T15:56:34.406Z] Running in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-18148/src/github.com/elastic/beats/Metricbeat-Windows
[2020-05-04T15:56:34.482Z] Running in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-18148/src/github.com/elastic/beats/Generators-Metricbeat-Mac-OS-X
[2020-05-04T15:56:34.554Z] Running in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-18148/src/github.com/elastic/beats/Winlogbeat-Windows
[2020-05-04T15:56:34.633Z] Running in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-18148/src/github.com/elastic/beats/Filebeat-x-pack
[2020-05-04T15:56:34.710Z] Running in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-18148/src/github.com/elastic/beats/Auditbeat-crosscompile
[2020-05-04T15:56:34.779Z] Running in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-18148/src/github.com/elastic/beats/Filebeat-oss
[2020-05-04T15:56:34.868Z] Running in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-18148/src/github.com/elastic/beats/Metricbeat-OSS-Integration-tests
[2020-05-04T15:56:34.963Z] Running in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-18148/src/github.com/elastic/beats/Metricbeat-Python-integration-tests
[2020-05-04T15:56:35.053Z] Running in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-18148/src/github.com/elastic/beats/Libbeat-oss
[2020-05-04T15:56:35.127Z] Running in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-18148/src/github.com/elastic/beats/Heartbeat-Mac-OS-X
[2020-05-04T15:56:35.189Z] Running in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-18148/src/github.com/elastic/beats/Generators-Beat-Mac-OS-X
[2020-05-04T15:56:35.273Z] Running in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-18148/src/github.com/elastic/beats/Functionbeat-Mac-OS-X-x-pack
[2020-05-04T15:56:35.361Z] Running in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-18148/src/github.com/elastic/beats/Auditbeat-Mac-OS-X
[2020-05-04T15:56:35.430Z] Running in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-18148/src/github.com/elastic/beats/Libbeat-crosscompile
[2020-05-04T15:56:35.522Z] Running in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-18148/src/github.com/elastic/beats/Libbeat-stress-tests
[2020-05-04T15:56:35.591Z] Running in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-18148/src/github.com/elastic/beats/Heartbeat-Windows
[2020-05-04T15:56:35.667Z] Running in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-18148/src/github.com/elastic/beats/Metricbeat-x-pack
[2020-05-04T15:56:35.735Z] Running in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-18148/src/github.com/elastic/beats/Auditbeat-Windows
[2020-05-04T15:56:35.804Z] Running in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-18148/src/github.com/elastic/beats/Functionbeat-Windows
[2020-05-04T15:56:36.160Z] + cat
[2020-05-04T15:56:36.160Z] + /usr/local/bin/runbld ./runbld-script
[2020-05-04T15:56:36.160Z] Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF8
[2020-05-04T15:56:42.762Z] runbld>>> runbld started
[2020-05-04T15:56:42.762Z] runbld>>> 1.6.11/a66728ff8f4356963772e6e6d2069392fa06acbe
[2020-05-04T15:56:44.146Z] runbld>>> The following profiles matched the job 'Beats/beats-beats-mbp/PR-18148' in order of occurrence in the config (last value wins).
[2020-05-04T15:56:45.527Z] runbld>>> Debug logging enabled.
[2020-05-04T15:56:45.527Z] runbld>>> Storing result
[2020-05-04T15:56:45.527Z] runbld>>> Store result: created {:total 2, :successful 2, :failed 0} 1
[2020-05-04T15:56:45.527Z] runbld>>> BUILD: https://c150076387b5421f9154dfbf536e5c60.us-west1.gcp.cloud.es.io:9243/build-1587637540455/t/20200504155645-965DA149
[2020-05-04T15:56:45.527Z] runbld>>> Adding system facts.
[2020-05-04T15:56:46.482Z] runbld>>> Adding vcs info for the latest commit:  af7be2270cb939bf04230a42fde7407d974d802e
[2020-05-04T15:56:46.482Z] runbld>>> >>>>>>>>>>>> SCRIPT EXECUTION BEGIN >>>>>>>>>>>>
[2020-05-04T15:56:46.482Z] runbld>>> Adding /usr/lib/jvm/java-8-openjdk-amd64/bin to the path.
[2020-05-04T15:56:46.742Z] Processing JUnit reports with runbld...
[2020-05-04T15:56:46.742Z] + echo 'Processing JUnit reports with runbld...'
[2020-05-04T15:56:47.002Z] runbld>>> <<<<<<<<<<<< SCRIPT EXECUTION END <<<<<<<<<<<<
[2020-05-04T15:56:47.003Z] runbld>>> DURATION: 9ms
[2020-05-04T15:56:47.003Z] runbld>>> STDOUT: 40 bytes
[2020-05-04T15:56:47.003Z] runbld>>> STDERR: 49 bytes
[2020-05-04T15:56:47.003Z] runbld>>> WRAPPED PROCESS: SUCCESS (0)
[2020-05-04T15:56:47.003Z] runbld>>> Searching for build metadata in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-18148/src/github.com/elastic/beats
[2020-05-04T15:56:48.385Z] runbld>>> Storing build metadata: 
[2020-05-04T15:56:48.385Z] runbld>>> Adding test report.
[2020-05-04T15:56:48.385Z] runbld>>> Searching for junit test output files with the pattern: TEST-.*\.xml$ in: /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-18148/src/github.com/elastic/beats
[2020-05-04T15:56:49.765Z] runbld>>> Found 102 test output files
[2020-05-04T15:56:50.026Z] runbld>>> No testsuite node found in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-18148/src/github.com/elastic/beats/Metricbeat-x-pack/x-pack/metricbeat/build/TEST-go-integration-openmetrics.xml
[2020-05-04T15:56:50.026Z] runbld>>> No testsuite node found in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-18148/src/github.com/elastic/beats/Metricbeat-x-pack/x-pack/metricbeat/build/TEST-go-integration-istio.xml
[2020-05-04T15:56:50.026Z] runbld>>> No testsuite node found in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-18148/src/github.com/elastic/beats/Metricbeat-x-pack/x-pack/metricbeat/build/TEST-go-integration-iis.xml
[2020-05-04T15:56:50.287Z] runbld>>> No testsuite node found in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-18148/src/github.com/elastic/beats/Metricbeat-x-pack/x-pack/metricbeat/build/TEST-go-integration-activemq.xml
[2020-05-04T15:56:50.287Z] runbld>>> No testsuite node found in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-18148/src/github.com/elastic/beats/Metricbeat-x-pack/x-pack/metricbeat/build/TEST-go-integration-tomcat.xml
[2020-05-04T15:56:50.287Z] runbld>>> No testsuite node found in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-18148/src/github.com/elastic/beats/Metricbeat-x-pack/x-pack/metricbeat/build/TEST-go-integration-cloudfoundry.xml
[2020-05-04T15:56:51.231Z] runbld>>> No testsuite node found in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-18148/src/github.com/elastic/beats/Metricbeat-OSS-Integration-tests/metricbeat/build/TEST-go-integration-windows.xml
[2020-05-04T15:56:51.231Z] runbld>>> No testsuite node found in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-18148/src/github.com/elastic/beats/Metricbeat-OSS-Integration-tests/metricbeat/build/TEST-go-integration-graphite.xml
[2020-05-04T15:56:51.491Z] runbld>>> Test output logs contained: Errors: 0 Failures: 1 Tests: 8748 Skipped: 1006
[2020-05-04T15:56:51.491Z] runbld>>> Storing result
[2020-05-04T15:56:51.491Z] runbld>>> FAILURES: 1
[2020-05-04T15:56:52.061Z] runbld>>> Store result: updated {:total 2, :successful 2, :failed 0} 2
[2020-05-04T15:56:52.061Z] runbld>>> BUILD: https://c150076387b5421f9154dfbf536e5c60.us-west1.gcp.cloud.es.io:9243/build-1587637540455/t/20200504155645-965DA149
[2020-05-04T15:56:52.061Z] runbld>>> Email notification disabled by environment variable.
[2020-05-04T15:56:52.061Z] runbld>>> Slack notification disabled by environment variable.
[2020-05-04T15:56:57.677Z] Running on Jenkins in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-18148
[2020-05-04T15:56:57.790Z] [INFO] getVaultSecret: Getting secrets
[2020-05-04T15:56:57.848Z] Masking supported pattern matches of $VAULT_ADDR or $VAULT_ROLE_ID or $VAULT_SECRET_ID
[2020-05-04T15:56:58.599Z] + chmod 755 generate-build-data.sh
[2020-05-04T15:56:58.599Z] + ./generate-build-data.sh https://beats-ci.elastic.co/blue/rest/organizations/jenkins/pipelines/Beats/beats-beats-mbp/PR-18148/ https://beats-ci.elastic.co/blue/rest/organizations/jenkins/pipelines/Beats/beats-beats-mbp/PR-18148/runs/6 FAILURE 6361243
[2020-05-04T15:56:58.850Z] INFO: curl https://beats-ci.elastic.co/blue/rest/organizations/jenkins/pipelines/Beats/beats-beats-mbp/PR-18148/runs/6/steps/?limit=10000 -o steps-info.json
[2020-05-04T15:56:59.761Z] INFO: curl https://beats-ci.elastic.co/blue/rest/organizations/jenkins/pipelines/Beats/beats-beats-mbp/PR-18148/runs/6/tests/?status=FAILED -o tests-errors.json

@andrewkroh andrewkroh force-pushed the feature/dev-tools/config-go-text-template branch from 1321ab8 to e1227d0 Compare May 2, 2020 00:52
@elasticmachine
Copy link
Collaborator

Pinging @elastic/siem (Team:SIEM)

@andresrc andresrc removed the needs_team Indicates that the issue/PR needs a Team:* label label May 2, 2020
@andrewkroh andrewkroh force-pushed the feature/dev-tools/config-go-text-template branch 2 times, most recently from cf7876e to d433aa7 Compare May 3, 2020 15:58
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).
@andrewkroh andrewkroh force-pushed the feature/dev-tools/config-go-text-template branch from d433aa7 to af7be22 Compare May 4, 2020 14:10
Copy link
Contributor

@kvch kvch left a 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
@andrewkroh andrewkroh merged commit c81adcc into elastic:master May 4, 2020
andrewkroh added a commit to andrewkroh/beats that referenced this pull request May 4, 2020
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)
andrewkroh added a commit that referenced this pull request May 5, 2020
…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)
@andrewkroh andrewkroh added the release-note:dev_docs Contains a Dev Docs section label May 6, 2020
@ph ph mentioned this pull request Jun 17, 2020
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-note:dev_docs Contains a Dev Docs section review v7.8.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants