Module: Stoplight::Domain::_TrafficControl

Included in:
TrafficControl::ConsecutiveErrors, TrafficControl::ErrorRate
Defined in:
sig/_private/stoplight/domain/ports/traffic_control.rbs

Overview

Strategies for determining when a Stoplight should change color to red.

These strategies evaluate the current state and metrics of a Stoplight to decide if traffic should be stopped (i.e., if the light should turn RED).

Examples:

Creating a custom strategy

class ErrorRateStrategy
  def check_compatibility(config)
    if config.window_size.nil?
      incompatible("`window_size` should be set")
    else
      compatible
    end
  end

  def stop_traffic?(config, metrics)
    total = metrics.successes + metrics.failures
    return false if total < 10 # Minimum sample size

    error_rate = metrics.failures.fdiv(total)
    error_rate >= 0.5 # Stop traffic when error rate reaches 50%
  end
end

Instance Method Summary collapse

Instance Method Details

#==Boolean

Object methods

Parameters:

  • (Object)

Returns:

  • (Boolean)


37
# File 'sig/_private/stoplight/domain/ports/traffic_control.rbs', line 37

def ==: (untyped) -> bool

#check_compatibilityCompatibilityResult

Checks if the strategy is compatible with the given Stoplight configuration.

Parameters:

Returns:



29
# File 'sig/_private/stoplight/domain/ports/traffic_control.rbs', line 29

def check_compatibility: (Config) -> CompatibilityResult

#is_a?Boolean

Parameters:

  • (Object)

Returns:

  • (Boolean)


38
# File 'sig/_private/stoplight/domain/ports/traffic_control.rbs', line 38

def is_a?: (untyped) -> bool

#stop_traffic?Object

Determines whether traffic should be stopped based on the Stoplight's current state and metrics.

Parameters:

Returns:

  • true if traffic should be stopped otherwise false



34
# File 'sig/_private/stoplight/domain/ports/traffic_control.rbs', line 34

def stop_traffic?: (Config, Domain::MetricsSnapshot) -> bool