Skip to content

Commit 2c1a537

Browse files
authored
Merge pull request #837 from estolfo/RUBY-1136-odm-app-metadata
RUBY-1136 Allow ODM name and version to be included in app_metadata in a platform client option
2 parents 65ed5d9 + a7cf38f commit 2c1a537

File tree

3 files changed

+52
-5
lines changed

3 files changed

+52
-5
lines changed

lib/mongo/client.rb

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class Client
4848
:min_pool_size,
4949
:monitoring,
5050
:password,
51+
:platform,
5152
:read,
5253
:read_retry_interval,
5354
:replica_set,
@@ -200,10 +201,10 @@ def hash
200201
# certification authority certifications used to validate certs passed from the
201202
# other end of the connection. One of :ssl_ca_cert, :ssl_ca_cert_string or
202203
# :ssl_ca_cert_object (in order of priority) is required for :ssl_verify.
203-
# @option options [ Array<OpenSSL::X509::Certificate> ] :ssl_ca_cert_object An array of OpenSSL::X509::Certificate
204-
# reprenting the certification authority certifications used to validate certs passed from the
205-
# other end of the connection. One of :ssl_ca_cert, :ssl_ca_cert_string or
206-
# :ssl_ca_cert_object (in order of priority) is required for :ssl_verify.
204+
# @option options [ Array<OpenSSL::X509::Certificate> ] :ssl_ca_cert_object An array of
205+
# OpenSSL::X509::Certificate representing the certification authority certifications used
206+
# to validate certs passed from the other end of the connection. One of :ssl_ca_cert,
207+
# :ssl_ca_cert_string or :ssl_ca_cert_object (in order of priority) is required for :ssl_verify.
207208
# @option options [ Float ] :socket_timeout The timeout, in seconds, to
208209
# execute operations on a socket.
209210
# @option options [ String ] :user The user name.
@@ -222,6 +223,8 @@ def hash
222223
# for documents. Must respond to #generate.
223224
# @option options [ String, Symbol ] :app_name Application name that is printed to the
224225
# mongod logs upon establishing a connection in server versions >= 3.4.
226+
# @option options [ String ] :platform Platform information to include in the
227+
# metadata printed to the mongod logs upon establishing a connection in server versions >= 3.4.
225228
#
226229
# @since 2.0.0
227230
def initialize(addresses_or_uri, options = Options::Redacted.new)

lib/mongo/cluster/app_metadata.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ class AppMetadata
5353
# @since 2.4.0
5454
def initialize(cluster)
5555
@app_name = cluster.options[:app_name]
56+
@platform = cluster.options[:platform]
5657
end
5758

5859
# Get the bytes of the ismaster message including this metadata.
@@ -133,7 +134,12 @@ def architecture
133134
end
134135

135136
def platform
136-
[RUBY_VERSION, RUBY_PLATFORM, RbConfig::CONFIG['build']].join(', ')
137+
[
138+
@platform,
139+
RUBY_VERSION,
140+
RUBY_PLATFORM,
141+
RbConfig::CONFIG['build']
142+
].compact.join(', ')
137143
end
138144
end
139145
end

spec/mongo/client_spec.rb

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,44 @@
271271
expect(client.cluster.options[:heartbeat_frequency]).to eq(client.options[:heartbeat_frequency])
272272
end
273273
end
274+
275+
context 'when platform details are specified' do
276+
277+
let(:app_metadata) do
278+
client.cluster.app_metadata
279+
end
280+
281+
let(:client) do
282+
described_class.new(['127.0.0.1:27017'], :platform => 'mongoid-6.0.2')
283+
end
284+
285+
it 'includes the platform info in the app metadata' do
286+
expect(app_metadata.send(:full_client_document)[:platform]).to match(/mongoid-6\.0\.2/)
287+
end
288+
end
289+
290+
context 'when platform details are not specified' do
291+
292+
let(:app_metadata) do
293+
client.cluster.app_metadata
294+
end
295+
296+
let(:client) do
297+
described_class.new(['127.0.0.1:27017'])
298+
end
299+
300+
let(:platform_string) do
301+
[
302+
RUBY_VERSION,
303+
RUBY_PLATFORM,
304+
RbConfig::CONFIG['build']
305+
].join(', ')
306+
end
307+
308+
it 'does not include the platform info in the app metadata' do
309+
expect(app_metadata.send(:full_client_document)[:platform]).to eq(platform_string)
310+
end
311+
end
274312
end
275313

276314
context 'when providing a connection string' do

0 commit comments

Comments
 (0)