star_gates 0.3.1 → 0.4.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/.release-please-manifest.json +1 -1
- data/CHANGELOG.md +26 -0
- data/README.md +86 -22
- data/Rakefile +6 -1
- data/lib/star_gates/adapters/base_adapter.rb +2 -0
- data/lib/star_gates/adapters/redis_adapter.rb +15 -10
- data/lib/star_gates/application_star_gate.rb +107 -117
- data/lib/star_gates/circuit.rb +74 -109
- data/lib/star_gates/configuration.rb +26 -9
- data/lib/star_gates/dsl.rb +7 -10
- data/lib/star_gates/errors.rb +15 -3
- data/lib/star_gates/event_store/event_store.rb +6 -16
- data/lib/star_gates/event_store/memory_adapter.rb +7 -1
- data/lib/star_gates/events/base_event.rb +3 -1
- data/lib/star_gates/feature.rb +36 -60
- data/lib/star_gates/flags.rb +102 -25
- data/lib/star_gates/gate.rb +58 -46
- data/lib/star_gates/hexagonal/feature_aggregate.rb +49 -55
- data/lib/star_gates/hexagonal/feature_repository.rb +5 -27
- data/lib/star_gates/hexagonal/feature_service.rb +31 -33
- data/lib/star_gates/jsonrpc_rails_adapter.rb +24 -7
- data/lib/star_gates/projections/feature_projection.rb +40 -13
- data/lib/star_gates/registry.rb +3 -2
- data/lib/star_gates/retry_policy.rb +23 -0
- data/lib/star_gates/rollout.rb +15 -0
- data/lib/star_gates/telemetry/opentelemetry_adapter.rb +71 -75
- data/lib/star_gates/telemetry/prometheus_adapter.rb +82 -74
- data/lib/star_gates/telemetry/telemetry_adapter.rb +16 -15
- data/lib/star_gates/version.rb +1 -1
- data/lib/star_gates.rb +56 -58
- data/sig/star_gates.rbs +832 -0
- metadata +42 -10
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 9a3fe73641b898c85b2bcd78bafd6e5c6d4d455ca744101e6fe725e4fecc0d8a
|
|
4
|
+
data.tar.gz: f1bdb83dfa873a2965193b2cc171785fd8dcf78ce0b3cddf4198d7a407661d14
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d88faf515d89d1cbb79d29ec640e96c94135980245219beafb0c2e8557e8584cb8df43330a2c03747bd290c97420bcf404f642ccf18007320298ad113a13b47e
|
|
7
|
+
data.tar.gz: c1d54c6f0e1a26727a3be804c8ef432908f8a5c3faf137b8168964eb04b5aaba67c26e3c0a0db564ce4ece9c2f19373c61439d10be46b11222784a81eb423ce8
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,31 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.4.0](https://github.com/seuros/star_gates/compare/v0.3.2...v0.4.0) (2026-11-16)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### ⚠ BREAKING CHANGES
|
|
7
|
+
|
|
8
|
+
* run on the released fleet cores in Integer nanoseconds
|
|
9
|
+
|
|
10
|
+
### Features
|
|
11
|
+
|
|
12
|
+
* run on the released fleet cores in Integer nanoseconds ([1c51494](https://github.com/seuros/star_gates/commit/1c514944cfdfcfc58b82c2b77b54afb9a4a22473))
|
|
13
|
+
|
|
14
|
+
## [0.3.2](https://github.com/seuros/star_gates/compare/v0.3.1...v0.3.2) (2026-11-08)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
### Bug Fixes
|
|
18
|
+
|
|
19
|
+
* a feature timeout can no longer outlive the caller ([d9c108f](https://github.com/seuros/star_gates/commit/d9c108f1f47fd912ffed097ef9e70fff41078f35))
|
|
20
|
+
* a lone checkout can bundle ([90bb638](https://github.com/seuros/star_gates/commit/90bb638a78a33e4622c7ce459abbcd95bcf30bfc))
|
|
21
|
+
* a published flag value implies index membership ([3a60b40](https://github.com/seuros/star_gates/commit/3a60b4058d8ab5ce66643f479eb369c235803af4))
|
|
22
|
+
* bound the execution samples on the failure path too ([c516e97](https://github.com/seuros/star_gates/commit/c516e97542ab9d6a79c66f607c00eaa24ac3f542))
|
|
23
|
+
* check the budget before clamping it to a timeout ([6c7cc37](https://github.com/seuros/star_gates/commit/6c7cc37627adb295d30247a00c621b8956dbb765))
|
|
24
|
+
* measure latency with a t-digest instead of a trailing array ([f0e0beb](https://github.com/seuros/star_gates/commit/f0e0beb674a2bfd6097d1c104cd4cc927745bdc9))
|
|
25
|
+
* reclaim flag index slots instead of leaking them ([46002cc](https://github.com/seuros/star_gates/commit/46002ccb21188f6b8ac957bf50aaf570ae2e9cdb))
|
|
26
|
+
* replace deprecated ActiveSupport::Configurable with inheritable class config ([2a33f41](https://github.com/seuros/star_gates/commit/2a33f417f6d8d5a50e14deb2caee9b22d0fe3b1b))
|
|
27
|
+
* separate gate unavailability from the primary result ([85a1d35](https://github.com/seuros/star_gates/commit/85a1d352c0bbe2ee90923916de6d152ef7b625cb))
|
|
28
|
+
|
|
3
29
|
## [0.3.1](https://github.com/seuros/star_gates/compare/v0.3.0...v0.3.1) (2026-10-30)
|
|
4
30
|
|
|
5
31
|
|
data/README.md
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
# StarGates
|
|
2
2
|
|
|
3
3
|
[](https://badge.fury.io/rb/star_gates)
|
|
4
|
-
[](https://github.com/seuros/star_gates/actions/workflows/test.yml)
|
|
5
5
|
|
|
6
6
|
Feature flags, gradual rollouts, and circuit-protected execution for Ruby.
|
|
7
7
|
StarGates uses StateMachines for feature transitions, BreakerMachines for circuit
|
|
8
|
-
protection, and
|
|
8
|
+
protection, ChronoMachines for retries, and DeadlineMachines for time budgets.
|
|
9
|
+
|
|
10
|
+
Time is Integer nanoseconds throughout: timeouts, cooldowns, backoffs, execution
|
|
11
|
+
times, and every reported instant (`StarGates.monotonic_time`; event-sourced events
|
|
12
|
+
use wall-clock nanoseconds, `StarGates.wall_time`). Wrong types raise `TypeError`,
|
|
13
|
+
values out of range `RangeError`.
|
|
9
14
|
|
|
10
15
|
## Installation
|
|
11
16
|
|
|
@@ -34,7 +39,9 @@ StarGates.flags.reset!
|
|
|
34
39
|
|
|
35
40
|
Precedence: nonblank `FEATURE_<NAME>` environment variable, boolean configuration,
|
|
36
41
|
runtime override, then `false`. Names are case-insensitive; dashes become underscores.
|
|
37
|
-
Truthy strings are `true`, `1`, `yes`, and `on` (case-insensitive).
|
|
42
|
+
Truthy strings are `true`, `1`, `yes`, and `on` (case-insensitive). A flag name is a
|
|
43
|
+
String or Symbol of letters, digits, `_`, or `-`: another type raises `TypeError`, another
|
|
44
|
+
String `RangeError`.
|
|
38
45
|
|
|
39
46
|
For Rails, keep defaults explicit and resolve them lazily:
|
|
40
47
|
|
|
@@ -61,7 +68,9 @@ blindly; `prefix` (default `star_gates:flags`) namespaces them. A failed write r
|
|
|
61
68
|
`StarGates::Error`, and a value the store cannot return counts as no runtime override.
|
|
62
69
|
Listing (`all`, `enabled_flags`, `summary`) and `reset!` use a shared name index. Each new
|
|
63
70
|
name takes its own slot from an atomic `increment`, so workers adding flags at the same
|
|
64
|
-
moment never drop each other's names
|
|
71
|
+
moment never drop each other's names; an `increment` that answers no Integer
|
|
72
|
+
(`NullStore` answers nil) raises `StarGates::Error` before anything is written. Stores
|
|
73
|
+
without `increment` fall back to a
|
|
65
74
|
read-modify-write list, where a concurrent addition can drop a name from listings until
|
|
66
75
|
that flag next changes; lookups by name are unaffected either way. `reset!` and `remove`
|
|
67
76
|
clear runtime state and metadata, not environment/configuration. Switching `store` drops
|
|
@@ -71,10 +80,18 @@ process-local runtime state.
|
|
|
71
80
|
## Gates and rollouts
|
|
72
81
|
|
|
73
82
|
```ruby
|
|
83
|
+
NS_PER_SECOND = 1_000_000_000
|
|
84
|
+
|
|
85
|
+
# Open after 3 failures within a minute; probe again after 30 seconds.
|
|
86
|
+
PAYMENTS_POLICY = BreakerMachines::Policy.new(
|
|
87
|
+
BreakerMachines::Threshold.new(3, nil, 0), 60 * NS_PER_SECOND,
|
|
88
|
+
BreakerMachines::Recovery.new(30 * NS_PER_SECOND, 0.0, 1, 1), nil
|
|
89
|
+
)
|
|
90
|
+
|
|
74
91
|
StarGates.define do
|
|
75
92
|
gate :payments do
|
|
76
93
|
feature rollout: 25.percent
|
|
77
|
-
circuit
|
|
94
|
+
circuit PAYMENTS_POLICY
|
|
78
95
|
|
|
79
96
|
run { |context| PaymentAPI.charge(context[:amount]) }
|
|
80
97
|
fallback { |context| LegacyPaymentAPI.charge(context[:amount]) }
|
|
@@ -87,7 +104,11 @@ gate.call(key: 'account:42', amount: 100)
|
|
|
87
104
|
```
|
|
88
105
|
|
|
89
106
|
Features start disabled. Use `rollout_canary` for percentage/group targeting,
|
|
90
|
-
`enable` for full rollout, and `disable` to turn a feature off.
|
|
107
|
+
`enable` for full rollout, and `disable` to turn a feature off. An event
|
|
108
|
+
answers the performed transition, or `false` when refused, with the reason in
|
|
109
|
+
`<event>_refusal` (`gate.feature.disable_refusal # => :no_transition`); the
|
|
110
|
+
bang forms (`enable!`, ...) raise `StateMachines::InvalidTransition` carrying
|
|
111
|
+
it in `#reason`. Pass a stable
|
|
91
112
|
string or integer `key:` for percentage targeting, such as an account, resident,
|
|
92
113
|
or device identifier.
|
|
93
114
|
|
|
@@ -98,27 +119,55 @@ For group targeting, pass `groups: [:beta]` to match `feature group: :beta`.
|
|
|
98
119
|
A predicate such as `feature group: ->(context) { context[:region] == 'eu' }`
|
|
99
120
|
receives the full context passed to the gate.
|
|
100
121
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
122
|
+
A rollout is an Integer percentage, 0..100; a group is a Symbol or a Proc.
|
|
123
|
+
|
|
124
|
+
`circuit` takes a `BreakerMachines::Policy` and an optional `StarGates::RetryPolicy`,
|
|
125
|
+
positionally, as `StarGates::Circuit.new(policy, retry_policy, feature:, auto_rollback:)`
|
|
126
|
+
does; `feature:` and `auto_rollback:` are runtime-only. When a circuit opens, its
|
|
127
|
+
feature rolls back from enabled to canary, or from canary to disabled.
|
|
128
|
+
|
|
129
|
+
Gates use their fallback when the primary is unavailable. Without a fallback, `call`
|
|
130
|
+
raises `StarGates::UnavailableError`, whose `refusal` says why: `:ineligible` (the
|
|
131
|
+
feature is off for this context), `:failed` (the primary raised; it is the `cause`),
|
|
132
|
+
`:exceeded` (the time budget ran out), or the circuit's own refusal (`:open`, `:busy`,
|
|
133
|
+
`:full`).
|
|
105
134
|
|
|
106
135
|
### Retries
|
|
107
136
|
|
|
108
|
-
|
|
137
|
+
A `RetryPolicy` is a ChronoMachines strategy and an attempt budget that counts the
|
|
138
|
+
first try, in `ChronoMachines::Retry`'s order:
|
|
109
139
|
|
|
110
140
|
```ruby
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
retry_config: {
|
|
114
|
-
max_attempts: 3,
|
|
115
|
-
base_delay: 0.1,
|
|
116
|
-
multiplier: 2,
|
|
117
|
-
max_delay: 5
|
|
118
|
-
}
|
|
141
|
+
backoff = ChronoMachines::Exponential.new(100_000_000, 2.0, 5 * NS_PER_SECOND, 1.0)
|
|
142
|
+
circuit PAYMENTS_POLICY, StarGates::RetryPolicy.new(backoff, 3)
|
|
119
143
|
```
|
|
120
144
|
|
|
121
|
-
Retries are opt-in
|
|
145
|
+
Retries are opt-in. A call the circuit refuses is never retried: the refusal is the
|
|
146
|
+
answer. Exhausted retries re-raise the last exception.
|
|
147
|
+
|
|
148
|
+
### Timeouts
|
|
149
|
+
|
|
150
|
+
`ApplicationStarGate` features take `timeout:` in Integer nanoseconds, narrowed by
|
|
151
|
+
the ambient `DeadlineMachines` budget. A spent budget does not run the block.
|
|
152
|
+
|
|
153
|
+
### Event sourcing
|
|
154
|
+
|
|
155
|
+
`StarGates.configure_foundation` wires an event store, repository, and projection.
|
|
156
|
+
Commands answer the aggregate or a refusal symbol and change nothing:
|
|
157
|
+
`:not_found`, `:invalid_transition`, `:stale_state` (the feature is not in the
|
|
158
|
+
`from_state` given), `:version_conflict` (a concurrent writer saved first).
|
|
159
|
+
States and event names are Symbols; a String is a `TypeError` and changes nothing.
|
|
160
|
+
The projection reads the same through any adapter (Symbol keys and state names, even
|
|
161
|
+
from Redis's JSON). `StarGates.recent_transitions` answers
|
|
162
|
+
`{ transitions:, total_found:, limit:, generated_at: }` with event sourcing on or off,
|
|
163
|
+
and every transition is `{ feature:, from:, to:, event:, occurred_at: }` in both
|
|
164
|
+
modes: `feature` the String feature id (the gate name without event sourcing),
|
|
165
|
+
`from`, `to` and `event` Symbols, `occurred_at` wall-clock Integer nanoseconds.
|
|
166
|
+
|
|
167
|
+
With jsonrpc-rails, include `StarGates::JsonrpcRailsAdapter` in a controller and route
|
|
168
|
+
to its `handle_jsonrpc` action (`post '/jsonrpc', to: 'features#handle_jsonrpc'`). The
|
|
169
|
+
adapter defines no method Rails' controllers already have, so `process` and the rest of
|
|
170
|
+
the dispatch stay Rails'.
|
|
122
171
|
|
|
123
172
|
## Rails
|
|
124
173
|
|
|
@@ -147,7 +196,9 @@ end
|
|
|
147
196
|
```
|
|
148
197
|
|
|
149
198
|
Circuit events include `circuit.auto_rollback`, `circuit.half_open`,
|
|
150
|
-
`circuit.recovered`, and `circuit.retry
|
|
199
|
+
`circuit.recovered`, and `circuit.retry` (`next_delay` in nanoseconds), prefixed with
|
|
200
|
+
`star_gates.`. Telemetry adapters take durations in nanoseconds; the Prometheus
|
|
201
|
+
adapter reports seconds, its base unit.
|
|
151
202
|
|
|
152
203
|
## Examples
|
|
153
204
|
|
|
@@ -188,7 +239,6 @@ ship.engage_warp('Alpha Centauri', key: 'crew:1', groups: [:pilots])
|
|
|
188
239
|
- [Transition history](test/dummy/demos/transition_demo.rb): recorded feature transitions.
|
|
189
240
|
- [Introspection](test/dummy/demos/introspection_demo.rb): status, analytics, and context simulation.
|
|
190
241
|
- [Application payment feature](test/dummy/demos/application_payment_feature.rb): application-level features.
|
|
191
|
-
- [JSON-RPC controller](test/dummy/demos/jsonrpc_rails_controller.rb): optional JSON-RPC integration.
|
|
192
242
|
|
|
193
243
|
Run standalone examples from the repository root:
|
|
194
244
|
|
|
@@ -202,9 +252,15 @@ bundle exec ruby test/dummy/demos/payment_feature.rb
|
|
|
202
252
|
bin/setup
|
|
203
253
|
bundle exec rake test
|
|
204
254
|
bundle exec rake test:rails
|
|
255
|
+
bundle exec rake rbs
|
|
205
256
|
dictator lint .
|
|
206
257
|
```
|
|
207
258
|
|
|
259
|
+
The Gemfile resolves released sibling gems. To test against sibling checkouts, put
|
|
260
|
+
`gem 'breaker_machines', path: '../breaker_machines'` (and the others) in an
|
|
261
|
+
untracked `Gemfile.local`, which the Gemfile evaluates when present, and compile each
|
|
262
|
+
sibling's extension in its own tree first (`bundle exec rake compile`).
|
|
263
|
+
|
|
208
264
|
Tests run with padded_cell and Minitest 6. Gem tests and Rails integration tests
|
|
209
265
|
run in separate processes. `bundle exec rake` runs both suites. To select gem tests
|
|
210
266
|
directly or pass runner options:
|
|
@@ -216,6 +272,14 @@ bundle exec rake test TESTOPTS='-j 4 --seed 1234'
|
|
|
216
272
|
|
|
217
273
|
See [CHANGELOG.md](CHANGELOG.md) for release history.
|
|
218
274
|
|
|
275
|
+
## 📡 Credits
|
|
276
|
+
|
|
277
|
+
**AMS Fowler**, NCC-2010, *Fowler*-class gatekeeper.
|
|
278
|
+
|
|
279
|
+
Named for Martin Fowler's *FeatureToggle* (2010), the note that gave feature
|
|
280
|
+
flags a name and the warning that came with it: every toggle is debt until it
|
|
281
|
+
is removed.
|
|
282
|
+
|
|
219
283
|
## License
|
|
220
284
|
|
|
221
285
|
[BSD-3-Clause](LICENSE.txt).
|
data/Rakefile
CHANGED
|
@@ -4,12 +4,18 @@ require_relative 'base_adapter'
|
|
|
4
4
|
|
|
5
5
|
module StarGates
|
|
6
6
|
module Adapters
|
|
7
|
+
# TTLs (`default_ttl`, `expires_in:`) are Integer nanoseconds, rounded up
|
|
8
|
+
# to Redis's milliseconds at the boundary.
|
|
7
9
|
class RedisAdapter < BaseAdapter
|
|
10
|
+
NS_PER_MS = 1_000_000
|
|
11
|
+
DEFAULT_TTL = 3600 * 1_000_000_000
|
|
12
|
+
private_constant :NS_PER_MS, :DEFAULT_TTL
|
|
13
|
+
|
|
8
14
|
def initialize(config = {})
|
|
9
15
|
super
|
|
10
16
|
@redis = config[:redis] || redis_from_config
|
|
11
17
|
@key_prefix = config[:key_prefix] || 'star_gates'
|
|
12
|
-
@default_ttl = config[:default_ttl] ||
|
|
18
|
+
@default_ttl = config[:default_ttl] || DEFAULT_TTL
|
|
13
19
|
end
|
|
14
20
|
|
|
15
21
|
def store(key, value)
|
|
@@ -27,7 +33,7 @@ module StarGates
|
|
|
27
33
|
end
|
|
28
34
|
|
|
29
35
|
def exists?(key)
|
|
30
|
-
@redis.exists
|
|
36
|
+
@redis.exists(prefixed_key(key)).positive?
|
|
31
37
|
end
|
|
32
38
|
|
|
33
39
|
def cache_fetch(key, expires_in: nil, &block)
|
|
@@ -38,19 +44,13 @@ module StarGates
|
|
|
38
44
|
deserialize(cached)
|
|
39
45
|
elsif block_given?
|
|
40
46
|
value = block.call
|
|
41
|
-
if value
|
|
42
|
-
serialized = serialize(value)
|
|
43
|
-
ttl = expires_in || @default_ttl
|
|
44
|
-
@redis.setex(prefixed, ttl, serialized)
|
|
45
|
-
end
|
|
47
|
+
write_expiring(prefixed, value, expires_in) if value
|
|
46
48
|
value
|
|
47
49
|
end
|
|
48
50
|
end
|
|
49
51
|
|
|
50
52
|
def cache_write(key, value, expires_in: nil)
|
|
51
|
-
|
|
52
|
-
ttl = expires_in || @default_ttl
|
|
53
|
-
@redis.setex(prefixed_key(key), ttl, serialized)
|
|
53
|
+
write_expiring(prefixed_key(key), value, expires_in)
|
|
54
54
|
end
|
|
55
55
|
|
|
56
56
|
def cache_delete(key)
|
|
@@ -79,6 +79,11 @@ module StarGates
|
|
|
79
79
|
|
|
80
80
|
private
|
|
81
81
|
|
|
82
|
+
def write_expiring(key, value, expires_in)
|
|
83
|
+
ttl = expires_in || @default_ttl
|
|
84
|
+
@redis.set(key, serialize(value), px: (ttl + NS_PER_MS - 1) / NS_PER_MS)
|
|
85
|
+
end
|
|
86
|
+
|
|
82
87
|
def prefixed_key(key)
|
|
83
88
|
"#{@key_prefix}:#{key}"
|
|
84
89
|
end
|