satee-openfeature-provider 0.2.0 → 0.3.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/CHANGELOG.md +21 -0
- data/README.md +70 -7
- data/lib/satee/openfeature/provider/bucket.rb +34 -0
- data/lib/satee/openfeature/provider/flag.rb +6 -1
- data/lib/satee/openfeature/provider/flag_file.rb +22 -6
- data/lib/satee/openfeature/provider/murmur3.rb +54 -0
- data/lib/satee/openfeature/provider/targeting_key.rb +21 -0
- data/lib/satee/openfeature/provider/version.rb +1 -1
- data/lib/satee/openfeature/provider.rb +17 -4
- data/sig/satee/openfeature/provider/bucket.rbs +15 -0
- data/sig/satee/openfeature/provider/flag.rbs +3 -2
- data/sig/satee/openfeature/provider/flag_file.rbs +2 -0
- data/sig/satee/openfeature/provider/murmur3.rbs +21 -0
- data/sig/satee/openfeature/provider/targeting_key.rbs +9 -0
- data/sig/satee/openfeature/provider.rbs +3 -1
- metadata +7 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c68b16b1da341f2b72b7b94423fbdb3b33ddca8fc76a0fead750d8ca0077f942
|
|
4
|
+
data.tar.gz: bb87d303f371765f72fbbc365ea437c25500d221742b424be19567c5c283ad0e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 7be485213aa6db6c59c2643481406e1db9d39c5d50f26e3f7fd8485de1336f2e8184a630c9ea6d90ab50324a7a2802f75e3140b07a48b25685b6f583eb251639
|
|
7
|
+
data.tar.gz: a949ef8fa3a4a355cc18c50354b5bdb1a5c5064bd253d12b62d51482c45c57202b4e983ea8a1ea53e21e738c919f7080c4647f1d4410e7b270a6683079d35a47
|
data/CHANGELOG.md
CHANGED
|
@@ -1 +1,22 @@
|
|
|
1
1
|
Release notes are on [GitHub Releases](https://github.com/satee-dev/satee-openfeature-provider-ruby/releases).
|
|
2
|
+
|
|
3
|
+
## 0.3.0
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
|
|
7
|
+
- **Percentage rollouts.** A flag rolled out to a share of users is on for the targeting keys whose bucket is below
|
|
8
|
+
the share, with the reason `TARGETING_MATCH`. Buckets come from the flag key and the targeting key, so a user gets
|
|
9
|
+
the same answer every time, in every process and every Satee provider, each flag buckets on its own, and raising the
|
|
10
|
+
share keeps everyone who already had the flag. A rollout is close to N% of users, not exactly N%.
|
|
11
|
+
- Without a targeting key, or with an empty one or one that is not a string, a rolled-out flag returns `false`, the
|
|
12
|
+
`off` variant, with the reason `DEFAULT` and no error code, so a caller's default can't turn the rollout on for
|
|
13
|
+
every keyless request. Pass `targeting_key` in the evaluation context; see the README for a Rails example.
|
|
14
|
+
- `PROVIDER_CONFIGURATION_CHANGED` also names an enabled flag whose rollout share changed, or that was rolled out or
|
|
15
|
+
whose rollout ended.
|
|
16
|
+
|
|
17
|
+
### Changed
|
|
18
|
+
|
|
19
|
+
- **Reads the `/v2/` flag file** instead of `/v1/`. Releases before this one keep working on the `/v1/` file, but see a
|
|
20
|
+
rolled-out flag as off for everyone.
|
|
21
|
+
|
|
22
|
+
Passes the Satee provider conformance suite v0.6.0.
|
data/README.md
CHANGED
|
@@ -57,7 +57,9 @@ the key, the path ID or the flag file URL; a line names the key only by its last
|
|
|
57
57
|
|
|
58
58
|
Every Satee flag is boolean. Reading a flag is a lookup in memory. Once flags have loaded:
|
|
59
59
|
|
|
60
|
-
- A flag returns the value of its default variant, `on` (`true`) or `off` (`false`), with the reason `STATIC`.
|
|
60
|
+
- A flag that is not rolled out returns the value of its default variant, `on` (`true`) or `off` (`false`), with the reason `STATIC`.
|
|
61
|
+
- A flag rolled out to a share of users returns `on` or `off` by the targeting key you pass, with the reason
|
|
62
|
+
`TARGETING_MATCH`, or `off` with the reason `DEFAULT` without one. See [Percentage rollouts](#percentage-rollouts).
|
|
61
63
|
- A flag that is not held returns the default you passed, with the error code `FLAG_NOT_FOUND`.
|
|
62
64
|
- A disabled flag returns the default you passed, with the reason `DISABLED` and no error code.
|
|
63
65
|
- Reading an enabled flag with a getter other than `fetch_boolean_value` or `fetch_boolean_details` returns the default
|
|
@@ -65,6 +67,64 @@ Every Satee flag is boolean. Reading a flag is a lookup in memory. Once flags ha
|
|
|
65
67
|
|
|
66
68
|
Before any flags have loaded, every flag returns the default you passed, with the error code `PROVIDER_NOT_READY`.
|
|
67
69
|
|
|
70
|
+
## Percentage rollouts
|
|
71
|
+
|
|
72
|
+
A flag can be on for a share of your users, such as 10%. Pass a stable ID for the user, such as their account ID, as
|
|
73
|
+
the targeting key:
|
|
74
|
+
|
|
75
|
+
```ruby
|
|
76
|
+
context = OpenFeature::SDK::EvaluationContext.new(targeting_key: user.id.to_s)
|
|
77
|
+
flags.fetch_boolean_value(flag_key: "new-checkout", default_value: false, evaluation_context: context)
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
The provider hashes the flag key together with the targeting key into one of 100 buckets, and the flag is on for the
|
|
81
|
+
keys whose bucket is below the share. It works this out in memory, with no request. So:
|
|
82
|
+
|
|
83
|
+
- It is sticky. The same targeting key always gets the same answer for a flag, in every process, and in every Satee
|
|
84
|
+
provider, whatever its language.
|
|
85
|
+
- Raising the share keeps every user who already had the flag on and adds more. Lowering it only turns users off.
|
|
86
|
+
- Each flag buckets on its own. Two flags at 10% are on for two different sets of users, not the same 10%.
|
|
87
|
+
- A rollout is close to N%, not exactly N%. Each key lands in a bucket by its hash, so of 10,000 users at 10%, about
|
|
88
|
+
1,000 get the flag. With fewer users the count strays further.
|
|
89
|
+
|
|
90
|
+
The targeting key is hashed as its UTF-8 bytes, exactly as given. It isn't trimmed, case-folded or
|
|
91
|
+
Unicode-normalized, so `User-1` and `user-1` are two users. A key in another encoding is converted to UTF-8 first, so
|
|
92
|
+
the same text gets the same answer whatever encoding it is held in. A binary (`ASCII-8BIT`) key's bytes are read as
|
|
93
|
+
UTF-8. A key that is not valid text in its encoding counts as missing.
|
|
94
|
+
|
|
95
|
+
### Without a targeting key
|
|
96
|
+
|
|
97
|
+
When the targeting key is missing, empty, not a string or not valid text, a rolled-out flag returns `false`, the `off` variant, with
|
|
98
|
+
the reason `DEFAULT` and no error code, whatever default you passed. A number is not a string, so pass a numeric ID
|
|
99
|
+
with `to_s`. The flag doesn't return an error here because OpenFeature replaces the value with your default on an
|
|
100
|
+
error: a caller passing `default_value: true` would then turn a 10% rollout on for every request without a key.
|
|
101
|
+
|
|
102
|
+
Satee writes a flag at 0% as off and at 100% as on for everyone, so going from 99% to 100% turns the flag on for
|
|
103
|
+
callers without a key too.
|
|
104
|
+
|
|
105
|
+
### Rails
|
|
106
|
+
|
|
107
|
+
Pass the signed-in user's ID with every read. Signed-out visitors have no key, so they get `off`:
|
|
108
|
+
|
|
109
|
+
```ruby
|
|
110
|
+
class ApplicationController < ActionController::Base
|
|
111
|
+
helper_method :feature_enabled?
|
|
112
|
+
|
|
113
|
+
private
|
|
114
|
+
|
|
115
|
+
def feature_enabled?(flag_key)
|
|
116
|
+
context = OpenFeature::SDK::EvaluationContext.new(targeting_key: current_user&.id&.to_s)
|
|
117
|
+
OpenFeature::SDK.build_client.fetch_boolean_value(flag_key:, default_value: false, evaluation_context: context)
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
### Older releases
|
|
123
|
+
|
|
124
|
+
The provider reads the `/v2/` flag file, which carries rollouts. Older releases read the `/v1/` file, which Satee
|
|
125
|
+
still publishes. They keep working, but they see a rolled-out flag as off for everyone. Upgrade every app that reads
|
|
126
|
+
a rolled-out flag.
|
|
127
|
+
|
|
68
128
|
## Polling and changes
|
|
69
129
|
|
|
70
130
|
The provider polls every `poll_interval` seconds with the flag file's ETag, so an unchanged file costs a `304`. A new
|
|
@@ -80,7 +140,7 @@ OpenFeature::SDK.add_handler(OpenFeature::SDK::ProviderEvent::PROVIDER_CONFIGURA
|
|
|
80
140
|
```
|
|
81
141
|
|
|
82
142
|
A key counts as changed when it was added or removed, was enabled or disabled, or is enabled and its default variant
|
|
83
|
-
changed.
|
|
143
|
+
changed, its rollout share changed, or it was rolled out or its rollout ended.
|
|
84
144
|
|
|
85
145
|
## When Satee is down
|
|
86
146
|
|
|
@@ -219,21 +279,24 @@ pinned to one commit. Every check in it runs as part of RSpec.
|
|
|
219
279
|
|
|
220
280
|
### Live check
|
|
221
281
|
|
|
222
|
-
Before a release, the owner checks the provider against `flags.satee.dev` with a real server key
|
|
223
|
-
|
|
282
|
+
Before a release, the owner checks the provider against `flags.satee.dev` with a real server key, once with a flag
|
|
283
|
+
that is enabled and not rolled out in that project, and once with a rolled-out flag and a targeting key. From a
|
|
284
|
+
checkout:
|
|
224
285
|
|
|
225
286
|
```sh
|
|
226
287
|
SATEE_SDK_KEY=<server key> bundle exec ruby -Ilib -e '
|
|
227
288
|
require "satee/openfeature/provider"
|
|
228
289
|
OpenFeature::SDK.configure { |config| config.set_provider_and_wait(Satee::OpenFeature::Provider.new) }
|
|
229
|
-
|
|
290
|
+
context = OpenFeature::SDK::EvaluationContext.new(targeting_key: ARGV[1])
|
|
291
|
+
details = OpenFeature::SDK.build_client.fetch_boolean_details(flag_key: ARGV.fetch(0), default_value: false, evaluation_context: context)
|
|
230
292
|
puts [details.value, details.variant, details.reason, details.error_code].inspect
|
|
231
293
|
OpenFeature::SDK.shutdown
|
|
232
|
-
' <flag key>
|
|
294
|
+
' <flag key> [targeting key]
|
|
233
295
|
```
|
|
234
296
|
|
|
235
297
|
It passes when it prints the flag's value and variant with the reason `"STATIC"` and no error code, for example
|
|
236
|
-
`[true, "on", "STATIC", nil]
|
|
298
|
+
`[true, "on", "STATIC", nil]`, and for the rolled-out flag with the reason `"TARGETING_MATCH"`, for example
|
|
299
|
+
`[false, "off", "TARGETING_MATCH", nil]`. Change the flag in Satee and run it again: the new value shows.
|
|
237
300
|
|
|
238
301
|
## License
|
|
239
302
|
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Satee
|
|
4
|
+
module OpenFeature
|
|
5
|
+
class Provider
|
|
6
|
+
# Which of 100 buckets a targeting key falls in for a flag: the same in every Satee provider, so a user gets the
|
|
7
|
+
# same answer from each of them.
|
|
8
|
+
module Bucket
|
|
9
|
+
# Both strings must be valid UTF-8; their bytes are hashed exactly as given.
|
|
10
|
+
def self.of(flag_key, targeting_key)
|
|
11
|
+
(Murmur3.hash32(input(flag_key, targeting_key)) * 100) >> 32
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
# The CBOR encoding of the array [flag_key, targeting_key].
|
|
15
|
+
def self.input(flag_key, targeting_key)
|
|
16
|
+
"\x82".b << text(flag_key) << text(targeting_key)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def self.text(string)
|
|
20
|
+
length = string.bytesize
|
|
21
|
+
header =
|
|
22
|
+
if length < 24 then [0x60 + length].pack("C")
|
|
23
|
+
elsif length < 0x100 then [0x78, length].pack("CC")
|
|
24
|
+
elsif length < 0x1_0000 then [0x79, length].pack("Cn")
|
|
25
|
+
elsif length < 0x1_0000_0000 then [0x7a, length].pack("CN")
|
|
26
|
+
else [0x7b, length].pack("CQ>")
|
|
27
|
+
end
|
|
28
|
+
header << string.b
|
|
29
|
+
end
|
|
30
|
+
private_class_method :text
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
@@ -3,7 +3,12 @@
|
|
|
3
3
|
module Satee
|
|
4
4
|
module OpenFeature
|
|
5
5
|
class Provider
|
|
6
|
-
|
|
6
|
+
# share is the percentage of targeting keys a rolled-out flag is on for, and nil for a plain flag.
|
|
7
|
+
class Flag < Data.define(:enabled, :variant, :share)
|
|
8
|
+
def initialize(enabled:, variant:, share: nil)
|
|
9
|
+
super
|
|
10
|
+
end
|
|
11
|
+
|
|
7
12
|
def value = variant == "on"
|
|
8
13
|
end
|
|
9
14
|
end
|
|
@@ -41,7 +41,6 @@ module Satee
|
|
|
41
41
|
enabled = STATES.fetch(definition["state"]) do
|
|
42
42
|
raise InvalidFlagFile, "#{flag} has a state other than \"ENABLED\" or \"DISABLED\""
|
|
43
43
|
end
|
|
44
|
-
raise InvalidFlagFile, "#{flag} has targeting rules" if definition.key?("targeting")
|
|
45
44
|
unless definition["variants"] == VARIANTS
|
|
46
45
|
raise InvalidFlagFile, "#{flag} does not have exactly the variants on: true and off: false"
|
|
47
46
|
end
|
|
@@ -51,9 +50,26 @@ module Satee
|
|
|
51
50
|
raise InvalidFlagFile, "#{flag} has a defaultVariant other than \"on\" or \"off\""
|
|
52
51
|
end
|
|
53
52
|
|
|
54
|
-
|
|
53
|
+
share = parse_share(flag, definition) if definition.key?("targeting")
|
|
54
|
+
Flag.new(enabled:, variant:, share:)
|
|
55
55
|
end
|
|
56
|
-
|
|
56
|
+
|
|
57
|
+
# The one targeting a flag may have, written in exactly one way, so every provider evaluates a flag the same way
|
|
58
|
+
# or refuses its file.
|
|
59
|
+
def self.parse_share(flag, definition)
|
|
60
|
+
targeting = definition["targeting"]
|
|
61
|
+
buckets = targeting["fractional"] if targeting.is_a?(Hash) && targeting.keys == ["fractional"]
|
|
62
|
+
share =
|
|
63
|
+
case buckets
|
|
64
|
+
in [["on", Integer => on], ["off", Integer => off]] if on >= 0 && off >= 0 && on + off == 100 then on
|
|
65
|
+
else raise InvalidFlagFile, "#{flag} has targeting other than a rollout to a share of users"
|
|
66
|
+
end
|
|
67
|
+
unless definition["defaultVariant"] == "off"
|
|
68
|
+
raise InvalidFlagFile, "#{flag} has targeting but a defaultVariant other than \"off\""
|
|
69
|
+
end
|
|
70
|
+
share
|
|
71
|
+
end
|
|
72
|
+
private_class_method :parse_flag, :parse_share, :new
|
|
57
73
|
|
|
58
74
|
def initialize(revision:, flags:)
|
|
59
75
|
@revision = revision
|
|
@@ -61,13 +77,13 @@ module Satee
|
|
|
61
77
|
freeze
|
|
62
78
|
end
|
|
63
79
|
|
|
64
|
-
# Keys added or removed, whose state changed, or that are enabled in both files with another variant.
|
|
65
|
-
# disabled flag serves the caller's default, so its variant changing changes nothing.
|
|
80
|
+
# Keys added or removed, whose state changed, or that are enabled in both files with another variant or share.
|
|
81
|
+
# A disabled flag serves the caller's default, so its variant or share changing changes nothing.
|
|
66
82
|
def changed_keys(previous)
|
|
67
83
|
(flags.keys | previous.flags.keys).select do |key|
|
|
68
84
|
now = flags[key]
|
|
69
85
|
before = previous.flags[key]
|
|
70
|
-
now.nil? || before.nil? || now.enabled != before.enabled || (now.enabled && now.variant != before.variant)
|
|
86
|
+
now.nil? || before.nil? || now.enabled != before.enabled || (now.enabled && (now.variant != before.variant || now.share != before.share))
|
|
71
87
|
end
|
|
72
88
|
end
|
|
73
89
|
end
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Satee
|
|
4
|
+
module OpenFeature
|
|
5
|
+
class Provider
|
|
6
|
+
# MurmurHash3, the x86 32-bit variant.
|
|
7
|
+
module Murmur3
|
|
8
|
+
MASK = 0xffff_ffff
|
|
9
|
+
C1 = 0xcc9e_2d51
|
|
10
|
+
C2 = 0x1b87_3593
|
|
11
|
+
private_constant :MASK, :C1, :C2
|
|
12
|
+
|
|
13
|
+
# The hash of a string's bytes, whatever its encoding, as an unsigned 32-bit integer.
|
|
14
|
+
def self.hash32(bytes, seed = 0)
|
|
15
|
+
length = bytes.bytesize
|
|
16
|
+
whole = length / 4
|
|
17
|
+
hash = seed & MASK
|
|
18
|
+
|
|
19
|
+
blocks = bytes.unpack("V#{whole}") #: Array[Integer]
|
|
20
|
+
blocks.each do |block|
|
|
21
|
+
hash ^= scramble(block)
|
|
22
|
+
hash = rotate(hash, 13)
|
|
23
|
+
hash = (hash * 5 + 0xe654_6b64) & MASK
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
tail = 0
|
|
27
|
+
bytes.byteslice(whole * 4, length - whole * 4).to_s.each_byte.with_index do |byte, index|
|
|
28
|
+
tail |= byte << (8 * index)
|
|
29
|
+
end
|
|
30
|
+
hash ^= scramble(tail) unless length % 4 == 0
|
|
31
|
+
|
|
32
|
+
finalize(hash ^ (length & MASK))
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def self.scramble(block)
|
|
36
|
+
(rotate((block * C1) & MASK, 15) * C2) & MASK
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def self.rotate(value, bits)
|
|
40
|
+
((value << bits) | (value >> (32 - bits))) & MASK
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def self.finalize(hash)
|
|
44
|
+
hash ^= hash >> 16
|
|
45
|
+
hash = (hash * 0x85eb_ca6b) & MASK
|
|
46
|
+
hash ^= hash >> 13
|
|
47
|
+
hash = (hash * 0xc2b2_ae35) & MASK
|
|
48
|
+
hash ^ (hash >> 16)
|
|
49
|
+
end
|
|
50
|
+
private_class_method :scramble, :rotate, :finalize
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Satee
|
|
4
|
+
module OpenFeature
|
|
5
|
+
class Provider
|
|
6
|
+
module TargetingKey
|
|
7
|
+
# The key as UTF-8, or nil when it can't bucket: not a String, empty, or not valid text. A key in another
|
|
8
|
+
# encoding is transcoded, so the same text lands in the same bucket whatever encoding the host holds it in. A
|
|
9
|
+
# binary string declares no encoding, so its bytes are read as UTF-8.
|
|
10
|
+
def self.utf8(value)
|
|
11
|
+
return unless value.is_a?(String) && !value.empty?
|
|
12
|
+
|
|
13
|
+
key = (value.encoding == Encoding::BINARY) ? String.new(value, encoding: Encoding::UTF_8) : value.encode(Encoding::UTF_8)
|
|
14
|
+
key if key.valid_encoding?
|
|
15
|
+
rescue EncodingError
|
|
16
|
+
nil
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -70,7 +70,7 @@ module Satee
|
|
|
70
70
|
end
|
|
71
71
|
|
|
72
72
|
def fetch_boolean_value(flag_key:, default_value:, evaluation_context: nil)
|
|
73
|
-
resolve(flag_key, default_value, :boolean)
|
|
73
|
+
resolve(flag_key, default_value, :boolean, evaluation_context)
|
|
74
74
|
end
|
|
75
75
|
|
|
76
76
|
def fetch_string_value(flag_key:, default_value:, evaluation_context: nil)
|
|
@@ -98,7 +98,7 @@ module Satee
|
|
|
98
98
|
def build_poller
|
|
99
99
|
Poller.new(
|
|
100
100
|
transport: @transport.new(
|
|
101
|
-
URI::HTTPS.build(host: HOST, path: "/
|
|
101
|
+
URI::HTTPS.build(host: HOST, path: "/v2/#{@sdk_key.path_id}/flags.json"),
|
|
102
102
|
user_agent: "satee-openfeature-ruby/#{VERSION}"
|
|
103
103
|
),
|
|
104
104
|
clock: @clock,
|
|
@@ -114,7 +114,7 @@ module Satee
|
|
|
114
114
|
@flag_file = flag_file
|
|
115
115
|
end
|
|
116
116
|
|
|
117
|
-
def resolve(flag_key, default_value, type)
|
|
117
|
+
def resolve(flag_key, default_value, type, evaluation_context = nil)
|
|
118
118
|
flag_file = @flag_file
|
|
119
119
|
return error(default_value, ErrorCode::PROVIDER_NOT_READY, "Flags have not loaded yet") unless flag_file
|
|
120
120
|
|
|
@@ -126,7 +126,20 @@ module Satee
|
|
|
126
126
|
return error(default_value, ErrorCode::TYPE_MISMATCH, "Flag #{flag_key.inspect} is a boolean, not #{type}")
|
|
127
127
|
end
|
|
128
128
|
|
|
129
|
-
|
|
129
|
+
share = flag.share
|
|
130
|
+
return ResolutionDetails.new(value: flag.value, variant: flag.variant, reason: Reason::STATIC) unless share
|
|
131
|
+
|
|
132
|
+
roll_out(flag_key, share, evaluation_context&.targeting_key)
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
# A caller without a usable key gets off, not an error: an error code would make the SDK serve the caller's
|
|
136
|
+
# default, which would switch the rollout on for every keyless caller that passes true.
|
|
137
|
+
def roll_out(flag_key, share, targeting_key)
|
|
138
|
+
key = TargetingKey.utf8(targeting_key)
|
|
139
|
+
return ResolutionDetails.new(value: false, variant: "off", reason: Reason::DEFAULT) unless key
|
|
140
|
+
|
|
141
|
+
on = Bucket.of(flag_key, key) < share
|
|
142
|
+
ResolutionDetails.new(value: on, variant: on ? "on" : "off", reason: Reason::TARGETING_MATCH)
|
|
130
143
|
end
|
|
131
144
|
|
|
132
145
|
def error(default_value, code, message)
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
module Satee
|
|
2
|
+
module OpenFeature
|
|
3
|
+
class Provider
|
|
4
|
+
module Bucket
|
|
5
|
+
def self.of: (String flag_key, String targeting_key) -> Integer
|
|
6
|
+
|
|
7
|
+
def self.input: (String flag_key, String targeting_key) -> String
|
|
8
|
+
|
|
9
|
+
private
|
|
10
|
+
|
|
11
|
+
def self.text: (String string) -> String
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -4,10 +4,11 @@ module Satee
|
|
|
4
4
|
class Flag < Data
|
|
5
5
|
attr_reader enabled: bool
|
|
6
6
|
attr_reader variant: String
|
|
7
|
+
attr_reader share: Integer?
|
|
7
8
|
|
|
8
|
-
def self.new: (enabled: bool, variant: String) -> instance
|
|
9
|
+
def self.new: (enabled: bool, variant: String, ?share: Integer?) -> instance
|
|
9
10
|
|
|
10
|
-
def initialize: (enabled: bool, variant: String) -> void
|
|
11
|
+
def initialize: (enabled: bool, variant: String, ?share: Integer?) -> void
|
|
11
12
|
|
|
12
13
|
def value: () -> bool
|
|
13
14
|
end
|
|
@@ -17,6 +17,8 @@ module Satee
|
|
|
17
17
|
|
|
18
18
|
def self.parse_flag: (String key, untyped definition) -> Flag
|
|
19
19
|
|
|
20
|
+
def self.parse_share: (String flag, Hash[String, untyped] definition) -> Integer
|
|
21
|
+
|
|
20
22
|
def self.new: (revision: Integer, flags: Hash[String, Flag]) -> FlagFile
|
|
21
23
|
|
|
22
24
|
def initialize: (revision: Integer, flags: Hash[String, Flag]) -> void
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
module Satee
|
|
2
|
+
module OpenFeature
|
|
3
|
+
class Provider
|
|
4
|
+
module Murmur3
|
|
5
|
+
MASK: Integer
|
|
6
|
+
C1: Integer
|
|
7
|
+
C2: Integer
|
|
8
|
+
|
|
9
|
+
def self.hash32: (String bytes, ?Integer seed) -> Integer
|
|
10
|
+
|
|
11
|
+
private
|
|
12
|
+
|
|
13
|
+
def self.scramble: (Integer block) -> Integer
|
|
14
|
+
|
|
15
|
+
def self.rotate: (Integer value, Integer bits) -> Integer
|
|
16
|
+
|
|
17
|
+
def self.finalize: (Integer hash) -> Integer
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -49,7 +49,9 @@ module Satee
|
|
|
49
49
|
|
|
50
50
|
def replace_flags: (FlagFile flag_file) -> void
|
|
51
51
|
|
|
52
|
-
def resolve: (String flag_key, untyped default_value, Symbol type) -> ::OpenFeature::SDK::Provider::ResolutionDetails
|
|
52
|
+
def resolve: (String flag_key, untyped default_value, Symbol type, ?::OpenFeature::SDK::EvaluationContext? evaluation_context) -> ::OpenFeature::SDK::Provider::ResolutionDetails
|
|
53
|
+
|
|
54
|
+
def roll_out: (String flag_key, Integer share, untyped targeting_key) -> ::OpenFeature::SDK::Provider::ResolutionDetails
|
|
53
55
|
|
|
54
56
|
def error: (untyped default_value, String code, String message) -> ::OpenFeature::SDK::Provider::ResolutionDetails
|
|
55
57
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: satee-openfeature-provider
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Satee
|
|
@@ -61,6 +61,7 @@ files:
|
|
|
61
61
|
- LICENSE
|
|
62
62
|
- README.md
|
|
63
63
|
- lib/satee/openfeature/provider.rb
|
|
64
|
+
- lib/satee/openfeature/provider/bucket.rb
|
|
64
65
|
- lib/satee/openfeature/provider/clock.rb
|
|
65
66
|
- lib/satee/openfeature/provider/configuration_error.rb
|
|
66
67
|
- lib/satee/openfeature/provider/defect.rb
|
|
@@ -70,12 +71,15 @@ files:
|
|
|
70
71
|
- lib/satee/openfeature/provider/fork_restart.rb
|
|
71
72
|
- lib/satee/openfeature/provider/invalid_flag_file.rb
|
|
72
73
|
- lib/satee/openfeature/provider/log.rb
|
|
74
|
+
- lib/satee/openfeature/provider/murmur3.rb
|
|
73
75
|
- lib/satee/openfeature/provider/poller.rb
|
|
74
76
|
- lib/satee/openfeature/provider/sdk_key.rb
|
|
75
77
|
- lib/satee/openfeature/provider/stderr_logger.rb
|
|
78
|
+
- lib/satee/openfeature/provider/targeting_key.rb
|
|
76
79
|
- lib/satee/openfeature/provider/transport.rb
|
|
77
80
|
- lib/satee/openfeature/provider/version.rb
|
|
78
81
|
- sig/satee/openfeature/provider.rbs
|
|
82
|
+
- sig/satee/openfeature/provider/bucket.rbs
|
|
79
83
|
- sig/satee/openfeature/provider/clock.rbs
|
|
80
84
|
- sig/satee/openfeature/provider/configuration_error.rbs
|
|
81
85
|
- sig/satee/openfeature/provider/defect.rbs
|
|
@@ -85,9 +89,11 @@ files:
|
|
|
85
89
|
- sig/satee/openfeature/provider/fork_restart.rbs
|
|
86
90
|
- sig/satee/openfeature/provider/invalid_flag_file.rbs
|
|
87
91
|
- sig/satee/openfeature/provider/log.rbs
|
|
92
|
+
- sig/satee/openfeature/provider/murmur3.rbs
|
|
88
93
|
- sig/satee/openfeature/provider/poller.rbs
|
|
89
94
|
- sig/satee/openfeature/provider/sdk_key.rbs
|
|
90
95
|
- sig/satee/openfeature/provider/stderr_logger.rbs
|
|
96
|
+
- sig/satee/openfeature/provider/targeting_key.rbs
|
|
91
97
|
- sig/satee/openfeature/provider/transport.rbs
|
|
92
98
|
homepage: https://github.com/satee-dev/satee-openfeature-provider-ruby
|
|
93
99
|
licenses:
|