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.
Files changed (235) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/UPGRADING.md +303 -0
  4. data/lib/generators/stoplight/install/install_generator.rb +6 -1
  5. data/lib/stoplight/admin/dependencies.rb +1 -1
  6. data/lib/stoplight/admin/helpers.rb +20 -4
  7. data/lib/stoplight/admin/lights_repository/light.rb +22 -6
  8. data/lib/stoplight/admin/lights_repository.rb +6 -5
  9. data/lib/stoplight/admin/views/_card.erb +8 -5
  10. data/lib/stoplight/color.rb +9 -0
  11. data/lib/stoplight/data_store.rb +28 -0
  12. data/lib/stoplight/domain/compatibility_result.rb +7 -7
  13. data/lib/stoplight/domain/config.rb +38 -39
  14. data/lib/stoplight/domain/error_tracking_policy.rb +27 -0
  15. data/lib/stoplight/domain/failure.rb +1 -1
  16. data/lib/stoplight/domain/light/configuration_builder_interface.rb +2 -0
  17. data/lib/stoplight/domain/light.rb +15 -46
  18. data/lib/stoplight/domain/light_info.rb +7 -0
  19. data/lib/stoplight/domain/metrics_snapshot.rb +58 -0
  20. data/lib/stoplight/domain/state_snapshot.rb +29 -23
  21. data/lib/stoplight/domain/storage/recovery_lock_token.rb +15 -0
  22. data/lib/stoplight/domain/strategies/green_run_strategy.rb +18 -26
  23. data/lib/stoplight/domain/strategies/red_run_strategy.rb +9 -12
  24. data/lib/stoplight/domain/strategies/yellow_run_strategy.rb +41 -51
  25. data/lib/stoplight/domain/tracker/recovery_probe.rb +16 -33
  26. data/lib/stoplight/domain/tracker/request.rb +12 -31
  27. data/lib/stoplight/domain/traffic_control/consecutive_errors.rb +8 -11
  28. data/lib/stoplight/domain/traffic_control/error_rate.rb +19 -15
  29. data/lib/stoplight/domain/traffic_recovery/consecutive_successes.rb +6 -10
  30. data/lib/stoplight/domain/traffic_recovery.rb +3 -4
  31. data/lib/stoplight/error.rb +46 -0
  32. data/lib/stoplight/infrastructure/{data_store/fail_safe.rb → fail_safe/data_store.rb} +39 -51
  33. data/lib/stoplight/infrastructure/fail_safe/storage/metrics.rb +65 -0
  34. data/lib/stoplight/infrastructure/fail_safe/storage/recovery_lock.rb +69 -0
  35. data/lib/stoplight/infrastructure/fail_safe/storage/recovery_lock_token.rb +19 -0
  36. data/lib/stoplight/infrastructure/fail_safe/storage/state.rb +62 -0
  37. data/lib/stoplight/infrastructure/{data_store/memory → memory/data_store}/metrics.rb +2 -2
  38. data/lib/stoplight/infrastructure/{data_store/memory → memory/data_store}/recovery_lock_store.rb +10 -12
  39. data/lib/stoplight/infrastructure/{data_store/memory → memory/data_store}/recovery_lock_token.rb +3 -6
  40. data/lib/stoplight/infrastructure/{data_store/memory → memory/data_store}/sliding_window.rb +21 -26
  41. data/lib/stoplight/infrastructure/{data_store/memory → memory/data_store}/state.rb +3 -3
  42. data/lib/stoplight/infrastructure/{data_store/memory.rb → memory/data_store.rb} +36 -32
  43. data/lib/stoplight/infrastructure/memory/storage/recovery_lock.rb +35 -0
  44. data/lib/stoplight/infrastructure/memory/storage/recovery_metrics.rb +16 -0
  45. data/lib/stoplight/infrastructure/memory/storage/state.rb +155 -0
  46. data/lib/stoplight/infrastructure/memory/storage/unbounded_metrics.rb +103 -0
  47. data/lib/stoplight/infrastructure/memory/storage/window_metrics.rb +101 -0
  48. data/lib/stoplight/infrastructure/notifier/fail_safe.rb +9 -21
  49. data/lib/stoplight/infrastructure/notifier/generic.rb +4 -14
  50. data/lib/stoplight/infrastructure/notifier/io.rb +1 -2
  51. data/lib/stoplight/infrastructure/notifier/logger.rb +1 -2
  52. data/lib/stoplight/infrastructure/{data_store/redis → redis/data_store}/recovery_lock_store.rb +9 -22
  53. data/lib/stoplight/infrastructure/{data_store/redis → redis/data_store}/recovery_lock_token.rb +7 -14
  54. data/lib/stoplight/infrastructure/{data_store/redis → redis/data_store}/scripting.rb +22 -20
  55. data/lib/stoplight/infrastructure/{data_store/redis.rb → redis/data_store.rb} +47 -55
  56. data/lib/stoplight/infrastructure/redis/storage/key_space.rb +51 -0
  57. data/lib/stoplight/infrastructure/redis/storage/metrics.rb +40 -0
  58. data/lib/stoplight/infrastructure/redis/storage/recovery_lock/release_lock.lua +6 -0
  59. data/lib/stoplight/infrastructure/redis/storage/recovery_lock.rb +64 -0
  60. data/lib/stoplight/infrastructure/redis/storage/recovery_metrics.rb +20 -0
  61. data/lib/stoplight/infrastructure/redis/storage/scripting.rb +18 -0
  62. data/lib/stoplight/infrastructure/redis/storage/state/transition_to_green.lua +10 -0
  63. data/lib/stoplight/infrastructure/redis/storage/state/transition_to_red.lua +10 -0
  64. data/lib/stoplight/infrastructure/redis/storage/state/transition_to_yellow.lua +9 -0
  65. data/lib/stoplight/infrastructure/redis/storage/state.rb +141 -0
  66. data/lib/stoplight/infrastructure/redis/storage/unbounded_metrics/record_failure.lua +28 -0
  67. data/lib/stoplight/infrastructure/redis/storage/unbounded_metrics/record_success.lua +26 -0
  68. data/lib/stoplight/infrastructure/redis/storage/unbounded_metrics.rb +123 -0
  69. data/lib/stoplight/infrastructure/redis/storage/window_metrics/metrics_snapshot.lua +26 -0
  70. data/lib/stoplight/infrastructure/redis/storage/window_metrics/record_failure.lua +36 -0
  71. data/lib/stoplight/infrastructure/redis/storage/window_metrics/record_success.lua +35 -0
  72. data/lib/stoplight/infrastructure/redis/storage/window_metrics.rb +174 -0
  73. data/lib/stoplight/infrastructure/storage/compatibility_metrics.rb +3 -10
  74. data/lib/stoplight/infrastructure/storage/compatibility_recovery_lock.rb +8 -11
  75. data/lib/stoplight/infrastructure/storage/compatibility_recovery_metrics.rb +6 -14
  76. data/lib/stoplight/infrastructure/storage/compatibility_state.rb +6 -17
  77. data/lib/stoplight/infrastructure/system_clock.rb +16 -0
  78. data/lib/stoplight/notifier.rb +11 -0
  79. data/lib/stoplight/state.rb +9 -0
  80. data/lib/stoplight/types.rb +29 -0
  81. data/lib/stoplight/undefined.rb +16 -0
  82. data/lib/stoplight/version.rb +1 -1
  83. data/lib/stoplight/wiring/config_compatibility_validator.rb +54 -0
  84. data/lib/stoplight/wiring/configuration_dsl.rb +101 -0
  85. data/lib/stoplight/wiring/data_store_backend.rb +26 -0
  86. data/lib/stoplight/wiring/default.rb +1 -1
  87. data/lib/stoplight/wiring/default_config.rb +21 -0
  88. data/lib/stoplight/wiring/default_configuration.rb +70 -53
  89. data/lib/stoplight/wiring/light_builder.rb +76 -63
  90. data/lib/stoplight/wiring/light_factory/traffic_control_dsl.rb +3 -3
  91. data/lib/stoplight/wiring/light_factory/traffic_recovery_dsl.rb +4 -4
  92. data/lib/stoplight/wiring/light_factory.rb +78 -52
  93. data/lib/stoplight/wiring/memory/backend.rb +57 -0
  94. data/lib/stoplight/wiring/redis/backend.rb +116 -0
  95. data/lib/stoplight/wiring/storage_set.rb +12 -0
  96. data/lib/stoplight/wiring/storage_set_builder.rb +51 -0
  97. data/lib/stoplight/wiring/system/light_builder.rb +47 -0
  98. data/lib/stoplight/wiring/system/light_factory.rb +64 -0
  99. data/lib/stoplight/wiring/system.rb +129 -0
  100. data/lib/stoplight.rb +196 -25
  101. data/sig/_private/generators/stoplight/install/install_generator.rbs +22 -0
  102. data/sig/_private/stoplight/common/deprecations.rbs +9 -0
  103. data/sig/_private/stoplight/data_store.rbs +6 -0
  104. data/sig/_private/stoplight/domain/compatibility_result.rbs +18 -0
  105. data/sig/_private/stoplight/domain/config.rbs +65 -0
  106. data/sig/_private/stoplight/domain/error_tracking_policy.rbs +14 -0
  107. data/sig/_private/stoplight/domain/failure.rbs +16 -0
  108. data/sig/_private/stoplight/domain/light.rbs +25 -0
  109. data/sig/_private/stoplight/domain/light_info.rbs +19 -0
  110. data/sig/_private/stoplight/domain/metrics_snapshot.rbs +38 -0
  111. data/sig/_private/stoplight/domain/ports/clock.rbs +18 -0
  112. data/sig/_private/stoplight/domain/ports/data_store.rbs +76 -0
  113. data/{lib/stoplight/domain/light_factory.rb → sig/_private/stoplight/domain/ports/light_factory.rbs} +33 -28
  114. data/sig/_private/stoplight/domain/ports/metrics_store.rbs +29 -0
  115. data/sig/_private/stoplight/domain/ports/recovery_lock_store.rbs +52 -0
  116. data/sig/_private/stoplight/domain/ports/recovery_lock_token.rbs +6 -0
  117. data/sig/_private/stoplight/domain/ports/run_strategy.rbs +14 -0
  118. data/sig/_private/stoplight/domain/ports/state_store.rbs +79 -0
  119. data/sig/_private/stoplight/domain/ports/traffic_control.rbs +41 -0
  120. data/sig/_private/stoplight/domain/ports/traffic_recovery.rbs +47 -0
  121. data/sig/_private/stoplight/domain/state_snapshot.rbs +32 -0
  122. data/sig/_private/stoplight/domain/storage/recovery_lock_token.rbs +11 -0
  123. data/sig/_private/stoplight/domain/strategies/green_run_strategy.rbs +17 -0
  124. data/sig/_private/stoplight/domain/strategies/red_run_strategy.rbs +17 -0
  125. data/sig/_private/stoplight/domain/strategies/yellow_run_strategy.rbs +42 -0
  126. data/{lib/stoplight/domain/tracker/base.rb → sig/_private/stoplight/domain/tracker/base.rbs} +0 -4
  127. data/sig/_private/stoplight/domain/tracker/recovery_probe.rbs +25 -0
  128. data/sig/_private/stoplight/domain/tracker/request.rbs +26 -0
  129. data/sig/_private/stoplight/domain/traffic_control/consecutive_errors.rbs +9 -0
  130. data/sig/_private/stoplight/domain/traffic_control/error_rate.rbs +13 -0
  131. data/sig/_private/stoplight/domain/traffic_recovery/consecutive_successes.rbs +9 -0
  132. data/sig/_private/stoplight/domain/traffic_recovery.rbs +9 -0
  133. data/sig/_private/stoplight/infrastructure/fail_safe/data_store.rbs +26 -0
  134. data/sig/_private/stoplight/infrastructure/fail_safe/storage/metrics.rbs +25 -0
  135. data/sig/_private/stoplight/infrastructure/fail_safe/storage/recovery_lock.rbs +29 -0
  136. data/sig/_private/stoplight/infrastructure/fail_safe/storage/recovery_lock_token.rbs +19 -0
  137. data/sig/_private/stoplight/infrastructure/fail_safe/storage/state.rbs +25 -0
  138. data/sig/_private/stoplight/infrastructure/memory/data_store/metrics.rbs +25 -0
  139. data/sig/_private/stoplight/infrastructure/memory/data_store/recovery_lock_store.rbs +19 -0
  140. data/sig/_private/stoplight/infrastructure/memory/data_store/recovery_lock_token.rbs +17 -0
  141. data/sig/_private/stoplight/infrastructure/memory/data_store/sliding_window.rbs +27 -0
  142. data/sig/_private/stoplight/infrastructure/memory/data_store/state.rbs +17 -0
  143. data/sig/_private/stoplight/infrastructure/memory/data_store.rbs +30 -0
  144. data/sig/_private/stoplight/infrastructure/memory/storage/recovery_lock.rbs +15 -0
  145. data/sig/_private/stoplight/infrastructure/memory/storage/recovery_metrics.rbs +10 -0
  146. data/sig/_private/stoplight/infrastructure/memory/storage/state.rbs +28 -0
  147. data/sig/_private/stoplight/infrastructure/memory/storage/unbounded_metrics.rbs +25 -0
  148. data/sig/_private/stoplight/infrastructure/memory/storage/window_metrics.rbs +26 -0
  149. data/sig/_private/stoplight/infrastructure/notifier/fail_safe.rbs +17 -0
  150. data/sig/_private/stoplight/infrastructure/notifier/generic.rbs +18 -0
  151. data/sig/_private/stoplight/infrastructure/notifier/io.rbs +14 -0
  152. data/sig/_private/stoplight/infrastructure/notifier/logger.rbs +14 -0
  153. data/sig/_private/stoplight/infrastructure/redis/data_store/recovery_lock_store.rbs +24 -0
  154. data/sig/_private/stoplight/infrastructure/redis/data_store/recovery_lock_token.rbs +21 -0
  155. data/sig/_private/stoplight/infrastructure/redis/data_store/scripting.rbs +34 -0
  156. data/sig/_private/stoplight/infrastructure/redis/data_store.rbs +67 -0
  157. data/sig/_private/stoplight/infrastructure/redis/storage/key_space.rbs +19 -0
  158. data/sig/_private/stoplight/infrastructure/redis/storage/metrics.rbs +17 -0
  159. data/sig/_private/stoplight/infrastructure/redis/storage/recovery_lock.rbs +26 -0
  160. data/sig/_private/stoplight/infrastructure/redis/storage/recovery_metrics.rbs +10 -0
  161. data/sig/_private/stoplight/infrastructure/redis/storage/scripting.rbs +13 -0
  162. data/sig/_private/stoplight/infrastructure/redis/storage/state.rbs +32 -0
  163. data/sig/_private/stoplight/infrastructure/redis/storage/unbounded_metrics.rbs +21 -0
  164. data/sig/_private/stoplight/infrastructure/redis/storage/window_metrics.rbs +34 -0
  165. data/sig/_private/stoplight/infrastructure/storage/compatibility_metrics.rbs +17 -0
  166. data/sig/_private/stoplight/infrastructure/storage/compatibility_recovery_lock.rbs +13 -0
  167. data/sig/_private/stoplight/infrastructure/storage/compatibility_recovery_metrics.rbs +14 -0
  168. data/sig/_private/stoplight/infrastructure/storage/compatibility_state.rbs +14 -0
  169. data/sig/_private/stoplight/infrastructure/system_clock.rbs +7 -0
  170. data/sig/_private/stoplight/system/light_builder.rbs +23 -0
  171. data/sig/_private/stoplight/system/light_factory.rbs +17 -0
  172. data/sig/_private/stoplight/types.rbs +6 -0
  173. data/sig/_private/stoplight/wiring/config_compatibility_validator.rbs +19 -0
  174. data/sig/_private/stoplight/wiring/configuration_dsl.rbs +43 -0
  175. data/sig/_private/stoplight/wiring/data_store_backend.rbs +11 -0
  176. data/sig/_private/stoplight/wiring/default.rbs +26 -0
  177. data/{lib/stoplight/wiring/data_store/memory.rb → sig/_private/stoplight/wiring/default_config.rbs} +1 -4
  178. data/sig/_private/stoplight/wiring/default_configuration.rbs +29 -0
  179. data/sig/_private/stoplight/wiring/light_builder.rbs +48 -0
  180. data/sig/_private/stoplight/wiring/light_factory/traffic_control_dsl.rbs +7 -0
  181. data/sig/_private/stoplight/wiring/light_factory/traffic_recovery_dsl.rbs +7 -0
  182. data/sig/_private/stoplight/wiring/light_factory.rbs +16 -0
  183. data/sig/_private/stoplight/wiring/memory/backend.rbs +26 -0
  184. data/sig/_private/stoplight/wiring/notifier_factory.rbs +10 -0
  185. data/sig/_private/stoplight/wiring/redis/backend.rbs +38 -0
  186. data/sig/_private/stoplight/wiring/storage_set.rbs +38 -0
  187. data/sig/_private/stoplight/wiring/storage_set_builder.rbs +15 -0
  188. data/sig/_private/stoplight/wiring/system.rbs +15 -0
  189. data/sig/_private/stoplight.rbs +48 -0
  190. data/sig/stoplight/color.rbs +7 -0
  191. data/sig/stoplight/data_store.rbs +19 -0
  192. data/sig/stoplight/error.rbs +20 -0
  193. data/sig/stoplight/notifier.rbs +11 -0
  194. data/sig/stoplight/ports/configuration.rbs +19 -0
  195. data/sig/stoplight/ports/exception_matcher.rbs +8 -0
  196. data/sig/stoplight/ports/light.rbs +12 -0
  197. data/sig/stoplight/ports/light_info.rbs +5 -0
  198. data/sig/stoplight/ports/state_transition_notifier.rbs +15 -0
  199. data/sig/stoplight/ports/system.rbs +21 -0
  200. data/sig/stoplight/state.rbs +7 -0
  201. data/sig/stoplight/undefined.rbs +9 -0
  202. data/sig/stoplight/version.rbs +3 -0
  203. data/sig/stoplight.rbs +66 -0
  204. metadata +175 -47
  205. data/lib/stoplight/domain/color.rb +0 -11
  206. data/lib/stoplight/domain/data_store.rb +0 -146
  207. data/lib/stoplight/domain/error.rb +0 -42
  208. data/lib/stoplight/domain/metrics.rb +0 -64
  209. data/lib/stoplight/domain/recovery_lock_token.rb +0 -15
  210. data/lib/stoplight/domain/state.rb +0 -11
  211. data/lib/stoplight/domain/state_transition_notifier.rb +0 -25
  212. data/lib/stoplight/domain/storage/metrics.rb +0 -42
  213. data/lib/stoplight/domain/storage/recovery_lock.rb +0 -56
  214. data/lib/stoplight/domain/storage/state.rb +0 -87
  215. data/lib/stoplight/domain/strategies/run_strategy.rb +0 -22
  216. data/lib/stoplight/domain/traffic_control/base.rb +0 -74
  217. data/lib/stoplight/domain/traffic_recovery/base.rb +0 -79
  218. data/lib/stoplight/wiring/data_store/base.rb +0 -11
  219. data/lib/stoplight/wiring/data_store/redis.rb +0 -25
  220. data/lib/stoplight/wiring/default_factory_builder.rb +0 -25
  221. data/lib/stoplight/wiring/light/default_config.rb +0 -18
  222. data/lib/stoplight/wiring/light/system_config.rb +0 -11
  223. data/lib/stoplight/wiring/light_factory/compatibility_validator.rb +0 -55
  224. data/lib/stoplight/wiring/light_factory/config_normalizer.rb +0 -71
  225. data/lib/stoplight/wiring/light_factory/configuration_pipeline.rb +0 -72
  226. data/lib/stoplight/wiring/public_api.rb +0 -29
  227. /data/lib/stoplight/infrastructure/{data_store/redis → redis/data_store}/lua_scripts/get_metrics.lua +0 -0
  228. /data/lib/stoplight/infrastructure/{data_store/redis → redis/data_store}/lua_scripts/record_failure.lua +0 -0
  229. /data/lib/stoplight/infrastructure/{data_store/redis → redis/data_store}/lua_scripts/record_recovery_probe_failure.lua +0 -0
  230. /data/lib/stoplight/infrastructure/{data_store/redis → redis/data_store}/lua_scripts/record_recovery_probe_success.lua +0 -0
  231. /data/lib/stoplight/infrastructure/{data_store/redis → redis/data_store}/lua_scripts/record_success.lua +0 -0
  232. /data/lib/stoplight/infrastructure/{data_store/redis → redis/data_store}/lua_scripts/release_lock.lua +0 -0
  233. /data/lib/stoplight/infrastructure/{data_store/redis → redis/data_store}/lua_scripts/transition_to_green.lua +0 -0
  234. /data/lib/stoplight/infrastructure/{data_store/redis → redis/data_store}/lua_scripts/transition_to_red.lua +0 -0
  235. /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,15 @@
