featureflip 2.11.0 → 2.13.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
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c41498d43abe3f592e70ef93178a39bbabfc481072cf1862b3a18399ad3972db
|
|
4
|
+
data.tar.gz: 00b9495f23ece99027e3c03c647616cd240a11338f8376511ac4bbd2ce46e826
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 3c397937ed703003e47e5999a9ffd0cd6004ce0ee02e0b216ba6c99c06dec2b03a37ceb9163b8fba36cc413747782fc13ccd84ed7218e307cd21f92ded5566da
|
|
7
|
+
data.tar.gz: ca65db25d697572ceae8f048bb5672407639fd9aeebf0bc3e0f691cfd08e3993983d78c80f80ad9997852725ebd319ca0b19c069c455fde3b8b43c4c54f73e41
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
module Featureflip
|
|
2
|
+
module Evaluation
|
|
3
|
+
# Canonical spelling of a floating-point rollout bucket value (#4236): the same
|
|
4
|
+
# text as ECMAScript Number::toString and the Evaluation API's
|
|
5
|
+
# BucketValueFormatter.CanonicalNumber, so every SDK hashes one number to one
|
|
6
|
+
# bucket. Used only on the bucket path; condition evaluation is unaffected.
|
|
7
|
+
module CanonicalNumber
|
|
8
|
+
# A BigDecimal below 1e21 with no fractional part keeps its exact integer digits (like
|
|
9
|
+
# the engine's raw integer text); anything else goes through Float (#4236). The 1e21
|
|
10
|
+
# cap is where ECMAScript spelling turns exponential, and stops BigDecimal("1E+999999999")
|
|
11
|
+
# expanding to a billion digits per evaluation (#4246). BigDecimal#exponent is n in
|
|
12
|
+
# 0.ddd * 10**n, so |d| < 1e21 is exponent <= 21.
|
|
13
|
+
def self.format_big_decimal(d)
|
|
14
|
+
return format(d.to_f) unless d.finite?
|
|
15
|
+
return d.to_i.to_s if d.exponent <= 21 && d.frac.zero?
|
|
16
|
+
|
|
17
|
+
format(d.to_f)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def self.format(x)
|
|
21
|
+
return "NaN" if x.nan?
|
|
22
|
+
return (x.positive? ? "Infinity" : "-Infinity") if x.infinite?
|
|
23
|
+
return "0" if x.zero?
|
|
24
|
+
return "-" + format(-x) if x.negative?
|
|
25
|
+
|
|
26
|
+
# Float#to_s is the shortest round-trip form (e.g. "0.1", "100.25", "1.0e+21").
|
|
27
|
+
# Kernel.format("%.{p}e", ...) with the first round-tripping p is NOT always
|
|
28
|
+
# shortest: for 2**-44 the nearest 16-digit decimal does not round-trip but a
|
|
29
|
+
# neighbour does, so the loop yields 17 digits where ECMAScript yields 16.
|
|
30
|
+
mantissa, exp10 = x.to_s.split("e")
|
|
31
|
+
int_part, frac_part = mantissa.split(".")
|
|
32
|
+
frac_part ||= ""
|
|
33
|
+
all_digits = int_part + frac_part
|
|
34
|
+
lead = all_digits.length - all_digits.sub(/\A0+/, "").length
|
|
35
|
+
lead = all_digits.length - 1 if lead >= all_digits.length
|
|
36
|
+
exp = exp10.to_i + int_part.length - 1 - lead
|
|
37
|
+
digits = all_digits[lead..].sub(/0+\z/, "")
|
|
38
|
+
digits = "0" if digits.empty?
|
|
39
|
+
k = digits.length
|
|
40
|
+
n = exp + 1
|
|
41
|
+
|
|
42
|
+
if k <= n && n <= 21
|
|
43
|
+
digits + "0" * (n - k)
|
|
44
|
+
elsif n.positive? && n <= 21
|
|
45
|
+
"#{digits[0, n]}.#{digits[n..]}"
|
|
46
|
+
elsif n > -6 && n <= 0
|
|
47
|
+
"0." + "0" * -n + digits
|
|
48
|
+
else
|
|
49
|
+
e = n - 1
|
|
50
|
+
head = k > 1 ? "#{digits[0]}.#{digits[1..]}" : digits
|
|
51
|
+
"#{head}e#{e >= 0 ? '+' : '-'}#{e.abs}"
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
require_relative "condition_evaluator"
|
|
2
2
|
require_relative "bucketing"
|
|
3
|
+
require_relative "canonical_number"
|
|
4
|
+
require_relative "unbucketable_warnings"
|
|
3
5
|
|
|
4
6
|
module Featureflip
|
|
5
7
|
module Evaluation
|
|
@@ -9,8 +11,9 @@ module Featureflip
|
|
|
9
11
|
# the JS reference implementation; see prerequisite_spec.rb depth test.
|
|
10
12
|
MAX_PREREQUISITE_DEPTH = 10
|
|
11
13
|
|
|
12
|
-
def initialize
|
|
14
|
+
def initialize(logger: nil)
|
|
13
15
|
@condition_evaluator = ConditionEvaluator.new
|
|
16
|
+
@logger = logger
|
|
14
17
|
end
|
|
15
18
|
|
|
16
19
|
def evaluate(flag, context, get_segment: nil, all_flags: {})
|
|
@@ -63,7 +66,21 @@ module Featureflip
|
|
|
63
66
|
|
|
64
67
|
if conditions_match
|
|
65
68
|
variation_key = resolve_serve(rule.serve, context)
|
|
69
|
+
# A rollout that can't bucket the context doesn't match; fall to the next rule (#4236).
|
|
70
|
+
if variation_key.nil?
|
|
71
|
+
warn_unbucketable(flag, rule.id, rule.serve)
|
|
72
|
+
next
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
# A served key that names no variation is malformed config: report Error (no
|
|
76
|
+
# rule id) with the served key, like the engine's ServeVariation (#4236).
|
|
66
77
|
variation = flag.get_variation(variation_key)
|
|
78
|
+
if variation.nil?
|
|
79
|
+
result = Models::EvaluationDetail.new(value: nil, reason: "Error", variation_key: variation_key)
|
|
80
|
+
memo[flag.key] = result
|
|
81
|
+
return result
|
|
82
|
+
end
|
|
83
|
+
|
|
67
84
|
result = Models::EvaluationDetail.new(
|
|
68
85
|
value: variation&.value,
|
|
69
86
|
reason: "RuleMatch",
|
|
@@ -76,9 +93,18 @@ module Featureflip
|
|
|
76
93
|
end
|
|
77
94
|
|
|
78
95
|
variation_key = resolve_serve(flag.fallthrough, context)
|
|
96
|
+
if variation_key.nil?
|
|
97
|
+
warn_unbucketable(flag, nil, flag.fallthrough)
|
|
98
|
+
variation_key = flag.fallthrough.variation || ""
|
|
99
|
+
end
|
|
79
100
|
variation = flag.get_variation(variation_key)
|
|
101
|
+
if variation.nil?
|
|
102
|
+
result = Models::EvaluationDetail.new(value: nil, reason: "Error", variation_key: variation_key)
|
|
103
|
+
memo[flag.key] = result
|
|
104
|
+
return result
|
|
105
|
+
end
|
|
80
106
|
result = Models::EvaluationDetail.new(
|
|
81
|
-
value: variation
|
|
107
|
+
value: variation.value,
|
|
82
108
|
reason: "Fallthrough",
|
|
83
109
|
variation_key: variation_key
|
|
84
110
|
)
|
|
@@ -123,14 +149,26 @@ module Featureflip
|
|
|
123
149
|
|
|
124
150
|
def off_result(flag, reason:, prerequisite_key: nil)
|
|
125
151
|
variation = flag.get_variation(flag.off_variation)
|
|
152
|
+
# An off variation the flag doesn't define is malformed config: report Error
|
|
153
|
+
# (value nil, the key kept), like the engine's ServeVariation (#4236).
|
|
154
|
+
if variation.nil?
|
|
155
|
+
return Models::EvaluationDetail.new(value: nil, reason: "Error", variation_key: flag.off_variation)
|
|
156
|
+
end
|
|
157
|
+
|
|
126
158
|
Models::EvaluationDetail.new(
|
|
127
|
-
value: variation
|
|
159
|
+
value: variation.value,
|
|
128
160
|
reason: reason,
|
|
129
161
|
variation_key: flag.off_variation,
|
|
130
162
|
prerequisite_key: prerequisite_key
|
|
131
163
|
)
|
|
132
164
|
end
|
|
133
165
|
|
|
166
|
+
def warn_unbucketable(flag, rule_id, serve)
|
|
167
|
+
UnbucketableWarnings.warn(@logger, flag.key, rule_id, serve.bucket_by || "userId")
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
# Returns the variation key to serve, or nil when a Rollout serve can't bucket
|
|
171
|
+
# the context (see resolve_rollout). A Fixed serve never returns nil.
|
|
134
172
|
def resolve_serve(serve, context)
|
|
135
173
|
if serve.type == "Fixed"
|
|
136
174
|
serve.variation || ""
|
|
@@ -145,7 +183,12 @@ module Featureflip
|
|
|
145
183
|
# Alias "userId" <-> "user_id" for the built-in user identifier
|
|
146
184
|
bucket_value = context["user_id"] if bucket_value.nil? && bucket_by == "userId"
|
|
147
185
|
bucket_value = context["userId"] if bucket_value.nil? && bucket_by == "user_id"
|
|
148
|
-
bucket_value_str =
|
|
186
|
+
bucket_value_str =
|
|
187
|
+
if bucket_value.nil? then ""
|
|
188
|
+
elsif bucket_value.is_a?(Float) then CanonicalNumber.format(bucket_value)
|
|
189
|
+
elsif defined?(::BigDecimal) && bucket_value.is_a?(::BigDecimal) then CanonicalNumber.format_big_decimal(bucket_value)
|
|
190
|
+
else bucket_value.to_s
|
|
191
|
+
end
|
|
149
192
|
|
|
150
193
|
# A Rollout serve can arrive with no weighted variations -- env-level PercentageRollout
|
|
151
194
|
# has nowhere to store per-variation weights, so the mapper emits type=Rollout with no
|
|
@@ -153,14 +196,10 @@ module Featureflip
|
|
|
153
196
|
# empty key. Mirrors the engine + C#/Java SDK evaluators.
|
|
154
197
|
return serve.variation || "" if (serve.variations || []).empty?
|
|
155
198
|
|
|
156
|
-
#
|
|
157
|
-
#
|
|
158
|
-
#
|
|
159
|
-
|
|
160
|
-
# guaranteed only for keyed contexts (#1457).
|
|
161
|
-
if bucket_value_str == "" && %w[userId user_id].include?(bucket_by) && !(serve.variations || []).empty?
|
|
162
|
-
return serve.variations[0].key
|
|
163
|
-
end
|
|
199
|
+
# A missing, nil or empty bucket value can't be bucketed: return nil so the caller
|
|
200
|
+
# skips the rule (or serves the fallthrough's variation) instead of hashing the empty
|
|
201
|
+
# string into an arbitrary bucket. Whitespace, "0", 0 and false bucket normally (#4236).
|
|
202
|
+
return nil if bucket_value_str == ""
|
|
164
203
|
|
|
165
204
|
bucket = Bucketing.compute_bucket(serve.salt || "", bucket_value_str)
|
|
166
205
|
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
require "set"
|
|
2
|
+
|
|
3
|
+
module Featureflip
|
|
4
|
+
module Evaluation
|
|
5
|
+
# Process-wide, deduplicated warning for a percentage rollout that was skipped
|
|
6
|
+
# because the context has no value for its bucket-by attribute (#4236).
|
|
7
|
+
#
|
|
8
|
+
# Logs once per (flag key, rule id or "fallthrough", bucket_by). The set is
|
|
9
|
+
# capped at MAX_KEYS; once full, unseen keys are dropped silently. Only the
|
|
10
|
+
# flag key, rule id and bucket-by attribute NAME are logged, never a context
|
|
11
|
+
# value.
|
|
12
|
+
module UnbucketableWarnings
|
|
13
|
+
MAX_KEYS = 1000
|
|
14
|
+
|
|
15
|
+
@mutex = Mutex.new
|
|
16
|
+
@seen = Set.new
|
|
17
|
+
|
|
18
|
+
class << self
|
|
19
|
+
def warn(logger, flag_key, rule_id, bucket_by)
|
|
20
|
+
where = rule_id.nil? ? "fallthrough" : "rule #{rule_id}"
|
|
21
|
+
key = [flag_key, where, bucket_by]
|
|
22
|
+
|
|
23
|
+
@mutex.synchronize do
|
|
24
|
+
return if @seen.include?(key) || @seen.size >= MAX_KEYS
|
|
25
|
+
|
|
26
|
+
@seen.add(key)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
logger&.warn(
|
|
30
|
+
"[featureflip] Skipped the percentage rollout in flag \"#{flag_key}\" (#{where}): " \
|
|
31
|
+
"the context has no value for \"#{bucket_by}\". " \
|
|
32
|
+
"Pass a stable id in that attribute to include this context in the rollout."
|
|
33
|
+
)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# Number of distinct keys recorded so far.
|
|
37
|
+
def count
|
|
38
|
+
@mutex.synchronize { @seen.size }
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# Clears the dedup set. For tests.
|
|
42
|
+
def reset
|
|
43
|
+
@mutex.synchronize { @seen.clear }
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
@@ -85,7 +85,7 @@ module Featureflip
|
|
|
85
85
|
# the "different config" warning.
|
|
86
86
|
@inspectors = config.inspectors || []
|
|
87
87
|
@store = Store::FlagStore.new
|
|
88
|
-
@evaluator = Evaluation::Evaluator.new
|
|
88
|
+
@evaluator = Evaluation::Evaluator.new(logger: @config.logger)
|
|
89
89
|
@initialized = false
|
|
90
90
|
@closed = false
|
|
91
91
|
@test_mode = false
|
|
@@ -185,7 +185,7 @@ module Featureflip
|
|
|
185
185
|
|
|
186
186
|
flag = @store.get_flag(key)
|
|
187
187
|
unless flag
|
|
188
|
-
record_evaluation(key, context, nil)
|
|
188
|
+
record_evaluation(key, context, nil, reason: "FlagNotFound")
|
|
189
189
|
notify_inspectors(key, context, default_value, reason: "FlagNotFound")
|
|
190
190
|
return Models::EvaluationDetail.new(value: default_value, reason: "FlagNotFound")
|
|
191
191
|
end
|
|
@@ -224,7 +224,10 @@ module Featureflip
|
|
|
224
224
|
reason = "Error"
|
|
225
225
|
end
|
|
226
226
|
|
|
227
|
-
record_evaluation(
|
|
227
|
+
record_evaluation(
|
|
228
|
+
key, context, result.variation_key,
|
|
229
|
+
reason: reason, rule_id: result.rule_id, prerequisite_key: result.prerequisite_key
|
|
230
|
+
)
|
|
228
231
|
notify_inspectors(
|
|
229
232
|
key, context, value,
|
|
230
233
|
reason: reason,
|
|
@@ -244,6 +247,7 @@ module Featureflip
|
|
|
244
247
|
# Prerequisite-resolution failures return PrerequisiteFailed cleanly through
|
|
245
248
|
# the evaluator; this rescue only fires on unexpected exceptions (malformed
|
|
246
249
|
# config, programming errors), so prerequisite_key has no defined value.
|
|
250
|
+
record_evaluation(key, context, nil, reason: "Error")
|
|
247
251
|
notify_inspectors(key, context, default_value, reason: "Error")
|
|
248
252
|
Models::EvaluationDetail.new(value: default_value, reason: "Error", prerequisite_key: nil)
|
|
249
253
|
end
|
|
@@ -521,16 +525,36 @@ module Featureflip
|
|
|
521
525
|
event
|
|
522
526
|
end
|
|
523
527
|
|
|
524
|
-
|
|
528
|
+
# The kebab-case reason categories the Evaluation event carries (#4268), so
|
|
529
|
+
# the source of traffic reads the same whichever SDK reported it. The
|
|
530
|
+
# PascalCase names stay the public EvaluationDetail API; only the event is
|
|
531
|
+
# translated.
|
|
532
|
+
WIRE_REASONS = {
|
|
533
|
+
"RuleMatch" => "rule-match",
|
|
534
|
+
"Fallthrough" => "fallthrough",
|
|
535
|
+
"FlagDisabled" => "flag-disabled",
|
|
536
|
+
"FlagNotFound" => "flag-not-found",
|
|
537
|
+
"PrerequisiteFailed" => "prerequisite-failed",
|
|
538
|
+
"Error" => "error"
|
|
539
|
+
}.freeze
|
|
540
|
+
|
|
541
|
+
# +ruleId+ rides only on a rule match: an Error read can still carry the rule
|
|
542
|
+
# that selected a malformed variation, and that rule did not serve the
|
|
543
|
+
# traffic. Absent optionals are compacted away so they are omitted, never null.
|
|
544
|
+
def record_evaluation(key, context, variation_key, reason:, rule_id: nil, prerequisite_key: nil)
|
|
525
545
|
return unless @event_processor
|
|
526
546
|
|
|
527
|
-
|
|
547
|
+
event = {
|
|
528
548
|
type: "Evaluation",
|
|
529
549
|
flagKey: key,
|
|
530
550
|
userId: resolve_event_user_id(context),
|
|
531
551
|
variation: variation_key,
|
|
532
|
-
timestamp: Time.now.utc.iso8601
|
|
533
|
-
|
|
552
|
+
timestamp: Time.now.utc.iso8601,
|
|
553
|
+
prerequisiteKey: prerequisite_key,
|
|
554
|
+
reason: WIRE_REASONS[reason],
|
|
555
|
+
ruleId: reason == "RuleMatch" ? rule_id : nil
|
|
556
|
+
}
|
|
557
|
+
@event_processor.queue_event(event.compact)
|
|
534
558
|
end
|
|
535
559
|
|
|
536
560
|
# Fire the registered evaluation inspectors. Called once per variation call
|
|
@@ -579,7 +603,7 @@ module Featureflip
|
|
|
579
603
|
@config = Config.new
|
|
580
604
|
@inspectors = []
|
|
581
605
|
@store = Store::FlagStore.new
|
|
582
|
-
@evaluator = Evaluation::Evaluator.new
|
|
606
|
+
@evaluator = Evaluation::Evaluator.new(logger: @config.logger)
|
|
583
607
|
@initialized = true
|
|
584
608
|
@closed = false
|
|
585
609
|
@test_mode = true
|
data/lib/featureflip/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: featureflip
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.
|
|
4
|
+
version: 2.13.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Featureflip
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-10-
|
|
11
|
+
date: 2026-10-27 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: logger
|
|
@@ -79,8 +79,10 @@ files:
|
|
|
79
79
|
- lib/featureflip/data_source/streaming.rb
|
|
80
80
|
- lib/featureflip/errors.rb
|
|
81
81
|
- lib/featureflip/evaluation/bucketing.rb
|
|
82
|
+
- lib/featureflip/evaluation/canonical_number.rb
|
|
82
83
|
- lib/featureflip/evaluation/condition_evaluator.rb
|
|
83
84
|
- lib/featureflip/evaluation/evaluator.rb
|
|
85
|
+
- lib/featureflip/evaluation/unbucketable_warnings.rb
|
|
84
86
|
- lib/featureflip/events/event.rb
|
|
85
87
|
- lib/featureflip/events/event_processor.rb
|
|
86
88
|
- lib/featureflip/http/client.rb
|