Class: Amigo::Autoscaler::Handlers::Sentry

Inherits:
Amigo::Autoscaler::Handler show all
Defined in:
lib/amigo/autoscaler/handlers/sentry.rb

Instance Method Summary collapse

Constructor Details

#initialize(interval: 300, message: "Some queues have a high latency", level: :warn) ⇒ Sentry

Returns a new instance of Sentry.

Parameters:

  • interval (Integer) (defaults to: 300)

    How many seconds between Sentry alerts? This is similar to alert_interval on the Autoscaler, but Sentry has its own interval, since it is used for reporting, and not latency reduction.

  • message (String) (defaults to: "Some queues have a high latency")

    Message to capture.

  • level (:debug, :info, :warning, :warn, :error, :fatal) (defaults to: :warn)

    Sentry level.



15
16
17
18
19
20
21
# File 'lib/amigo/autoscaler/handlers/sentry.rb', line 15

def initialize(interval: 300, message: "Some queues have a high latency", level: :warn)
  @interval = interval
  @message = message
  @level = level
  @last_alerted = Time.at(0)
  super()
end

Instance Method Details

#scale_downObject



34
# File 'lib/amigo/autoscaler/handlers/sentry.rb', line 34

def scale_down(**) = nil

#scale_up(high_latencies:, depth:, duration:, pool_usage:) ⇒ Object



23
24
25
26
27
28
29
30
31
32
# File 'lib/amigo/autoscaler/handlers/sentry.rb', line 23

def scale_up(high_latencies:, depth:, duration:, pool_usage:, **)
  now = Time.now
  call_sentry = @last_alerted < (now - @interval)
  return unless call_sentry
  ::Sentry.with_scope do |scope|
    scope&.set_extras(high_latencies:, depth:, duration:, pool_usage:)
    ::Sentry.capture_message(@message, level: @level)
  end
  @last_alerted = now
end