featureflip 2.15.0 → 2.16.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: 15b0723d1722a5537c1d86f006e1b31f44041a3375821037bd120f0638cf4ea8
4
- data.tar.gz: 2ee4100d6030d53db2d8ed3d6b281d2d365fe0ffbcb927ed2754236c404cc20f
3
+ metadata.gz: 683f76f782b1dd8ce94fd499611e94e0481665776d16714f2a1a2f4896a4ac6a
4
+ data.tar.gz: bbcffa0c8d82bcf1997ed890cd9bfecc5228a290773cb02400ee0df172db20da
5
5
  SHA512:
6
- metadata.gz: 29e129490227e460f958a12f5912127df85617cffa97365f909a83d7b638cae0c379cbf47bdcb32242b0671f0ccf934adceb4c4b3757eeabe928a14186131718
7
- data.tar.gz: 906d860e2606afb9db5a5d83d7ad561fbf97b7d97899215f9f7504e14b0e990f749846246d3041bf22422e48c488c7c996a5f16111a9daeb84888fc219bd1f19
6
+ metadata.gz: e8f7b14c10ee600ecbc83f7aeb71de7b986cb7f1278e47d4aa6774380dadbfbee82b3f565c08bb24867656fe3fe2ca96c239c73e2ddd35348d8f525dd393228b
7
+ data.tar.gz: b8eed413fc35c498cac6fcbed6a215ca66a5ea175fa0156b3901ec868aac402772eee1c4a168292f75bfefc3d63593240f10867b7dbed8b784e071368530dbf3
@@ -50,11 +50,17 @@ module Featureflip
50
50
  @drain_started = 0
51
51
  @drain_finished = 0
52
52
  @drain_done = ConditionVariable.new
53
+
54
+ # The process whose events are in @queue. A forking server (Puma preload_app!,
55
+ # Unicorn) copies this object, queue and all, into every worker, but those events
56
+ # belong to the parent, which sends them itself. See #adopt_after_fork.
57
+ @pid = Process.pid
53
58
  end
54
59
 
55
60
  def queue_event(event)
56
61
  dropped = 0
57
62
  @mutex.synchronize do
63
+ adopt_after_fork
58
64
  # After #stop nothing will flush again, so buffering here would only leak.
59
65
  return if @stopped
60
66
 
@@ -81,6 +87,7 @@ module Featureflip
81
87
  # returned the in-flight promise (#2477).
82
88
  def flush
83
89
  mine = @mutex.synchronize do
90
+ adopt_after_fork
84
91
  if @drain_in_flight
85
92
  nil
86
93
  else
@@ -154,7 +161,10 @@ module Featureflip
154
161
  # Closed BEFORE the final flush so a failure there is dropped rather than
155
162
  # re-queued: nothing will flush again, and retrying until the queue drains would
156
163
  # hang shutdown for as long as the endpoint stayed down. One attempt, then let go.
157
- @mutex.synchronize { @stopped = true }
164
+ @mutex.synchronize do
165
+ adopt_after_fork
166
+ @stopped = true
167
+ end
158
168
  # drain, not flush: shutdown must never be the call that gets coalesced
159
169
  # away. If the interval tick's drain happens to be in flight, flush would
160
170
  # wait for it and return, and anything queued after that loop's last look
@@ -167,6 +177,23 @@ module Featureflip
167
177
 
168
178
  private
169
179
 
180
+ # First touch in a forked child: drop what was queued in the parent, which still
181
+ # sends those events itself, so sending them here too would deliver each one twice
182
+ # per worker (#5778). The coalescing state goes with it, because a drain that was in
183
+ # flight at the fork ran on a thread the child does not have, and waiting for it
184
+ # would hang. Events queued after this point are the child's own and are sent as
185
+ # usual. Caller holds @mutex.
186
+ def adopt_after_fork
187
+ return if @pid == Process.pid
188
+
189
+ @pid = Process.pid
190
+ @queue.clear
191
+ @drain_in_flight = false
192
+ @drain_finished = @drain_started
193
+ @auto_flush_in_flight = false
194
+ @next_auto_flush_at = 0.0
195
+ end
196
+
170
197
  # Batch-size-triggered flush. Returns true only if it actually sent.
171
198
  #
172
199
  # A re-queued batch leaves the queue at or above @flush_batch_size, so without a gate
