stoplight 6.0.0.rc2 → 6.0.0.rc3
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/UPGRADING.md +26 -0
- data/lib/stoplight/admin/helpers.rb +4 -0
- data/lib/stoplight/admin/views/_card.erb +3 -3
- data/lib/stoplight/admin.rb +2 -2
- data/lib/stoplight/color.rb +3 -3
- data/lib/stoplight/domain/state_snapshot.rb +1 -1
- data/lib/stoplight/infrastructure/redis/storage/state.rb +1 -1
- data/lib/stoplight/state.rb +3 -3
- data/lib/stoplight/version.rb +1 -1
- data/lib/stoplight/wiring/system.rb +20 -7
- data/sig/stoplight/admin/actions/action.rbs +1 -1
- data/sig/stoplight/admin/helpers.rbs +3 -0
- data/sig/stoplight/domain/types.rbs +6 -6
- data/sig/stoplight/wiring/system.rbs +22 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 97295cc794acc8de621f091e6cb0cfc7903f2f3bc5c439773c7888cb267bd197
|
|
4
|
+
data.tar.gz: c154e63a6dcd7094d56173647f022ed800514969db64655aac9dd3aefedd566a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b6d7af0c9ad656fca39fb69bcc563e22cb955e3ec60e24e0615a7877fa3f09d7fe58152d7cb1a8797190529bab55b92ecfda544a4fddb7dbe1c16539adbe30b3
|
|
7
|
+
data.tar.gz: 5e222668a15bdd9e7b5b384ec83fb9b94e61e069d34cc509da7855325740e932fb72afcd31f91db5ed74847ce2509f019a8b10db550245741cbb73ab37c484b3
|
data/UPGRADING.md
CHANGED
|
@@ -15,6 +15,7 @@ Here's what you'll want to tackle during your upgrade, roughly ordered from the
|
|
|
15
15
|
- [ ] Round any fractional `window_size` up to a whole number of seconds
|
|
16
16
|
- [ ] Round any fractional `cool_off_time` up to a whole number of seconds, at least 1
|
|
17
17
|
- [ ] Drop `warn_on_clock_skew` from your Redis data store setup
|
|
18
|
+
- [ ] Compare `light.color` and `light.state` against symbols, not strings, and pass a symbol to `light.lock`
|
|
18
19
|
- [ ] Test thoroughly in a staging environment
|
|
19
20
|
|
|
20
21
|
### Lights Are Registered and Reused
|
|
@@ -250,6 +251,31 @@ Stoplight::DataStore::Redis.new(redis)
|
|
|
250
251
|
All time-dependent decisions are now made from Redis's own clock, so every instance reads the same time no matter
|
|
251
252
|
what its host believes. With the coordination problem solved at the source, there is no skew left to warn about.
|
|
252
253
|
|
|
254
|
+
### Colors and Lock States Are Symbols
|
|
255
|
+
|
|
256
|
+
`light.color` now returns `:green`, `:yellow`, or `:red` instead of `"green"`, `"yellow"`, or `"red"`, and
|
|
257
|
+
`light.state` returns `:unlocked`, `:locked_green`, or `:locked_red`. The constants under `Stoplight::Color` and
|
|
258
|
+
`Stoplight::State` hold the same symbols, and every telemetry event carries them too: `from_color` and `to_color` on
|
|
259
|
+
each transition, `from_state` and `to_state` on `LockChanged`.
|
|
260
|
+
|
|
261
|
+
`light.lock` only recognises the symbols, so `light.lock("red")` now raises `Stoplight::Error::IncorrectColor`.
|
|
262
|
+
|
|
263
|
+
Code that compares against the constants keeps working. Code that compares against, or passes, string literals needs
|
|
264
|
+
updating:
|
|
265
|
+
|
|
266
|
+
```ruby
|
|
267
|
+
# Old way that won't work anymore
|
|
268
|
+
alert! if light.color == "red"
|
|
269
|
+
light.lock("green")
|
|
270
|
+
|
|
271
|
+
# New way
|
|
272
|
+
alert! if light.color == Stoplight::Color::RED
|
|
273
|
+
light.lock(Stoplight::Color::GREEN)
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
Symbols are the idiomatic Ruby choice for a closed set of values. Anything that serializes them - logs, metrics tags,
|
|
277
|
+
the Admin dashboard's JSON - renders the same text as before.
|
|
278
|
+
|
|
253
279
|
### Getting Help
|
|
254
280
|
|
|
255
281
|
If you run into anything this guide doesn't cover, post to our [Discussions forum]. The configuration errors in 6.0
|
|
@@ -28,15 +28,15 @@
|
|
|
28
28
|
</p>
|
|
29
29
|
<span class="flex items-center text-sm font-medium text-gray-500 dark:text-gray-400 truncate me-3">
|
|
30
30
|
<span class="flex w-2.5 h-2.5 bg-<%= color %>-600 rounded-full me-1.5 shrink-0"></span>
|
|
31
|
-
<% if light
|
|
31
|
+
<% if red?(light) %>
|
|
32
32
|
Open
|
|
33
|
-
<% elsif light
|
|
33
|
+
<% elsif yellow?(light) %>
|
|
34
34
|
Half-Open
|
|
35
35
|
<% else %>
|
|
36
36
|
Closed
|
|
37
37
|
<% end %>
|
|
38
38
|
|
|
39
|
-
<% if light
|
|
39
|
+
<% if yellow?(light) %>
|
|
40
40
|
(Recovering)
|
|
41
41
|
<% elsif light.locked? %>
|
|
42
42
|
(Locked)
|
data/lib/stoplight/admin.rb
CHANGED
|
@@ -142,14 +142,14 @@ module Stoplight
|
|
|
142
142
|
|
|
143
143
|
patch "/systems/:system_id/lights/:light_id/lock" do
|
|
144
144
|
light_id = T.must(params[:light_id])
|
|
145
|
-
color = T.must(params[:color])
|
|
145
|
+
color = T.must(params[:color]).to_sym
|
|
146
146
|
dependencies.lock_action.call(light_id:, color:)
|
|
147
147
|
|
|
148
148
|
redirect system_url(current_system_id, "/lights")
|
|
149
149
|
end
|
|
150
150
|
|
|
151
151
|
patch "/systems/:system_id/lights/lock" do
|
|
152
|
-
color = T.must(params[:color])
|
|
152
|
+
color = T.must(params[:color]).to_sym
|
|
153
153
|
dependencies.lock_all_action.call(color:)
|
|
154
154
|
|
|
155
155
|
redirect system_url(current_system_id, "/lights")
|
data/lib/stoplight/color.rb
CHANGED
|
@@ -23,7 +23,7 @@ module Stoplight
|
|
|
23
23
|
# @!attribute time
|
|
24
24
|
# The time when the snapshot was taken
|
|
25
25
|
|
|
26
|
-
# @return [
|
|
26
|
+
# @return [Symbol] one of +Color::GREEN+, +Color::RED+, or +Color::YELLOW+
|
|
27
27
|
def color
|
|
28
28
|
if locked_state == State::LOCKED_GREEN
|
|
29
29
|
Color::GREEN
|
|
@@ -63,7 +63,7 @@ module Stoplight
|
|
|
63
63
|
|
|
64
64
|
Domain::StateSnapshot.new(
|
|
65
65
|
breached_at: breached_at_raw && clock.at(breached_at_raw.to_f),
|
|
66
|
-
locked_state: locked_state || Stoplight::State::UNLOCKED,
|
|
66
|
+
locked_state: locked_state&.to_sym || Stoplight::State::UNLOCKED,
|
|
67
67
|
recovery_scheduled_after: recovery_scheduled_after_raw && clock.at(recovery_scheduled_after_raw.to_f),
|
|
68
68
|
recovery_started_at: recovery_started_at_raw && clock.at(recovery_started_at_raw.to_f),
|
|
69
69
|
time: clock.current_time
|
data/lib/stoplight/state.rb
CHANGED
data/lib/stoplight/version.rb
CHANGED
|
@@ -46,6 +46,9 @@ module Stoplight
|
|
|
46
46
|
REGISTRATION_FRAME_LIMIT = 5
|
|
47
47
|
private_constant :REGISTRATION_FRAME_LIMIT
|
|
48
48
|
|
|
49
|
+
Registration = Data.define(:light, :digest, :backtrace, :without_settings)
|
|
50
|
+
private_constant :Registration
|
|
51
|
+
|
|
49
52
|
attr_reader :name
|
|
50
53
|
# @api private
|
|
51
54
|
attr_reader :config
|
|
@@ -113,6 +116,16 @@ module Stoplight
|
|
|
113
116
|
traffic_control: T.undefined,
|
|
114
117
|
traffic_recovery: T.undefined
|
|
115
118
|
)
|
|
119
|
+
without_settings = cool_off_time.is_a?(Undefined) && threshold.is_a?(Undefined) &&
|
|
120
|
+
recovery_threshold.is_a?(Undefined) && window_size.is_a?(Undefined) &&
|
|
121
|
+
tracked_errors.is_a?(Undefined) && skipped_errors.is_a?(Undefined) &&
|
|
122
|
+
traffic_control.is_a?(Undefined) && traffic_recovery.is_a?(Undefined)
|
|
123
|
+
|
|
124
|
+
if without_settings
|
|
125
|
+
registration = @lights[name]
|
|
126
|
+
return registration.light if registration&.without_settings
|
|
127
|
+
end
|
|
128
|
+
|
|
116
129
|
light_dsl = LightConfigurationDsl.new(
|
|
117
130
|
name:,
|
|
118
131
|
cool_off_time:,
|
|
@@ -126,8 +139,8 @@ module Stoplight
|
|
|
126
139
|
)
|
|
127
140
|
config_digest = light_dsl.digest
|
|
128
141
|
|
|
129
|
-
|
|
130
|
-
|
|
142
|
+
registration = @lights[name] || begin
|
|
143
|
+
backtrace = ExternalCaller.backtrace.first(REGISTRATION_FRAME_LIMIT)
|
|
131
144
|
config = light_dsl.configure!(@config)
|
|
132
145
|
@lights.compute_if_absent(name) do
|
|
133
146
|
built = LightFactory.new(
|
|
@@ -137,12 +150,12 @@ module Stoplight
|
|
|
137
150
|
telemetry: @telemetry
|
|
138
151
|
).build
|
|
139
152
|
@registry.register(config)
|
|
140
|
-
|
|
153
|
+
Registration.new(light: built, digest: config_digest, backtrace:, without_settings:)
|
|
141
154
|
end
|
|
142
155
|
end
|
|
143
156
|
|
|
144
|
-
if config_digest !=
|
|
145
|
-
original_site =
|
|
157
|
+
if config_digest != registration.digest
|
|
158
|
+
original_site = registration.backtrace.map { |frame| " #{frame}" }.join("\n")
|
|
146
159
|
|
|
147
160
|
raise Stoplight::Error::ConfigurationError, <<~MSG, ExternalCaller.backtrace
|
|
148
161
|
Light `#{name}` already registered with different configuration.
|
|
@@ -154,12 +167,12 @@ module Stoplight
|
|
|
154
167
|
MSG
|
|
155
168
|
end
|
|
156
169
|
|
|
157
|
-
light
|
|
170
|
+
registration.light
|
|
158
171
|
end
|
|
159
172
|
|
|
160
173
|
# @raise [Stoplight::Error::UnregisteredLightError] if no light was registered under +name+
|
|
161
174
|
def light(name)
|
|
162
|
-
@lights[name]&.
|
|
175
|
+
@lights[name]&.light || raise(Stoplight::Error::UnregisteredLightError, <<~MSG)
|
|
163
176
|
Light `#{name}` was never registered on system `#{@name}`.
|
|
164
177
|
Call `.register(#{name.inspect}, ...)` at boot before using it.
|
|
165
178
|
MSG
|
|
@@ -3,6 +3,9 @@ module Stoplight
|
|
|
3
3
|
module Helpers : Sinatra::Base
|
|
4
4
|
COLORS: Array[Domain::color]
|
|
5
5
|
|
|
6
|
+
def red?: (LightView) -> bool
|
|
7
|
+
def yellow?: (LightView) -> bool
|
|
8
|
+
|
|
6
9
|
def dependencies: -> Dependencies
|
|
7
10
|
def system_url: (String system_id, String path) -> String
|
|
8
11
|
def asset_path: (String) -> String
|
|
@@ -5,15 +5,15 @@ module Stoplight
|
|
|
5
5
|
type duration_ms = Float
|
|
6
6
|
|
|
7
7
|
# Light Colors
|
|
8
|
-
type green =
|
|
9
|
-
type yellow =
|
|
10
|
-
type red =
|
|
8
|
+
type green = :green
|
|
9
|
+
type yellow = :yellow
|
|
10
|
+
type red = :red
|
|
11
11
|
type color = green | yellow | red
|
|
12
12
|
|
|
13
13
|
# Light States
|
|
14
|
-
type unlocked =
|
|
15
|
-
type locked_green =
|
|
16
|
-
type locked_red =
|
|
14
|
+
type unlocked = :unlocked
|
|
15
|
+
type locked_green = :locked_green
|
|
16
|
+
type locked_red = :locked_red
|
|
17
17
|
type state = unlocked | locked_green | locked_red
|
|
18
18
|
|
|
19
19
|
type recovery_decision = :green | :yellow | :red
|
|
@@ -6,7 +6,28 @@ module Stoplight
|
|
|
6
6
|
@name: String
|
|
7
7
|
REGISTRATION_FRAME_LIMIT: Integer
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
class Registration < Data
|
|
10
|
+
attr_reader light: Domain::Light
|
|
11
|
+
attr_reader digest: Integer
|
|
12
|
+
attr_reader backtrace: Array[String]
|
|
13
|
+
attr_reader without_settings: bool
|
|
14
|
+
|
|
15
|
+
def self.new: (
|
|
16
|
+
light: Domain::Light,
|
|
17
|
+
digest: Integer,
|
|
18
|
+
backtrace: Array[String],
|
|
19
|
+
without_settings: bool,
|
|
20
|
+
) -> instance
|
|
21
|
+
|
|
22
|
+
def initialize: (
|
|
23
|
+
light: Domain::Light,
|
|
24
|
+
digest: Integer,
|
|
25
|
+
backtrace: Array[String],
|
|
26
|
+
without_settings: bool,
|
|
27
|
+
) -> void
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
@lights: Concurrent::Map[String, Registration]
|
|
10
31
|
@failover_system: _System?
|
|
11
32
|
@registry: Domain::_Registry
|
|
12
33
|
@telemetry: Domain::Telemetry::Bus
|