stoplight 5.6.0 → 5.8.0
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 +26 -5
- data/lib/stoplight/admin/lights_repository/light.rb +22 -6
- data/lib/stoplight/admin/lights_repository.rb +20 -16
- data/lib/stoplight/admin/views/_card.erb +8 -5
- data/lib/stoplight/admin.rb +2 -1
- data/lib/stoplight/color.rb +9 -0
- data/lib/stoplight/common/deprecations.rb +11 -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 -35
- 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 +122 -16
- data/lib/stoplight/domain/light.rb +44 -64
- 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 +74 -58
- data/lib/stoplight/domain/tracker/recovery_probe.rb +27 -43
- data/lib/stoplight/domain/tracker/request.rb +24 -39
- 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 +8 -18
- data/lib/stoplight/domain/traffic_recovery.rb +3 -5
- data/lib/stoplight/error.rb +46 -0
- data/lib/stoplight/infrastructure/fail_safe/data_store.rb +152 -0
- 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/memory/data_store/recovery_lock_store.rb +52 -0
- data/lib/stoplight/infrastructure/memory/data_store/recovery_lock_token.rb +17 -0
- 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} +90 -57
- 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 +50 -0
- 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/redis/data_store/lua_scripts/record_recovery_probe_failure.lua +27 -0
- data/lib/stoplight/infrastructure/redis/data_store/lua_scripts/record_recovery_probe_success.lua +23 -0
- data/lib/stoplight/infrastructure/redis/data_store/lua_scripts/release_lock.lua +6 -0
- data/lib/stoplight/infrastructure/redis/data_store/recovery_lock_store.rb +60 -0
- data/lib/stoplight/infrastructure/redis/data_store/recovery_lock_token.rb +28 -0
- data/lib/stoplight/infrastructure/redis/data_store/scripting.rb +73 -0
- data/lib/stoplight/infrastructure/{data_store/redis.rb → redis/data_store.rb} +173 -210
- 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 +41 -0
- data/lib/stoplight/infrastructure/storage/compatibility_recovery_lock.rb +33 -0
- data/lib/stoplight/infrastructure/storage/compatibility_recovery_metrics.rb +47 -0
- data/lib/stoplight/infrastructure/storage/compatibility_state.rb +44 -0
- 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 +2 -2
- 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 +198 -0
- data/lib/stoplight/wiring/light_factory/traffic_control_dsl.rb +26 -0
- data/lib/stoplight/wiring/light_factory/traffic_recovery_dsl.rb +21 -0
- data/lib/stoplight/wiring/light_factory.rb +74 -135
- data/lib/stoplight/wiring/memory/backend.rb +57 -0
- data/lib/stoplight/wiring/notifier_factory.rb +26 -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 +209 -23
- 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/sig/_private/stoplight/domain/tracker/base.rbs +8 -0
- 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/sig/_private/stoplight/wiring/default_config.rbs +7 -0
- 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 +199 -36
- data/lib/stoplight/domain/color.rb +0 -11
- data/lib/stoplight/domain/data_store.rb +0 -130
- data/lib/stoplight/domain/error.rb +0 -42
- data/lib/stoplight/domain/metrics.rb +0 -85
- data/lib/stoplight/domain/state.rb +0 -11
- data/lib/stoplight/domain/state_transition_notifier.rb +0 -25
- data/lib/stoplight/domain/strategies/run_strategy.rb +0 -27
- data/lib/stoplight/domain/tracker/base.rb +0 -41
- data/lib/stoplight/domain/traffic_control/base.rb +0 -74
- data/lib/stoplight/domain/traffic_recovery/base.rb +0 -80
- data/lib/stoplight/infrastructure/data_store/redis/lua.rb +0 -25
- data/lib/stoplight/infrastructure/dependency_injection/container.rb +0 -249
- data/lib/stoplight/infrastructure/dependency_injection/unresolved_dependency_error.rb +0 -13
- data/lib/stoplight/wiring/container.rb +0 -80
- data/lib/stoplight/wiring/default_factory_builder.rb +0 -25
- data/lib/stoplight/wiring/fail_safe_data_store.rb +0 -147
- data/lib/stoplight/wiring/fail_safe_notifier.rb +0 -79
- data/lib/stoplight/wiring/light/default_config.rb +0 -18
- data/lib/stoplight/wiring/light/system_config.rb +0 -11
- data/lib/stoplight/wiring/public_api.rb +0 -28
- data/lib/stoplight/wiring/system_container.rb +0 -9
- data/lib/stoplight/wiring/system_light_factory.rb +0 -17
- /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_success.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
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Stoplight
|
|
4
|
-
module Wiring
|
|
5
|
-
# This container implements an instance of +Stoplight::Infrastructure::DependencyInjection::Container+
|
|
6
|
-
# with Stoplight-specific wiring knowledge. It defines how to construct and connect
|
|
7
|
-
# all the components needed for a circuit breaker to function.
|
|
8
|
-
#
|
|
9
|
-
# ## Default Configuration
|
|
10
|
-
#
|
|
11
|
-
# The container is pre-configured with sensible defaults:
|
|
12
|
-
# - Data Store - in-memory storage
|
|
13
|
-
# - STDERR notifier
|
|
14
|
-
# - No-op error notifier
|
|
15
|
-
# - Consecutive failure detection
|
|
16
|
-
# - Consecutive success recovery
|
|
17
|
-
#
|
|
18
|
-
# @see Infrastructure::DependencyInjection::Container Generic DI container
|
|
19
|
-
# @see Stoplight::Wiring::LightFactory Factory that uses this container
|
|
20
|
-
# @api private
|
|
21
|
-
Container = Infrastructure::DependencyInjection::Container.define do
|
|
22
|
-
register(:config, Light::DefaultConfig)
|
|
23
|
-
register(:error_notifier, Default::ERROR_NOTIFIER)
|
|
24
|
-
register(:traffic_control, Default::TRAFFIC_CONTROL)
|
|
25
|
-
register(:traffic_recovery, Default::TRAFFIC_RECOVERY)
|
|
26
|
-
|
|
27
|
-
register(:data_store, Default::DATA_STORE) do |data_store|
|
|
28
|
-
FailSafeDataStore.wrap(
|
|
29
|
-
data_store:,
|
|
30
|
-
error_notifier: resolve(:error_notifier)
|
|
31
|
-
)
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
register(:notifiers, Default::NOTIFIERS) do |notifiers|
|
|
35
|
-
error_notifier = resolve(:error_notifier)
|
|
36
|
-
notifiers.map { |notifier| Wiring::FailSafeNotifier.wrap(notifier:, error_notifier:) }
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
factory(:green_run_strategy) do
|
|
40
|
-
Domain::Strategies::GreenRunStrategy.new(
|
|
41
|
-
config: resolve(:config),
|
|
42
|
-
request_tracker: resolve(:request_tracker)
|
|
43
|
-
)
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
factory(:yellow_run_strategy) do
|
|
47
|
-
Domain::Strategies::YellowRunStrategy.new(
|
|
48
|
-
config: resolve(:config),
|
|
49
|
-
data_store: resolve(:data_store),
|
|
50
|
-
notifiers: resolve(:notifiers),
|
|
51
|
-
request_tracker: resolve(:recovery_probe_tracker)
|
|
52
|
-
)
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
factory(:red_run_strategy) do
|
|
56
|
-
Domain::Strategies::RedRunStrategy.new(
|
|
57
|
-
config: resolve(:config)
|
|
58
|
-
)
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
factory(:request_tracker) do
|
|
62
|
-
Domain::Tracker::Request.new(
|
|
63
|
-
data_store: resolve(:data_store),
|
|
64
|
-
traffic_control: resolve(:traffic_control),
|
|
65
|
-
notifiers: resolve(:notifiers),
|
|
66
|
-
config: resolve(:config)
|
|
67
|
-
)
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
factory(:recovery_probe_tracker) do
|
|
71
|
-
Domain::Tracker::RecoveryProbe.new(
|
|
72
|
-
data_store: resolve(:data_store),
|
|
73
|
-
traffic_recovery: resolve(:traffic_recovery),
|
|
74
|
-
notifiers: resolve(:notifiers),
|
|
75
|
-
config: resolve(:config)
|
|
76
|
-
)
|
|
77
|
-
end
|
|
78
|
-
end
|
|
79
|
-
end
|
|
80
|
-
end
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Stoplight
|
|
4
|
-
module Wiring
|
|
5
|
-
# Builds the default LightFactory from user-provided configuration which is
|
|
6
|
-
# used as the basis for all circuit breakers.
|
|
7
|
-
#
|
|
8
|
-
class DefaultFactoryBuilder
|
|
9
|
-
# @!attribute [r] configuration
|
|
10
|
-
# @return [Stoplight::Wiring::DefaultConfiguration]
|
|
11
|
-
#
|
|
12
|
-
attr_reader :configuration
|
|
13
|
-
|
|
14
|
-
def initialize
|
|
15
|
-
@configuration = DefaultConfiguration.new
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
# @return [Stoplight::Wiring::LightFactory]
|
|
19
|
-
# @api private the method is used internally by Stoplight
|
|
20
|
-
def build
|
|
21
|
-
LightFactory.new(Wiring::Container).with(**configuration.to_h)
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
end
|
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "securerandom"
|
|
4
|
-
|
|
5
|
-
module Stoplight
|
|
6
|
-
module Wiring
|
|
7
|
-
# A wrapper around a data store that provides fail-safe mechanisms using a
|
|
8
|
-
# circuit breaker. It ensures that operations on the data store can gracefully
|
|
9
|
-
# handle failures by falling back to default values when necessary.
|
|
10
|
-
#
|
|
11
|
-
# @api private
|
|
12
|
-
class FailSafeDataStore < Domain::DataStore
|
|
13
|
-
class << self
|
|
14
|
-
# Wraps a data store with fail-safe mechanisms.
|
|
15
|
-
#
|
|
16
|
-
# @param data_store [Stoplight::DataStore::Base] The data store to wrap.
|
|
17
|
-
# @param error_notifier [Proc] called when wrapped data store fails
|
|
18
|
-
# @return [Stoplight::DataStore::Base, FailSafe] The original data store if it is already
|
|
19
|
-
# a +Memory+ or +FailSafe+ instance, otherwise a new +FailSafe+ instance.
|
|
20
|
-
def wrap(data_store:, error_notifier:)
|
|
21
|
-
case data_store
|
|
22
|
-
in Infrastructure::DataStore::Memory
|
|
23
|
-
data_store
|
|
24
|
-
in self if data_store.error_notifier == error_notifier
|
|
25
|
-
data_store
|
|
26
|
-
in self
|
|
27
|
-
new(data_store: data_store.data_store, error_notifier:)
|
|
28
|
-
else
|
|
29
|
-
new(data_store:, error_notifier:)
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
# @!attribute data_store
|
|
35
|
-
# @return [Stoplight::DataStore::Base] The underlying primary data store being used
|
|
36
|
-
attr_reader :data_store
|
|
37
|
-
|
|
38
|
-
# @!attribute error_notifier
|
|
39
|
-
# @return [Proc]
|
|
40
|
-
attr_reader :error_notifier
|
|
41
|
-
|
|
42
|
-
# @!attribute failover_data_store
|
|
43
|
-
# @return [Stoplight::DataStore::Base] The fallback data store used when the primary fails.
|
|
44
|
-
private attr_reader :failover_data_store
|
|
45
|
-
|
|
46
|
-
# @!attribute circuit_breaker
|
|
47
|
-
# @return [Stoplight::Light] The circuit breaker used to handle data store failures.
|
|
48
|
-
private attr_reader :circuit_breaker
|
|
49
|
-
|
|
50
|
-
# @param data_store [Stoplight::Domain::DataStore]
|
|
51
|
-
# @param error_notifier [Proc]
|
|
52
|
-
def initialize(data_store:, error_notifier:, failover_data_store: Wiring::Default::DATA_STORE)
|
|
53
|
-
@data_store = data_store
|
|
54
|
-
@error_notifier = error_notifier
|
|
55
|
-
@failover_data_store = failover_data_store
|
|
56
|
-
@circuit_breaker = Stoplight.system_light("data_store:fail_safe:#{data_store.class.name}")
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
def names
|
|
60
|
-
with_fallback(:names) do
|
|
61
|
-
data_store.names
|
|
62
|
-
end
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
def get_metrics(config, *args, **kwargs)
|
|
66
|
-
with_fallback(:get_metrics, config, *args, **kwargs) do
|
|
67
|
-
data_store.get_metrics(config, *args, **kwargs)
|
|
68
|
-
end
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
def get_recovery_metrics(config, *args, **kwargs)
|
|
72
|
-
with_fallback(:get_recovery_metrics, config, *args, **kwargs) do
|
|
73
|
-
data_store.get_recovery_metrics(config, *args, **kwargs)
|
|
74
|
-
end
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
def get_state_snapshot(config)
|
|
78
|
-
with_fallback(:get_state_snapshot, config) do
|
|
79
|
-
data_store.get_state_snapshot(config)
|
|
80
|
-
end
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
def clear_windowed_metrics(config)
|
|
84
|
-
with_fallback(:clear_windowed_metrics, config) do
|
|
85
|
-
data_store.clear_windowed_metrics(config)
|
|
86
|
-
end
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
def record_failure(config, *args, **kwargs)
|
|
90
|
-
with_fallback(:record_failure, config, *args, **kwargs) do
|
|
91
|
-
data_store.record_failure(config, *args, **kwargs)
|
|
92
|
-
end
|
|
93
|
-
end
|
|
94
|
-
|
|
95
|
-
def record_success(config, *args, **kwargs)
|
|
96
|
-
with_fallback(:record_success, config, *args, **kwargs) do
|
|
97
|
-
data_store.record_success(config, *args, **kwargs)
|
|
98
|
-
end
|
|
99
|
-
end
|
|
100
|
-
|
|
101
|
-
def record_recovery_probe_success(config, *args, **kwargs)
|
|
102
|
-
with_fallback(:record_recovery_probe_success, config, *args, **kwargs) do
|
|
103
|
-
data_store.record_recovery_probe_success(config, *args, **kwargs)
|
|
104
|
-
end
|
|
105
|
-
end
|
|
106
|
-
|
|
107
|
-
def record_recovery_probe_failure(config, *args, **kwargs)
|
|
108
|
-
with_fallback(:record_recovery_probe_failure, config, *args, **kwargs) do
|
|
109
|
-
data_store.record_recovery_probe_failure(config, *args, **kwargs)
|
|
110
|
-
end
|
|
111
|
-
end
|
|
112
|
-
|
|
113
|
-
def set_state(config, *args, **kwargs)
|
|
114
|
-
with_fallback(:set_state, config, *args, **kwargs) do
|
|
115
|
-
data_store.set_state(config, *args, **kwargs)
|
|
116
|
-
end
|
|
117
|
-
end
|
|
118
|
-
|
|
119
|
-
def transition_to_color(config, *args, **kwargs)
|
|
120
|
-
with_fallback(:transition_to_color, config, *args, **kwargs) do
|
|
121
|
-
data_store.transition_to_color(config, *args, **kwargs)
|
|
122
|
-
end
|
|
123
|
-
end
|
|
124
|
-
|
|
125
|
-
def delete_light(config, *args, **kwargs)
|
|
126
|
-
with_fallback(:delete_light, config, *args, **kwargs) do
|
|
127
|
-
data_store.delete_light(config, *args, **kwargs)
|
|
128
|
-
end
|
|
129
|
-
end
|
|
130
|
-
|
|
131
|
-
def ==(other)
|
|
132
|
-
other.is_a?(self.class) && other.data_store == data_store && other.error_notifier == error_notifier
|
|
133
|
-
end
|
|
134
|
-
|
|
135
|
-
# @param method_name [Symbol] protected method name
|
|
136
|
-
private def with_fallback(method_name, *args, **kwargs, &code)
|
|
137
|
-
fallback = proc do |error|
|
|
138
|
-
config = args.first
|
|
139
|
-
error_notifier.call(error) if config && error
|
|
140
|
-
@failover_data_store.public_send(method_name, *args, **kwargs)
|
|
141
|
-
end
|
|
142
|
-
|
|
143
|
-
circuit_breaker.run(fallback, &code)
|
|
144
|
-
end
|
|
145
|
-
end
|
|
146
|
-
end
|
|
147
|
-
end
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Stoplight
|
|
4
|
-
module Wiring
|
|
5
|
-
# A wrapper around a notifier that provides fail-safe mechanisms using a
|
|
6
|
-
# circuit breaker. It ensures that a notification can gracefully
|
|
7
|
-
# handle failures.
|
|
8
|
-
#
|
|
9
|
-
# @api private
|
|
10
|
-
class FailSafeNotifier < Domain::StateTransitionNotifier
|
|
11
|
-
# @!attribute [r] notifier
|
|
12
|
-
# @return [Stoplight::Domain::StateTransitionNotifier] The underlying notifier being wrapped.
|
|
13
|
-
attr_reader :notifier
|
|
14
|
-
|
|
15
|
-
# @!attribute [r] error_notifier
|
|
16
|
-
# @return [Stoplight::Domain::StateTransitionNotifier] The underlying notifier being wrapped.
|
|
17
|
-
attr_reader :error_notifier
|
|
18
|
-
|
|
19
|
-
class << self
|
|
20
|
-
# Wraps a notifier with fail-safe mechanisms.
|
|
21
|
-
#
|
|
22
|
-
# @param notifier [Stoplight::Domain::StateTransitionNotifier] The notifier to wrap.
|
|
23
|
-
# @param error_notifier [Proc] called when wrapped data store fails
|
|
24
|
-
# @return [Stoplight::Notifier::FailSafe] The original notifier if it is already
|
|
25
|
-
# a +FailSafe+ instance, otherwise a new +FailSafe+ instance.
|
|
26
|
-
def wrap(notifier:, error_notifier:)
|
|
27
|
-
case notifier
|
|
28
|
-
in self if notifier.error_notifier == error_notifier
|
|
29
|
-
notifier
|
|
30
|
-
in self
|
|
31
|
-
new(notifier: notifier.notifier, error_notifier:)
|
|
32
|
-
else
|
|
33
|
-
new(notifier:, error_notifier:)
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
# Initializes a new instance of the +FailSafe+ class.
|
|
39
|
-
#
|
|
40
|
-
# @param notifier [Stoplight::Domain::StateTransitionNotifier] The notifier to wrap.
|
|
41
|
-
# @param error_notifier [Proc] called when wrapped data store fails
|
|
42
|
-
def initialize(notifier:, error_notifier:)
|
|
43
|
-
@notifier = notifier
|
|
44
|
-
@error_notifier = error_notifier
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
# Sends a notification using the wrapped notifier with fail-safe mechanisms.
|
|
48
|
-
#
|
|
49
|
-
# @param config [Stoplight::Domain::Config] The light configuration.
|
|
50
|
-
# @param from_color [String] The initial color of the light.
|
|
51
|
-
# @param to_color [String] The target color of the light.
|
|
52
|
-
# @param error [Exception, nil] An optional error to include in the notification.
|
|
53
|
-
# @return [void]
|
|
54
|
-
def notify(config, from_color, to_color, error = nil)
|
|
55
|
-
fallback = proc do |exception|
|
|
56
|
-
error_notifier.call(exception) if exception
|
|
57
|
-
nil
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
circuit_breaker.run(fallback) do
|
|
61
|
-
notifier.notify(config, from_color, to_color, error)
|
|
62
|
-
end
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
# @return [Boolean]
|
|
66
|
-
def ==(other)
|
|
67
|
-
other.is_a?(self.class) && notifier == other.notifier
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
# @return [Stoplight::Light] The circuit breaker used to handle failures.
|
|
71
|
-
private def circuit_breaker
|
|
72
|
-
@circuit_breaker ||= Stoplight.system_light(
|
|
73
|
-
"stoplight:notifier:fail_safe:#{notifier.class.name}",
|
|
74
|
-
notifiers: []
|
|
75
|
-
)
|
|
76
|
-
end
|
|
77
|
-
end
|
|
78
|
-
end
|
|
79
|
-
end
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Stoplight
|
|
4
|
-
module Wiring
|
|
5
|
-
module Light
|
|
6
|
-
# Provides default settings for the Stoplight library.
|
|
7
|
-
# @api private
|
|
8
|
-
DefaultConfig = Domain::Config.empty.with(
|
|
9
|
-
cool_off_time: Default::COOL_OFF_TIME,
|
|
10
|
-
threshold: Default::THRESHOLD,
|
|
11
|
-
recovery_threshold: Default::RECOVERY_THRESHOLD,
|
|
12
|
-
window_size: Default::WINDOW_SIZE,
|
|
13
|
-
tracked_errors: Default::TRACKED_ERRORS,
|
|
14
|
-
skipped_errors: Default::SKIPPED_ERRORS
|
|
15
|
-
)
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
end
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Stoplight
|
|
4
|
-
module Wiring
|
|
5
|
-
# Public API facade for backward compatibility and convenience
|
|
6
|
-
# @api public
|
|
7
|
-
module PublicApi
|
|
8
|
-
# Aliases for domain concepts
|
|
9
|
-
Color = Domain::Color
|
|
10
|
-
Error = Domain::Error
|
|
11
|
-
State = Domain::State
|
|
12
|
-
|
|
13
|
-
# Namespace aliases for data stores
|
|
14
|
-
module DataStore
|
|
15
|
-
Redis = Infrastructure::DataStore::Redis
|
|
16
|
-
Memory = Infrastructure::DataStore::Memory
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
# Namespace aliases for notifiers
|
|
20
|
-
module Notifier
|
|
21
|
-
Base = Domain::StateTransitionNotifier
|
|
22
|
-
Generic = Infrastructure::Notifier::Generic
|
|
23
|
-
IO = Infrastructure::Notifier::IO
|
|
24
|
-
Logger = Infrastructure::Notifier::Logger
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
end
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
# frozon_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Stoplight
|
|
4
|
-
module Wiring
|
|
5
|
-
# Factory for internal system lights used by the Stoplight itself.
|
|
6
|
-
#
|
|
7
|
-
# System lights are isolated from user configuration to prevent
|
|
8
|
-
# user settings from breaking the library's own circuit breakers.
|
|
9
|
-
# For example, the FailSafe data store wrapper uses a system light
|
|
10
|
-
# to protect against data store failures.
|
|
11
|
-
#
|
|
12
|
-
# @api private
|
|
13
|
-
SystemLightFactory = Wiring::LightFactory.new(
|
|
14
|
-
Wiring::SystemContainer.with(config: Light::SystemConfig)
|
|
15
|
-
)
|
|
16
|
-
end
|
|
17
|
-
end
|
/data/lib/stoplight/infrastructure/{data_store/redis → redis/data_store/lua_scripts}/get_metrics.lua
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|