-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
base: 2.x
Are you sure you want to change the base?
Conversation
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]>
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.
Thread.sleep(100); | ||
for (int i = 0; i < 20; i++) { | ||
if (context.getConfiguration() != oldConfig) { | ||
break; | ||
} | ||
Thread.sleep(50); | ||
} |
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.
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); |
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.
Ugh! Can we do something better?
Proposal
- Use a dedicated new test class (e.g.,
MonitorUriTest
) - Create a random file (using
@TempDir
from JUnit) - Programmatically create a configuration pointing to this file in a
MonitorUri
component - Create a
LoggerContext
from this configuration - Modify the random file
- 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 |
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.
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"> |
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'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>
final ConfigurationSource configSource, | ||
final Collection<Source> auxiliarySources, |
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.
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") |
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.
Always target the version this feature will (supposedly) be shipped with:
@Version("2.21.0") | |
@Version("2.25.0") |
initializeMonitoring(intervalSeconds, ""); | ||
} | ||
|
||
public void initializeMonitoring(final int intervalSeconds, final String monitorUris) { |
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 think this should be Set<URI> monitorUris
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