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
29 changes: 15 additions & 14 deletions spec/runners/unified/event_subscriber.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,43 +31,44 @@ def add_wanted_events(kind)

class StoringEventSubscriber
def initialize(&block)
@operations = {}
@handler = block
end

def started(event)
started_at = Time.now
@operations[event.operation_id] = [event, started_at]
@handler.call(
'name' => event.class.name.sub(/.*::/, '') + 'Event',
'commandName' => event.command_name,
'startTime' => started_at.to_f,
'databaseName' => event.database_name,
'observedAt' => Time.now.to_f,
'address' => event.address.seed,
'requestId' => event.request_id,
'operationId' => event.operation_id,
'connectionId' => event.connection_id,
)
end

def succeeded(event)
started_event, started_at = @operations.delete(event.operation_id)
raise "Started event for #{event.operation_id} not found" unless started_event
@handler.call(
'name' => event.class.name.sub(/.*::/, '') + 'Event',
'commandName' => started_event.command_name,
'commandName' => event.command_name,
'duration' => event.duration,
'startTime' => started_at.to_f,
'address' => started_event.address.seed,
'observedAt' => Time.now.to_f,
'address' => event.address.seed,
'requestId' => event.request_id,
'operationId' => event.operation_id,
)
end

def failed(event)
started_event, started_at = @operations.delete(event.operation_id)
raise "Started event for #{event.operation_id} not found" unless started_event
@handler.call(
'name' => event.class.name.sub(/.*::/, '') + 'Event',
'commandName' => started_event.command_name,
'commandName' => event.command_name,
'duration' => event.duration,
'failure' => event.failure,
'startTime' => started_at.to_f,
'address' => started_event.address.seed,
'observedAt' => Time.now.to_f,
'address' => event.address.seed,
'requestId' => event.request_id,
'operationId' => event.operation_id,
)
end

Expand Down
1 change: 1 addition & 0 deletions spec/runners/unified/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ def create_entities
end
end
opts[:sdam_proc] = lambda do |client|
client.subscribe(Mongo::Monitoring::COMMAND, subscriber)
client.subscribe(Mongo::Monitoring::CONNECTION_POOL, subscriber)
end
end
Expand Down