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,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Stoplight
4
+ interface _Configuration
5
+ def notifiers: -> Array[state_transition_notifier]
6
+
7
+ def cool_off_time=: (duration) -> void
8
+ def threshold=: (percentage | Integer) -> void
9
+ def recovery_threshold=: (Integer) -> void
10
+ def window_size=: (duration?) -> void
11
+ def tracked_errors=: (Array[_ExceptionMatcher] | _ExceptionMatcher) -> void
12
+ def skipped_errors=: (Array[_ExceptionMatcher] | _ExceptionMatcher) -> void
13
+ def traffic_control=: (traffic_control) -> void
14
+ def traffic_recovery=: (traffic_recovery) -> void
15
+ def error_notifier=: (error_notifier) -> void
16
+ def data_store=: (data_store) -> void
17
+ def notifiers=:(Array[state_transition_notifier]) -> void
18
+ end
19
+ end
@@ -0,0 +1,8 @@
1
+ module Stoplight
2
+ interface _ExceptionMatcher
3
+ def ===: (untyped) -> bool
4
+
5
+ # Object methods
6
+ def is_a?: (untyped) -> bool
7
+ end
8
+ end
@@ -0,0 +1,12 @@
1
+ module Stoplight
2
+ interface _Light
3
+ def name: -> String
4
+
5
+ def state: -> state
6
+ def color: -> color
7
+ def run: [T] (?(^(StandardError?) -> T)?) { () -> T } -> T
8
+ def lock: (color) -> _Light
9
+ def unlock: -> _Light
10
+ def ==: (untyped) -> bool
11
+ end
12
+ end
@@ -0,0 +1,5 @@
1
+ module Stoplight
2
+ interface _LightInfo
3
+ def name: -> String
4
+ end
5
+ end
@@ -0,0 +1,15 @@
1
+ module Stoplight
2
+ interface _StateTransitionNotifier
3
+ # Sends a notification when a Stoplight changes state.
4
+ #
5
+ # @param config The Stoplight instance triggering the notification.
6
+ # @param from_color The previous state color of the Stoplight.
7
+ # @param to_color The new state color of the Stoplight.
8
+ # @param error The error (if any) that caused the state change.
9
+ def notify: (_LightInfo, color from_color, color to_color, ?StandardError? error) -> void
10
+
11
+ # Object methods needed for comparison/inspection
12
+ def ==: (untyped) -> bool
13
+ def class: -> Class
14
+ end
15
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Stoplight
4
+ # A System is a composition root that groups related circuit breakers
5
+ # with shared configuration.
6
+ interface _System
7
+ def name: -> String
8
+
9
+ def light: (
10
+ String name,
11
+ ?cool_off_time: optional[duration],
12
+ ?threshold: optional[percentage | Integer],
13
+ ?recovery_threshold: optional[Integer],
14
+ ?window_size: optional[duration?],
15
+ ?skipped_errors: optional[Array[_ExceptionMatcher]],
16
+ ?tracked_errors: optional[Array[_ExceptionMatcher]],
17
+ ?traffic_control: optional[traffic_control],
18
+ ?traffic_recovery: optional[traffic_recovery]
19
+ ) -> _Light
20
+ end
21
+ end
@@ -0,0 +1,7 @@
1
+ module Stoplight
2
+ module State
3
+ UNLOCKED: unlocked
4
+ LOCKED_GREEN: locked_green
5
+ LOCKED_RED: locked_red
6
+ end
7
+ end
@@ -0,0 +1,9 @@
1
+ module Stoplight
2
+ class Undefined
3
+ include Singleton
4
+
5
+ def self.instance: -> instance
6
+ def inspect: -> String
7
+ def to_s: -> String
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ module Stoplight
2
+ VERSION: Gem::Version
3
+ end
data/sig/stoplight.rbs ADDED
@@ -0,0 +1,66 @@
1
+ module Stoplight
2
+ type optional[T] = Undefined | T
3
+
4
+ type timestamp = Float | Integer
5
+ type redis = ::Redis | ConnectionPool[::Redis]
6
+
7
+ # Light Colors
8
+ type green = "green"
9
+ type yellow = "yellow"
10
+ type red = "red"
11
+ type color = green | yellow | red
12
+
13
+ # Light States
14
+ type unlocked = "unlocked"
15
+ type locked_green = "locked_green"
16
+ type locked_red = "locked_red"
17
+ type state = unlocked | locked_green | locked_red
18
+
19
+ # Duration in seconds (1, 23, 0.4, etc.)
20
+ type duration = Float | Integer
21
+ # Percentage as decimal (0.0 to 1.0)
22
+ type percentage = Float
23
+
24
+ type error_notifier = ^(StandardError) -> void
25
+ type traffic_control = :consecutive_errors | :error_rate | {error_rate: {min_requests: Integer}}
26
+ type traffic_recovery = :consecutive_successes
27
+ type data_store = DataStore::Redis | DataStore::Memory
28
+ type state_transition_notifier = _StateTransitionNotifier
29
+ type notification_formatter = ^(Domain::Config light, color, color, StandardError?) -> String
30
+
31
+ def self.configure: (?trust_me_im_an_engineer: bool) ?{ (_Configuration) -> void } -> void
32
+
33
+ def self.light: (
34
+ String name,
35
+ ?cool_off_time: optional[duration],
36
+ ?threshold: optional[percentage | Integer],
37
+ ?recovery_threshold: optional[Integer],
38
+ ?window_size: optional[duration?],
39
+ ?tracked_errors: optional[Array[_ExceptionMatcher] | _ExceptionMatcher],
40
+ ?skipped_errors: optional[Array[_ExceptionMatcher] | _ExceptionMatcher],
41
+ ?data_store: optional[data_store],
42
+ ?error_notifier: optional[error_notifier],
43
+ ?notifiers: optional[Array[state_transition_notifier]],
44
+ ?traffic_control: optional[traffic_control],
45
+ ?traffic_recovery: optional[traffic_recovery],
46
+ ) -> _Light
47
+ end
48
+
49
+ module Kernel
50
+ # For a method usable both as Kernel.Stoplight() and just Stoplight()
51
+ def self?.Stoplight: (
52
+ String name,
53
+ ?cool_off_time: Stoplight::optional[Stoplight::duration],
54
+ ?threshold: Stoplight::optional[Stoplight::percentage | Integer],
55
+ ?recovery_threshold: Stoplight::optional[Integer],
56
+ ?window_size: Stoplight::optional[Stoplight::duration?],
57
+ ?tracked_errors: Stoplight::optional[Array[Stoplight::_ExceptionMatcher] | Stoplight::_ExceptionMatcher],
58
+ ?skipped_errors: Stoplight::optional[Array[Stoplight::_ExceptionMatcher] | Stoplight::_ExceptionMatcher],
59
+ ?data_store: Stoplight::optional[Stoplight::data_store],
60
+ ?error_notifier: Stoplight::optional[Stoplight::error_notifier],
61
+ ?notifiers: Stoplight::optional[Array[Stoplight::state_transition_notifier]],
62
+ ?traffic_control: Stoplight::optional[Stoplight::traffic_control],
63
+ ?traffic_recovery: Stoplight::optional[Stoplight::traffic_recovery],
64
+ ) -> Stoplight::_Light
65
+ end
66
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stoplight
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.7.0
4
+ version: 5.8.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cameron Desautels
@@ -51,6 +51,7 @@ files:
51
51
  - CHANGELOG.md