@@ -0,0 +1,90 @@
1
+ require "rails/railtie"
2
+ require "active_support/ordered_options"
3
+
4
+ module Featureflip
5
+ # Builds the shared client when a Rails app boots. Loaded by `require "featureflip"`
6
+ # only when Rails::Railtie is already defined, so non-Rails apps never see it and the
7
+ # gem does not depend on Rails.
8
+ #
9
+ # # config/application.rb or an environment file
10
+ # config.featureflip.sdk_key = ENV["FEATUREFLIP_SDK_KEY"] # optional, see below
11
+ # config.featureflip.poll_interval = 60
12
+ #
13
+ # Any Featureflip::Config option can be set on config.featureflip. The SDK key is
14
+ # read from config.featureflip.sdk_key, then FEATUREFLIP_SDK_KEY, then
15
+ # credentials.featureflip.sdk_key. With no key the client is not built and a warning
16
+ # is logged.
17
+ #
18
+ # The client is the same one the singleton API uses:
19
+ # Rails.application.config.featureflip_client
20
+ # Featureflip.bool_variation("flag", { "user_id" => "1" }, false)
21
+ class Railtie < ::Rails::Railtie
22
+ WRAPPER_NAME = "featureflip-rails".freeze
23
+
24
+ config.featureflip = ActiveSupport::OrderedOptions.new
25
+
26
+ # after_initialize, so config/initializers and credentials are all loaded.
27
+ config.after_initialize do |app|
28
+ Featureflip::Railtie.setup(app)
29
+ end
30
+
31
+ class << self
32
+ # Builds the client from app.config.featureflip and stores it at
33
+ # app.config.featureflip_client. Returns nil (after a warning) when no SDK key
34
+ # is configured. A failed first fetch raises Featureflip::InitializationError
35
+ # and stops boot; set `snapshot_store` to start from the last known flags
36
+ # instead.
37
+ def setup(app)
38
+ options = app.config.featureflip.to_h.transform_keys(&:to_sym)
39
+ sdk_key = options.delete(:sdk_key) || ENV["FEATUREFLIP_SDK_KEY"] || credentials_key(app)
40
+
41
+ if sdk_key.nil? || sdk_key.to_s.strip.empty?
42
+ logger&.warn("Featureflip: no SDK key configured (config.featureflip.sdk_key, " \
43
+ "FEATUREFLIP_SDK_KEY or credentials featureflip.sdk_key); " \
44
+ "the client was not started")
45
+ return app.config.featureflip_client = nil
46
+ end
47
+
48
+ Featureflip.configure do |c|
49
+ c.sdk_key = sdk_key
50
+ c.logger = logger if logger
51
+ c.wrapper_name = WRAPPER_NAME
52
+ c.wrapper_version = ::Rails.version
53
+ options.each do |name, value|
54
+ setter = "#{name}="
55
+ raise ConfigurationError, "Unknown config.featureflip option: #{name}" unless c.respond_to?(setter)
56
+
57
+ c.public_send(setter, value)
58
+ end
59
+ end
60
+
61
+ register_shutdown
62
+ app.config.featureflip_client = Featureflip.default_client
63
+ end
64
+
65
+ def shutdown
66
+ Featureflip.close
67
+ end
68
+
69
+ private
70
+
71
+ def logger
72
+ ::Rails.logger
73
+ end
74
+
75
+ def credentials_key(app)
76
+ app.credentials.dig(:featureflip, :sdk_key)
77
+ rescue StandardError
78
+ # A missing or unreadable master key must not stop an app that sets the key elsewhere.
79
+ nil
80
+ end
81
+
82
+ def register_shutdown
83
+ return if @shutdown_registered
84
+
85
+ @shutdown_registered = true
86
+ at_exit { shutdown }
87
+ end
88
+ end
89
+ end
90
+ end
@@ -1,3 +1,3 @@
1
1
  module Featureflip
2
- VERSION = "2.15.0"
2
+ VERSION = "2.16.0"
3
3
  end
data/lib/featureflip.rb CHANGED
@@ -20,6 +20,7 @@ require_relative "featureflip/data_source/streaming"
20
20
  require_relative "featureflip/data_source/polling"
21
21
  require_relative "featureflip/shared_core"
22
22
  require_relative "featureflip/client"
23
+ require_relative "featureflip/railtie" if defined?(Rails::Railtie)
23
24
 
24
25
  module Featureflip
25
26
  @mutex = Mutex.new
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.15.0
4
+ version: 2.16.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-11-16 00:00:00.000000000 Z
11
+ date: 2026-11-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: logger
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '1.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: railties
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '7.1'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '7.1'
69
83
  description: Server-side SDK for evaluating feature flags with Featureflip
70
84
  email:
71
85
  executables: []
@@ -91,6 +105,7 @@ files:
91
105
  - lib/featureflip/models/evaluation_event.rb
92
106
  - lib/featureflip/models/flag.rb
93
107
  - lib/featureflip/models/segment.rb
108
+ - lib/featureflip/railtie.rb
94
109
  - lib/featureflip/redacting_logger.rb
95
110
  - lib/featureflip/sdk_identity.rb
96
111
  - lib/featureflip/shared_core.rb