1
+ module Stoplight
2
+ module Infrastructure
3
+ module Memory
4
+ module Storage
5
+ class RecoveryLock
6
+ include Domain::_RecoveryLockStore
7
+
8
+ private attr_reader lock: Mutex
9
+
10
+ def initialize: -> void
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,10 @@
1
+ module Stoplight
2
+ module Infrastructure
3
+ module Memory
4
+ module Storage
5
+ class RecoveryMetrics < UnboundedMetrics
6
+ end
7
+ end
8
+ end
9
+ end
10
+ 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,14 @@
1
+ module Stoplight
2
+ module Infrastructure
3
+ module Notifier
4
+ class IO
5
+ include _StateTransitionNotifier
6
+ include Generic[::IO]
7
+
8
+ def io: -> ::IO
9
+
10
+ def put: (String message) -> void
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,14 @@
1
+ module Stoplight
2
+ module Infrastructure
3
+ module Notifier
4
+ class Logger
5
+ include _StateTransitionNotifier
6
+ include Generic[::Logger]
7
+
8
+ def logger: -> ::Logger
9
+
10
+ def put: (String message) -> void
11
+ end
12
+ end
13
+ end
14
+ 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,10 @@
1
+ module Stoplight
2
+ module Infrastructure
3
+ module Redis
4
+ module Storage
5
+ class RecoveryMetrics < UnboundedMetrics
6
+ end
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,13 @@
1
+ module Stoplight
2
+ module Infrastructure
3
+ module Redis
4
+ module Storage
5
+ class Scripting < Infrastructure::Redis::DataStore::Scripting
6
+ SCRIPTS_ROOT: String
7
+
8
+ def default_scripts_root: -> String
9
+ end
10
+ end
11
+ end
12
+ end
13
+ 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