lib/mongo/server/monitor.rb in mongo-2.14.1 vs lib/mongo/server/monitor.rb in mongo-2.15.0.alpha

- old
+ new

@@ -61,19 +61,29 @@ # @option options [ Float ] :connect_timeout The timeout, in seconds, to # use when establishing the monitoring connection. # @option options [ Float ] :heartbeat_interval The interval between # regular server checks. # @option options [ Logger ] :logger A custom logger to use. + # @option options [ Mongo::Server::Monitor::AppMetadata ] :monitor_app_metadata + # The metadata to use for regular monitoring connection. + # @option options [ Mongo::Server::Monitor::AppMetadata ] :push_monitor_app_metadata + # The metadata to use for push monitor's connection. # @option options [ Float ] :socket_timeout The timeout, in seconds, to # execute operations on the monitoring connection. # # @since 2.0.0 # @api private def initialize(server, event_listeners, monitoring, options = {}) unless monitoring.is_a?(Monitoring) raise ArgumentError, "Wrong monitoring type: #{monitoring.inspect}" end + unless options[:app_metadata] + raise ArgumentError, 'App metadata is required' + end + unless options[:push_monitor_app_metadata] + raise ArgumentError, 'Push monitor app metadata is required' + end @server = server @event_listeners = event_listeners @monitoring = monitoring @options = options.freeze @mutex = Mutex.new @@ -271,11 +281,19 @@ end if @connection result = server.round_trip_time_averager.measure do begin - message = @connection.dispatch_bytes(Monitor::Connection::ISMASTER_BYTES) + ismaster_bytes = if server_api = options[:server_api] + ismaster_doc = Monitor::Connection::ISMASTER.merge( + Utils.transform_server_api(server_api) + ) + Protocol::Query.new(Database::ADMIN, Database::COMMAND, ismaster_doc, limit: -1).serialize.to_s + else + Monitor::Connection::ISMASTER_BYTES + end + message = @connection.dispatch_bytes(ismaster_bytes) message.documents.first rescue Mongo::Error @connection.disconnect! @connection = nil raise @@ -295,9 +313,10 @@ self, TopologyVersion.new(result['topologyVersion']), monitoring, **Utils.shallow_symbolize_keys(options.merge( socket_timeout: heartbeat_interval + connection.socket_timeout, + app_metadata: options[:push_monitor_app_metadata], )), ) end push_monitor.run! else