Skip to content

RUBY-3241 URI option for monitoring type#2989

Open
comandeo-mongo wants to merge 2 commits intomongodb:masterfrom
comandeo-mongo:3241-server-monitoring-mode
Open

RUBY-3241 URI option for monitoring type#2989
comandeo-mongo wants to merge 2 commits intomongodb:masterfrom
comandeo-mongo:3241-server-monitoring-mode

Conversation

@comandeo-mongo
Copy link
Contributor

@comandeo-mongo comandeo-mongo commented Feb 28, 2026

Implements the serverMonitoringMode URI option per the URI options spec. Accepted values are stream, poll, or auto (default).

  • When set to poll, the driver never creates a push monitor, even if the server supports streaming (4.4+).
  • When set to stream, streaming is used whenever the server supports it. The default auto mode behaves like poll on FaaS platforms and like stream otherwise.

@comandeo-mongo comandeo-mongo marked this pull request as ready for review February 28, 2026 11:13
@comandeo-mongo comandeo-mongo requested a review from a team as a code owner February 28, 2026 11:13
@comandeo-mongo comandeo-mongo added the feature A PR for a new feature label Feb 28, 2026
Copy link
Contributor

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

Adds support for a new serverMonitoringMode URI/client option to control whether the driver uses SDAM streaming (awaitable hello) vs polling, and updates unified test runner support for SDAM/heartbeat events.

Changes:

  • Add serverMonitoringMode parsing/stringifying via Mongo::URI::OptionsMapper, plus URI spec coverage (valid values, case-insensitivity, invalid value warning).
  • Gate push monitor (streaming) startup in Mongo::Server::Monitor behind a new streaming_enabled? decision.
  • Extend unified spec runner/assertions to subscribe to server heartbeat events, filter SDAM events, and assert the awaited field.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
spec/runners/unified/test.rb Subscribes unified runner to SERVER_HEARTBEAT events when requested.
spec/runners/unified/assertions.rb Adds SDAM event filtering and awaited assertion support.
spec/mongo/uri_spec.rb Adds tests for serverMonitoringMode URI option parsing/roundtripping/warnings.
spec/mongo/server/monitor_spec.rb Adds unit tests for Monitor#streaming_enabled? across modes and environments.
lib/mongo/uri/options_mapper.rb Introduces serverMonitoringMode option mapping and value conversion/stringification.
lib/mongo/uri.rb Defines SERVER_MONITORING_MODES accepted values for URI parsing.
lib/mongo/server/monitor.rb Adds streaming_enabled? and uses it to enable/disable push monitoring.
lib/mongo/client.rb Adds :server_monitoring_mode to VALID_OPTIONS.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +367 to +371
mode = options[:server_monitoring_mode] || :auto
case mode
when :poll
false
when :stream
Copy link

Copilot AI Feb 28, 2026

Choose a reason for hiding this comment

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

streaming_enabled? can return nil if :server_monitoring_mode is set to an unexpected value (e.g. a String like "poll" or any other symbol), because the case has no else. This makes the method violate its boolean contract and will implicitly disable streaming without any warning. Consider normalizing string values (e.g. downcase+to_sym) and adding an else branch that logs a warning and defaults to :auto (or raises) so the return value is always true/false.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature A PR for a new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants