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

NIFI-9688 Improve Logback shutdown handling #5805

Merged
merged 2 commits into from
Feb 28, 2022

Conversation

exceptionfactory
Copy link
Contributor

Description of PR

NIFI-9688 Improves Logback shutdown handling, avoiding premature closure of the Logback context during application shutdown, and enabling log messages to be written during application termination.

The default LogbackServletContainerInitializer registers a LogbackServletContainerListener that closes the Logback context on web application shutdown. When Jetty registers NiFi web applications, it configures the Logback initializer using the standard Java ServiceLoader. With this behavior, Jetty calls contextDestroyed on the Logback Listener before NiFi termination has completed. This results is missing a number of log messages when shutting down NiFi.

Setting the logbackDisableServletContainerInitializer environment variable to true disables the default Logback listener registration, avoiding the premature context shutdown. Adding the DelayingShutdownHook to the logback.xml configuration allows Logback to perform a clean shutdown after NiFi termination has finished.

In order to streamline the review of the contribution we ask you
to ensure the following steps have been taken:

For all changes:

  • Is there a JIRA ticket associated with this PR? Is it referenced
    in the commit message?

  • Does your PR title start with NIFI-XXXX where XXXX is the JIRA number you are trying to resolve? Pay particular attention to the hyphen "-" character.

  • Has your PR been rebased against the latest commit within the target branch (typically main)?

  • Is your initial contribution a single, squashed commit? Additional commits in response to PR reviewer feedback should be made on this branch and pushed to allow change tracking. Do not squash or use --force when pushing to allow for clean monitoring of changes.

For code changes:

  • Have you ensured that the full suite of tests is executed via mvn -Pcontrib-check clean install at the root nifi folder?
  • Have you written or updated unit tests to verify your changes?
  • Have you verified that the full build is successful on JDK 8?
  • Have you verified that the full build is successful on JDK 11?
  • If adding new dependencies to the code, are these dependencies licensed in a way that is compatible for inclusion under ASF 2.0?
  • If applicable, have you updated the LICENSE file, including the main LICENSE file under nifi-assembly?
  • If applicable, have you updated the NOTICE file, including the main NOTICE file found under nifi-assembly?
  • If adding new Properties, have you added .displayName in addition to .name (programmatic access) for each of the new properties?

For documentation related changes:

  • Have you ensured that format looks appropriate for the output in which it is rendered?

Note:

Please ensure that once the PR is submitted, you check GitHub Actions CI for build issues and submit an update to your PR as soon as possible.

- Added environment variable to disable Logback shutdown on web application termination
- Added shutdown hook to Logback configuration
Copy link
Contributor

@greyp9 greyp9 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes look good. I wanted to document that the use of nifi.sh run and Ctrl+C may not take advantage of this improvement. nifi.sh start and nifi.sh stop do show the shutdown logging. Also tested an invocation of one of the system tests (with a modified bootstrap.conf).

@@ -50,6 +50,9 @@ export NIFI_PID_DIR
NIFI_LOG_DIR="$(setOrDefault "$NIFI_LOG_DIR" "$NIFI_HOME/logs")"
export NIFI_LOG_DIR

# Disable automatic Logback Initializer to avoid shutdown on web application termination
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be good to document alternatives to the use of the environment variable to activate this behavior. I noticed this issue in the context of working on the system tests. There is a bootstrap.conf available to set system properties, for example.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for feedback @greyp9! The Logback documentation describes the configuration options under the WebShutdownHook section. Will update this pull request to include changes to bootstrap.conf in the system tests.

@markap14
Copy link
Contributor

Thanks @exceptionfactory ! Definitely a great catch. I was really confused just the other day because i wasn't seeing some logs that I expected on shutdown. And then I found this Jira. Thanks for fixing!

@markap14 markap14 merged commit 52f2139 into apache:main Feb 28, 2022
krisztina-zsihovszki pushed a commit to krisztina-zsihovszki/nifi that referenced this pull request Jun 28, 2022
* NIFI-9688 Improved Logback shutdown handling
- Added environment variable to disable Logback shutdown on web application termination
- Added shutdown hook to Logback configuration
- Added Logback shutdown hook configuration to system tests
Lehel44 pushed a commit to Lehel44/nifi that referenced this pull request Jul 1, 2022
* NIFI-9688 Improved Logback shutdown handling
- Added environment variable to disable Logback shutdown on web application termination
- Added shutdown hook to Logback configuration
- Added Logback shutdown hook configuration to system tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants