Skip to content

Added logging specification tests #1740

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 7 commits into
base: main
Choose a base branch
from
Open

Conversation

rozza
Copy link
Member

@rozza rozza commented Jun 16, 2025

@rozza rozza requested a review from Copilot June 16, 2025 13:33
Copilot

This comment was marked as resolved.

@rozza rozza requested a review from Copilot June 16, 2025 13:44
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR removes skip markers for several logging tests and updates logging-related code to support the new logging specification tests. Key changes include:

  • Enabling logging specification tests by removing skip instructions for JAVA-4770.
  • Updating test methods to include new ignoreMessages parameters.
  • Refactoring logging routines in core connection components to use StructuredLogger.

Reviewed Changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated no comments.

Show a summary per file
File Description
driver-sync/src/test/functional/com/mongodb/client/unified/UnifiedTestModifications.java Removed skip markers for logging tests.
driver-sync/src/test/functional/com/mongodb/client/unified/UnifiedTest.java Added parameter to pass ignoreMessages to log message assertion.
driver-sync/src/test/functional/com/mongodb/client/unified/LogMatcher.java Updated log filtering and renaming helper methods.
driver-sync/src/test/functional/com/mongodb/client/unified/ContextElement.java Updated mapping to utilize the new log document conversion method.
driver-reactive-streams/src/test/functional/com/mongodb/reactivestreams/client/unified/UnifiedServerDiscoveryAndMonitoringTest.java Minor formatting update.
driver-core/src/main/com/mongodb/internal/logging/LogMessage.java Added a new log entry type AWAITED.
driver-core/src/main/com/mongodb/internal/connection/SingleServerCluster.java Modified the order of setting the server instance relative to publishing a description.
driver-core/src/main/com/mongodb/internal/connection/LoadBalancedCluster.java Replaced topology closed logging with topology monitoring stopping.
driver-core/src/main/com/mongodb/internal/connection/DefaultServerMonitor.java Added structured logging methods for heartbeat events and monitoring lifecycle.
driver-core/src/main/com/mongodb/internal/connection/DefaultServer.java Introduced StructuredLogger for connection logging.
driver-core/src/main/com/mongodb/internal/connection/BaseCluster.java Updated logging method names to align with the new structured logging pattern.
Comments suppressed due to low confidence (1)

driver-core/src/main/com/mongodb/internal/connection/SingleServerCluster.java:63

  • Reordering the call to server.set so that it occurs after publishDescription may impact the initialization flow. Please verify that this change is intentional and does not introduce any race conditions.
server.set(createServer(settings.getHosts().get(0)));

@@ -58,9 +58,9 @@ public SingleServerCluster(final ClusterId clusterId, final ClusterSettings sett
// synchronized in the constructor because the change listener is re-entrant to this instance.
// In other words, we are leaking a reference to "this" from the constructor.
withLock(() -> {
server.set(createServer(settings.getHosts().get(0)));
publishDescription(ServerDescription.builder().state(CONNECTING).address(settings.getHosts().get(0))
Copy link
Member Author

@rozza rozza Jun 16, 2025

Choose a reason for hiding this comment

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

The tests expect the toplogy description changed to connecting & unknown to be logged before the starting the server monitor log message.

Creating the server first meant that they were the wrong way around.

@rozza rozza requested review from a team and katcharov and removed request for a team June 16, 2025 15:56
@rozza rozza marked this pull request as ready for review June 17, 2025 13:45
@rozza rozza requested a review from a team as a code owner June 17, 2025 13:45
Copy link
Collaborator

@katcharov katcharov left a comment

Choose a reason for hiding this comment

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

LGTM!

new LogMessage.Entry(TOPOLOGY_ID, serverId.getClusterId()),
new LogMessage.Entry(AWAITED, awaited)),
"Heartbeat started for {}:{} on connection with driver-generated ID {} and server-generated ID {} "
+ "in topology with ID {}. Awaited: {}"));
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is extremely minor, but the + is not indented here, but is below.

Copy link
Member Author

Choose a reason for hiding this comment

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

Nit removed 🐛

@@ -336,7 +336,7 @@ public <T> void waitForServerMonitorEvents(final String client, final Class<T> e
BsonDocument expectedEventContents = getEventContents(expectedEvent);
try {
serverMonitorListener.waitForEvents(expectedEventType,
event -> serverMonitorEventMatches(expectedEventContents, event, null), count, Duration.ofSeconds(10));
event -> serverMonitorEventMatches(expectedEventContents, event, null), count, Duration.ofSeconds(30));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why?

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated to 15 - I just wanted to ensure that the server monitor through runs at least once. I think it defaults to every 10 seconds.

rozza added 2 commits June 19, 2025 16:58
Changed to 15 to ensure servermonitor runs at least once.
@jyemin jyemin self-requested a review June 19, 2025 22:48
Copy link
Collaborator

@jyemin jyemin left a comment

Choose a reason for hiding this comment

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

Strangely, when I run the tests locally, both the sync and reactive runners consistently fail the standalone-logging: Topology lifecycle test.

java.lang.AssertionError: Expected BSON values to be equal

Assertion Context:

Value Matching Context:
   Key: message
   Expected value:
      BsonString{value='Topology description changed'}
   Actual value:
      BsonString{value='Stopped server monitoring'}

I imagine you're not seeing that?

@@ -235,14 +235,15 @@ public static void applyCustomizations(final TestDef def) {

// server-discovery-and-monitoring (SDAM)

def.retry("Flaky test,due to a race waiting for the failed heartbeat.")
Copy link
Collaborator

Choose a reason for hiding this comment

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

I hate to add new flaky tests off the bat like this. Do you understand the root cause of the flakiness? I'm curious also if they are flaky for other drivers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants