123456789_123456789_123456789_123456789_123456789_

Class: Mongo::Monitoring::Event::CommandSucceeded

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
Instance Chain:
Inherits: Mongo::Event::Base
Defined in: lib/mongo/monitoring/event/command_succeeded.rb

Overview

::Mongo::Monitoring::Event that is fired when a command operation succeeds.

Since:

  • 2.1.0

Constant Summary

Secure - Included

REDACTED_COMMANDS

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Secure - Included

#compression_allowed?

Is compression allowed for a given command message.

#redacted

Redact secure information from the document if:

#sensitive?

Check whether the command is sensitive in terms of command monitoring spec.

::Mongo::Event::Base - Inherited

#summary

Returns a concise yet useful summary of the event.

#short_class_name

Class Method Details

.generate(address, operation_id, command_payload, reply_payload, duration, started_event:, server_connection_id: nil, service_id: nil) ⇒ CommandCompleted

This method is for internal use only.

Create the event from a wire protocol message payload.

Examples:

Create the event.

CommandSucceeded.generate(address, 1, command_payload, reply_payload, 0.5)

Parameters:

  • address (Server::Address)

    The server address.

  • operation_id (Integer)

    The operation id.

  • command_payload (Hash)

    The command message payload.

  • reply_payload (Hash)

    The reply message payload.

  • duration (Float)

    The duration of the command in seconds.

  • started_event (Monitoring::Event::CommandStarted)

    The corresponding started event.

  • service_id (Object)

    The service id, if any.

Returns:

  • (CommandCompleted)

    The event.

Since:

  • 2.1.0

[ GitHub ]

  
# File 'lib/mongo/monitoring/event/command_succeeded.rb', line 123

def self.generate(address, operation_id, command_payload,
  reply_payload, duration, started_event:, server_connection_id: nil,
  service_id: nil
)
  new(
    command_payload[:command_name],
    command_payload[:database_name],
    address,
    command_payload[:request_id],
    operation_id,
    generate_reply(command_payload, reply_payload),
    duration,
    started_event: started_event,
    server_connection_id: server_connection_id,
    service_id: service_id,
  )
end

.generate_reply(command_payload, reply_payload) (private)

Since:

  • 2.1.0

[ GitHub ]

  
# File 'lib/mongo/monitoring/event/command_succeeded.rb', line 143

def self.generate_reply(command_payload, reply_payload)
  if reply_payload
    reply = reply_payload[:reply]
    if cursor = reply[:cursor]
      if !cursor.key?(Collection::NS)
        cursor.merge!(Collection::NS => namespace(command_payload))
      end
    end
    reply
  else
    BSON::Document.new(Operation::Result::OK => 1)
  end
end

.namespace(payload) (private)

Since:

  • 2.1.0

[ GitHub ]

  
# File 'lib/mongo/monitoring/event/command_succeeded.rb', line 157

def self.namespace(payload)
  command = payload[:command]
  "#{payload[:database_name]}.#{command[:collection] || command.values.first}"
end

Instance Attribute Details

#addressServer::Address (readonly)

Returns:

  • (Server::Address)

    address The server address.

Since:

  • 2.1.0

[ GitHub ]

  
# File 'lib/mongo/monitoring/event/command_succeeded.rb', line 29

attr_reader :address

#command_nameString (readonly)

Returns:

  • (String)

    command_name The name of the command.

Since:

  • 2.1.0

[ GitHub ]

  
# File 'lib/mongo/monitoring/event/command_succeeded.rb', line 32

attr_reader :command_name

#database_nameString (readonly)

Returns:

  • (String)

    database_name The name of the database.

Since:

  • 2.1.0

[ GitHub ]

  
# File 'lib/mongo/monitoring/event/command_succeeded.rb', line 38

attr_reader :database_name

#durationFloat (readonly)

Returns:

  • (Float)

    duration The duration of the event.

Since:

  • 2.1.0

[ GitHub ]

  
# File 'lib/mongo/monitoring/event/command_succeeded.rb', line 41

attr_reader :duration

#operation_idInteger (readonly)

Returns:

  • (Integer)

    operation_id The operation id.

Since:

  • 2.1.0

[ GitHub ]

  
# File 'lib/mongo/monitoring/event/command_succeeded.rb', line 44

attr_reader :operation_id

#replyBSON::Document (readonly)

Returns:

  • (BSON::Document)

    reply The command reply.

Since:

  • 2.1.0

[ GitHub ]

  
# File 'lib/mongo/monitoring/event/command_succeeded.rb', line 35

attr_reader :reply

#request_idInteger (readonly)

Returns:

  • (Integer)

    request_id The request id.

Since:

  • 2.1.0

[ GitHub ]

  
# File 'lib/mongo/monitoring/event/command_succeeded.rb', line 47

attr_reader :request_id

#server_connection_idInteger (readonly)

Returns:

  • (Integer)

    server_connection_id The server connection id.

Since:

  • 2.1.0

[ GitHub ]

  
# File 'lib/mongo/monitoring/event/command_succeeded.rb', line 50

attr_reader :server_connection_id

#service_idnil | Object (readonly)

Returns:

  • (nil | Object)

    The service id, if any.

Since:

  • 2.1.0

[ GitHub ]

  
# File 'lib/mongo/monitoring/event/command_succeeded.rb', line 53

attr_reader :service_id

#started_eventMonitoring::Event::CommandStarted (readonly)

This method is for internal use only.

Returns:

Since:

  • 2.1.0

[ GitHub ]

  
# File 'lib/mongo/monitoring/event/command_succeeded.rb', line 59

attr_reader :started_event

Instance Method Details

#summaryString

Note:

This method is experimental and subject to change.

Returns a concise yet useful summary of the event.

Returns:

  • (String)

    String summary of the event.

Since:

  • 2.1.0

[ GitHub ]

  
# File 'lib/mongo/monitoring/event/command_succeeded.rb', line 101

def summary
  "#<#{short_class_name} address=#{address} #{database_name}.#{command_name}>"
end