52
52
  - LICENSE.md
53
53
  - README.md
54
+ - UPGRADING.md
54
55
  - lib/generators/stoplight/install/USAGE
55
56
  - lib/generators/stoplight/install/install_generator.rb
56
57
  - lib/generators/stoplight/install/templates/stoplight.rb.erb
@@ -72,85 +73,212 @@ files:
72
73
  - lib/stoplight/admin/views/_card.erb
73
74
  - lib/stoplight/admin/views/index.erb
74
75
  - lib/stoplight/admin/views/layout.erb
76
+ - lib/stoplight/color.rb
75
77
  - lib/stoplight/common/deprecations.rb
76
- - lib/stoplight/domain/color.rb
78
+ - lib/stoplight/data_store.rb
77
79
  - lib/stoplight/domain/compatibility_result.rb
78
80
  - lib/stoplight/domain/config.rb
79
- - lib/stoplight/domain/data_store.rb
80
- - lib/stoplight/domain/error.rb
81
+ - lib/stoplight/domain/error_tracking_policy.rb
81
82
  - lib/stoplight/domain/failure.rb
82
83
  - lib/stoplight/domain/light.rb
83
84
  - lib/stoplight/domain/light/configuration_builder_interface.rb
84
- - lib/stoplight/domain/light_factory.rb
85
- - lib/stoplight/domain/metrics.rb
86
- - lib/stoplight/domain/recovery_lock_token.rb
87
- - lib/stoplight/domain/state.rb
85
+ - lib/stoplight/domain/light_info.rb
86
+ - lib/stoplight/domain/metrics_snapshot.rb
88
87
  - lib/stoplight/domain/state_snapshot.rb
89
- - lib/stoplight/domain/state_transition_notifier.rb
90
- - lib/stoplight/domain/storage/metrics.rb
91
- - lib/stoplight/domain/storage/recovery_lock.rb
92
- - lib/stoplight/domain/storage/state.rb
88
+ - lib/stoplight/domain/storage/recovery_lock_token.rb
93
89
  - lib/stoplight/domain/strategies/green_run_strategy.rb
94
90
  - lib/stoplight/domain/strategies/red_run_strategy.rb
95
- - lib/stoplight/domain/strategies/run_strategy.rb
96
91
  - lib/stoplight/domain/strategies/yellow_run_strategy.rb
97
- - lib/stoplight/domain/tracker/base.rb
98
92
  - lib/stoplight/domain/tracker/recovery_probe.rb
99
93
  - lib/stoplight/domain/tracker/request.rb
100
- - lib/stoplight/domain/traffic_control/base.rb
101
94
  - lib/stoplight/domain/traffic_control/consecutive_errors.rb
102
95
  - lib/stoplight/domain/traffic_control/error_rate.rb
103
96
  - lib/stoplight/domain/traffic_recovery.rb
104
- - lib/stoplight/domain/traffic_recovery/base.rb
105
97
  - lib/stoplight/domain/traffic_recovery/consecutive_successes.rb
106
- - lib/stoplight/infrastructure/data_store/fail_safe.rb
107
- - lib/stoplight/infrastructure/data_store/memory.rb
108
- - lib/stoplight/infrastructure/data_store/memory/metrics.rb
109
- - lib/stoplight/infrastructure/data_store/memory/recovery_lock_store.rb
110
- - lib/stoplight/infrastructure/data_store/memory/recovery_lock_token.rb
111
- - lib/stoplight/infrastructure/data_store/memory/sliding_window.rb
112
- - lib/stoplight/infrastructure/data_store/memory/state.rb
113
- - lib/stoplight/infrastructure/data_store/redis.rb
114
- - lib/stoplight/infrastructure/data_store/redis/lua_scripts/get_metrics.lua
115
- - lib/stoplight/infrastructure/data_store/redis/lua_scripts/record_failure.lua
116
- - lib/stoplight/infrastructure/data_store/redis/lua_scripts/record_recovery_probe_failure.lua
117
- - lib/stoplight/infrastructure/data_store/redis/lua_scripts/record_recovery_probe_success.lua
118
- - lib/stoplight/infrastructure/data_store/redis/lua_scripts/record_success.lua
119
- - lib/stoplight/infrastructure/data_store/redis/lua_scripts/release_lock.lua
120
- - lib/stoplight/infrastructure/data_store/redis/lua_scripts/transition_to_green.lua
121
- - lib/stoplight/infrastructure/data_store/redis/lua_scripts/transition_to_red.lua
122
- - lib/stoplight/infrastructure/data_store/redis/lua_scripts/transition_to_yellow.lua
123
- - lib/stoplight/infrastructure/data_store/redis/recovery_lock_store.rb
124
- - lib/stoplight/infrastructure/data_store/redis/recovery_lock_token.rb
125
- - lib/stoplight/infrastructure/data_store/redis/scripting.rb
98
+ - lib/stoplight/error.rb
99
+ - lib/stoplight/infrastructure/fail_safe/data_store.rb
100
+ - lib/stoplight/infrastructure/fail_safe/storage/metrics.rb
101
+ - lib/stoplight/infrastructure/fail_safe/storage/recovery_lock.rb
102
+ - lib/stoplight/infrastructure/fail_safe/storage/recovery_lock_token.rb
103
+ - lib/stoplight/infrastructure/fail_safe/storage/state.rb
104
+ - lib/stoplight/infrastructure/memory/data_store.rb
105
+ - lib/stoplight/infrastructure/memory/data_store/metrics.rb
106
+ - lib/stoplight/infrastructure/memory/data_store/recovery_lock_store.rb
107
+ - lib/stoplight/infrastructure/memory/data_store/recovery_lock_token.rb
108
+ - lib/stoplight/infrastructure/memory/data_store/sliding_window.rb
109
+ - lib/stoplight/infrastructure/memory/data_store/state.rb
110
+ - lib/stoplight/infrastructure/memory/storage/recovery_lock.rb
111
+ - lib/stoplight/infrastructure/memory/storage/recovery_metrics.rb
112
+ - lib/stoplight/infrastructure/memory/storage/state.rb
113
+ - lib/stoplight/infrastructure/memory/storage/unbounded_metrics.rb
114
+ - lib/stoplight/infrastructure/memory/storage/window_metrics.rb
126
115
  - lib/stoplight/infrastructure/notifier/fail_safe.rb
127
116
  - lib/stoplight/infrastructure/notifier/generic.rb
128
117
  - lib/stoplight/infrastructure/notifier/io.rb
129
118
  - lib/stoplight/infrastructure/notifier/logger.rb
119
+ - lib/stoplight/infrastructure/redis/data_store.rb
120
+ - lib/stoplight/infrastructure/redis/data_store/lua_scripts/get_metrics.lua
121
+ - lib/stoplight/infrastructure/redis/data_store/lua_scripts/record_failure.lua
122
+ - lib/stoplight/infrastructure/redis/data_store/lua_scripts/record_recovery_probe_failure.lua
123
+ - lib/stoplight/infrastructure/redis/data_store/lua_scripts/record_recovery_probe_success.lua
124
+ - lib/stoplight/infrastructure/redis/data_store/lua_scripts/record_success.lua
125
+ - lib/stoplight/infrastructure/redis/data_store/lua_scripts/release_lock.lua
126
+ - lib/stoplight/infrastructure/redis/data_store/lua_scripts/transition_to_green.lua
127
+ - lib/stoplight/infrastructure/redis/data_store/lua_scripts/transition_to_red.lua
128
+ - lib/stoplight/infrastructure/redis/data_store/lua_scripts/transition_to_yellow.lua
129
+ - lib/stoplight/infrastructure/redis/data_store/recovery_lock_store.rb
130
+ - lib/stoplight/infrastructure/redis/data_store/recovery_lock_token.rb
131
+ - lib/stoplight/infrastructure/redis/data_store/scripting.rb
132
+ - lib/stoplight/infrastructure/redis/storage/key_space.rb
133
+ - lib/stoplight/infrastructure/redis/storage/metrics.rb
134
+ - lib/stoplight/infrastructure/redis/storage/recovery_lock.rb
135
+ - lib/stoplight/infrastructure/redis/storage/recovery_lock/release_lock.lua
136
+ - lib/stoplight/infrastructure/redis/storage/recovery_metrics.rb
137
+ - lib/stoplight/infrastructure/redis/storage/scripting.rb
138
+ - lib/stoplight/infrastructure/redis/storage/state.rb
139
+ - lib/stoplight/infrastructure/redis/storage/state/transition_to_green.lua
140
+ - lib/stoplight/infrastructure/redis/storage/state/transition_to_red.lua
141
+ - lib/stoplight/infrastructure/redis/storage/state/transition_to_yellow.lua
142
+ - lib/stoplight/infrastructure/redis/storage/unbounded_metrics.rb
143
+ - lib/stoplight/infrastructure/redis/storage/unbounded_metrics/record_failure.lua
144
+ - lib/stoplight/infrastructure/redis/storage/unbounded_metrics/record_success.lua
145
+ - lib/stoplight/infrastructure/redis/storage/window_metrics.rb
146
+ - lib/stoplight/infrastructure/redis/storage/window_metrics/metrics_snapshot.lua
147
+ - lib/stoplight/infrastructure/redis/storage/window_metrics/record_failure.lua
148
+ - lib/stoplight/infrastructure/redis/storage/window_metrics/record_success.lua
130
149
  - lib/stoplight/infrastructure/storage/compatibility_metrics.rb
131
150
  - lib/stoplight/infrastructure/storage/compatibility_recovery_lock.rb
132
151
  - lib/stoplight/infrastructure/storage/compatibility_recovery_metrics.rb
133
152
  - lib/stoplight/infrastructure/storage/compatibility_state.rb
153
+ - lib/stoplight/infrastructure/system_clock.rb
154
+ - lib/stoplight/notifier.rb
134
155
  - lib/stoplight/rspec.rb
135
156
  - lib/stoplight/rspec/generic_notifier.rb
157
+ - lib/stoplight/state.rb
158
+ - lib/stoplight/types.rb
159
+ - lib/stoplight/undefined.rb
136
160
  - lib/stoplight/version.rb
137
- - lib/stoplight/wiring/data_store/base.rb
138
- - lib/stoplight/wiring/data_store/memory.rb
139
- - lib/stoplight/wiring/data_store/redis.rb
161
+ - lib/stoplight/wiring/config_compatibility_validator.rb
162
+ - lib/stoplight/wiring/configuration_dsl.rb
163
+ - lib/stoplight/wiring/data_store_backend.rb
140
164
  - lib/stoplight/wiring/default.rb
165
+ - lib/stoplight/wiring/default_config.rb
141
166
  - lib/stoplight/wiring/default_configuration.rb
142
- - lib/stoplight/wiring/default_factory_builder.rb
143
- - lib/stoplight/wiring/light/default_config.rb
144
- - lib/stoplight/wiring/light/system_config.rb
145
167
  - lib/stoplight/wiring/light_builder.rb
146
168
  - lib/stoplight/wiring/light_factory.rb
147
- - lib/stoplight/wiring/light_factory/compatibility_validator.rb
148
- - lib/stoplight/wiring/light_factory/config_normalizer.rb
149
- - lib/stoplight/wiring/light_factory/configuration_pipeline.rb
150
169
  - lib/stoplight/wiring/light_factory/traffic_control_dsl.rb
151
170
  - lib/stoplight/wiring/light_factory/traffic_recovery_dsl.rb
171
+ - lib/stoplight/wiring/memory/backend.rb
152
172
  - lib/stoplight/wiring/notifier_factory.rb
153
- - lib/stoplight/wiring/public_api.rb
173
+ - lib/stoplight/wiring/redis/backend.rb
174
+ - lib/stoplight/wiring/storage_set.rb
175
+ - lib/stoplight/wiring/storage_set_builder.rb
176
+ - lib/stoplight/wiring/system.rb
177
+ - lib/stoplight/wiring/system/light_builder.rb
178
+ - lib/stoplight/wiring/system/light_factory.rb
179
+ - sig/_private/generators/stoplight/install/install_generator.rbs
180
+ - sig/_private/stoplight.rbs
181
+ - sig/_private/stoplight/common/deprecations.rbs
182
+ - sig/_private/stoplight/data_store.rbs
183
+ - sig/_private/stoplight/domain/compatibility_result.rbs
184
+ - sig/_private/stoplight/domain/config.rbs
185
+ - sig/_private/stoplight/domain/error_tracking_policy.rbs
186
+ - sig/_private/stoplight/domain/failure.rbs
187
+ - sig/_private/stoplight/domain/light.rbs
188
+ - sig/_private/stoplight/domain/light_info.rbs
189
+ - sig/_private/stoplight/domain/metrics_snapshot.rbs
190
+ - sig/_private/stoplight/domain/ports/clock.rbs
191
+ - sig/_private/stoplight/domain/ports/data_store.rbs
192
+ - sig/_private/stoplight/domain/ports/light_factory.rbs
193
+ - sig/_private/stoplight/domain/ports/metrics_store.rbs
194
+ - sig/_private/stoplight/domain/ports/recovery_lock_store.rbs
195
+ - sig/_private/stoplight/domain/ports/recovery_lock_token.rbs
196
+ - sig/_private/stoplight/domain/ports/run_strategy.rbs
197
+ - sig/_private/stoplight/domain/ports/state_store.rbs
198
+ - sig/_private/stoplight/domain/ports/traffic_control.rbs
199
+ - sig/_private/stoplight/domain/ports/traffic_recovery.rbs
200
+ - sig/_private/stoplight/domain/state_snapshot.rbs
201
+ - sig/_private/stoplight/domain/storage/recovery_lock_token.rbs
202
+ - sig/_private/stoplight/domain/strategies/green_run_strategy.rbs
203
+ - sig/_private/stoplight/domain/strategies/red_run_strategy.rbs
204
+ - sig/_private/stoplight/domain/strategies/yellow_run_strategy.rbs
205
+ - sig/_private/stoplight/domain/tracker/base.rbs
206
+ - sig/_private/stoplight/domain/tracker/recovery_probe.rbs
207
+ - sig/_private/stoplight/domain/tracker/request.rbs
208
+ - sig/_private/stoplight/domain/traffic_control/consecutive_errors.rbs
209
+ - sig/_private/stoplight/domain/traffic_control/error_rate.rbs
210
+ - sig/_private/stoplight/domain/traffic_recovery.rbs
211
+ - sig/_private/stoplight/domain/traffic_recovery/consecutive_successes.rbs
212
+ - sig/_private/stoplight/infrastructure/fail_safe/data_store.rbs
213
+ - sig/_private/stoplight/infrastructure/fail_safe/storage/metrics.rbs
214
+ - sig/_private/stoplight/infrastructure/fail_safe/storage/recovery_lock.rbs
215
+ - sig/_private/stoplight/infrastructure/fail_safe/storage/recovery_lock_token.rbs
216
+ - sig/_private/stoplight/infrastructure/fail_safe/storage/state.rbs
217
+ - sig/_private/stoplight/infrastructure/memory/data_store.rbs
218
+ - sig/_private/stoplight/infrastructure/memory/data_store/metrics.rbs
219
+ - sig/_private/stoplight/infrastructure/memory/data_store/recovery_lock_store.rbs
220
+ - sig/_private/stoplight/infrastructure/memory/data_store/recovery_lock_token.rbs
221
+ - sig/_private/stoplight/infrastructure/memory/data_store/sliding_window.rbs
222
+ - sig/_private/stoplight/infrastructure/memory/data_store/state.rbs
223
+ - sig/_private/stoplight/infrastructure/memory/storage/recovery_lock.rbs
224
+ - sig/_private/stoplight/infrastructure/memory/storage/recovery_metrics.rbs
225
+ - sig/_private/stoplight/infrastructure/memory/storage/state.rbs
226
+ - sig/_private/stoplight/infrastructure/memory/storage/unbounded_metrics.rbs
227
+ - sig/_private/stoplight/infrastructure/memory/storage/window_metrics.rbs
228
+ - sig/_private/stoplight/infrastructure/notifier/fail_safe.rbs
229
+ - sig/_private/stoplight/infrastructure/notifier/generic.rbs
230
+ - sig/_private/stoplight/infrastructure/notifier/io.rbs
231
+ - sig/_private/stoplight/infrastructure/notifier/logger.rbs
232
+ - sig/_private/stoplight/infrastructure/redis/data_store.rbs
233
+ - sig/_private/stoplight/infrastructure/redis/data_store/recovery_lock_store.rbs
234
+ - sig/_private/stoplight/infrastructure/redis/data_store/recovery_lock_token.rbs
235
+ - sig/_private/stoplight/infrastructure/redis/data_store/scripting.rbs
236
+ - sig/_private/stoplight/infrastructure/redis/storage/key_space.rbs
237
+ - sig/_private/stoplight/infrastructure/redis/storage/metrics.rbs
238
+ - sig/_private/stoplight/infrastructure/redis/storage/recovery_lock.rbs
239
+ - sig/_private/stoplight/infrastructure/redis/storage/recovery_metrics.rbs
240
+ - sig/_private/stoplight/infrastructure/redis/storage/scripting.rbs
241
+ - sig/_private/stoplight/infrastructure/redis/storage/state.rbs
242
+ - sig/_private/stoplight/infrastructure/redis/storage/unbounded_metrics.rbs
243
+ - sig/_private/stoplight/infrastructure/redis/storage/window_metrics.rbs
244
+ - sig/_private/stoplight/infrastructure/storage/compatibility_metrics.rbs
245
+ - sig/_private/stoplight/infrastructure/storage/compatibility_recovery_lock.rbs
246
+ - sig/_private/stoplight/infrastructure/storage/compatibility_recovery_metrics.rbs
247
+ - sig/_private/stoplight/infrastructure/storage/compatibility_state.rbs
248
+ - sig/_private/stoplight/infrastructure/system_clock.rbs
249
+ - sig/_private/stoplight/system/light_builder.rbs
250
+ - sig/_private/stoplight/system/light_factory.rbs
251
+ - sig/_private/stoplight/types.rbs
252
+ - sig/_private/stoplight/wiring/config_compatibility_validator.rbs
253
+ - sig/_private/stoplight/wiring/configuration_dsl.rbs
254
+ - sig/_private/stoplight/wiring/data_store_backend.rbs
255
+ - sig/_private/stoplight/wiring/default.rbs
256
+ - sig/_private/stoplight/wiring/default_config.rbs
257
+ - sig/_private/stoplight/wiring/default_configuration.rbs
258
+ - sig/_private/stoplight/wiring/light_builder.rbs
259
+ - sig/_private/stoplight/wiring/light_factory.rbs
260
+ - sig/_private/stoplight/wiring/light_factory/traffic_control_dsl.rbs
261
+ - sig/_private/stoplight/wiring/light_factory/traffic_recovery_dsl.rbs
262
+ - sig/_private/stoplight/wiring/memory/backend.rbs
263
+ - sig/_private/stoplight/wiring/notifier_factory.rbs
264
+ - sig/_private/stoplight/wiring/redis/backend.rbs
265
+ - sig/_private/stoplight/wiring/storage_set.rbs
266
+ - sig/_private/stoplight/wiring/storage_set_builder.rbs
267
+ - sig/_private/stoplight/wiring/system.rbs
268
+ - sig/stoplight.rbs
269
+ - sig/stoplight/color.rbs
270
+ - sig/stoplight/data_store.rbs
271
+ - sig/stoplight/error.rbs
272
+ - sig/stoplight/notifier.rbs
273
+ - sig/stoplight/ports/configuration.rbs
274
+ - sig/stoplight/ports/exception_matcher.rbs
275
+ - sig/stoplight/ports/light.rbs
276
+ - sig/stoplight/ports/light_info.rbs
277
+ - sig/stoplight/ports/state_transition_notifier.rbs
278
+ - sig/stoplight/ports/system.rbs
279
+ - sig/stoplight/state.rbs
280
+ - sig/stoplight/undefined.rbs
281
+ - sig/stoplight/version.rbs
154
282
  homepage: https://github.com/bolshakov/stoplight
