Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions lib/mongo/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class Client
:min_pool_size,
:monitoring,
:password,
:platform,
:read,
:read_retry_interval,
:replica_set,
Expand Down Expand Up @@ -200,10 +201,10 @@ def hash
# certification authority certifications used to validate certs passed from the
# other end of the connection. One of :ssl_ca_cert, :ssl_ca_cert_string or
# :ssl_ca_cert_object (in order of priority) is required for :ssl_verify.
# @option options [ Array<OpenSSL::X509::Certificate> ] :ssl_ca_cert_object An array of OpenSSL::X509::Certificate
# reprenting the certification authority certifications used to validate certs passed from the
# other end of the connection. One of :ssl_ca_cert, :ssl_ca_cert_string or
# :ssl_ca_cert_object (in order of priority) is required for :ssl_verify.
# @option options [ Array<OpenSSL::X509::Certificate> ] :ssl_ca_cert_object An array of
# OpenSSL::X509::Certificate representing the certification authority certifications used
# to validate certs passed from the other end of the connection. One of :ssl_ca_cert,
# :ssl_ca_cert_string or :ssl_ca_cert_object (in order of priority) is required for :ssl_verify.
# @option options [ Float ] :socket_timeout The timeout, in seconds, to
# execute operations on a socket.
# @option options [ String ] :user The user name.
Expand All @@ -222,6 +223,8 @@ def hash
# for documents. Must respond to #generate.
# @option options [ String, Symbol ] :app_name Application name that is printed to the
# mongod logs upon establishing a connection in server versions >= 3.4.
# @option options [ String ] :platform Platform information to include in the
# metadata printed to the mongod logs upon establishing a connection in server versions >= 3.4.
#
# @since 2.0.0
def initialize(addresses_or_uri, options = Options::Redacted.new)
Expand Down
8 changes: 7 additions & 1 deletion lib/mongo/cluster/app_metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class AppMetadata
# @since 2.4.0
def initialize(cluster)
@app_name = cluster.options[:app_name]
@platform = cluster.options[:platform]
end

# Get the bytes of the ismaster message including this metadata.
Expand Down Expand Up @@ -133,7 +134,12 @@ def architecture
end

def platform
[RUBY_VERSION, RUBY_PLATFORM, RbConfig::CONFIG['build']].join(', ')
[
@platform,
RUBY_VERSION,
RUBY_PLATFORM,
RbConfig::CONFIG['build']
].compact.join(', ')
end
end
end
Expand Down
38 changes: 38 additions & 0 deletions spec/mongo/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,44 @@
expect(client.cluster.options[:heartbeat_frequency]).to eq(client.options[:heartbeat_frequency])
end
end

context 'when platform details are specified' do

let(:app_metadata) do
client.cluster.app_metadata
end

let(:client) do
described_class.new(['127.0.0.1:27017'], :platform => 'mongoid-6.0.2')
end

it 'includes the platform info in the app metadata' do
expect(app_metadata.send(:full_client_document)[:platform]).to match(/mongoid-6\.0\.2/)
end
end

context 'when platform details are not specified' do

let(:app_metadata) do
client.cluster.app_metadata
end

let(:client) do
described_class.new(['127.0.0.1:27017'])
end

let(:platform_string) do
[
RUBY_VERSION,
RUBY_PLATFORM,
RbConfig::CONFIG['build']
].join(', ')
end

it 'does not include the platform info in the app metadata' do
expect(app_metadata.send(:full_client_document)[:platform]).to eq(platform_string)
end
end
end

context 'when providing a connection string' do
Expand Down