Hi,
Thanks for continuing the discussion here
Doing some more tests it seems your hitting a bug in go-ucfg itself. A bug fix should be available in this PR.
You can try (and confirm fix works) by checking out the branch and recompile. Steps to test the PR with beats:
# 1. remove the vendored go-ucfg
$ cd $GOPATH/github.com/elastic/beats/vendor/github.com/elastic
$ rm -fR go-ucfg
# 2. clone and check out go-ucfg branch including fix
$ cd $GOPATH/github.com/elastic
$ git clone https://github.com/urso/go-ucfg.git
$ cd go-ucfg
$ git checkout enh/parse
# 3. rebuild filebeat
$ cd $GOPATH/github.com/elastic/beats/filebeat
$ make
The PR includes new tests, checking for your exact use-case: https://github.com/urso/go-ucfg/blob/enh/parse/structs_test.go#L54
With this change config should be:
filebeat.yml
output.logstash:
hosts: '${LOGSTASH_HOSTS:localhost:5043}'
Using LOGSTASH_HOSTS="host1:5043,host2:5043"
should make it work.
In 5.x support for env-vars has been changed and expanded. In 1.x release, env variables have been expanded like string-templates, potentially resulting in YAML parsing errors (with potentially wrong line number). Plus, silently dropping configs if environment variable was missing. In 5.x variable expansion was introduced and more sophisticated variable parsing from configuration itself (after parsing). Variable expansion + parsing + support for overwriting settings in other config files or from command line + referencing other settings in any config file or environment variable + custom error message unfortunately doesn't mix well with plain template like text replacement.
You can for example print an error message if not logstash output is set:
output.logstash:
hosts: '${LOGSTASH_HOSTS:?No logstash host configured}'
and overwrite the hosts from command line -E output.logstash.hosts=host1:5043,host2:5043
Or have a configure default host:
default.host=${TEST_HOST:localhost}
output.logstash:
hosts: '${LOGSTASH_HOSTS:${default.host}:5043}'
and change default host from command line using -E default.host=other-host
.
The 5.x config file format is documented here: https://www.elastic.co/guide/en/beats/libbeat/current/config-file-format.html
Unfortunately the section on environment variable support is still lacking