Introduce CLI flag -environment#15422
Conversation
|
@jsoriano @andrewkroh Some idea for fixing the logging configuration not being ignored when running via systemd. WDYT? |
I think this can be a good approach for the issues raised in #12024 👍 |
|
We will also need to update docs where we mention the default value for |
13f090c to
45540f2
Compare
|
cc @elastic/apm-server |
jsoriano
left a comment
There was a problem hiding this comment.
It mostly LGTM, I have added some minor comments. Thanks for addressing this issue!
libbeat/logp/configure/logging.go
Outdated
There was a problem hiding this comment.
We should add docs about this new flag.
There was a problem hiding this comment.
It is kind of a private flag (a hack) I just introduced as a workaround. I rather wish to remove the flag again in the future. Maybe for 8.0 we have to rethink some logging defaults. e.g. maybe we can detect the environment we are running in, or just log to stdout/stderr by default.
There was a problem hiding this comment.
Yep, I think we could consider logging to stdout/stderr by default on 8.0.
libbeat/logp/configure/logging.go
Outdated
There was a problem hiding this comment.
Yep, I think we could consider logging to stdout/stderr by default on 8.0.
d5d0ded to
0063bbb
Compare
CHANGELOG.next.asciidoc
Outdated
There was a problem hiding this comment.
Looks like a line got dropped from the changelog somehow. The full text of this should be:
Fix panics that could result from invalid TLS certificates. This can affect Beats that connect over TLS, or Beats that accept connections over TLS and validate client certificates. {pull}14146[14146]
There was a problem hiding this comment.
It's not clear up front that this setting relates to logging. Here's my suggested edit based on what I think you're saying here:
For logging purposes, specifies the environment that {beatname_uc} is running in.
This setting is used to select a default log output when no log output is configured.
Supported values are: `systemd`, `container`, `macos_service`, and `windows_service`.
If `systemd` or `container` is specified, {beatname_uc} will log to stdout and stderr
by default.
There was a problem hiding this comment.
Thanks, will update. Initially I didn't want to this setting to be about logging only. A generic flag like environment is not really bound to logging. Other subsystems could also be configured differently based on the environment. On the other hand I'd prefer to not have this flag at all...
dedemorton
left a comment
There was a problem hiding this comment.
LGTM. We can always revisit the description later on if the -environment option stays around and gets used for other things. :-)
992c4df to
fe92cd5
Compare
|
Jenkins, test this. |
1 similar comment
|
Jenkins, test this. |
Add windows_service, macos_service, and container envionment types. If beats are installed using our scripts the `-environment` flag will always be set. Replace `-e` with `-environment docker` CLI flag in the Dockerfile. Although it's uncommon, users can not overwrite the logging configuration in docker containers as well. The docker(container) environment and systemd environment will default to stdout/stderr logging. All other environments continue to use file rotation as default.
14d3ff4 to
64aff4c
Compare
* Introduce CLI flag -environment Introduce CLI flags -environment to control the default logging settings the Beat should use if no logging is configured. The behavior of -e does not change. By replacing `-e` with `-environment system` in the system unit file we continue to log to stdout/stderr by default, but users are still able to overwrite settings. * Add more environment types Add windows_service, macos_service, and container envionment types. If beats are installed using our scripts the `-environment` flag will always be set. Replace `-e` with `-environment docker` CLI flag in the Dockerfile. Although it's uncommon, users can not overwrite the logging configuration in docker containers as well. The docker(container) environment and systemd environment will default to stdout/stderr logging. All other environments continue to use file rotation as default. (cherry picked from commit 1d3d4d1)
* Introduce CLI flag -environment (#15422) * Introduce CLI flag -environment Introduce CLI flags -environment to control the default logging settings the Beat should use if no logging is configured. The behavior of -e does not change. By replacing `-e` with `-environment system` in the system unit file we continue to log to stdout/stderr by default, but users are still able to overwrite settings. * Add more environment types Add windows_service, macos_service, and container envionment types. If beats are installed using our scripts the `-environment` flag will always be set. Replace `-e` with `-environment docker` CLI flag in the Dockerfile. Although it's uncommon, users can not overwrite the logging configuration in docker containers as well. The docker(container) environment and systemd environment will default to stdout/stderr logging. All other environments continue to use file rotation as default. (cherry picked from commit 1d3d4d1)
Type of change
What does this PR do?
Introduce CLI flags -environment to control the default logging settings
the Beat should use if no logging is configured. The behavior of -e does
not change. By replacing
-ewith-environment systemin the systemunit file we continue to log to stdout/stderr by default, but users are
still able to overwrite settings.
For now (I'm targeting 7.x) I tried to not introduce any breaking changes one way or the other on the config file or CLI level. So the idea is to replace the
-eflag with the-environmentflag in the systemd unit file. If-environment systemdis given the default log output is stdout/stderr, while we keep file based logging as default for other environments.Why is it important?
If beats are started via systemd unit files the
-eCLI flag is added to the list of CLI arguments. This was introduced in #8942. The-eflag its purpose is to disable the configured logging output and always log to stdout/stderr. By to enforcing the-eflag the users logging configurations is not honored (for example see the reports in #12024).Checklist
How to test this PR locally
The PR changes how beats are started as Windows Service, macOS service (installed via launchctl), docker container, and via systemd (deb/rpm). For testing Beats must be installed in a few different environment types to check if logs are correctly written to the default target and if log settings can be overwritten.
Running beat locally via command line:
-environment systemdis given on the command line-environmentflag, without logging configured should create log files as usualRunning a beat via systemd:
/var/log/<beatname>when settinglogging.to_stderr: falseandlogging.to_file: trueRunning beat using old init scripts:
/var/log/<beatname>by defaultRunning as container:
docker logis this is really the case.Running on windows
Running as service on macOS
Related issues