-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[feat][broker] Support dynamic update log level at runtime #14200
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
base: master
Are you sure you want to change the base?
[feat][broker] Support dynamic update log level at runtime #14200
Conversation
pulsar-client-tools/src/main/java/org/apache/pulsar/admin/cli/CmdBrokers.java
Outdated
Show resolved
Hide resolved
pulsar-client-tools/src/main/java/org/apache/pulsar/admin/cli/CmdBrokers.java
Outdated
Show resolved
Hide resolved
pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/BrokersBase.java
Outdated
Show resolved
Hide resolved
pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/BrokersBase.java
Outdated
Show resolved
Hide resolved
pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/BrokersBase.java
Show resolved
Hide resolved
pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/BrokersBase.java
Outdated
Show resolved
Hide resolved
pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/BrokersBase.java
Outdated
Show resolved
Hide resolved
pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/BrokersBase.java
Outdated
Show resolved
Hide resolved
7d28dd8 to
041f15e
Compare
| additivity: true | ||
| AppenderRef: | ||
| - ref: "${sys:pulsar.log.appender}" | ||
| level: "${sys:pulsar.log.level}" |
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.
This should not be changed as we should keep default behavior.
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.
as default pulsar.log.level=info
i have do a test in product env as follow:

remove this item seems do not change default log4j behavior.
as answer in [stackoverflow:programmatically-change-log-level-in-log4j2 :
i have try all mentioned way to change logger level by programmatically way, it not work unless remove level: "${sys:pulsar.log.level}"
Have you ever had similar problems?
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.
User may already have set pulsar.log.level=warn in their deployment. Will this PR change the 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.
i have set pulsar.log.level=warn for test. but not what i expected. described as this issue #14298
update: 🤲
i have a test, result as follow:
as log4j2.yaml using way,

pulsar.log.level go into effect only set by ENV property PULSAR_LOG_LEVEL which set in pulsar_env.sh while service starting.
while service running, change pulsar.log.level in log4j2.yaml is not work, pulsar.log.level is unmodifiable now.
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.
User may already have set
pulsar.log.level=warnin their deployment. Will this PR change the settings?
i have a test
if User set pulsar.log.level=warn in their deployment while starting service.
this PR will not change the settings , all loggers's level is warn, meanwhile , the PR featrue also works.
level: "${sys:pulsar.log.level}"
this line config is redundant and will disturb the programmatically way.
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.
this PR will not change the settings
I am a little confused that if you removed this, how would user's previous setting (set by ENV property PULSAR_LOG_LEVEL in pulsar_env.sh) take effect?
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.
i have a test in standalone mode after removed this line.
pulsar.log.levelset by ENV property PULSAR_LOG_LEVEL in pulsar_env.sh towarn
so remove this line would not invalidate user's previous setting (set by ENV property PULSAR_LOG_LEVEL in pulsar_env.sh
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.
Can you explain from the code, why pulsar.log.level this system env could still take effect after we delete from log4j2.yaml? Did we pass this variable to log4j somewhere else?
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.
Can you explain from the code, why pulsar.log.level this system env could still take effect after we delete from log4j2.yaml? Did we pass this variable to log4j somewhere else?
+1, from the source code here https://github.com/apache/pulsar/blob/master/bin/pulsar#L299, I think we can't remove this line here.
eolivelli
left a comment
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.
Very interesting work.
I left some suggestions, PTAL
pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/BrokersBase.java
Outdated
Show resolved
Hide resolved
pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/BrokersBase.java
Outdated
Show resolved
Hide resolved
pulsar-client-tools/src/main/java/org/apache/pulsar/admin/cli/CmdBrokers.java
Show resolved
Hide resolved
041f15e to
ce21dc7
Compare
ce21dc7 to
0172610
Compare
|
cc @eolivelli @Jason918 PTAL again thanks |
|
/pulsarbot run-failure-checks |
eolivelli
left a comment
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.
IIRC log4j supports automatic reloading of configuration files.
Isn't it enough for you?
pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/BrokersBase.java
Outdated
Show resolved
Hide resolved
yes, Log4j has the ability to automatically configure itself during initialization and reload config while config files changed. |
0172610 to
c1f5ea4
Compare
| additivity: true | ||
| AppenderRef: | ||
| - ref: "${sys:pulsar.log.appender}" | ||
| level: "${sys:pulsar.log.level}" |
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.
Can you explain from the code, why pulsar.log.level this system env could still take effect after we delete from log4j2.yaml? Did we pass this variable to log4j somewhere else?
+1, from the source code here https://github.com/apache/pulsar/blob/master/bin/pulsar#L299, I think we can't remove this line here.
| @ApiResponse(code = 403, message = "You don't have admin permission to update logger level."), | ||
| @ApiResponse(code = 500, message = "Internal server error")}) | ||
| public void updateLoggerLevelDynamically(@Suspended final AsyncResponse asyncResponse, | ||
| @PathParam("classname") String classname, |
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.
It should be the logger name here, not the class name. Usually, we will use the class name as the logger name, but not 100%
pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/BrokersBase.java
Show resolved
Hide resolved
| @ApiResponse(code = 204, message = "class logger level updated successfully"), | ||
| @ApiResponse(code = 403, message = "You don't have admin permission to update logger level."), | ||
| @ApiResponse(code = 500, message = "Internal server error")}) | ||
| public void updateLoggerLevelDynamically(@Suspended final AsyncResponse asyncResponse, |
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.
Is it able to provide a get method to get the current applied log levels?
| * | ||
| * @throws PulsarAdminException if update logger level failed. | ||
| */ | ||
| void updateLoggerLevel(String classname, String level) throws PulsarAdminException; |
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.
| void updateLoggerLevel(String classname, String level) throws PulsarAdminException; | |
| void updateLoggerLevel(String loggerName, String level) throws PulsarAdminException; |
| * Reset logger level dynamically in runtime asynchronously. | ||
| * @return CompletableFuture | ||
| */ | ||
| CompletableFuture<Void> updateLoggerLevelAsync(String classname, String level); |
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.
| CompletableFuture<Void> updateLoggerLevelAsync(String classname, String level); | |
| CompletableFuture<Void> updateLoggerLevelAsync(String loggerName, String level); |
| private class UpdateLoggerLevelCmd extends CliCommand { | ||
| @Parameter(names = {"-c", "--classname"}, description = | ||
| "The except class name,if set \"ROOT\" will take effect to rootLogger", required = true) | ||
| private String classname; |
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.
| private String classname; | |
| private String loggerName; |
|
|
||
| @Parameters(commandDescription = "Dynamic update logger level in runtime by classname.") | ||
| private class UpdateLoggerLevelCmd extends CliCommand { | ||
| @Parameter(names = {"-c", "--classname"}, description = |
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.
| @Parameter(names = {"-c", "--classname"}, description = | |
| @Parameter(names = {"-l", "--logger-name"}, description = |
|
The pr had no activity for 30 days, mark with Stale label. |
|
The pr had no activity for 30 days, mark with Stale label. |



Motivation
As default, Broker log level set by
log4j2.yamlwithpulsar.log.level=info, if developers want to update log level to debug, need to Modifylog42j.yaml#pulsar.log.level=debugand then restart Broker service.This PR support developers dynamic update Broker log level at runtime,It is very useful for online trouble shooting without having to stop Broker service and start it again.
Modifications
bin/pulsar-admin brokers update-logger-level --classname ${CLASSNAME} --level ${LEVEL})/admin/v2/brokers/log4j/{classname}/{level})Verifying this change
org.apache.pulsar.admin.cli.PulsarAdminToolTest#brokersDoes this pull request potentially affect one of the following parts:
If
yeswas chosen, please highlight the changesDocumentation
doc-not-needed