Class: Stoplight::Domain::TrafficControl::ConsecutiveErrors Private

Inherits:
Object
  • Object
show all
Defined in:
lib/stoplight/domain/traffic_control/consecutive_errors.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

A strategy that stops the traffic based on consecutive failures number.

This strategy implements two distinct behaviors based on whether a window size is configured:

  1. When window_size is set: The Stoplight turns red when the total number of failures within the window reaches the threshold.

  2. When window_size is not set: The Stoplight turns red when consecutive failures reach the threshold.

Will switch to red if 5 consecutive failures occur within the 60-second window

Will switch to red only if 5 consecutive failures occur regardless of the time window

Examples:

With window-based configuration

traffic_control = Stoplight::Domain::TrafficControl::ConsecutiveErrors.new
config = Stoplight::Domain::Config.new(threshold: 5, window_size: 60, traffic_control:)

With total number of consecutive failures configuration

traffic_control = Stoplight::Domain::TrafficControl::ConsecutiveErrors.new
config = Stoplight::Domain::Config.new(threshold: 5, window_size: nil, traffic_control:)

Instance Method Summary collapse

Instance Method Details

#==(other) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



44
45
46
# File 'lib/stoplight/domain/traffic_control/consecutive_errors.rb', line 44

def ==(other)
  other.is_a?(self.class)
end

#check_compatibility(config) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



30
31
32
33
34
35
36
37
38
# File 'lib/stoplight/domain/traffic_control/consecutive_errors.rb', line 30

def check_compatibility(config)
  if config.threshold <= 0
    CompatibilityResult.incompatible("`threshold` should be bigger than 0")
  elsif !config.threshold.is_a?(Integer)
    CompatibilityResult.incompatible("`threshold` should be an integer")
  else
    CompatibilityResult.compatible
  end
end

#stop_traffic?(config, metrics) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


40
41
42
# File 'lib/stoplight/domain/traffic_control/consecutive_errors.rb', line 40

def stop_traffic?(config, metrics)
  metrics.consecutive_errors >= config.threshold
end