-
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
Adding ability to expand environment variables used in config file #715
Adding ability to expand environment variables used in config file #715
Conversation
7fb2cea
to
0c920e6
Compare
// current environment variables. The replacement is case-sensitive. References | ||
// to undefined variables are replaced by the empty string. A default value | ||
// can be given by using the form ${var:default value}. | ||
func expandEnv(config []byte) []byte { |
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.
Is there a reason we can't use the function provided by golang? https://golang.org/pkg/os/#ExpandEnv
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.
os.ExpandEnv(key)
is os.Expand(key, os.Getenv)
and that's what this does, but with two differences. 1) It logs each replacement which is very important for end-user troubleshooting. 2) It supports setting a default value if you use the form ${var:default value}
.
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.
That is great, especially the logging. Makes later debugging much easier.
I'm generally +1 on this one. I also like the other Elasticsearch config option, which is to overwrite variables from CLI with something like |
@tsg +1 on the -D option. I think there are 2 different use cases: Environment variables for larger deployments, client flags more for testing. Of course, one can compensate for the other. |
…nfig Adding ability to expand environment variables used in config file
Just curious, what's the ETA for this to be publicly available? |
@yoanisgil The best option to already use and test this feature is using our nightly builds: https://beats-nightlies.s3.amazonaws.com/index.html |
@ruflin thanks for the update. I guess I could give it a try but I was just wondering whether this is ready for production usage or not (hence my question about an ETA for public availability). |
@yoanisgil It will be part of the next major release, but it is hard to give an exact date. The nightly builds are quite stable, but of course I would not recommend to run them in production, as we still heavily change stuff on a daily base (and sometimes break stuff). |
Hi |
Adds feature requested in #114. If we choose to accept this enhancement then the documentation will need updated.
Overview
This feature replaces
${var}
or$var
in config files according to the values of the current environment variables.${var:default value}
.Examples
name: $NAME
export NAME=elastic
name: elastic
name: ${NAME}
export NAME=elastic
name: elastic
name: ${NAME:beats}
name: beats
name: ${NAME:beats}
export NAME=elastic
name: elastic
hosts: [$HOSTS]
export HOSTS="'localhost:9200', 'localhost:9202'"
hosts: ['localhost:9200', 'localhost:9202']
Troubleshooting
When logging is enabled at the
info
level or higher, a message is logged for each environment variable replacement. For example: