Class: Karafka::Monitor

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/karafka/monitor.rb

Overview

Note:

This class acts as a singleton because we are only permitted to have single monitor per running process (just as logger)

Monitor is used to hookup external monitoring services to monitor how Karafka works It provides a standarized API for checking incoming messages/enqueueing etc By default it implements logging functionalities but can be replaced with any more

sophisticated logging/monitoring system like Errbit, Airbrake, NewRelic

Keep in mind, that if you create your own monitor object, you will have to implement also logging functionality (or just inherit, super and do whatever you want)

Instance Method Summary collapse

Instance Method Details

#notice(caller_class, options = {}) ⇒ Object

Note:

We don’t provide a name of method in which this was called, because we can take it directly from Ruby (see #caller_label method of this class for more details)

This method is executed in many important places in the code (during data flow), like the moment before #perform_async, etc. For full list just grep for ‘monitor.notice’

Examples:

Notice about consuming with controller_class

Karafka.monitor.notice(self.class, controller_class: controller_class)

Notice about terminating with a signal

Karafka.monitor.notice(self.class, signal: signal)

Parameters:

  • caller_class (Class)

    class of object that executed this call

  • options (Hash) (defaults to: {})

    hash with options that we passed to notice. It differs based on of who and when is calling



24
25
26
# File 'lib/karafka/monitor.rb', line 24

def notice(caller_class, options = {})
  logger.info("#{caller_class}##{caller_label} with #{options}")
end

#notice_error(caller_class, e) ⇒ Object

Note:

We don’t provide a name of method in which this was called, because we can take it directly from Ruby (see #caller_label method of this class for more details)

This method is executed when we want to notify about an error that happened somewhere in the system

Examples:

Notify about error

Karafka.monitor.notice(self.class, e)

Parameters:

  • caller_class (Class)

    class of object that executed this call

  • e (Exception)

    exception that was raised



36
37
38
39
40
41
42
43
44
# File 'lib/karafka/monitor.rb', line 36

def notice_error(caller_class, e)
  caller_exceptions_map.each do |level, types|
    next unless types.include?(caller_class)

    return logger.public_send(level, e)
  end

  logger.info(e)
end