-
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
Document complex object support in env vars #4200
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,13 +6,20 @@ | |
//// Use the appropriate variables defined in the index.asciidoc file to | ||
//// resolve Beat names: beatname_uc and beatname_lc. | ||
//// Use the following include to pull this content into a doc file: | ||
//// :standalone: | ||
//// include::../../libbeat/docs/shared-env-vars.asciidoc[] | ||
//// Specify :standalone: when this file is pulled into and index. When | ||
//// the file is embedded in another file, do no specify :standalone: | ||
////////////////////////////////////////////////////////////////////////// | ||
|
||
ifdef::standalone[] | ||
|
||
[[using-environ-vars]] | ||
== Using Environment Variables in the Configuration | ||
|
||
You can use environment variable references in the +{beatname_lc}.yml+ file to | ||
endif::[] | ||
|
||
You can use environment variable references in the config file to | ||
set values that need to be configurable during deployment. To do this, use: | ||
|
||
`${VAR}` | ||
|
@@ -22,18 +29,36 @@ 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. To specify a default value, use: | ||
you specify a default value or custom error text. | ||
|
||
To specify a default value, use: | ||
|
||
`${VAR:default_value}` | ||
|
||
Where `default_value` is the value to use if the environment variable is | ||
undefined. | ||
|
||
To specify custom error text, use: | ||
|
||
`${VAR:?error_text}` | ||
|
||
Where `error_text` is custom text that will be prepended to the error | ||
message if the environment variable cannot be expanded. | ||
|
||
If you need to use a literal `${` in your configuration file then you can write | ||
`$${` to escape the expansion. | ||
|
||
After changing the value of an environment variable, you need to restart | ||
{beatname_uc} to pick up the new value. | ||
the Beat to pick up the new value. | ||
|
||
[NOTE] | ||
================================== | ||
You can also specify environment variables when you override a config | ||
setting from the command line by using the `-E` option. For example: | ||
|
||
`-E name=${NAME}` | ||
|
||
================================== | ||
|
||
[float] | ||
=== Examples | ||
|
@@ -43,9 +68,43 @@ and what each configuration looks like after replacement: | |
|
||
[options="header"] | ||
|================================== | ||
|Config source |Environment setting |Config after replacement | ||
|`name: ${NAME}` |`export NAME=elastic` |`name: elastic` | ||
|`name: ${NAME}` |no setting |`name:` | ||
|`name: ${NAME:beats}` |no setting |`name: beats` | ||
|`name: ${NAME:beats}` |`export NAME=elastic` |`name: elastic` | ||
|Config source |Environment setting |Config after replacement | ||
|`name: ${NAME}` |`export NAME=elastic` |`name: elastic` | ||
|`name: ${NAME}` |no setting |`name:` | ||
|`name: ${NAME:beats}` |no setting |`name: beats` | ||
|`name: ${NAME:beats}` |`export NAME=elastic` |`name: elastic` | ||
|`name: ${NAME:?You need to set the NAME environment variable}` |no setting | None. Returns an error message that's prepended with the custom text. | ||
|`name: ${NAME:?You need to set the NAME environment variable}` |`export NAME=elastic` | `name: elastic` | ||
|================================== | ||
|
||
[float] | ||
=== Specifying Complex Objects in Environment Variables | ||
|
||
You can specify complex objects, such as lists or dictionaries, in environment | ||
variables by using a JSON-like syntax. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe we want to be more explicit here, as e.g.: Like with JSON, dictionaries and lists are constructed using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good idea. fixed. |
||
|
||
As with JSON, dictionaries and lists are constructed using `{}` and `[]`. But | ||
unlike JSON, the syntax allows for trailing commas and slightly different string | ||
quotation rules. Strings can be unquoted, single-quoted, or double-quoted, as a | ||
convenience for simple settings and to make it easier for you to mix quotation | ||
usage in the shell. Arrays at the top-level do not require brackets (`[]`). | ||
|
||
For example, the following environment variable is set to a list: | ||
|
||
[source,yaml] | ||
------------------------------------------------------------------------------- | ||
ES_HOSTS="10.45.3.2:9220,10.45.3.1:9230" | ||
------------------------------------------------------------------------------- | ||
|
||
You can reference this variable in the config file: | ||
|
||
[source,yaml] | ||
------------------------------------------------------------------------------- | ||
output.elasticsearch: | ||
hosts: '${ES_HOSTS}' | ||
------------------------------------------------------------------------------- | ||
|
||
When the Beat loads the config file, it resolves the environment variable and | ||
replaces it with the specified list before reading the `hosts` setting. | ||
|
||
NOTE: Do not use double-quotes (`"`) to wrap regular expressions, or the backslash (`\`) will be interpreted as an escape character. |
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.
maybe include sample config and final config here?
e.g. with
-E output='{elasticsearch.enabled: false, console.pretty: true}'
and a config file like:
then the final configuration presented to the beat becomes:
That is, overwriting fields with complex objects will merge the object with the original configuration, not changing/overwriting any other settings.
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.
added