Class: Stoplight::Domain::Tracker::RecoveryProbe

Inherits:
Base
  • Object
show all
Defined in:
lib/stoplight/domain/tracker/recovery_probe.rb,
sig/_private/stoplight/domain/tracker/recovery_probe.rbs

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(traffic_recovery:, notifiers:, config:, metrics_store:, state_store:) ⇒ RecoveryProbe

Returns a new instance of RecoveryProbe.



7
8
9
10
11
12
13
# File 'lib/stoplight/domain/tracker/recovery_probe.rb', line 7

def initialize(traffic_recovery:, notifiers:, config:, metrics_store:, state_store:)
  @traffic_recovery = traffic_recovery
  @notifiers = notifiers
  @config = config
  @metrics_store = metrics_store
  @state_store = state_store
end

Instance Attribute Details

#configConfig (readonly)

Returns the value of attribute config.

Returns:



32
33
34
# File 'lib/stoplight/domain/tracker/recovery_probe.rb', line 32

def config
  @config
end

#metrics_store_MetricsStore (readonly)

Returns the value of attribute metrics_store.

Returns:



33
34
35
# File 'lib/stoplight/domain/tracker/recovery_probe.rb', line 33

def metrics_store
  @metrics_store
end

#notifiersArray[state_transition_notifier] (readonly)

Returns the value of attribute notifiers.

Returns:

  • (Array[state_transition_notifier])


31
32
33
# File 'lib/stoplight/domain/tracker/recovery_probe.rb', line 31

def notifiers
  @notifiers
end

#state_store_StateStore (readonly)

Returns the value of attribute state_store.

Returns:



34
35
36
# File 'lib/stoplight/domain/tracker/recovery_probe.rb', line 34

def state_store
  @state_store
end

#traffic_recovery_TrafficRecovery (readonly)

Returns the value of attribute traffic_recovery.

Returns:



30
31
32
# File 'lib/stoplight/domain/tracker/recovery_probe.rb', line 30

def traffic_recovery
  @traffic_recovery
end

Instance Method Details

#record_failure(exception) ⇒ void

This method returns an undefined value.

Parameters:

  • exception (Exception)


16
17
18
19
20
# File 'lib/stoplight/domain/tracker/recovery_probe.rb', line 16

def record_failure(exception)
  metrics_store.record_failure(exception)

  recover
end

#record_successvoid

This method returns an undefined value.



22
23
24
25
26
# File 'lib/stoplight/domain/tracker/recovery_probe.rb', line 22

def record_success
  metrics_store.record_success

  recover
end

#recovervoid

This method returns an undefined value.



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/stoplight/domain/tracker/recovery_probe.rb', line 36

def recover
  recovery_metrics = metrics_store.metrics_snapshot
  recovery_result = traffic_recovery.determine_color(config, recovery_metrics)

  return if recovery_result == TrafficRecovery::YELLOW

  from_color, to_color = case recovery_result
  when TrafficRecovery::GREEN then [Color::YELLOW, Color::GREEN]
  when TrafficRecovery::RED then [Color::YELLOW, Color::RED]
  else
    raise "recovery strategy returned unexpected color: #{recovery_result}"
  end

  state_store.transition_to_color(to_color)
  metrics_store.clear
  info = LightInfo.new(name: config.name)
  notifiers.each do |notifier|
    notifier.notify(info, from_color, to_color, nil)
  end
end