Skip to content

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

Open
wants to merge 3 commits into
base: 2.x
Choose a base branch
from

Conversation

MichaelMorrisEst
Copy link
Contributor

@MichaelMorrisEst MichaelMorrisEst commented Feb 26, 2025

A change detected in either the config file itself or the provided additional URIs shall result in a reconfigure
See #3074

Checklist

  • Base your changes on 2.x branch if you are targeting Log4j 2; use main otherwise
  • ./mvnw verify succeeds (if it fails due to code formatting issues reported by Spotless, simply run ./mvnw spotless:apply and retry)
  • Non-trivial changes contain an entry file in the src/changelog/.2.x.x directory
  • Tests for the changes are provided
  • Commits are signed (optional, but highly recommended)

@vy vy self-assigned this Mar 14, 2025
@vy vy added api Affects the public API configuration Affects the configuration system in a general way labels Mar 14, 2025
Copy link
Member

@vy vy left a 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.

@MichaelMorrisEst
Copy link
Contributor Author

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!

Copy link
Member

@vy vy left a 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.

Comment on lines 57 to 59
monitoredFiles.entrySet().stream()
.forEach(monitoredFile ->
monitoredFile.setValue(monitoredFile.getKey().lastModified()));
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't you be monitoredFiles.get(file) and then...?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not applicable any more with changes from other comments

Comment on lines 46 to 52
Long lastModifiedMillis = 0L;
for (final File monitoredFile : monitoredFiles.keySet()) {
if (monitoredFile.lastModified() > lastModifiedMillis) {
lastModifiedMillis = monitoredFile.lastModified();
}
}
return lastModifiedMillis;
Copy link
Member

Choose a reason for hiding this comment

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

I think this can be simplified with a stream() and min().

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not applicable any more with changes from other comments

Comment on lines 74 to 79
public void addMonitorUris(final List<URI> monitorUris) {
monitorUris.forEach(uri -> {
File additionalFile = new Source(uri).getFile();
monitoredFiles.put(additionalFile, additionalFile.lastModified());
});
}
Copy link
Member

Choose a reason for hiding this comment

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

I'm not really sure if ConfigurationFW should have a concept of monitor URIs. Instead, the call-site can call watching(Source) multiple times, but this time super.watching(source) will be overriden incorrectly. I have the impression that there is an impedance mismatch. That is, we're trying to extend CFW to support multiple files. Instead, in AbstractConfiguration, can't we create a CFW for each monitor URI?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes that works too, updated accordingly

try {
javaNetUris.add(new URI(uri.getUri()));
} catch (URISyntaxException e) {
LOGGER.error("Error parsing monitor URI: " + uri, e);
Copy link
Member

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.

Copy link
Contributor Author

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

getConfigurationSource(),
uris,
watchManager.getIntervalSeconds());
watchManager.addMonitorUris(configurationSource.getSource(), uris);
Copy link
Member

Choose a reason for hiding this comment

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

Can't we instead for each URI create a new ConfigurationFileWatcher and register it using watchManager.watch(cfgSource, watcher)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes that works too, updated accordingly

Copy link

github-actions bot commented Apr 13, 2025

Job Requested goals Build Tool Version Build Outcome Build Scan®
build-macos-latest clean install 3.9.8 Build Scan PUBLISHED
build-ubuntu-latest clean install 3.9.8 Build Scan PUBLISHED
build-windows-latest clean install 3.9.8 Build Scan PUBLISHED
Generated by gradle/develocity-actions

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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api Affects the public API configuration Affects the configuration system in a general way
Projects
Status: To triage
Development

Successfully merging this pull request may close these issues.

2 participants