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

Add option to provide URIs to monitor in addition to the config file #3501

Open
wants to merge 1 commit 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)

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]>
@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.

Comment on lines +559 to +565
Thread.sleep(100);
for (int i = 0; i < 20; i++) {
if (context.getConfiguration() != oldConfig) {
break;
}
Thread.sleep(50);
}
Copy link
Member

Choose a reason for hiding this comment

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

Could you use Awaitility instead of looping with sleep, please?

final long orig = file.lastModified();
final long newTime = orig + 10000;
assertTrue(file.setLastModified(newTime), "setLastModified should have succeeded.");
TimeUnit.SECONDS.sleep(MONITOR_INTERVAL_SECONDS + 1);
Copy link
Member

Choose a reason for hiding this comment

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

Ugh! Can we do something better?

Proposal

  1. Use a dedicated new test class (e.g., MonitorUriTest)
  2. Create a random file (using @TempDir from JUnit)
  3. Programmatically create a configuration pointing to this file in a MonitorUri component
  4. Create a LoggerContext from this configuration
  5. Modify the random file
  6. Verify that the configuration is reloaded (I presume you can find examples in existing tests on how to perform this check.)

@@ -64,4 +64,25 @@ void testReconfiguration(final LoggerContext context) throws Exception {
} while (newConfig == oldConfig && loopCount++ < 5);
assertNotSame(newConfig, oldConfig, "Reconfiguration failed");
}

@Test
Copy link
Member

Choose a reason for hiding this comment

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

We can remove this if we can have a dedicated MonitorUriTest I hinted earlier.

@@ -15,7 +15,7 @@
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<Configuration status="OFF" name="XMLConfigTest" monitorInterval="1">
<Configuration status="OFF" name="XMLConfigTest" monitorInterval="1" monitorUris="target/test-classes/org/apache/logging/log4j/core/net/ssl/keyStore.p12">
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 reading through the changes, I don't know if it is supported, but please use a dedicated element instead:

<Configuration monitorInterval="1">
  <MonitorUris>
    <Uri>file:///path/to/file</Uri> <!-- Note that this needs to be a URI, not just a path! -->
  <MonitorUris>
<Configuration>

Comment on lines +283 to +284
final ConfigurationSource configSource,
final Collection<Source> auxiliarySources,
Copy link
Member

Choose a reason for hiding this comment

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

Why don't we just provide a single Set<Source> monitorSources?

@@ -20,7 +20,7 @@
* @since 2.4
*/
@Export
@Version("2.20.1")
@Version("2.21.0")
Copy link
Member

Choose a reason for hiding this comment

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

Always target the version this feature will (supposedly) be shipped with:

Suggested change
@Version("2.21.0")
@Version("2.25.0")

initializeMonitoring(intervalSeconds, "");
}

public void initializeMonitoring(final int intervalSeconds, final String monitorUris) {
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 should be Set<URI> monitorUris

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
None yet
Development

Successfully merging this pull request may close these issues.

2 participants