stoplight 5.7.0 → 5.8.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/UPGRADING.md +303 -0
- data/lib/generators/stoplight/install/install_generator.rb +6 -1
- data/lib/stoplight/admin/dependencies.rb +1 -1
- data/lib/stoplight/admin/helpers.rb +20 -4
- data/lib/stoplight/admin/lights_repository/light.rb +22 -6
- data/lib/stoplight/admin/lights_repository.rb +6 -5
- data/lib/stoplight/admin/views/_card.erb +8 -5
- data/lib/stoplight/color.rb +9 -0
- data/lib/stoplight/data_store.rb +28 -0
- data/lib/stoplight/domain/compatibility_result.rb +7 -7
- data/lib/stoplight/domain/config.rb +38 -39
- data/lib/stoplight/domain/error_tracking_policy.rb +27 -0
- data/lib/stoplight/domain/failure.rb +1 -1
- data/lib/stoplight/domain/light/configuration_builder_interface.rb +2 -0
- data/lib/stoplight/domain/light.rb +15 -46
- data/lib/stoplight/domain/light_info.rb +7 -0
- data/lib/stoplight/domain/metrics_snapshot.rb +58 -0
- data/lib/stoplight/domain/state_snapshot.rb +29 -23
- data/lib/stoplight/domain/storage/recovery_lock_token.rb +15 -0
- data/lib/stoplight/domain/strategies/green_run_strategy.rb +18 -26
- data/lib/stoplight/domain/strategies/red_run_strategy.rb +9 -12
- data/lib/stoplight/domain/strategies/yellow_run_strategy.rb +41 -51
- data/lib/stoplight/domain/tracker/recovery_probe.rb +16 -33
- data/lib/stoplight/domain/tracker/request.rb +12 -31
- data/lib/stoplight/domain/traffic_control/consecutive_errors.rb +8 -11
- data/lib/stoplight/domain/traffic_control/error_rate.rb +19 -15
- data/lib/stoplight/domain/traffic_recovery/consecutive_successes.rb +6 -10
- data/lib/stoplight/domain/traffic_recovery.rb +3 -4
- data/lib/stoplight/error.rb +46 -0
- data/lib/stoplight/infrastructure/{data_store/fail_safe.rb → fail_safe/data_store.rb} +39 -51
- data/lib/stoplight/infrastructure/fail_safe/storage/metrics.rb +65 -0
- data/lib/stoplight/infrastructure/fail_safe/storage/recovery_lock.rb +69 -0
- data/lib/stoplight/infrastructure/fail_safe/storage/recovery_lock_token.rb +19 -0
- data/lib/stoplight/infrastructure/fail_safe/storage/state.rb +62 -0
- data/lib/stoplight/infrastructure/{data_store/memory → memory/data_store}/metrics.rb +2 -2
- data/lib/stoplight/infrastructure/{data_store/memory → memory/data_store}/recovery_lock_store.rb +10 -12
- data/lib/stoplight/infrastructure/{data_store/memory → memory/data_store}/recovery_lock_token.rb +3 -6
- data/lib/stoplight/infrastructure/{data_store/memory → memory/data_store}/sliding_window.rb +21 -26
- data/lib/stoplight/infrastructure/{data_store/memory → memory/data_store}/state.rb +3 -3
- data/lib/stoplight/infrastructure/{data_store/memory.rb → memory/data_store.rb} +36 -32
- data/lib/stoplight/infrastructure/memory/storage/recovery_lock.rb +35 -0
- data/lib/stoplight/infrastructure/memory/storage/recovery_metrics.rb +16 -0
- data/lib/stoplight/infrastructure/memory/storage/state.rb +155 -0
- data/lib/stoplight/infrastructure/memory/storage/unbounded_metrics.rb +103 -0
- data/lib/stoplight/infrastructure/memory/storage/window_metrics.rb +101 -0
- data/lib/stoplight/infrastructure/notifier/fail_safe.rb +9 -21
- data/lib/stoplight/infrastructure/notifier/generic.rb +4 -14
- data/lib/stoplight/infrastructure/notifier/io.rb +1 -2
- data/lib/stoplight/infrastructure/notifier/logger.rb +1 -2
- data/lib/stoplight/infrastructure/{data_store/redis → redis/data_store}/recovery_lock_store.rb +9 -22
- data/lib/stoplight/infrastructure/{data_store/redis → redis/data_store}/recovery_lock_token.rb +7 -14
- data/lib/stoplight/infrastructure/{data_store/redis → redis/data_store}/scripting.rb +22 -20
- data/lib/stoplight/infrastructure/{data_store/redis.rb → redis/data_store.rb} +47 -55
- data/lib/stoplight/infrastructure/redis/storage/key_space.rb +51 -0
- data/lib/stoplight/infrastructure/redis/storage/metrics.rb +40 -0
- data/lib/stoplight/infrastructure/redis/storage/recovery_lock/release_lock.lua +6 -0
- data/lib/stoplight/infrastructure/redis/storage/recovery_lock.rb +64 -0
- data/lib/stoplight/infrastructure/redis/storage/recovery_metrics.rb +20 -0
- data/lib/stoplight/infrastructure/redis/storage/scripting.rb +18 -0
- data/lib/stoplight/infrastructure/redis/storage/state/transition_to_green.lua +10 -0
- data/lib/stoplight/infrastructure/redis/storage/state/transition_to_red.lua +10 -0
- data/lib/stoplight/infrastructure/redis/storage/state/transition_to_yellow.lua +9 -0
- data/lib/stoplight/infrastructure/redis/storage/state.rb +141 -0
- data/lib/stoplight/infrastructure/redis/storage/unbounded_metrics/record_failure.lua +28 -0
- data/lib/stoplight/infrastructure/redis/storage/unbounded_metrics/record_success.lua +26 -0
- data/lib/stoplight/infrastructure/redis/storage/unbounded_metrics.rb +123 -0
- data/lib/stoplight/infrastructure/redis/storage/window_metrics/metrics_snapshot.lua +26 -0
- data/lib/stoplight/infrastructure/redis/storage/window_metrics/record_failure.lua +36 -0
- data/lib/stoplight/infrastructure/redis/storage/window_metrics/record_success.lua +35 -0
- data/lib/stoplight/infrastructure/redis/storage/window_metrics.rb +174 -0
- data/lib/stoplight/infrastructure/storage/compatibility_metrics.rb +3 -10
- data/lib/stoplight/infrastructure/storage/compatibility_recovery_lock.rb +8 -11
- data/lib/stoplight/infrastructure/storage/compatibility_recovery_metrics.rb +6 -14
- data/lib/stoplight/infrastructure/storage/compatibility_state.rb +6 -17
- data/lib/stoplight/infrastructure/system_clock.rb +16 -0
- data/lib/stoplight/notifier.rb +11 -0
- data/lib/stoplight/state.rb +9 -0
- data/lib/stoplight/types.rb +29 -0
- data/lib/stoplight/undefined.rb +16 -0
- data/lib/stoplight/version.rb +1 -1
- data/lib/stoplight/wiring/config_compatibility_validator.rb +54 -0
- data/lib/stoplight/wiring/configuration_dsl.rb +101 -0
- data/lib/stoplight/wiring/data_store_backend.rb +26 -0
- data/lib/stoplight/wiring/default.rb +1 -1
- data/lib/stoplight/wiring/default_config.rb +21 -0
- data/lib/stoplight/wiring/default_configuration.rb +70 -53
- data/lib/stoplight/wiring/light_builder.rb +76 -63
- data/lib/stoplight/wiring/light_factory/traffic_control_dsl.rb +3 -3
- data/lib/stoplight/wiring/light_factory/traffic_recovery_dsl.rb +4 -4
- data/lib/stoplight/wiring/light_factory.rb +78 -52
- data/lib/stoplight/wiring/memory/backend.rb +57 -0
- data/lib/stoplight/wiring/redis/backend.rb +116 -0
- data/lib/stoplight/wiring/storage_set.rb +12 -0
- data/lib/stoplight/wiring/storage_set_builder.rb +51 -0
- data/lib/stoplight/wiring/system/light_builder.rb +47 -0
- data/lib/stoplight/wiring/system/light_factory.rb +64 -0
- data/lib/stoplight/wiring/system.rb +129 -0
- data/lib/stoplight.rb +196 -25
- data/sig/_private/generators/stoplight/install/install_generator.rbs +22 -0
- data/sig/_private/stoplight/common/deprecations.rbs +9 -0
- data/sig/_private/stoplight/data_store.rbs +6 -0
- data/sig/_private/stoplight/domain/compatibility_result.rbs +18 -0
- data/sig/_private/stoplight/domain/config.rbs +65 -0
- data/sig/_private/stoplight/domain/error_tracking_policy.rbs +14 -0
- data/sig/_private/stoplight/domain/failure.rbs +16 -0
- data/sig/_private/stoplight/domain/light.rbs +25 -0
- data/sig/_private/stoplight/domain/light_info.rbs +19 -0
- data/sig/_private/stoplight/domain/metrics_snapshot.rbs +38 -0
- data/sig/_private/stoplight/domain/ports/clock.rbs +18 -0
- data/sig/_private/stoplight/domain/ports/data_store.rbs +76 -0
- data/{lib/stoplight/domain/light_factory.rb → sig/_private/stoplight/domain/ports/light_factory.rbs} +33 -28
- data/sig/_private/stoplight/domain/ports/metrics_store.rbs +29 -0
- data/sig/_private/stoplight/domain/ports/recovery_lock_store.rbs +52 -0
- data/sig/_private/stoplight/domain/ports/recovery_lock_token.rbs +6 -0
- data/sig/_private/stoplight/domain/ports/run_strategy.rbs +14 -0
- data/sig/_private/stoplight/domain/ports/state_store.rbs +79 -0
- data/sig/_private/stoplight/domain/ports/traffic_control.rbs +41 -0
- data/sig/_private/stoplight/domain/ports/traffic_recovery.rbs +47 -0
- data/sig/_private/stoplight/domain/state_snapshot.rbs +32 -0
- data/sig/_private/stoplight/domain/storage/recovery_lock_token.rbs +11 -0
- data/sig/_private/stoplight/domain/strategies/green_run_strategy.rbs +17 -0
- data/sig/_private/stoplight/domain/strategies/red_run_strategy.rbs +17 -0
- data/sig/_private/stoplight/domain/strategies/yellow_run_strategy.rbs +42 -0
- data/{lib/stoplight/domain/tracker/base.rb → sig/_private/stoplight/domain/tracker/base.rbs} +0 -4
- data/sig/_private/stoplight/domain/tracker/recovery_probe.rbs +25 -0
- data/sig/_private/stoplight/domain/tracker/request.rbs +26 -0
- data/sig/_private/stoplight/domain/traffic_control/consecutive_errors.rbs +9 -0
- data/sig/_private/stoplight/domain/traffic_control/error_rate.rbs +13 -0
- data/sig/_private/stoplight/domain/traffic_recovery/consecutive_successes.rbs +9 -0
- data/sig/_private/stoplight/domain/traffic_recovery.rbs +9 -0
- data/sig/_private/stoplight/infrastructure/fail_safe/data_store.rbs +26 -0
- data/sig/_private/stoplight/infrastructure/fail_safe/storage/metrics.rbs +25 -0
- data/sig/_private/stoplight/infrastructure/fail_safe/storage/recovery_lock.rbs +29 -0
- data/sig/_private/stoplight/infrastructure/fail_safe/storage/recovery_lock_token.rbs +19 -0
- data/sig/_private/stoplight/infrastructure/fail_safe/storage/state.rbs +25 -0
- data/sig/_private/stoplight/infrastructure/memory/data_store/metrics.rbs +25 -0
- data/sig/_private/stoplight/infrastructure/memory/data_store/recovery_lock_store.rbs +19 -0
- data/sig/_private/stoplight/infrastructure/memory/data_store/recovery_lock_token.rbs +17 -0
- data/sig/_private/stoplight/infrastructure/memory/data_store/sliding_window.rbs +27 -0
- data/sig/_private/stoplight/infrastructure/memory/data_store/state.rbs +17 -0
- data/sig/_private/stoplight/infrastructure/memory/data_store.rbs +30 -0
- data/sig/_private/stoplight/infrastructure/memory/storage/recovery_lock.rbs +15 -0
- data/sig/_private/stoplight/infrastructure/memory/storage/recovery_metrics.rbs +10 -0
- data/sig/_private/stoplight/infrastructure/memory/storage/state.rbs +28 -0
- data/sig/_private/stoplight/infrastructure/memory/storage/unbounded_metrics.rbs +25 -0
- data/sig/_private/stoplight/infrastructure/memory/storage/window_metrics.rbs +26 -0
- data/sig/_private/stoplight/infrastructure/notifier/fail_safe.rbs +17 -0
- data/sig/_private/stoplight/infrastructure/notifier/generic.rbs +18 -0
- data/sig/_private/stoplight/infrastructure/notifier/io.rbs +14 -0
- data/sig/_private/stoplight/infrastructure/notifier/logger.rbs +14 -0
- data/sig/_private/stoplight/infrastructure/redis/data_store/recovery_lock_store.rbs +24 -0
- data/sig/_private/stoplight/infrastructure/redis/data_store/recovery_lock_token.rbs +21 -0
- data/sig/_private/stoplight/infrastructure/redis/data_store/scripting.rbs +34 -0
- data/sig/_private/stoplight/infrastructure/redis/data_store.rbs +67 -0
- data/sig/_private/stoplight/infrastructure/redis/storage/key_space.rbs +19 -0
- data/sig/_private/stoplight/infrastructure/redis/storage/metrics.rbs +17 -0
- data/sig/_private/stoplight/infrastructure/redis/storage/recovery_lock.rbs +26 -0
- data/sig/_private/stoplight/infrastructure/redis/storage/recovery_metrics.rbs +10 -0
- data/sig/_private/stoplight/infrastructure/redis/storage/scripting.rbs +13 -0
- data/sig/_private/stoplight/infrastructure/redis/storage/state.rbs +32 -0
- data/sig/_private/stoplight/infrastructure/redis/storage/unbounded_metrics.rbs +21 -0
- data/sig/_private/stoplight/infrastructure/redis/storage/window_metrics.rbs +34 -0
- data/sig/_private/stoplight/infrastructure/storage/compatibility_metrics.rbs +17 -0
- data/sig/_private/stoplight/infrastructure/storage/compatibility_recovery_lock.rbs +13 -0
- data/sig/_private/stoplight/infrastructure/storage/compatibility_recovery_metrics.rbs +14 -0
- data/sig/_private/stoplight/infrastructure/storage/compatibility_state.rbs +14 -0
- data/sig/_private/stoplight/infrastructure/system_clock.rbs +7 -0
- data/sig/_private/stoplight/system/light_builder.rbs +23 -0
- data/sig/_private/stoplight/system/light_factory.rbs +17 -0
- data/sig/_private/stoplight/types.rbs +6 -0
- data/sig/_private/stoplight/wiring/config_compatibility_validator.rbs +19 -0
- data/sig/_private/stoplight/wiring/configuration_dsl.rbs +43 -0
- data/sig/_private/stoplight/wiring/data_store_backend.rbs +11 -0
- data/sig/_private/stoplight/wiring/default.rbs +26 -0
- data/{lib/stoplight/wiring/data_store/memory.rb → sig/_private/stoplight/wiring/default_config.rbs} +1 -4
- data/sig/_private/stoplight/wiring/default_configuration.rbs +29 -0
- data/sig/_private/stoplight/wiring/light_builder.rbs +48 -0
- data/sig/_private/stoplight/wiring/light_factory/traffic_control_dsl.rbs +7 -0
- data/sig/_private/stoplight/wiring/light_factory/traffic_recovery_dsl.rbs +7 -0
- data/sig/_private/stoplight/wiring/light_factory.rbs +16 -0
- data/sig/_private/stoplight/wiring/memory/backend.rbs +26 -0
- data/sig/_private/stoplight/wiring/notifier_factory.rbs +10 -0
- data/sig/_private/stoplight/wiring/redis/backend.rbs +38 -0
- data/sig/_private/stoplight/wiring/storage_set.rbs +38 -0
- data/sig/_private/stoplight/wiring/storage_set_builder.rbs +15 -0
- data/sig/_private/stoplight/wiring/system.rbs +15 -0
- data/sig/_private/stoplight.rbs +48 -0
- data/sig/stoplight/color.rbs +7 -0
- data/sig/stoplight/data_store.rbs +19 -0
- data/sig/stoplight/error.rbs +20 -0
- data/sig/stoplight/notifier.rbs +11 -0
- data/sig/stoplight/ports/configuration.rbs +19 -0
- data/sig/stoplight/ports/exception_matcher.rbs +8 -0
- data/sig/stoplight/ports/light.rbs +12 -0
- data/sig/stoplight/ports/light_info.rbs +5 -0
- data/sig/stoplight/ports/state_transition_notifier.rbs +15 -0
- data/sig/stoplight/ports/system.rbs +21 -0
- data/sig/stoplight/state.rbs +7 -0
- data/sig/stoplight/undefined.rbs +9 -0
- data/sig/stoplight/version.rbs +3 -0
- data/sig/stoplight.rbs +66 -0
- metadata +175 -47
- data/lib/stoplight/domain/color.rb +0 -11
- data/lib/stoplight/domain/data_store.rb +0 -146
- data/lib/stoplight/domain/error.rb +0 -42
- data/lib/stoplight/domain/metrics.rb +0 -64
- data/lib/stoplight/domain/recovery_lock_token.rb +0 -15
- data/lib/stoplight/domain/state.rb +0 -11
- data/lib/stoplight/domain/state_transition_notifier.rb +0 -25
- data/lib/stoplight/domain/storage/metrics.rb +0 -42
- data/lib/stoplight/domain/storage/recovery_lock.rb +0 -56
- data/lib/stoplight/domain/storage/state.rb +0 -87
- data/lib/stoplight/domain/strategies/run_strategy.rb +0 -22
- data/lib/stoplight/domain/traffic_control/base.rb +0 -74
- data/lib/stoplight/domain/traffic_recovery/base.rb +0 -79
- data/lib/stoplight/wiring/data_store/base.rb +0 -11
- data/lib/stoplight/wiring/data_store/redis.rb +0 -25
- data/lib/stoplight/wiring/default_factory_builder.rb +0 -25
- data/lib/stoplight/wiring/light/default_config.rb +0 -18
- data/lib/stoplight/wiring/light/system_config.rb +0 -11
- data/lib/stoplight/wiring/light_factory/compatibility_validator.rb +0 -55
- data/lib/stoplight/wiring/light_factory/config_normalizer.rb +0 -71
- data/lib/stoplight/wiring/light_factory/configuration_pipeline.rb +0 -72
- data/lib/stoplight/wiring/public_api.rb +0 -29
- /data/lib/stoplight/infrastructure/{data_store/redis → redis/data_store}/lua_scripts/get_metrics.lua +0 -0
- /data/lib/stoplight/infrastructure/{data_store/redis → redis/data_store}/lua_scripts/record_failure.lua +0 -0
- /data/lib/stoplight/infrastructure/{data_store/redis → redis/data_store}/lua_scripts/record_recovery_probe_failure.lua +0 -0
- /data/lib/stoplight/infrastructure/{data_store/redis → redis/data_store}/lua_scripts/record_recovery_probe_success.lua +0 -0
- /data/lib/stoplight/infrastructure/{data_store/redis → redis/data_store}/lua_scripts/record_success.lua +0 -0
- /data/lib/stoplight/infrastructure/{data_store/redis → redis/data_store}/lua_scripts/release_lock.lua +0 -0
- /data/lib/stoplight/infrastructure/{data_store/redis → redis/data_store}/lua_scripts/transition_to_green.lua +0 -0
- /data/lib/stoplight/infrastructure/{data_store/redis → redis/data_store}/lua_scripts/transition_to_red.lua +0 -0
- /data/lib/stoplight/infrastructure/{data_store/redis → redis/data_store}/lua_scripts/transition_to_yellow.lua +0 -0
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
module Stoplight
|
|
2
|
+
module Infrastructure
|
|
3
|
+
module FailSafe
|
|
4
|
+
module Storage
|
|
5
|
+
class RecoveryLock
|
|
6
|
+
attr_reader primary_store: Domain::_RecoveryLockStore
|
|
7
|
+
attr_reader error_notifier: error_notifier
|
|
8
|
+
attr_reader failover_store: Domain::_RecoveryLockStore
|
|
9
|
+
attr_reader circuit_breaker: Domain::Light
|
|
10
|
+
|
|
11
|
+
def initialize: (
|
|
12
|
+
primary_store: Domain::_RecoveryLockStore,
|
|
13
|
+
error_notifier: error_notifier,
|
|
14
|
+
failover_store: Domain::_RecoveryLockStore,
|
|
15
|
+
circuit_breaker: Domain::Light
|
|
16
|
+
) -> void
|
|
17
|
+
|
|
18
|
+
def acquire_lock: -> RecoveryLockToken?
|
|
19
|
+
def release_lock: (RecoveryLockToken) -> void
|
|
20
|
+
|
|
21
|
+
def wrap_token: (
|
|
22
|
+
(:primary | :failover) origin,
|
|
23
|
+
Domain::_RecoveryLockToken? token,
|
|
24
|
+
) -> FailSafe::Storage::RecoveryLockToken?
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
module Stoplight
|
|
2
|
+
module Infrastructure
|
|
3
|
+
module FailSafe
|
|
4
|
+
module Storage
|
|
5
|
+
class RecoveryLockToken
|
|
6
|
+
include Domain::_RecoveryLockToken
|
|
7
|
+
|
|
8
|
+
attr_reader underlying_token: Domain::_RecoveryLockToken
|
|
9
|
+
attr_reader origin: :primary | :failover
|
|
10
|
+
|
|
11
|
+
def initialize: (
|
|
12
|
+
underlying_token: Domain::_RecoveryLockToken,
|
|
13
|
+
origin: (:primary | :failover)
|
|
14
|
+
) -> void
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
module Stoplight
|
|
2
|
+
module Infrastructure
|
|
3
|
+
module FailSafe
|
|
4
|
+
module Storage
|
|
5
|
+
class State
|
|
6
|
+
include Domain::_StateStore
|
|
7
|
+
|
|
8
|
+
attr_reader primary_store: Domain::_StateStore
|
|
9
|
+
attr_reader error_notifier: error_notifier
|
|
10
|
+
attr_reader failover_store: Domain::_StateStore
|
|
11
|
+
attr_reader circuit_breaker: _Light
|
|
12
|
+
|
|
13
|
+
def initialize: (
|
|
14
|
+
primary_store: Domain::_StateStore,
|
|
15
|
+
error_notifier: error_notifier,
|
|
16
|
+
failover_store: Domain::_StateStore,
|
|
17
|
+
circuit_breaker: _Light,
|
|
18
|
+
) -> void
|
|
19
|
+
|
|
20
|
+
def fallback: [T] { () -> T } -> ^(StandardError?) -> T
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Stoplight
|
|
4
|
+
module Infrastructure
|
|
5
|
+
module Memory
|
|
6
|
+
class DataStore
|
|
7
|
+
class Metrics
|
|
8
|
+
attr_accessor consecutive_errors: Integer
|
|
9
|
+
attr_accessor consecutive_successes: Integer
|
|
10
|
+
attr_accessor last_error: Domain::Failure?
|
|
11
|
+
attr_accessor last_success_at: Time?
|
|
12
|
+
|
|
13
|
+
def initialize: (
|
|
14
|
+
?consecutive_errors: Integer,
|
|
15
|
+
?consecutive_successes: Integer,
|
|
16
|
+
?last_error: Domain::Failure?,
|
|
17
|
+
?last_success_at: Time?
|
|
18
|
+
) -> void
|
|
19
|
+
|
|
20
|
+
def last_error_at: -> Time?
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
module Stoplight
|
|
2
|
+
module Infrastructure
|
|
3
|
+
module Memory
|
|
4
|
+
class DataStore
|
|
5
|
+
class RecoveryLockStore
|
|
6
|
+
private attr_reader locks: Concurrent::Map[String, Mutex]
|
|
7
|
+
|
|
8
|
+
def initialize: -> void
|
|
9
|
+
|
|
10
|
+
def acquire_lock: (String light_name) -> RecoveryLockToken?
|
|
11
|
+
|
|
12
|
+
def release_lock: (RecoveryLockToken recovery_lock_token) -> void
|
|
13
|
+
|
|
14
|
+
private def lock_for: (String light_name) -> Mutex
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Stoplight
|
|
4
|
+
module Infrastructure
|
|
5
|
+
module Memory
|
|
6
|
+
class DataStore
|
|
7
|
+
class RecoveryLockToken
|
|
8
|
+
include Domain::_RecoveryLockToken
|
|
9
|
+
|
|
10
|
+
attr_reader light_name: String
|
|
11
|
+
|
|
12
|
+
def initialize: (light_name: String) -> void
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
module Stoplight
|
|
2
|
+
module Infrastructure
|
|
3
|
+
module Memory
|
|
4
|
+
class DataStore
|
|
5
|
+
class SlidingWindow
|
|
6
|
+
private attr_reader buckets: Hash[Integer, Integer]
|
|
7
|
+
private attr_accessor running_sum: Integer
|
|
8
|
+
private attr_reader clock: Domain::_Clock
|
|
9
|
+
|
|
10
|
+
def initialize: (clock: Domain::_Clock) -> void
|
|
11
|
+
|
|
12
|
+
def increment: -> void
|
|
13
|
+
|
|
14
|
+
def sum_in_window: (Time window_start) -> Integer
|
|
15
|
+
|
|
16
|
+
private def slide_window!: (Time window_start) -> void
|
|
17
|
+
|
|
18
|
+
private def current_bucket: -> Integer
|
|
19
|
+
|
|
20
|
+
private def bucket_for_time: (Time time) -> Integer
|
|
21
|
+
|
|
22
|
+
def inspect: -> String
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Stoplight
|
|
4
|
+
module Infrastructure
|
|
5
|
+
module Memory
|
|
6
|
+
class DataStore
|
|
7
|
+
class State
|
|
8
|
+
attr_accessor recovered_at: Time?
|
|
9
|
+
attr_accessor locked_state: state
|
|
10
|
+
attr_accessor recovery_scheduled_after: Time?
|
|
11
|
+
attr_accessor recovery_started_at: Time?
|
|
12
|
+
attr_accessor breached_at: Time?
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
module Stoplight
|
|
2
|
+
module Infrastructure
|
|
3
|
+
module Memory
|
|
4
|
+
class DataStore
|
|
5
|
+
include Domain::_DataStore
|
|
6
|
+
include MonitorMixin
|
|
7
|
+
|
|
8
|
+
KEY_SEPARATOR: String
|
|
9
|
+
|
|
10
|
+
@errors: Hash[String, SlidingWindow]
|
|
11
|
+
@successes: Hash[String, SlidingWindow]
|
|
12
|
+
@metrics: Hash[String, Metrics]
|
|
13
|
+
@recovery_metrics: Hash[String, Metrics]
|
|
14
|
+
@states: Hash[String, State]
|
|
15
|
+
|
|
16
|
+
private attr_reader recovery_lock_store: RecoveryLockStore
|
|
17
|
+
private attr_reader clock: Domain::_Clock
|
|
18
|
+
|
|
19
|
+
def initialize: (
|
|
20
|
+
recovery_lock_store: RecoveryLockStore,
|
|
21
|
+
clock: Domain::_Clock
|
|
22
|
+
) -> void
|
|
23
|
+
|
|
24
|
+
private def transition_to_green: (Domain::Config config) -> bool
|
|
25
|
+
private def transition_to_yellow: (Domain::Config config) -> bool
|
|
26
|
+
private def transition_to_red: (Domain::Config config) -> bool
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
module Stoplight
|
|
2
|
+
module Infrastructure
|
|
3
|
+
module Memory
|
|
4
|
+
module Storage
|
|
5
|
+
class State
|
|
6
|
+
include Domain::_StateStore
|
|
7
|
+
|
|
8
|
+
attr_accessor locked_state: state
|
|
9
|
+
attr_accessor recovered_at: Time?
|
|
10
|
+
attr_accessor recovery_scheduled_after: Time?
|
|
11
|
+
attr_accessor recovery_started_at: Time?
|
|
12
|
+
attr_accessor breached_at: Time?
|
|
13
|
+
attr_reader mutex: Mutex
|
|
14
|
+
attr_reader clock: Domain::_Clock
|
|
15
|
+
attr_reader cool_off_time: timestamp
|
|
16
|
+
|
|
17
|
+
def initialize: (clock: Domain::_Clock, cool_off_time: timestamp) -> void
|
|
18
|
+
|
|
19
|
+
def transition_to_green: -> bool
|
|
20
|
+
|
|
21
|
+
def transition_to_yellow: -> bool
|
|
22
|
+
|
|
23
|
+
def transition_to_red: -> bool
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
module Stoplight
|
|
2
|
+
module Infrastructure
|
|
3
|
+
module Memory
|
|
4
|
+
module Storage
|
|
5
|
+
class UnboundedMetrics
|
|
6
|
+
include Domain::_MetricsStore
|
|
7
|
+
|
|
8
|
+
attr_accessor consecutive_errors: Integer
|
|
9
|
+
attr_accessor consecutive_successes: Integer
|
|
10
|
+
attr_accessor last_error: Domain::Failure?
|
|
11
|
+
attr_accessor last_success_at: Time?
|
|
12
|
+
|
|
13
|
+
attr_reader mutex: Mutex
|
|
14
|
+
attr_reader clock: Domain::_Clock
|
|
15
|
+
|
|
16
|
+
def initialize: (clock: Domain::_Clock) -> void
|
|
17
|
+
|
|
18
|
+
def last_error_at: -> Time?
|
|
19
|
+
|
|
20
|
+
private def initialize_metrics: -> void
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
module Stoplight
|
|
2
|
+
module Infrastructure
|
|
3
|
+
module Memory
|
|
4
|
+
module Storage
|
|
5
|
+
class WindowMetrics
|
|
6
|
+
include Domain::_MetricsStore
|
|
7
|
+
|
|
8
|
+
attr_reader mutex: Mutex
|
|
9
|
+
attr_reader clock: Domain::_Clock
|
|
10
|
+
|
|
11
|
+
@window_size: duration
|
|
12
|
+
@consecutive_errors: Integer
|
|
13
|
+
@consecutive_successes: Integer
|
|
14
|
+
@last_error: Domain::Failure?
|
|
15
|
+
@last_success_at: Time?
|
|
16
|
+
@successes: Infrastructure::Memory::DataStore::SlidingWindow
|
|
17
|
+
@errors: Infrastructure::Memory::DataStore::SlidingWindow
|
|
18
|
+
|
|
19
|
+
def initialize: (window_size: duration, clock: Domain::_Clock) -> void
|
|
20
|
+
|
|
21
|
+
def initialize_metrics: -> void
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
module Stoplight
|
|
2
|
+
module Infrastructure
|
|
3
|
+
module Notifier
|
|
4
|
+
class FailSafe
|
|
5
|
+
include _StateTransitionNotifier
|
|
6
|
+
|
|
7
|
+
attr_reader notifier: state_transition_notifier
|
|
8
|
+
attr_reader error_notifier: error_notifier
|
|
9
|
+
@circuit_breaker: Domain::Light?
|
|
10
|
+
|
|
11
|
+
def initialize: (notifier: state_transition_notifier, error_notifier: error_notifier) -> void
|
|
12
|
+
|
|
13
|
+
private def circuit_breaker: -> Domain::Light
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
module Stoplight
|
|
2
|
+
module Infrastructure
|
|
3
|
+
module Notifier
|
|
4
|
+
module Generic[T]
|
|
5
|
+
DEFAULT_FORMATTER: notification_formatter
|
|
6
|
+
@object: T
|
|
7
|
+
|
|
8
|
+
attr_reader formatter: notification_formatter
|
|
9
|
+
|
|
10
|
+
def initialize: (T object, ?notification_formatter? formatter) -> void
|
|
11
|
+
|
|
12
|
+
def notify: (Domain::Config light, color, color, StandardError?) -> String
|
|
13
|
+
|
|
14
|
+
private def put: (String) -> void
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
module Stoplight
|
|
2
|
+
module Infrastructure
|
|
3
|
+
module Redis
|
|
4
|
+
class DataStore
|
|
5
|
+
class RecoveryLockStore
|
|
6
|
+
attr_reader redis: redis
|
|
7
|
+
|
|
8
|
+
attr_reader lock_timeout: Integer
|
|
9
|
+
attr_reader scripting: Scripting
|
|
10
|
+
|
|
11
|
+
def initialize: (
|
|
12
|
+
redis: redis,
|
|
13
|
+
lock_timeout: Integer,
|
|
14
|
+
scripting: Scripting
|
|
15
|
+
) -> void
|
|
16
|
+
|
|
17
|
+
def acquire_lock: (String light_name) -> RecoveryLockToken?
|
|
18
|
+
|
|
19
|
+
def release_lock: (RecoveryLockToken recovery_lock) -> void
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
module Stoplight
|
|
2
|
+
module Infrastructure
|
|
3
|
+
module Redis
|
|
4
|
+
class DataStore
|
|
5
|
+
class RecoveryLockToken
|
|
6
|
+
include Domain::_RecoveryLockToken
|
|
7
|
+
|
|
8
|
+
attr_reader light_name: String
|
|
9
|
+
|
|
10
|
+
attr_reader token: String
|
|
11
|
+
|
|
12
|
+
def initialize: (light_name: String) -> void
|
|
13
|
+
|
|
14
|
+
def lock_key: -> String
|
|
15
|
+
|
|
16
|
+
private def key: (*_ToS) -> String
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
module Stoplight
|
|
2
|
+
module Infrastructure
|
|
3
|
+
module Redis
|
|
4
|
+
class DataStore
|
|
5
|
+
class Scripting
|
|
6
|
+
SCRIPTS_ROOT: String
|
|
7
|
+
|
|
8
|
+
def self.default_scripts_root: -> String
|
|
9
|
+
|
|
10
|
+
attr_reader scripts_root: String
|
|
11
|
+
|
|
12
|
+
attr_reader shas: Hash[interned, String]
|
|
13
|
+
|
|
14
|
+
attr_reader redis: redis
|
|
15
|
+
|
|
16
|
+
def initialize: (
|
|
17
|
+
redis: redis,
|
|
18
|
+
?scripts_root: String,
|
|
19
|
+
) -> void
|
|
20
|
+
|
|
21
|
+
def call: (
|
|
22
|
+
interned script_name,
|
|
23
|
+
?keys: Array[_ToS],
|
|
24
|
+
?args: Array[_ToS]
|
|
25
|
+
) -> untyped
|
|
26
|
+
|
|
27
|
+
private def reload_script: (interned script_name) -> String
|
|
28
|
+
|
|
29
|
+
private def script_sha: (interned script_name) -> String
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
module Stoplight
|
|
2
|
+
module Infrastructure
|
|
3
|
+
module Redis
|
|
4
|
+
class DataStore
|
|
5
|
+
include Domain::_DataStore
|
|
6
|
+
|
|
7
|
+
BUCKET_SIZE: Integer
|
|
8
|
+
KEY_SEPARATOR: String
|
|
9
|
+
KEY_PREFIX: String
|
|
10
|
+
METRICS_TTL: Integer
|
|
11
|
+
METADATA_TTL: Integer
|
|
12
|
+
SKEW_TOLERANCE: Integer
|
|
13
|
+
METRICS_RETENTION_TIME: Integer
|
|
14
|
+
|
|
15
|
+
def self.key: (*_ToS) -> String
|
|
16
|
+
|
|
17
|
+
def self.buckets_for_window: (
|
|
18
|
+
String light_name,
|
|
19
|
+
metric: String,
|
|
20
|
+
window_end: Time | Numeric,
|
|
21
|
+
window_size: Integer
|
|
22
|
+
) -> Array[String]
|
|
23
|
+
|
|
24
|
+
def self.bucket_key: (
|
|
25
|
+
String light_name,
|
|
26
|
+
metric: String,
|
|
27
|
+
time: Time | Numeric,
|
|
28
|
+
) -> String
|
|
29
|
+
|
|
30
|
+
def self.bucket_size: -> Integer
|
|
31
|
+
|
|
32
|
+
private attr_reader recovery_lock_store: RecoveryLockStore
|
|
33
|
+
private attr_reader scripting: Scripting
|
|
34
|
+
private attr_reader redis: redis
|
|
35
|
+
private attr_reader warn_on_clock_skew: bool
|
|
36
|
+
private attr_reader clock: Domain::_Clock
|
|
37
|
+
|
|
38
|
+
def initialize: (
|
|
39
|
+
redis: redis,
|
|
40
|
+
recovery_lock_store: RecoveryLockStore,
|
|
41
|
+
scripting: Scripting,
|
|
42
|
+
warn_on_clock_skew: bool,
|
|
43
|
+
clock: Domain::_Clock
|
|
44
|
+
) -> void
|
|
45
|
+
|
|
46
|
+
private def transition_to_green: (Domain::Config config) -> bool
|
|
47
|
+
private def transition_to_yellow: (Domain::Config config) -> bool
|
|
48
|
+
private def transition_to_red: (Domain::Config config) -> bool
|
|
49
|
+
private def deserialize_failure: (String? failure_json) -> Domain::Failure?
|
|
50
|
+
private def serialize_failure: (Domain::Failure failure) -> String
|
|
51
|
+
private def key: (*String) -> String
|
|
52
|
+
private def failure_bucket_keys: (Domain::Config config, window_end: Time | Integer) -> Array[String]
|
|
53
|
+
private def success_bucket_keys: (Domain::Config config, window_end: Time | Integer) -> Array[String]
|
|
54
|
+
private def recovery_probe_failure_bucket_keys: (Domain::Config config, window_end: Time | Integer) -> Array[String]
|
|
55
|
+
private def recovery_probe_success_bucket_keys: (Domain::Config config, window_end: Time | Integer) -> Array[String]
|
|
56
|
+
private def successes_key: (Domain::Config config, time: Time) -> String
|
|
57
|
+
private def errors_key: (Domain::Config config, time: Time) -> String
|
|
58
|
+
private def recovery_metrics_key: (Domain::Config config) -> String
|
|
59
|
+
private def metadata_key: (Domain::Config config) -> String
|
|
60
|
+
private def metrics_ttl: -> Integer
|
|
61
|
+
private def metadata_ttl: -> Integer
|
|
62
|
+
private def detect_clock_skew: -> void
|
|
63
|
+
private def should_sample?: (Float) -> bool
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
module Stoplight
|
|
2
|
+
module Infrastructure
|
|
3
|
+
module Redis
|
|
4
|
+
module Storage
|
|
5
|
+
class KeySpace
|
|
6
|
+
def system_id: -> String
|
|
7
|
+
def light_id: -> String
|
|
8
|
+
|
|
9
|
+
def self.build: (system_name: _ToS, light_name: _ToS) -> KeySpace
|
|
10
|
+
|
|
11
|
+
def self.hash_name: (_ToS) -> String
|
|
12
|
+
|
|
13
|
+
def initialize: (system_id: String, light_id: String) -> void
|
|
14
|
+
def key: (*_ToS) -> String
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
module Stoplight
|
|
2
|
+
module Infrastructure
|
|
3
|
+
module Redis
|
|
4
|
+
module Storage
|
|
5
|
+
class Metrics
|
|
6
|
+
include Domain::_MetricsStore
|
|
7
|
+
|
|
8
|
+
def serialize_exception: (StandardError, timestamp: Float) -> String
|
|
9
|
+
|
|
10
|
+
def deserialize_failure: (String?) -> Domain::Failure?
|
|
11
|
+
|
|
12
|
+
private def metrics_ttl: -> Integer
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
module Stoplight
|
|
2
|
+
module Infrastructure
|
|
3
|
+
module Redis
|
|
4
|
+
module Storage
|
|
5
|
+
class RecoveryLock
|
|
6
|
+
include Domain::_RecoveryLockStore
|
|
7
|
+
|
|
8
|
+
attr_reader config: Domain::Config
|
|
9
|
+
attr_reader redis: redis
|
|
10
|
+
attr_reader scripting: Scripting
|
|
11
|
+
attr_reader key_space: KeySpace
|
|
12
|
+
|
|
13
|
+
def initialize: (
|
|
14
|
+
config: Domain::Config,
|
|
15
|
+
redis: redis,
|
|
16
|
+
scripting: Scripting,
|
|
17
|
+
key_space: KeySpace
|
|
18
|
+
) -> void
|
|
19
|
+
|
|
20
|
+
def lock_key: -> String
|
|
21
|
+
def lock_timeout: -> Integer
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
module Stoplight
|
|
2
|
+
module Infrastructure
|
|
3
|
+
module Redis
|
|
4
|
+
module Storage
|
|
5
|
+
class State
|
|
6
|
+
include Domain::_StateStore
|
|
7
|
+
|
|
8
|
+
attr_reader redis: redis
|
|
9
|
+
attr_reader scripting: Scripting
|
|
10
|
+
attr_reader key_space: KeySpace
|
|
11
|
+
attr_reader clock: Domain::_Clock
|
|
12
|
+
attr_reader cool_off_time: timestamp
|
|
13
|
+
attr_reader state_key: String
|
|
14
|
+
|
|
15
|
+
def initialize: (
|
|
16
|
+
clock: Domain::_Clock,
|
|
17
|
+
redis: redis,
|
|
18
|
+
scripting: Scripting,
|
|
19
|
+
key_space: KeySpace,
|
|
20
|
+
cool_off_time: timestamp
|
|
21
|
+
) -> void
|
|
22
|
+
|
|
23
|
+
def transition_to_green: -> bool
|
|
24
|
+
|
|
25
|
+
def transition_to_yellow: -> bool
|
|
26
|
+
|
|
27
|
+
def transition_to_red: -> bool
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|