mongo 2.0.6 → 2.1.0.beta
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/lib/mongo.rb +2 -0
- data/lib/mongo/bulk_write.rb +1 -0
- data/lib/mongo/bulk_write/bulk_writable.rb +87 -31
- data/lib/mongo/bulk_write/deletable.rb +8 -7
- data/lib/mongo/bulk_write/insertable.rb +4 -3
- data/lib/mongo/bulk_write/ordered_bulk_write.rb +6 -6
- data/lib/mongo/bulk_write/replacable.rb +4 -3
- data/lib/mongo/bulk_write/result.rb +138 -0
- data/lib/mongo/bulk_write/unordered_bulk_write.rb +5 -8
- data/lib/mongo/bulk_write/updatable.rb +8 -7
- data/lib/mongo/client.rb +36 -4
- data/lib/mongo/cluster.rb +39 -4
- data/lib/mongo/cluster/topology/replica_set.rb +20 -4
- data/lib/mongo/cluster/topology/sharded.rb +1 -1
- data/lib/mongo/collection.rb +282 -29
- data/lib/mongo/collection/view/aggregation.rb +32 -4
- data/lib/mongo/collection/view/iterable.rb +2 -1
- data/lib/mongo/collection/view/map_reduce.rb +3 -1
- data/lib/mongo/collection/view/readable.rb +89 -14
- data/lib/mongo/collection/view/writable.rb +11 -5
- data/lib/mongo/cursor.rb +11 -3
- data/lib/mongo/dbref.rb +113 -0
- data/lib/mongo/error.rb +6 -2
- data/lib/mongo/error/parser.rb +1 -1
- data/lib/mongo/event/description_changed.rb +1 -1
- data/lib/mongo/grid/file.rb +1 -1
- data/lib/mongo/grid/fs.rb +2 -5
- data/lib/mongo/monitoring.rb +199 -0
- data/lib/mongo/monitoring/command_log_subscriber.rb +88 -0
- data/lib/mongo/monitoring/event.rb +17 -0
- data/lib/mongo/monitoring/event/command_failed.rb +96 -0
- data/lib/mongo/monitoring/event/command_started.rb +88 -0
- data/lib/mongo/monitoring/event/command_succeeded.rb +96 -0
- data/lib/mongo/monitoring/publishable.rb +96 -0
- data/lib/mongo/operation.rb +1 -0
- data/lib/mongo/operation/executable.rb +1 -1
- data/lib/mongo/operation/parallel_scan.rb +76 -0
- data/lib/mongo/operation/parallel_scan/result.rb +72 -0
- data/lib/mongo/operation/specifiable.rb +18 -0
- data/lib/mongo/operation/write/bulk/bulk_delete.rb +1 -1
- data/lib/mongo/operation/write/bulk/bulk_insert.rb +1 -1
- data/lib/mongo/operation/write/bulk/bulk_mergable.rb +2 -2
- data/lib/mongo/operation/write/bulk/bulk_update.rb +1 -1
- data/lib/mongo/operation/write/bulk/bulk_update/result.rb +13 -1
- data/lib/mongo/protocol/delete.rb +8 -13
- data/lib/mongo/protocol/get_more.rb +13 -13
- data/lib/mongo/protocol/insert.rb +8 -13
- data/lib/mongo/protocol/kill_cursors.rb +7 -11
- data/lib/mongo/protocol/query.rb +58 -20
- data/lib/mongo/protocol/reply.rb +12 -0
- data/lib/mongo/protocol/update.rb +13 -14
- data/lib/mongo/server.rb +23 -2
- data/lib/mongo/server/connectable.rb +0 -22
- data/lib/mongo/server/connection.rb +29 -0
- data/lib/mongo/server/description.rb +23 -1
- data/lib/mongo/server/monitor.rb +17 -1
- data/lib/mongo/server/monitor/connection.rb +24 -0
- data/lib/mongo/socket/ssl.rb +28 -16
- data/lib/mongo/socket/tcp.rb +1 -1
- data/lib/mongo/socket/unix.rb +1 -1
- data/lib/mongo/uri.rb +12 -5
- data/lib/mongo/version.rb +1 -1
- data/spec/mongo/auth/cr_spec.rb +9 -1
- data/spec/mongo/auth/ldap_spec.rb +9 -1
- data/spec/mongo/auth/scram_spec.rb +9 -1
- data/spec/mongo/auth/x509_spec.rb +9 -1
- data/spec/mongo/{bulk/bulk_write_spec.rb → bulk_write_spec.rb} +15 -15
- data/spec/mongo/client_spec.rb +42 -0
- data/spec/mongo/cluster/topology/replica_set_spec.rb +16 -9
- data/spec/mongo/cluster/topology/sharded_spec.rb +11 -3
- data/spec/mongo/cluster/topology/single_spec.rb +12 -4
- data/spec/mongo/cluster_spec.rb +55 -10
- data/spec/mongo/collection/view/aggregation_spec.rb +123 -1
- data/spec/mongo/collection/view/explainable_spec.rb +1 -1
- data/spec/mongo/collection/view/map_reduce_spec.rb +1 -1
- data/spec/mongo/collection/view/readable_spec.rb +251 -6
- data/spec/mongo/collection/view/writable_spec.rb +4 -4
- data/spec/mongo/collection/view_spec.rb +233 -71
- data/spec/mongo/collection_spec.rb +905 -9
- data/spec/mongo/crud_spec.rb +2 -2
- data/spec/mongo/cursor_spec.rb +3 -3
- data/spec/mongo/dbref_spec.rb +149 -0
- data/spec/mongo/monitoring_spec.rb +168 -0
- data/spec/mongo/operation/map_reduce_spec.rb +1 -1
- data/spec/mongo/operation/write/bulk/bulk_delete_spec.rb +1 -1
- data/spec/mongo/operation/write/bulk/bulk_insert_spec.rb +2 -2
- data/spec/mongo/operation/write/bulk/bulk_update_spec.rb +1 -1
- data/spec/mongo/operation/write/delete_spec.rb +1 -1
- data/spec/mongo/operation/write/insert_spec.rb +2 -2
- data/spec/mongo/operation/write/update_spec.rb +1 -1
- data/spec/mongo/protocol/query_spec.rb +0 -29
- data/spec/mongo/server/connection_pool_spec.rb +18 -6
- data/spec/mongo/server/connection_spec.rb +12 -4
- data/spec/mongo/server/description_spec.rb +7 -3
- data/spec/mongo/server/monitor_spec.rb +30 -0
- data/spec/mongo/server_discovery_and_monitoring_spec.rb +11 -4
- data/spec/mongo/server_selection_spec.rb +14 -6
- data/spec/mongo/server_spec.rb +27 -8
- data/spec/mongo/socket/ssl_spec.rb +94 -8
- data/spec/mongo/uri_spec.rb +25 -9
- data/spec/spec_helper.rb +29 -20
- data/spec/support/authorization.rb +19 -4
- data/spec/support/certificates/client.pem +4 -4
- data/spec/support/crud/read.rb +9 -10
- data/spec/support/crud/write.rb +24 -20
- data/spec/support/sdam/rs/equal_electionids.yml +45 -0
- data/spec/support/sdam/rs/new_primary_new_electionid.yml +98 -0
- data/spec/support/sdam/rs/null_election_id.yml +144 -0
- data/spec/support/sdam/rs/primary_disconnect_electionid.yml +124 -0
- data/spec/support/sdam/sharded/mongos_disconnect.yml +104 -0
- data/spec/support/server_discovery_and_monitoring.rb +19 -2
- data/spec/support/shared/bulk_write.rb +26 -22
- data/spec/support/shared/server_selector.rb +2 -1
- metadata +31 -7
- metadata.gz.sig +0 -0
- data/lib/mongo/error/invalid_uri_option.rb +0 -38
data/lib/mongo/error.rb
CHANGED
@@ -43,11 +43,16 @@ module Mongo
|
|
43
43
|
# @since 2.0.0
|
44
44
|
WRITE_ERRORS = 'writeErrors'.freeze
|
45
45
|
|
46
|
-
# The constant for write concern
|
46
|
+
# The constant for a write concern error.
|
47
47
|
#
|
48
48
|
# @since 2.0.0
|
49
49
|
WRITE_CONCERN_ERROR = 'writeConcernError'.freeze
|
50
50
|
|
51
|
+
# The constant for write concern errors.
|
52
|
+
#
|
53
|
+
# @since 2.1.0
|
54
|
+
WRITE_CONCERN_ERRORS = 'writeConcernErrors'.freeze
|
55
|
+
|
51
56
|
# Constant for an unknown error.
|
52
57
|
#
|
53
58
|
# @since 2.0.0
|
@@ -75,7 +80,6 @@ require 'mongo/error/invalid_server_preference'
|
|
75
80
|
require 'mongo/error/invalid_signature'
|
76
81
|
require 'mongo/error/invalid_update_document'
|
77
82
|
require 'mongo/error/invalid_uri'
|
78
|
-
require 'mongo/error/invalid_uri_option'
|
79
83
|
require 'mongo/error/max_bson_size'
|
80
84
|
require 'mongo/error/max_message_size'
|
81
85
|
require 'mongo/error/multi_index_drop'
|
data/lib/mongo/error/parser.rb
CHANGED
data/lib/mongo/grid/file.rb
CHANGED
@@ -30,7 +30,7 @@ module Mongo
|
|
30
30
|
# @return [ Array<Chunk> ] chunks The file chunks.
|
31
31
|
attr_reader :chunks
|
32
32
|
|
33
|
-
# @return [ IO ] data The raw
|
33
|
+
# @return [ IO ] data The raw data for the file.
|
34
34
|
attr_reader :data
|
35
35
|
|
36
36
|
# @return [ Metadata ] metadata The file metadata.
|
data/lib/mongo/grid/fs.rb
CHANGED
@@ -70,15 +70,12 @@ module Mongo
|
|
70
70
|
#
|
71
71
|
# @param [ Grid::File ] file The file to insert.
|
72
72
|
#
|
73
|
-
# @return [
|
73
|
+
# @return [ BSON::ObjectId ] The file id.
|
74
74
|
#
|
75
75
|
# @since 2.0.0
|
76
76
|
def insert_one(file)
|
77
77
|
files_collection.insert_one(file.metadata)
|
78
|
-
|
79
|
-
ops << { :insert_one => chunk }
|
80
|
-
end
|
81
|
-
result = chunks_collection.bulk_write(inserts, ordered: true)
|
78
|
+
result = chunks_collection.insert_many(file.chunks)
|
82
79
|
validate_md5!(file) if write_concern.get_last_error
|
83
80
|
file.id
|
84
81
|
end
|
@@ -0,0 +1,199 @@
|
|
1
|
+
# Copyright (C) 2015 MongoDB, Inc.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the 'License');
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an 'AS IS' BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
require 'mongo/monitoring/event'
|
16
|
+
require 'mongo/monitoring/publishable'
|
17
|
+
require 'mongo/monitoring/command_log_subscriber'
|
18
|
+
|
19
|
+
module Mongo
|
20
|
+
|
21
|
+
# The class defines behaviour for the performance monitoring API.
|
22
|
+
#
|
23
|
+
# @since 2.1.0
|
24
|
+
class Monitoring
|
25
|
+
|
26
|
+
# The command topic.
|
27
|
+
#
|
28
|
+
# @since 2.1.0
|
29
|
+
COMMAND = 'Command'.freeze
|
30
|
+
|
31
|
+
@@operation_id = 0
|
32
|
+
@@operation_id_lock = Mutex.new
|
33
|
+
|
34
|
+
# Used for generating unique operation ids to link events together.
|
35
|
+
#
|
36
|
+
# @example Get the next operation id.
|
37
|
+
# Monitoring.next_operation_id
|
38
|
+
#
|
39
|
+
# @return [ Integer ] The next operation id.
|
40
|
+
#
|
41
|
+
# @since 2.1.0
|
42
|
+
def self.next_operation_id
|
43
|
+
@@operation_id_lock.synchronize do
|
44
|
+
@@operation_id += 1
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
# Provides behaviour around global subscribers.
|
49
|
+
#
|
50
|
+
# @since 2.1.0
|
51
|
+
module Global
|
52
|
+
extend self
|
53
|
+
|
54
|
+
# Subscribe a listener to an event topic.
|
55
|
+
#
|
56
|
+
# @example Subscribe to the topic.
|
57
|
+
# Monitoring::Global.subscribe(QUERY, subscriber)
|
58
|
+
#
|
59
|
+
# @param [ String ] topic The event topic.
|
60
|
+
# @param [ Object ] subscriber The subscriber to handle the event.
|
61
|
+
#
|
62
|
+
# @since 2.1.0
|
63
|
+
def subscribe(topic, subscriber)
|
64
|
+
subscribers_for(topic).push(subscriber)
|
65
|
+
end
|
66
|
+
|
67
|
+
# Get all the global subscribers.
|
68
|
+
#
|
69
|
+
# @example Get all the global subscribers.
|
70
|
+
# Monitoring::Global.subscribers
|
71
|
+
#
|
72
|
+
# @return [ Hash<String, Object> ] The subscribers.
|
73
|
+
#
|
74
|
+
# @since 2.1.0
|
75
|
+
def subscribers
|
76
|
+
@subscribers ||= {}
|
77
|
+
end
|
78
|
+
|
79
|
+
private
|
80
|
+
|
81
|
+
def subscribers_for(topic)
|
82
|
+
subscribers[topic] ||= []
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
# Adds our internal command logging to the global subscribers.
|
87
|
+
#
|
88
|
+
# @since 2.1.0
|
89
|
+
Global.subscribe(COMMAND, CommandLogSubscriber.new)
|
90
|
+
|
91
|
+
# Initialize the monitoring.
|
92
|
+
#
|
93
|
+
# @api private
|
94
|
+
#
|
95
|
+
# @example Create the new monitoring.
|
96
|
+
# Monitoring.new(:monitoring => true)
|
97
|
+
#
|
98
|
+
# @param [ Hash ] options The options.
|
99
|
+
#
|
100
|
+
# @since 2.1.0
|
101
|
+
def initialize(options = {})
|
102
|
+
if options[:monitoring] != false
|
103
|
+
Global.subscribers.each do |topic, subscribers|
|
104
|
+
subscribers.each do |subscriber|
|
105
|
+
subscribe(topic, subscriber)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
# Publish a started event.
|
112
|
+
#
|
113
|
+
# @example Publish a started event.
|
114
|
+
# monitoring.started(COMMAND, event)
|
115
|
+
#
|
116
|
+
# @param [ String ] topic The event topic.
|
117
|
+
# @param [ Event ] event The event to publish.
|
118
|
+
#
|
119
|
+
# @since 2.1.0
|
120
|
+
def started(topic, event)
|
121
|
+
subscribers_for(topic).each{ |subscriber| subscriber.started(event) }
|
122
|
+
end
|
123
|
+
|
124
|
+
# Publish a succeeded event.
|
125
|
+
#
|
126
|
+
# @example Publish a succeeded event.
|
127
|
+
# monitoring.succeeded(COMMAND, event)
|
128
|
+
#
|
129
|
+
# @param [ String ] topic The event topic.
|
130
|
+
# @param [ Event ] event The event to publish.
|
131
|
+
#
|
132
|
+
# @since 2.1.0
|
133
|
+
def succeeded(topic, event)
|
134
|
+
subscribers_for(topic).each{ |subscriber| subscriber.succeeded(event) }
|
135
|
+
end
|
136
|
+
|
137
|
+
# Publish a failed event.
|
138
|
+
#
|
139
|
+
# @example Publish a failed event.
|
140
|
+
# monitoring.failed(COMMAND, event)
|
141
|
+
#
|
142
|
+
# @param [ String ] topic The event topic.
|
143
|
+
# @param [ Event ] event The event to publish.
|
144
|
+
#
|
145
|
+
# @since 2.1.0
|
146
|
+
def failed(topic, event)
|
147
|
+
subscribers_for(topic).each{ |subscriber| subscriber.failed(event) }
|
148
|
+
end
|
149
|
+
|
150
|
+
# Subscribe a listener to an event topic.
|
151
|
+
#
|
152
|
+
# @example Subscribe to the topic.
|
153
|
+
# monitoring.subscribe(QUERY, subscriber)
|
154
|
+
#
|
155
|
+
# @param [ String ] topic The event topic.
|
156
|
+
# @param [ Object ] subscriber The subscriber to handle the event.
|
157
|
+
#
|
158
|
+
# @since 2.1.0
|
159
|
+
def subscribe(topic, subscriber)
|
160
|
+
subscribers_for(topic).push(subscriber)
|
161
|
+
end
|
162
|
+
|
163
|
+
# Get all the subscribers.
|
164
|
+
#
|
165
|
+
# @example Get all the subscribers.
|
166
|
+
# monitoring.subscribers
|
167
|
+
#
|
168
|
+
# @return [ Hash<String, Object> ] The subscribers.
|
169
|
+
#
|
170
|
+
# @since 2.1.0
|
171
|
+
def subscribers
|
172
|
+
@subscribers ||= {}
|
173
|
+
end
|
174
|
+
|
175
|
+
# Determine if there are any subscribers for a particular event.
|
176
|
+
#
|
177
|
+
# @example Are there subscribers?
|
178
|
+
# monitoring.subscribers?(COMMAND)
|
179
|
+
#
|
180
|
+
# @param [ String ] topic The event topic.
|
181
|
+
#
|
182
|
+
# @return [ true, false ] If there are subscribers for the topic.
|
183
|
+
#
|
184
|
+
# @since 2.1.0
|
185
|
+
def subscribers?(topic)
|
186
|
+
!subscribers_for(topic).empty?
|
187
|
+
end
|
188
|
+
|
189
|
+
private
|
190
|
+
|
191
|
+
def initialize_copy(original)
|
192
|
+
@subscribers = original.subscribers.dup
|
193
|
+
end
|
194
|
+
|
195
|
+
def subscribers_for(topic)
|
196
|
+
subscribers[topic] ||= []
|
197
|
+
end
|
198
|
+
end
|
199
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
# Copyright (C) 2015 MongoDB, Inc.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the 'License');
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an 'AS IS' BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
module Mongo
|
16
|
+
class Monitoring
|
17
|
+
|
18
|
+
# Subscribes to command events and logs them.
|
19
|
+
#
|
20
|
+
# @since 2.1.0
|
21
|
+
class CommandLogSubscriber
|
22
|
+
|
23
|
+
# Constant for the max number of characters to print when inspecting
|
24
|
+
# a query field.
|
25
|
+
#
|
26
|
+
# @since 2.1.0
|
27
|
+
LOG_STRING_LIMIT = 250
|
28
|
+
|
29
|
+
# Handle the command started event.
|
30
|
+
#
|
31
|
+
# @example Handle the event.
|
32
|
+
# subscriber.started(event)
|
33
|
+
#
|
34
|
+
# @param [ CommandStartedEvent ] event The event.
|
35
|
+
#
|
36
|
+
# @since 2.1.0
|
37
|
+
def started(event)
|
38
|
+
if Logger.logger.debug?
|
39
|
+
log("#{prefix(event)} | STARTED | #{format(event.command)}")
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
# Handle the command succeeded event.
|
44
|
+
#
|
45
|
+
# @example Handle the event.
|
46
|
+
# subscriber.succeeded(event)
|
47
|
+
#
|
48
|
+
# @param [ CommandSucceededEvent ] event The event.
|
49
|
+
#
|
50
|
+
# @since 2.1.0
|
51
|
+
def succeeded(event)
|
52
|
+
if Logger.logger.debug?
|
53
|
+
log("#{prefix(event)} | SUCCEEDED | #{event.duration}s")
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
# Handle the command failed event.
|
58
|
+
#
|
59
|
+
# @example Handle the event.
|
60
|
+
# subscriber.failed(event)
|
61
|
+
#
|
62
|
+
# @param [ CommandFailedEvent ] event The event.
|
63
|
+
#
|
64
|
+
# @since 2.1.0
|
65
|
+
def failed(event)
|
66
|
+
if Logger.logger.debug?
|
67
|
+
log("#{prefix(event)} | FAILED | #{event.message} | #{event.duration}s")
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
private
|
72
|
+
|
73
|
+
def format(args)
|
74
|
+
((s = args.inspect).length > LOG_STRING_LIMIT) ? "#{s[0..LOG_STRING_LIMIT]}..." : s
|
75
|
+
rescue ArgumentError
|
76
|
+
'<Unable to inspect arguments>'
|
77
|
+
end
|
78
|
+
|
79
|
+
def log(message)
|
80
|
+
Logger.logger.debug(message)
|
81
|
+
end
|
82
|
+
|
83
|
+
def prefix(event)
|
84
|
+
"MONGODB | #{event.address.to_s} | #{event.database_name}.#{event.command_name}"
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# Copyright (C) 2015 MongoDB, Inc.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the 'License');
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an 'AS IS' BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
require 'mongo/monitoring/event/command_started'
|
16
|
+
require 'mongo/monitoring/event/command_succeeded'
|
17
|
+
require 'mongo/monitoring/event/command_failed'
|
@@ -0,0 +1,96 @@
|
|
1
|
+
# Copyright (C) 2015 MongoDB, Inc.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the 'License');
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an 'AS IS' BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
module Mongo
|
16
|
+
class Monitoring
|
17
|
+
module Event
|
18
|
+
|
19
|
+
# Event that is fired when a command operation fails.
|
20
|
+
#
|
21
|
+
# @since 2.1.0
|
22
|
+
class CommandFailed
|
23
|
+
|
24
|
+
# @return [ Server::Address ] address The server address.
|
25
|
+
attr_reader :address
|
26
|
+
|
27
|
+
# @return [ String ] command_name The name of the command.
|
28
|
+
attr_reader :command_name
|
29
|
+
|
30
|
+
# @return [ String ] database_name The name of the database_name.
|
31
|
+
attr_reader :database_name
|
32
|
+
|
33
|
+
# @return [ Float ] duration The duration of the command in seconds.
|
34
|
+
attr_reader :duration
|
35
|
+
|
36
|
+
# @return [ String ] message The error message.
|
37
|
+
attr_reader :message
|
38
|
+
|
39
|
+
# @return [ Integer ] operation_id The operation id.
|
40
|
+
attr_reader :operation_id
|
41
|
+
|
42
|
+
# @return [ Integer ] request_id The request id.
|
43
|
+
attr_reader :request_id
|
44
|
+
|
45
|
+
# Create the new event.
|
46
|
+
#
|
47
|
+
# @example Create the event.
|
48
|
+
#
|
49
|
+
# @param [ String ] command_name The name of the command.
|
50
|
+
# @param [ String ] database_name The database_name name.
|
51
|
+
# @param [ Server::Address ] address The server address.
|
52
|
+
# @param [ Integer ] request_id The request id.
|
53
|
+
# @param [ Integer ] operation_id The operation id.
|
54
|
+
# @param [ String ] message The error message.
|
55
|
+
# @param [ Float ] duration The duration the command took in seconds.
|
56
|
+
#
|
57
|
+
# @since 2.1.0
|
58
|
+
def initialize(command_name, database_name, address, request_id, operation_id, message, duration)
|
59
|
+
@command_name = command_name
|
60
|
+
@database_name = database_name
|
61
|
+
@address = address
|
62
|
+
@request_id = request_id
|
63
|
+
@operation_id = operation_id
|
64
|
+
@message = message
|
65
|
+
@duration = duration
|
66
|
+
end
|
67
|
+
|
68
|
+
# Create the event from a wire protocol message payload.
|
69
|
+
#
|
70
|
+
# @example Create the event.
|
71
|
+
# CommandFailed.generate(address, 1, payload, duration)
|
72
|
+
#
|
73
|
+
# @param [ Server::Address ] address The server address.
|
74
|
+
# @param [ Integer ] operation_id The operation id.
|
75
|
+
# @param [ Hash ] payload The message payload.
|
76
|
+
# @param [ String ] message The error message.
|
77
|
+
# @param [ Float ] duration The duration of the command in seconds.
|
78
|
+
#
|
79
|
+
# @return [ CommandFailed ] The event.
|
80
|
+
#
|
81
|
+
# @since 2.1.0
|
82
|
+
def self.generate(address, operation_id, payload, message, duration)
|
83
|
+
new(
|
84
|
+
payload[:command_name],
|
85
|
+
payload[:database_name],
|
86
|
+
address,
|
87
|
+
payload[:request_id],
|
88
|
+
operation_id,
|
89
|
+
message,
|
90
|
+
duration
|
91
|
+
)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|