Skip to content
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

Cherry-pick #15422 to 7.x: Introduce CLI flag -environment #15829

Merged
merged 2 commits into from
Jan 24, 2020

Conversation

urso
Copy link

@urso urso commented Jan 24, 2020

Cherry-pick of PR #15422 to 7.x branch. Original message:

Type of change

  • Bug fix

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 -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.

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 -e flag with the -environment flag in the systemd unit file. If -environment systemd is 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 -e CLI flag is added to the list of CLI arguments. This was introduced in #8942. The -e flag its purpose is to disable the configured logging output and always log to stdout/stderr. By to enforcing the -e flag the users logging configurations is not honored (for example see the reports in #12024).

Checklist

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation

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:

  • Running a beat (e.g. metricbeat with system module) locally without configuring logging output should log to stdout/stderr if -environment systemd is given on the command line
  • Running beat without -environment flag, without logging configured should create log files as usual

Running a beat via systemd:

  • The Beat should log to journald by default
  • Logs should be written to /var/log/<beatname> when setting logging.to_stderr: false and logging.to_file: true

Running beat using old init scripts:

  • Install Beat on system still using init scripts
  • Logs should be written to /var/log/<beatname> by default

Running as container:

  • The Beat should log to stdout/stderr by default. Check via docker log is this is really the case.
  • Configure to_file in the config file and log to a mounted directory. Check the Beat now writes logs to the configured path.

Running on windows

  • Install the windows package zip file on windows:
    • check the service is correctly installed
    • check the service can be started
    • check the service writes logs to the configured files

Running as service on macOS

  • Install the packaged Beat on macOS. Including launchd files and preference pane:
    • check the service is correctly installed and can be restarted
    • check the service writes logs to the configured files

Related issues

* 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)
@urso urso merged commit f0b0fe8 into elastic:7.x Jan 24, 2020
@urso urso deleted the backport_15422_7.x branch January 24, 2020 19:03
@andresrc andresrc added the Team:Integrations Label for the Integrations team label Mar 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport review Team:Integrations Label for the Integrations team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants