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

Include the default log4j config in Docker images #62758

Closed
pugnascotia opened this issue Sep 22, 2020 · 4 comments · Fixed by #65778
Closed

Include the default log4j config in Docker images #62758

pugnascotia opened this issue Sep 22, 2020 · 4 comments · Fixed by #65778
Assignees
Labels
:Core/Infra/Logging Log management and logging utilities >enhancement needs:triage Requires assignment of a team area label Team:Core/Infra Meta label for core/infra team v8.0.0-alpha1

Comments

@pugnascotia
Copy link
Contributor

At present we ship a custom log4j configuration in our Docker images. This done to make the images more "Docker-like", since the convention with Docker is to write all container output to stdout and stderr.

This is not ideal, because:

  • It is more difficult for Filebeat to use the right event.dataset value
  • There can be drift between the configurations
  • Users can't easily choose to use the default logging config and have to bind-mount their own config
  • Writing to stdout / stderr doesn't extend to the logging configurations that plugins can supply

Elasticsearch should make it easy to pick what style of logging to use in Docker. Ideally, the stdout/stderr logging config should be automatically derived from the default configs, so as to minimise drift.

@pugnascotia pugnascotia added >enhancement :Core/Infra/Logging Log management and logging utilities v8.0.0 labels Sep 22, 2020
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-core-infra (:Core/Infra/Logging)

@elasticmachine elasticmachine added the Team:Core/Infra Meta label for core/infra team label Sep 22, 2020
@pugnascotia pugnascotia self-assigned this Oct 13, 2020
@pugnascotia
Copy link
Contributor Author

pugnascotia commented Dec 2, 2020

I spent some time time thinking about this. I did consider whether we should simply stop tailoring logging for Docker in v8.0. This would be a simple solution, but users relying on the current logging arrangement would then have to recreate it themselves. Logging to stderr / stdout remains the expected default behaviour in the Docker world.

So then I wondered about shipping a log4j2.stack.properties file and a log4j2.docker.properties file in the Docker image, and changing the entrypoint script to symlink the appropriate file as log4j2.properties at runtime. This would only happen if there were no existing log4j2.properties file, so a user mounting their own config directory or properties file would be unaffected. A new environment variable would indicate the preferred logging style, for example ES_LOG_STYLE=stack or something like that. We might want to build the image with a default symlink pointing to the docker config, so that ES can still start if the entrypoint didn't run ES directly. This strategy with symlinks would avoid making changes in the LogConfigurator class.

There's also the question of whether it's possible to automatically generate a Docker log4j2.properties from the default copy. I actually wondered whether it would be easier to concoct some kind of meta-config, and generate both the stack and docker templates from that. Just a though, and probably an impractical one. It'll still likely be easier to somehow parse the stack config, and output a Docker variant.

@pugnascotia
Copy link
Contributor Author

One other possibility would be to convert the standard logging config to a docker-style config at runtime. While more complex, this would pick up any log configurations for installed plugins as well. Making this work in practise would likely be tricky, however.

@pugnascotia
Copy link
Contributor Author

In the course of looking into this, I started wondering if we should make it possible to direct GC logs to stderr, instead of to file as we do at present. It's a separate concern, and I think we'd need to make it opt-in because the usual settings that we apply result in a lot of logs, and stderr obviously has no file rotation.

pugnascotia added a commit to pugnascotia/elasticsearch that referenced this issue Dec 2, 2020
Closes elastic#62758.

Include the Stack log4j config in the Docker image, in order to make it
possible to write logs in a container environment in the same way as for
an archive or package deployment. This is useful in situations where the
user is bind-mounting the logs directory and has their own arrangements
for log shipping.
@rjernst rjernst added the needs:triage Requires assignment of a team area label label Dec 3, 2020
pugnascotia added a commit that referenced this issue Dec 10, 2020
Closes #62758.

Include the Stack log4j config in the Docker image, in order to
make it possible to write logs in a container environment in the
same way as for an archive or package deployment. This is useful
in situations where the user is bind-mounting the logs directory
and has their own arrangements for log shipping.

To use stack logging, set the environment variable `ES_LOG_STYLE`
to `file`. It can also be set to `console`, which is the same as
not specifying it at all.

The Docker logging config is now auto-generated at image build time,
by running the default config through a transformer program when
preparing the distribution in an image builder step.

Also, in the docker distribution `build.gradle`, I changed a helper
closure into a class with a static method in order to fix an
issue where the Docker image was always being rebuilt, even when
there were no changes.
pugnascotia added a commit to pugnascotia/elasticsearch that referenced this issue Dec 10, 2020
Backport of elastic#65778.

Closes elastic#62758.

Include the Stack log4j config in the Docker image, in order to
make it possible to write logs in a container environment in the
same way as for an archive or package deployment. This is useful
in situations where the user is bind-mounting the logs directory
and has their own arrangements for log shipping.

To use stack logging, set the environment variable `ES_LOG_STYLE`
to `file`. It can also be set to `console`, which is the same as
not specifying it at all.

The Docker logging config is now auto-generated at image build time,
by running the default config through a transformer program when
preparing the distribution in an image builder step.

Also, in the docker distribution `build.gradle`, I changed a helper
closure into a class with a static method in order to fix an
issue where the Docker image was always being rebuilt, even when
there were no changes.
pugnascotia added a commit that referenced this issue Dec 10, 2020
Backport of #65778.

Closes #62758.

Include the Stack log4j config in the Docker image, in order to
make it possible to write logs in a container environment in the
same way as for an archive or package deployment. This is useful
in situations where the user is bind-mounting the logs directory
and has their own arrangements for log shipping.

To use stack logging, set the environment variable `ES_LOG_STYLE`
to `file`. It can also be set to `console`, which is the same as
not specifying it at all.

The Docker logging config is now auto-generated at image build time,
by running the default config through a transformer program when
preparing the distribution in an image builder step.

Also, in the docker distribution `build.gradle`, I changed a helper
closure into a class with a static method in order to fix an
issue where the Docker image was always being rebuilt, even when
there were no changes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Core/Infra/Logging Log management and logging utilities >enhancement needs:triage Requires assignment of a team area label Team:Core/Infra Meta label for core/infra team v8.0.0-alpha1
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants