-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Add option to provide URIs to monitor in addition to the config file #3501
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: 2.x
Are you sure you want to change the base?
Conversation
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.
@MichaelMorrisEst, thanks so much for putting effort into this, much appreciated! 😍
I've dropped some remarks. I'd appreciate it if you can update the PR with requested changes. I will have some more remarks – e.g., adding docs – but I will share them last.
log4j-core-test/src/test/java/org/apache/logging/log4j/core/LoggerTest.java
Outdated
Show resolved
Hide resolved
log4j-core-test/src/test/java/org/apache/logging/log4j/core/LoggerTest.java
Outdated
Show resolved
Hide resolved
log4j-core-test/src/test/java/org/apache/logging/log4j/core/PropertiesFileConfigTest.java
Outdated
Show resolved
Hide resolved
log4j-core/src/main/java/org/apache/logging/log4j/core/config/AbstractConfiguration.java
Outdated
Show resolved
Hide resolved
log4j-core/src/main/java/org/apache/logging/log4j/core/config/builder/api/package-info.java
Outdated
Show resolved
Hide resolved
...core/src/main/java/org/apache/logging/log4j/core/config/builder/impl/BuiltConfiguration.java
Outdated
Show resolved
Hide resolved
Thanks for your comments @vy. The comment to use a dedicated element instead of an attribute changes the implementation quiet a bit. Please take a look when you have time, feedback gratefully received. Thanks! |
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.
@MichaelMorrisEst, I am extremely thankful for your effort and patience. I've some questions. I'd appreciate it if you can address them.
log4j-core/src/main/java/org/apache/logging/log4j/core/config/ConfigurationFileWatcher.java
Outdated
Show resolved
Hide resolved
log4j-core/src/main/java/org/apache/logging/log4j/core/config/ConfigurationFileWatcher.java
Outdated
Show resolved
Hide resolved
log4j-core/src/main/java/org/apache/logging/log4j/core/config/ConfigurationFileWatcher.java
Outdated
Show resolved
Hide resolved
try { | ||
javaNetUris.add(new URI(uri.getUri())); | ||
} catch (URISyntaxException e) { | ||
LOGGER.error("Error parsing monitor URI: " + uri, e); |
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.
Are we sure we want to proceed with (re)configuration obtained from an invalid configuration? I think we should propagate the exception and let it fail.
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.
My thinking here was to be consistent with other error scenarios, for example lines 726, 764, 790.
Also to let the exception propagate we would need to declare it on the doConfigure() method which could cause an impact on anyone with their own custom implementation which extends AbstractConfiguration
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.
See this recent discussion on how to handle configuration failures. In short, configuration failures should result in the entire configuration to fail, instead of applying in partially. Existing code that doesn't adhere to this needs to be fixed, but that is another issue.
log4j-core/src/main/java/org/apache/logging/log4j/core/config/AbstractConfiguration.java
Outdated
Show resolved
Hide resolved
A change detected in either the config file itself or the provided additional URIs shall result in a reconfigure Signed-off-by: MichaelMorris <[email protected]>
…ribute of the Configuration element Signed-off-by: MichaelMorris <[email protected]>
Signed-off-by: MichaelMorris <[email protected]>
ada292f
to
98cad4f
Compare
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.
Would you mind also updating configuration.adoc
such that
- Just before
Arbiters
section, create aMonitor URIs
section. - Link
Monitor URIs
and#configuration-attribute-monitorInterval
to each other with sufficient text and explanation.
if (uris != null && uris.size() > 0) { | ||
LOGGER.info( | ||
"Start watching for changes to {} and {} every {} seconds", | ||
getConfigurationSource(), | ||
uris, | ||
watchManager.getIntervalSeconds()); | ||
watchMonitorUris(); | ||
} else { | ||
LOGGER.info( | ||
"Start watching for changes to {} every {} seconds", | ||
getConfigurationSource(), | ||
watchManager.getIntervalSeconds()); | ||
} |
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't we simplify this as follows? (Can uris
be null at all?)
if (uris != null && uris.size() > 0) { | |
LOGGER.info( | |
"Start watching for changes to {} and {} every {} seconds", | |
getConfigurationSource(), | |
uris, | |
watchManager.getIntervalSeconds()); | |
watchMonitorUris(); | |
} else { | |
LOGGER.info( | |
"Start watching for changes to {} every {} seconds", | |
getConfigurationSource(), | |
watchManager.getIntervalSeconds()); | |
} | |
LOGGER.info( | |
"Start watching for changes to {} and {} every {} seconds", | |
getConfigurationSource(), | |
uris, | |
watchManager.getIntervalSeconds()); | |
watchMonitorUris(); |
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.
... and, this is the wrong place and time to do admit monitor URIs to the WatchManager
. Would you move this admission operation (i.e., the logic in watchMonitorUris
) to initializeWatchers
, please?
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.
Hi @vy
The reason I did not put it in initializeWatchers() is because initializeWatchers() is called before the elements are read. The top level attributes (including monitorInterval) have been read at this stage and can therefore be used, but the elements (including monitorUris) have not been.
Would it be ok to move invoking watchMonitorUris() to intialization() which is earlier than here, but after the elements have been read? This would avoid having to read the monitorUri element earlier and separately from the other elements.
I can move it to initializeWatchers() either if you still prefer that, and add code to read the monitorUri element separately to the other elements, but I think the above would be cleaner in the code.
try { | ||
javaNetUris.add(new URI(uri.getUri())); | ||
} catch (URISyntaxException e) { | ||
LOGGER.error("Error parsing monitor URI: " + uri, e); |
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.
See this recent discussion on how to handle configuration failures. In short, configuration failures should result in the entire configuration to fail, instead of applying in partially. Existing code that doesn't adhere to this needs to be fixed, but that is another issue.
A change detected in either the config file itself or the provided additional URIs shall result in a reconfigure
See #3074
Checklist
2.x
branch if you are targeting Log4j 2; usemain
otherwise./mvnw verify
succeeds (if it fails due to code formatting issues reported by Spotless, simply run./mvnw spotless:apply
and retry)src/changelog/.2.x.x
directory