155
283
  licenses:
156
284
  - MIT
@@ -169,7 +297,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
169
297
  - !ruby/object:Gem::Version
170
298
  version: '0'
171
299
  requirements: []
172
- rubygems_version: 3.6.9
300
+ rubygems_version: 4.0.3
173
301
  specification_version: 4
174
302
  summary: Traffic control for code.
175
303
  test_files: []
@@ -1,11 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Stoplight
4
- module Domain
5
- module Color
6
- GREEN = "green"
7
- YELLOW = "yellow"
8
- RED = "red"
9
- end
10
- end
11
- end
@@ -1,146 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Stoplight
4
- module Domain
5
- # @abstract
6
- # :nocov:
7
- class DataStore
8
- METRICS_RETENTION_TIME = 60 * 60 * 24 # 1 day
9
-
10
- # Retrieves the names of all lights stored in the data store.
11
- #
12
- # @return [Array<String>] An array of light names.
13
- def names
14
- raise NotImplementedError
15
- end
16
-
17
- # Retrieves metrics for a specific light configuration.
18
- #
19
- # @param config [Stoplight::Domain::Config]
20
- # @return [Stoplight::Domain::Metrics]
21
- def get_metrics(config)
22
- raise NotImplementedError
23
- end
24
-
25
- # Retrieves recovery metrics for a specific light configuration.
26
- #
27
- # @param config [Stoplight::Domain::Config]
28
- # @return [Stoplight::Domain::Metrics]
29
- def get_recovery_metrics(config)
30
- raise NotImplementedError
31
- end
32
-
33
- # Retrieves State Snapshot for a specific light configuration.
34
- #
35
- # @param config [Stoplight::Domain::Config] The light configuration.
36
- # @return [Stoplight::Domain::StateSnapshot]
37
- def get_state_snapshot(config)
38
- raise NotImplementedError
39
- end
40
-
41
- # Clears windowed metrics (successes/errors) to prevent
42
- # stale failures from before recovery from affecting post-recovery decisions.
43
- # Consecutive counts are intentionally preserved as they track current streaks.
44
- #
45
- # @param config [Stoplight::Domain::Config] The light configuration.
46
- # @return [void]
47
- def clear_metrics(config)
48
- raise NotImplementedError
49
- end
50
-
51
- def clear_recovery_metrics(config)
52
- raise NotImplementedError
53
- end
54
-
55
- # Records a failure for a specific light configuration.
56
- #
57
- # @param config [Stoplight::Domain::Config]
58
- # @param exception [Exception]
59
- # @return [void]
60
- def record_failure(config, exception)
61
- raise NotImplementedError
62
- end
63
-
64
- # Records a success for a specific light configuration.
65
- #
66
- # @param config [Stoplight::Domain::Config]
67
- # @return [void]
68
- def record_success(config)
69
- raise NotImplementedError
70
- end
71
-
72
- # Records a failed recovery probe for a specific light configuration.
73
- #
74
- # @param config [Stoplight::Domain::Config]
75
- # @param failure [Failure]
76
- # @return [void]
77
- def record_recovery_probe_failure(config, failure)
78
- raise NotImplementedError
79
- end
80
-
81
- # Records a successful recovery probe for a specific light configuration.
82
- #
83
- # @param config [Stoplight::Domain::Config]
84
- # @return [void]
85
- def record_recovery_probe_success(config)
86
- raise NotImplementedError
87
- end
88
-
89
- # Sets the state of a specific light configuration.
90
- #
91
- # @param config [Stoplight::Domain::Config]
92
- # @param state [String] The new state to set.
93
- # @return [String] The state that was set.
94
- def set_state(config, state)
95
- raise NotImplementedError
96
- end
97
-
98
- # Acquires recovery lock for serializing probe execution.
99
- #
100
- # @param config [Stoplight::Domain::Config]
101
- # @return [Stoplight::Domain::LockToken, nil] Lock if acquired, nil if contended
102
- def acquire_recovery_lock(config) = raise NotImplementedError
103
-
104
- # Releases previously acquired lock.
105
- #
106
- # @param lock [Stoplight::Domain::RecoveryLockToken]
107
- # @return [void]
108
- def release_recovery_lock(lock) = raise NotImplementedError
109
-
110
- # Transitions the Stoplight to the specified color.
111
- #
112
- # This method performs a color transition operation that works across distributed instances
113
- # of the light. It ensures that in a multi-instance environment, only one instance
114
- # is considered the "first" to perform the transition (and therefore responsible for
115
- # triggering notifications).
116
- #
117
- # @param config [Stoplight::Domain::Config]
118
- # @param color [String] The target color/state to transition to.
119
- # Should be one of Stoplight::Color::GREEN, Stoplight::Color::YELLOW, or Stoplight::Color::RED.
120
- #
121
- # @return [Boolean] Returns +true+ if this instance was the first to perform this specific transition
122
- # (and should therefore trigger notifications). Returns +false+ if another instance already
123
- # initiated this transition.
124
- #
125
- # @note In distributed environments with multiple instances, race conditions can occur when instances
126
- # attempt conflicting transitions simultaneously (e.g., one instance tries to transition from
127
- # YELLOW to GREEN while another tries YELLOW to RED). The implementation handles this, but
128
- # be aware that the last operation may determine the final color of the light.
129
- #
130
- def transition_to_color(config, color)
131
- raise NotImplementedError
132
- end
133
-
134
- # Deletes metadata (and related persistent state) for the given light.
135
- #
136
- # Implementations may choose to only remove metadata; metrics may expire via TTL.
137
- #
138
- # @param config [Stoplight::Domain::Config]
139
- # @return [void]
140
- def delete_light(config)
141
- raise NotImplementedError
142
- end
143
- end
144
- # :nocov:
145
- end
146
- end