star_gates 0.3.1 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.release-please-manifest.json +1 -1
- data/CHANGELOG.md +15 -0
- data/lib/star_gates/application_star_gate.rb +50 -23
- data/lib/star_gates/flags.rb +74 -16
- data/lib/star_gates/gate.rb +35 -24
- data/lib/star_gates/version.rb +1 -1
- data/lib/star_gates.rb +2 -0
- metadata +29 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 399927934b2d54eff9c1845dcb90d09985041fadcbde167c05664fccad0fd1c0
|
|
4
|
+
data.tar.gz: de20f67881038b0b15db64ceba479793b4bad7ca0863a6dfe8d009d20ed38597
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: bbd014d2f8fb483facd66a5a03433ba3289321ae370c780aff674b8c67a9533bae093bba8d273606616a8d5f39d859e8ba33cef684c74197d31de4348fda2089
|
|
7
|
+
data.tar.gz: e2a6b7ee9c7ce2183cc062dac45451539ea1a0e0446f3248cb69c721480c92cc876b8c8c558cc3d9e98cc5f683e9a4da63cd0b3b4aaccdfdbec19e22660b32b1
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.3.2](https://github.com/seuros/star_gates/compare/v0.3.1...v0.3.2) (2026-11-08)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Bug Fixes
|
|
7
|
+
|
|
8
|
+
* a feature timeout can no longer outlive the caller ([d9c108f](https://github.com/seuros/star_gates/commit/d9c108f1f47fd912ffed097ef9e70fff41078f35))
|
|
9
|
+
* a lone checkout can bundle ([90bb638](https://github.com/seuros/star_gates/commit/90bb638a78a33e4622c7ce459abbcd95bcf30bfc))
|
|
10
|
+
* a published flag value implies index membership ([3a60b40](https://github.com/seuros/star_gates/commit/3a60b4058d8ab5ce66643f479eb369c235803af4))
|
|
11
|
+
* bound the execution samples on the failure path too ([c516e97](https://github.com/seuros/star_gates/commit/c516e97542ab9d6a79c66f607c00eaa24ac3f542))
|
|
12
|
+
* check the budget before clamping it to a timeout ([6c7cc37](https://github.com/seuros/star_gates/commit/6c7cc37627adb295d30247a00c621b8956dbb765))
|
|
13
|
+
* measure latency with a t-digest instead of a trailing array ([f0e0beb](https://github.com/seuros/star_gates/commit/f0e0beb674a2bfd6097d1c104cd4cc927745bdc9))
|
|
14
|
+
* reclaim flag index slots instead of leaking them ([46002cc](https://github.com/seuros/star_gates/commit/46002ccb21188f6b8ac957bf50aaf570ae2e9cdb))
|
|
15
|
+
* replace deprecated ActiveSupport::Configurable with inheritable class config ([2a33f41](https://github.com/seuros/star_gates/commit/2a33f417f6d8d5a50e14deb2caee9b22d0fe3b1b))
|
|
16
|
+
* separate gate unavailability from the primary result ([85a1d35](https://github.com/seuros/star_gates/commit/85a1d352c0bbe2ee90923916de6d152ef7b625cb))
|
|
17
|
+
|
|
3
18
|
## [0.3.1](https://github.com/seuros/star_gates/compare/v0.3.0...v0.3.1) (2026-10-30)
|
|
4
19
|
|
|
5
20
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require 'active_support/
|
|
3
|
+
require 'active_support/ordered_options'
|
|
4
4
|
require 'active_support/core_ext/class/attribute'
|
|
5
5
|
require 'active_support/core_ext/hash/deep_merge'
|
|
6
6
|
require 'active_support/core_ext/hash/indifferent_access'
|
|
@@ -10,8 +10,6 @@ require_relative 'configuration'
|
|
|
10
10
|
|
|
11
11
|
module StarGates
|
|
12
12
|
class ApplicationStarGate < Feature
|
|
13
|
-
include ActiveSupport::Configurable
|
|
14
|
-
|
|
15
13
|
# Use ActiveSupport class attributes instead of custom implementation
|
|
16
14
|
class_attribute :feature_name
|
|
17
15
|
class_attribute :telemetry_tags, default: {}
|
|
@@ -67,7 +65,10 @@ module StarGates
|
|
|
67
65
|
end
|
|
68
66
|
end
|
|
69
67
|
|
|
70
|
-
|
|
68
|
+
def config
|
|
69
|
+
@config ||= self.class.config.inheritable_copy
|
|
70
|
+
end
|
|
71
|
+
|
|
71
72
|
def timeout
|
|
72
73
|
@merged_config[:timeout]
|
|
73
74
|
end
|
|
@@ -126,7 +127,10 @@ module StarGates
|
|
|
126
127
|
return {} unless performance_monitoring_enabled?
|
|
127
128
|
|
|
128
129
|
{
|
|
129
|
-
average_execution_time:
|
|
130
|
+
average_execution_time: average_execution_time,
|
|
131
|
+
median_execution_time: latency.quantile(0.5),
|
|
132
|
+
p95_execution_time: latency.quantile(0.95),
|
|
133
|
+
p99_execution_time: latency.quantile(0.99),
|
|
130
134
|
total_executions: @execution_count || 0,
|
|
131
135
|
error_rate: calculate_error_rate,
|
|
132
136
|
last_execution: @last_execution_time
|
|
@@ -144,8 +148,16 @@ module StarGates
|
|
|
144
148
|
)
|
|
145
149
|
end
|
|
146
150
|
|
|
147
|
-
# Class methods for configuration using ActiveSupport::Configurable
|
|
148
151
|
class << self
|
|
152
|
+
# Each class reads through to its parent's options and writes only its own.
|
|
153
|
+
def config
|
|
154
|
+
@config ||= if superclass.respond_to?(:config)
|
|
155
|
+
superclass.config.inheritable_copy
|
|
156
|
+
else
|
|
157
|
+
ActiveSupport::InheritableOptions.new
|
|
158
|
+
end
|
|
159
|
+
end
|
|
160
|
+
|
|
149
161
|
def configure(name = nil, **options)
|
|
150
162
|
self.feature_name = name if name
|
|
151
163
|
|
|
@@ -156,7 +168,6 @@ module StarGates
|
|
|
156
168
|
# Extract telemetry tags
|
|
157
169
|
self.telemetry_tags = extract_telemetry_tags(options)
|
|
158
170
|
|
|
159
|
-
# Set configuration using ActiveSupport::Configurable
|
|
160
171
|
remaining_options = options.except(*state_specific[:extracted_keys])
|
|
161
172
|
remaining_options.each do |key, value|
|
|
162
173
|
config.send("#{key}=", value)
|
|
@@ -231,7 +242,6 @@ module StarGates
|
|
|
231
242
|
end
|
|
232
243
|
|
|
233
244
|
def setup_telemetry
|
|
234
|
-
@execution_times = []
|
|
235
245
|
@execution_count = 0
|
|
236
246
|
@error_count = 0
|
|
237
247
|
@last_execution_time = nil
|
|
@@ -322,35 +332,52 @@ module StarGates
|
|
|
322
332
|
end
|
|
323
333
|
|
|
324
334
|
def with_timeout(seconds, &)
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
yield
|
|
329
|
-
end
|
|
335
|
+
DeadlineMachines.check!
|
|
336
|
+
budget = DeadlineMachines.clamp_sleep(seconds)
|
|
337
|
+
DeadlineMachines.with_deadline(budget) { Timeout.timeout(budget, &) }
|
|
330
338
|
rescue Timeout::Error
|
|
331
|
-
raise StarGates::UnavailableError, "Feature #{feature_identifier} timed out after #{
|
|
339
|
+
raise StarGates::UnavailableError, "Feature #{feature_identifier} timed out after #{budget}s"
|
|
332
340
|
end
|
|
333
341
|
|
|
334
342
|
def record_successful_execution(duration)
|
|
335
|
-
|
|
343
|
+
record_execution(duration)
|
|
344
|
+
end
|
|
336
345
|
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
@last_execution_time = Time.now
|
|
346
|
+
def record_failed_execution(duration, _error)
|
|
347
|
+
return unless performance_monitoring_enabled?
|
|
340
348
|
|
|
341
|
-
|
|
342
|
-
|
|
349
|
+
@error_count += 1
|
|
350
|
+
record_execution(duration)
|
|
343
351
|
end
|
|
344
352
|
|
|
345
|
-
|
|
353
|
+
# Cluster budget for the latency digest; error is about one part in this.
|
|
354
|
+
LATENCY_COMPRESSION = 100
|
|
355
|
+
|
|
356
|
+
def record_execution(duration)
|
|
346
357
|
return unless performance_monitoring_enabled?
|
|
347
358
|
|
|
348
|
-
|
|
359
|
+
latency.add(duration)
|
|
360
|
+
@latency_total = latency_total + duration
|
|
349
361
|
@execution_count += 1
|
|
350
|
-
@error_count += 1
|
|
351
362
|
@last_execution_time = Time.now
|
|
352
363
|
end
|
|
353
364
|
|
|
365
|
+
def average_execution_time
|
|
366
|
+
return 0 if @execution_count.nil? || @execution_count.zero?
|
|
367
|
+
|
|
368
|
+
latency_total / @execution_count
|
|
369
|
+
end
|
|
370
|
+
|
|
371
|
+
# Telemetry and performance monitoring are separate switches, so the digest
|
|
372
|
+
# is built where it is used rather than in either setup path.
|
|
373
|
+
def latency
|
|
374
|
+
@latency ||= ProbabilisticMachines::TDigest.new(compression: LATENCY_COMPRESSION)
|
|
375
|
+
end
|
|
376
|
+
|
|
377
|
+
def latency_total
|
|
378
|
+
@latency_total ||= 0.0
|
|
379
|
+
end
|
|
380
|
+
|
|
354
381
|
def calculate_error_rate
|
|
355
382
|
return 0 if @execution_count.nil? || @execution_count.zero?
|
|
356
383
|
|
data/lib/star_gates/flags.rb
CHANGED
|
@@ -5,6 +5,9 @@ module StarGates
|
|
|
5
5
|
# Runtime state uses Feature's lifecycle and is local to this process unless
|
|
6
6
|
# a shared store is configured.
|
|
7
7
|
class Flags
|
|
8
|
+
FIRST_SLOT = 1
|
|
9
|
+
CLAIM_WINNER = 1
|
|
10
|
+
|
|
8
11
|
attr_accessor :configuration
|
|
9
12
|
attr_reader :store
|
|
10
13
|
|
|
@@ -146,40 +149,86 @@ module StarGates
|
|
|
146
149
|
end
|
|
147
150
|
|
|
148
151
|
def store_update(name, enabled, metadata)
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
+
keeping_indexed(name) do
|
|
153
|
+
store_write(flag_key(name), enabled)
|
|
154
|
+
store_write(metadata_key(name), metadata.dup) if metadata
|
|
155
|
+
end
|
|
152
156
|
enabled
|
|
153
157
|
end
|
|
154
158
|
|
|
159
|
+
def keeping_indexed(name)
|
|
160
|
+
index_add(name)
|
|
161
|
+
yield
|
|
162
|
+
index_add(name)
|
|
163
|
+
end
|
|
164
|
+
|
|
155
165
|
def store_remove(name)
|
|
166
|
+
store_delete(index_remove(name))
|
|
156
167
|
store_delete([flag_key(name), metadata_key(name)])
|
|
157
168
|
end
|
|
158
169
|
|
|
159
170
|
def store_reset
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
keys
|
|
163
|
-
store_delete(keys + (slots ? slots + [index_sequence_key] : [index_key]))
|
|
171
|
+
keys = store_names.flat_map { |name| [flag_key(name), metadata_key(name)] }
|
|
172
|
+
store_delete(index_keys)
|
|
173
|
+
store_delete(keys)
|
|
164
174
|
end
|
|
165
175
|
|
|
166
176
|
def index_add(name)
|
|
167
|
-
return
|
|
168
|
-
return @mutex.synchronize { legacy_index_add(name) } unless @store.respond_to?(:increment)
|
|
177
|
+
return @mutex.synchronize { legacy_index_add(name) } unless sequenced_index?
|
|
169
178
|
|
|
170
|
-
|
|
171
|
-
|
|
179
|
+
entries = slot_entries
|
|
180
|
+
return if entries.value?(name)
|
|
181
|
+
|
|
182
|
+
store_write(index_slot_key(claim_slot(entries)), name)
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
def index_remove(name)
|
|
186
|
+
unless sequenced_index?
|
|
187
|
+
@mutex.synchronize { legacy_index_remove(name) }
|
|
188
|
+
return []
|
|
189
|
+
end
|
|
190
|
+
|
|
191
|
+
slot = slot_entries.key(name)
|
|
192
|
+
return [] unless slot
|
|
193
|
+
|
|
194
|
+
[index_slot_key(slot), slot_claim_key(slot)]
|
|
172
195
|
end
|
|
173
196
|
|
|
174
197
|
def store_names
|
|
175
|
-
|
|
176
|
-
|
|
198
|
+
sequenced_index? ? slot_entries.values.uniq : legacy_index
|
|
199
|
+
end
|
|
200
|
+
|
|
201
|
+
def index_keys
|
|
202
|
+
return [index_key] unless sequenced_index?
|
|
203
|
+
|
|
204
|
+
slot_range.flat_map { |slot| [index_slot_key(slot), slot_claim_key(slot)] } + [index_sequence_key]
|
|
205
|
+
end
|
|
206
|
+
|
|
207
|
+
def slot_entries
|
|
208
|
+
slots = slot_range.to_h { |slot| [index_slot_key(slot), slot] }
|
|
209
|
+
store_read(slots.keys).transform_keys { |key| slots.fetch(key) }
|
|
210
|
+
end
|
|
211
|
+
|
|
212
|
+
def slot_range
|
|
213
|
+
FIRST_SLOT..@store.read(index_sequence_key, raw: true).to_i
|
|
214
|
+
end
|
|
215
|
+
|
|
216
|
+
def claim_slot(entries)
|
|
217
|
+
reclaimed_slot(entries) || appended_slot
|
|
218
|
+
end
|
|
219
|
+
|
|
220
|
+
def reclaimed_slot(entries)
|
|
221
|
+
slot_range.find { |slot| !entries.key?(slot) && @store.increment(slot_claim_key(slot)) == CLAIM_WINNER }
|
|
177
222
|
end
|
|
178
223
|
|
|
179
|
-
def
|
|
180
|
-
|
|
224
|
+
def appended_slot
|
|
225
|
+
slot = @store.increment(index_sequence_key)
|
|
226
|
+
@store.increment(slot_claim_key(slot))
|
|
227
|
+
slot
|
|
228
|
+
end
|
|
181
229
|
|
|
182
|
-
|
|
230
|
+
def sequenced_index?
|
|
231
|
+
@store.respond_to?(:increment)
|
|
183
232
|
end
|
|
184
233
|
|
|
185
234
|
def legacy_index_add(name)
|
|
@@ -187,6 +236,11 @@ module StarGates
|
|
|
187
236
|
store_write(index_key, names + [name]) unless names.include?(name)
|
|
188
237
|
end
|
|
189
238
|
|
|
239
|
+
def legacy_index_remove(name)
|
|
240
|
+
names = legacy_index
|
|
241
|
+
store_write(index_key, names - [name]) if names.include?(name)
|
|
242
|
+
end
|
|
243
|
+
|
|
190
244
|
def legacy_index
|
|
191
245
|
names = @store.read(index_key)
|
|
192
246
|
names.is_a?(Array) ? names : []
|
|
@@ -241,6 +295,10 @@ module StarGates
|
|
|
241
295
|
"#{@prefix}:name:#{slot}"
|
|
242
296
|
end
|
|
243
297
|
|
|
298
|
+
def slot_claim_key(slot)
|
|
299
|
+
"#{@prefix}:name_claim:#{slot}"
|
|
300
|
+
end
|
|
301
|
+
|
|
244
302
|
def configuration_flags
|
|
245
303
|
values = configuration.is_a?(Proc) ? configuration.call : configuration
|
|
246
304
|
raise ArgumentError, 'configuration must be a Hash or a Proc returning a Hash' unless values.is_a?(Hash)
|
data/lib/star_gates/gate.rb
CHANGED
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
module StarGates
|
|
4
4
|
class Gate
|
|
5
|
+
UNAVAILABLE = Object.new
|
|
6
|
+
private_constant :UNAVAILABLE
|
|
7
|
+
|
|
5
8
|
attr_reader :name, :feature, :circuit, :run_block, :fallback_block
|
|
6
9
|
|
|
7
10
|
def initialize(name, feature: nil, circuit: nil, run_block: nil, fallback_block: nil)
|
|
@@ -13,30 +16,15 @@ module StarGates
|
|
|
13
16
|
end
|
|
14
17
|
|
|
15
18
|
def call(context = {})
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
else
|
|
21
|
-
feature.execute(context) { execute_run_block(context) }
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
# If feature returns nil (disabled), execute fallback
|
|
25
|
-
return result unless result.nil?
|
|
26
|
-
|
|
27
|
-
execute_fallback(context)
|
|
28
|
-
else
|
|
29
|
-
# Fallback to old behavior for compatibility
|
|
30
|
-
return execute_fallback(context) unless feature_enabled?(context)
|
|
31
|
-
|
|
32
|
-
if circuit
|
|
33
|
-
circuit.call { execute_run_block(context) }
|
|
34
|
-
else
|
|
35
|
-
execute_run_block(context)
|
|
36
|
-
end
|
|
19
|
+
result = begin
|
|
20
|
+
execute_primary(context)
|
|
21
|
+
rescue StandardError
|
|
22
|
+
UNAVAILABLE
|
|
37
23
|
end
|
|
38
|
-
|
|
39
|
-
execute_fallback(context)
|
|
24
|
+
|
|
25
|
+
return execute_fallback(context) if result.equal?(UNAVAILABLE)
|
|
26
|
+
|
|
27
|
+
result
|
|
40
28
|
end
|
|
41
29
|
|
|
42
30
|
def enabled_for?(context = {})
|
|
@@ -54,7 +42,7 @@ module StarGates
|
|
|
54
42
|
def status
|
|
55
43
|
{
|
|
56
44
|
name: name,
|
|
57
|
-
feature_enabled: feature
|
|
45
|
+
feature_enabled: feature.nil? || feature.enabled?,
|
|
58
46
|
feature_status: feature.respond_to?(:status) ? feature.status : nil,
|
|
59
47
|
circuit_open: circuit&.open? || false,
|
|
60
48
|
last_failure: circuit&.last_failure_time
|
|
@@ -63,6 +51,29 @@ module StarGates
|
|
|
63
51
|
|
|
64
52
|
private
|
|
65
53
|
|
|
54
|
+
def execute_primary(context)
|
|
55
|
+
return execute_feature(context) if feature.respond_to?(:execute)
|
|
56
|
+
return UNAVAILABLE unless feature_enabled?(context)
|
|
57
|
+
|
|
58
|
+
with_circuit { execute_run_block(context) }
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def execute_feature(context)
|
|
62
|
+
executed = false
|
|
63
|
+
result = with_circuit do
|
|
64
|
+
feature.execute(context) do
|
|
65
|
+
executed = true
|
|
66
|
+
execute_run_block(context)
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
executed ? result : UNAVAILABLE
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def with_circuit(&block)
|
|
74
|
+
circuit ? circuit.call(&block) : block.call
|
|
75
|
+
end
|
|
76
|
+
|
|
66
77
|
def feature_enabled?(context)
|
|
67
78
|
return true unless feature
|
|
68
79
|
|
data/lib/star_gates/version.rb
CHANGED
data/lib/star_gates.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: star_gates
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.3.
|
|
4
|
+
version: 0.3.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Abdelkader Boudih
|
|
@@ -79,6 +79,34 @@ dependencies:
|
|
|
79
79
|
- - ">="
|
|
80
80
|
- !ruby/object:Gem::Version
|
|
81
81
|
version: 0.22.1
|
|
82
|
+
- !ruby/object:Gem::Dependency
|
|
83
|
+
name: deadline_machines
|
|
84
|
+
requirement: !ruby/object:Gem::Requirement
|
|
85
|
+
requirements:
|
|
86
|
+
- - ">="
|
|
87
|
+
- !ruby/object:Gem::Version
|
|
88
|
+
version: '0.1'
|
|
89
|
+
type: :runtime
|
|
90
|
+
prerelease: false
|
|
91
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
92
|
+
requirements:
|
|
93
|
+
- - ">="
|
|
94
|
+
- !ruby/object:Gem::Version
|
|
95
|
+
version: '0.1'
|
|
96
|
+
- !ruby/object:Gem::Dependency
|
|
97
|
+
name: probabilistic_machines
|
|
98
|
+
requirement: !ruby/object:Gem::Requirement
|
|
99
|
+
requirements:
|
|
100
|
+
- - ">="
|
|
101
|
+
- !ruby/object:Gem::Version
|
|
102
|
+
version: '0.1'
|
|
103
|
+
type: :runtime
|
|
104
|
+
prerelease: false
|
|
105
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
106
|
+
requirements:
|
|
107
|
+
- - ">="
|
|
108
|
+
- !ruby/object:Gem::Version
|
|
109
|
+
version: '0.1'
|
|
82
110
|
- !ruby/object:Gem::Dependency
|
|
83
111
|
name: chrono_machines
|
|
84
112
|
requirement: !ruby/object:Gem::Requirement
|