-
Notifications
You must be signed in to change notification settings - Fork 816
Add ability to override configuration settings using environment variables #2147
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
Add ability to override configuration settings using environment variables #2147
Conversation
…ables Signed-off-by: Wing924 <[email protected]>
Signed-off-by: Wing924 <[email protected]>
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.
Thanks for your contribution. Could you describe your use case please? Cortex configuration can be overridden via CLI flags and CLI flags are usually the expected way to override some config using values from environment variables.
@pracucci As you say, put them on flags with environment variables is an option, but I don't like this because many components need to set the same flags: # cassandra settings
- -cassandra.addresses=$(CASSANDRA_ADDRESSES)
- -cassandra.username=$(CASSANDRA_USERNAME)
- -cassandra.password=$(CASSANDRA_PASSWORD) it looks very redundant to me. |
I'm not averse to this myself; having multiple ways of overriding config settings (flags and environment variables) is a oft requested feature in the Prometheus world, and the "config management is someone else's problem" approach has gone down particularly badly. Plus this PR includes docs and tests, so I can't find anything to nit pick! That being said I can see this being a little divisive, so I want to get a feeling from the other maintainers. But I'm +1 on this. |
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.
I agree you did a great job and I'm not against this change as well. I can see a value. However, I've the feeling it may be a possible breaking change (see the comment) reason why I'm wondering if we should enable this only via CLI flag.
CHANGELOG.md
Outdated
@@ -15,6 +15,7 @@ | |||
* `--experimental.distributor.user-subring-size` | |||
* [FEATURE] Added flag `-experimental.ruler.enable-api` to enable the ruler api which implements the Prometheus API `/api/v1/rules` and `/api/v1/alerts` endpoints under the configured `-http.prefix`. #1999 | |||
* [FEATURE] Added sharding support to compactor when using the experimental TSDB blocks storage. #2113 | |||
* [FEATURE] Add ability to override configuration settings using environment variables. #2147 |
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.
I would replace configuration settings
with YAML config file settings
to be more clear.
Signed-off-by: Wing924 <[email protected]>
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.
You did a very good job! LGTM.
I'm going to ping other maintainers as well, to see if there's any strong opinion about not doing env vars expansion in the config.
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.
lgtm
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.
++1
Inspired by cortexproject/cortex#2147 Fixes grafana#2311 Adds -config.expand-env as flag to loki and promtail.
* Support environment expansion in configuration Inspired by cortexproject/cortex#2147 Fixes #2311 Adds -config.expand-env as flag to loki and promtail. * Disable env expansion on logcli * Small nit updates
What this PR does:
You can use environment variable references in the config file to set values that need to be configurable during deployment.
To do this, use:
Where VAR is the name of the environment variable.
Each variable reference is replaced at startup by the value of the environment variable.
The replacement is case-sensitive and occurs before the YAML file is parsed.
References to undefined variables are replaced by empty strings unless you specify a default value or custom error text.
To specify a default value, use:
Where default_value is the value to use if the environment variable is undefined.
Which issue(s) this PR fixes:
Checklist
CHANGELOG.md
updated - the order of entries should be[CHANGE]
,[FEATURE]
,[ENHANCEMENT]
,[BUGFIX]