flipper 1.5.0.rc1 → 1.5.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/lib/flipper/cli.rb +11 -2
- data/lib/flipper/cloud/configuration.rb +15 -4
- data/lib/flipper/cloud/shared_memory.rb +37 -10
- data/lib/flipper/sem_ver.rb +5 -1
- data/lib/flipper/test_help.rb +14 -7
- data/lib/flipper/typecast.rb +16 -1
- data/lib/flipper/version.rb +1 -1
- data/lib/generators/flipper/table_prefix.rb +9 -6
- data/lib/generators/flipper/templates/update/migrations/01_create_flipper_tables.rb.erb +1 -1
- data/lib/generators/flipper/templates/update/migrations/02_change_flipper_gates_value_to_text.rb.erb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: bcd315c90967e5b1cf80a834bcadda7d0439fced33abf49a76300eca785e8f27
|
|
4
|
+
data.tar.gz: 22f0d9856d41984f0ac35be264bcfb0a07bdef7f5e59211c82c61d8535333ea0
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8e826172032e682aa69f6ae04394636325f3586b1927c3fb46185da2cefd5921b684aab71dd50a9b8586425b8a928fff59c03e55db681f993076f3c319aad142
|
|
7
|
+
data.tar.gz: fa4c786c16e36e48d246e50c673223fe88ea7d024466f807bc4d6b1747abc4a15caaf4267a1423b6713717ca675e7e905537f070a2c1f6ddc2af0c094c94a532
|
data/lib/flipper/cli.rb
CHANGED
|
@@ -46,9 +46,18 @@ module Flipper
|
|
|
46
46
|
c.on('-t NUM', '--percentage-of-time=NUM', Numeric, "#{action} for a percentage of time") do |num|
|
|
47
47
|
values << percentage(Types::PercentageOfTime, num)
|
|
48
48
|
end
|
|
49
|
-
c.on('-x expressions', '--expression=JSON', "#{action} for the given expression") do |
|
|
49
|
+
c.on('-x expressions', '--expression=JSON', "#{action} for the given expression") do |json|
|
|
50
50
|
begin
|
|
51
|
-
|
|
51
|
+
expression = Flipper::Expression.build(JSON.parse(json))
|
|
52
|
+
|
|
53
|
+
# Check before anything is enabled, so a bad expression doesn't
|
|
54
|
+
# leave the other values given with it half applied.
|
|
55
|
+
raise ArgumentError, "#{expression.value.inspect} is not an expression" unless expression.is_a?(Flipper::Expression)
|
|
56
|
+
if action == "enable" && expression.empty_groups?
|
|
57
|
+
raise ArgumentError, "#{expression.value.inspect} contains empty Any/All groups"
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
values << expression
|
|
52
61
|
rescue JSON::ParserError => e
|
|
53
62
|
ui.error "JSON parse error #{e.message}"
|
|
54
63
|
ui.trace(e)
|
|
@@ -136,7 +136,9 @@ module Flipper
|
|
|
136
136
|
# Fetch once for both the local adapter and memory.
|
|
137
137
|
snapshot = Flipper::Adapters::Memory.new(remote.get_all(cache_bust: cache_bust))
|
|
138
138
|
snapshot.sync_version = remote.sync_version
|
|
139
|
-
|
|
139
|
+
# Tracked like a poll's sync, so one that fails partway is synced again.
|
|
140
|
+
@memory.sync(snapshot.sync_version) { sync_memory(snapshot) }
|
|
141
|
+
nil
|
|
140
142
|
end
|
|
141
143
|
|
|
142
144
|
# Public: The method that will be used to synchronize local adapter with
|
|
@@ -247,19 +249,28 @@ module Flipper
|
|
|
247
249
|
return Flipper::Adapters::Poll.new(poller, local_adapter) unless @memory
|
|
248
250
|
|
|
249
251
|
Flipper::Adapters::Poll.new(poller, memory_adapter, synchronizer: -> {
|
|
250
|
-
sync_poll(poller.adapter)
|
|
252
|
+
sync_poll(poller.adapter, poller.synced_at)
|
|
251
253
|
})
|
|
252
254
|
end
|
|
253
255
|
|
|
254
256
|
# Every thread's Poll calls this after each poll. Threads don't wait on
|
|
255
257
|
# each other, so ones that read while a new version syncs sync it too.
|
|
256
|
-
|
|
258
|
+
# Once the version is synced, one thread per poll checks whether another
|
|
259
|
+
# process stored a different one, so the rest don't query the local
|
|
260
|
+
# adapter. A check that fails gives the poll back to the next thread.
|
|
261
|
+
def sync_poll(snapshot, polled_at)
|
|
257
262
|
version = snapshot.sync_version
|
|
258
|
-
|
|
263
|
+
claimed = false
|
|
264
|
+
if @memory.synced?(version)
|
|
265
|
+
claimed = @memory.claim_store_check(polled_at)
|
|
266
|
+
return unless claimed
|
|
267
|
+
return if @store.sync_version == version
|
|
268
|
+
end
|
|
259
269
|
|
|
260
270
|
@memory.sync(version) { sync_memory(snapshot) }
|
|
261
271
|
rescue StandardError
|
|
262
272
|
# Reads keep working from memory if the local adapter is down.
|
|
273
|
+
@memory.release_store_check(polled_at) if claimed
|
|
263
274
|
end
|
|
264
275
|
|
|
265
276
|
def http_adapter
|
|
@@ -12,7 +12,7 @@ module Flipper
|
|
|
12
12
|
|
|
13
13
|
def initialize(source = nil, threadsafe: true)
|
|
14
14
|
super
|
|
15
|
-
@syncing = 0
|
|
15
|
+
@syncing = Hash.new(0)
|
|
16
16
|
@overlaps = 0
|
|
17
17
|
@recopy = false
|
|
18
18
|
@changed_at = 0
|
|
@@ -50,23 +50,50 @@ module Flipper
|
|
|
50
50
|
!version.nil? && synchronize { @synced_version == version }
|
|
51
51
|
end
|
|
52
52
|
|
|
53
|
+
# Public: Returns true for the first thread to ask about the poll at
|
|
54
|
+
# polled_at, and false for the rest, so one thread per poll checks the
|
|
55
|
+
# local adapter's version. A thread still on an older poll gets false.
|
|
56
|
+
def claim_store_check(polled_at)
|
|
57
|
+
synchronize do
|
|
58
|
+
return false if @store_checked_at && polled_at <= @store_checked_at
|
|
59
|
+
@store_checked_at = polled_at
|
|
60
|
+
true
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
# Public: Gives back a claim whose check failed, so the next thread to
|
|
65
|
+
# read checks the poll at polled_at again.
|
|
66
|
+
def release_store_check(polled_at)
|
|
67
|
+
synchronize { @store_checked_at = nil if @store_checked_at == polled_at }
|
|
68
|
+
end
|
|
69
|
+
|
|
53
70
|
# Public: Runs the block that syncs version, then records it as synced.
|
|
54
|
-
# Records nothing if the block raises or
|
|
55
|
-
# time, because an older sync can write its flags after a newer
|
|
56
|
-
# next poll then syncs again and repairs them.
|
|
71
|
+
# Records nothing if the block raises or a sync of another version ran at
|
|
72
|
+
# the same time, because an older sync can write its flags after a newer
|
|
73
|
+
# one. The next poll then syncs again and repairs them. Threads syncing
|
|
74
|
+
# the same version write the same flags, so they can still record it,
|
|
75
|
+
# but one that raises may have left flags half written, so it forgets
|
|
76
|
+
# the recorded version and keeps syncs still running from recording.
|
|
57
77
|
def sync(version)
|
|
58
78
|
alone, overlaps = synchronize do
|
|
59
|
-
@syncing
|
|
60
|
-
@overlaps += 1 if
|
|
61
|
-
|
|
79
|
+
other_version = @syncing.any? { |syncing_version, _| syncing_version != version }
|
|
80
|
+
@overlaps += 1 if other_version
|
|
81
|
+
@syncing[version] += 1
|
|
82
|
+
[!other_version, @overlaps]
|
|
62
83
|
end
|
|
63
84
|
finished = false
|
|
64
85
|
yield
|
|
65
86
|
finished = true
|
|
66
87
|
ensure
|
|
67
88
|
synchronize do
|
|
68
|
-
@syncing -= 1
|
|
69
|
-
@
|
|
89
|
+
@syncing[version] -= 1
|
|
90
|
+
@syncing.delete(version) if @syncing[version] <= 0
|
|
91
|
+
if finished
|
|
92
|
+
@synced_version = version if alone && overlaps == @overlaps
|
|
93
|
+
else
|
|
94
|
+
@overlaps += 1
|
|
95
|
+
@synced_version = nil
|
|
96
|
+
end
|
|
70
97
|
end
|
|
71
98
|
end
|
|
72
99
|
|
|
@@ -77,7 +104,7 @@ module Flipper
|
|
|
77
104
|
end
|
|
78
105
|
|
|
79
106
|
def now
|
|
80
|
-
Process.clock_gettime(Process::CLOCK_MONOTONIC, :
|
|
107
|
+
Process.clock_gettime(Process::CLOCK_MONOTONIC, :float_second)
|
|
81
108
|
end
|
|
82
109
|
end
|
|
83
110
|
end
|
data/lib/flipper/sem_ver.rb
CHANGED
|
@@ -23,8 +23,12 @@ module Flipper
|
|
|
23
23
|
/x
|
|
24
24
|
EMPTY = [].freeze
|
|
25
25
|
|
|
26
|
-
# Returns a SemVer, or nil when the string isn't a version.
|
|
26
|
+
# Returns a SemVer, or nil when the string isn't a version. Strings with
|
|
27
|
+
# invalid bytes or in encodings that aren't ASCII compatible (like UTF-16)
|
|
28
|
+
# return nil too, since PATTERN can't match them without raising.
|
|
27
29
|
def self.parse(string)
|
|
30
|
+
return unless string.is_a?(::String) && string.valid_encoding? && string.encoding.ascii_compatible?
|
|
31
|
+
|
|
28
32
|
match = PATTERN.match(string)
|
|
29
33
|
return unless match
|
|
30
34
|
|
data/lib/flipper/test_help.rb
CHANGED
|
@@ -24,12 +24,14 @@ module Flipper
|
|
|
24
24
|
|
|
25
25
|
prune_named_test_adapters(Flipper.configuration).each do |named|
|
|
26
26
|
test_adapter = named_test_adapters[named]
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
27
|
+
# Clear the Memory adapter directly. Going through the named DSL can
|
|
28
|
+
# miss features a memoized list doesn't have, or reach the other store
|
|
29
|
+
# of a write-through adapter wrapping Memory.
|
|
30
|
+
Flipper.new(test_adapter[:adapter]).features.each(&:remove) if test_adapter
|
|
31
|
+
|
|
32
|
+
# Install a fresh one if the named configuration changed since we
|
|
33
|
+
# installed the test adapter (or we never did).
|
|
34
|
+
if test_adapter.nil? || test_adapter[:version] != named.version
|
|
33
35
|
install_named_test_adapter(named)
|
|
34
36
|
end
|
|
35
37
|
end
|
|
@@ -49,8 +51,13 @@ module Flipper
|
|
|
49
51
|
named_configurations.each { |named| install_named_test_adapter(named) }
|
|
50
52
|
end
|
|
51
53
|
|
|
54
|
+
# Kept on the module, not the object that includes it, so each test's
|
|
55
|
+
# flipper_reset sees the adapters flipper_configure installed at boot.
|
|
56
|
+
NAMED_TEST_ADAPTERS = {}
|
|
57
|
+
private_constant :NAMED_TEST_ADAPTERS
|
|
58
|
+
|
|
52
59
|
def named_test_adapters
|
|
53
|
-
|
|
60
|
+
NAMED_TEST_ADAPTERS
|
|
54
61
|
end
|
|
55
62
|
|
|
56
63
|
# Forget test adapters for named configurations that no longer exist and
|
data/lib/flipper/typecast.rb
CHANGED
|
@@ -82,12 +82,27 @@ module Flipper
|
|
|
82
82
|
# Returns a String.
|
|
83
83
|
def self.to_feature_name(value)
|
|
84
84
|
# U+2800 renders as a fixed-width blank but is not default-ignorable or whitespace.
|
|
85
|
-
value.to_s
|
|
85
|
+
to_utf8(value.to_s)
|
|
86
86
|
.scrub('')
|
|
87
87
|
.gsub(/[\p{Default_Ignorable_Code_Point}\p{Cc}\u2800]/, '')
|
|
88
88
|
.gsub(/\A[[:space:]]+|[[:space:]]+\z/, '')
|
|
89
89
|
end
|
|
90
90
|
|
|
91
|
+
# Private: Convert a string to UTF-8 so the unicode regexps above can
|
|
92
|
+
# match it. Binary strings are read as UTF-8, leaving scrub to drop
|
|
93
|
+
# invalid bytes. Encodings with no UTF-8 converter are read as UTF-8 only
|
|
94
|
+
# when their bytes are valid UTF-8, otherwise the name becomes empty.
|
|
95
|
+
def self.to_utf8(value)
|
|
96
|
+
return value if value.encoding == Encoding::UTF_8 || value.ascii_only?
|
|
97
|
+
return String.new(value, encoding: Encoding::UTF_8) if value.encoding == Encoding::BINARY
|
|
98
|
+
|
|
99
|
+
value.encode(Encoding::UTF_8, invalid: :replace, undef: :replace, replace: '')
|
|
100
|
+
rescue Encoding::ConverterNotFoundError
|
|
101
|
+
utf8 = String.new(value, encoding: Encoding::UTF_8)
|
|
102
|
+
utf8.valid_encoding? ? utf8 : ''
|
|
103
|
+
end
|
|
104
|
+
private_class_method :to_utf8
|
|
105
|
+
|
|
91
106
|
def self.features_hash(source)
|
|
92
107
|
normalized_source = {}
|
|
93
108
|
(source || {}).each do |feature_key, gates|
|
data/lib/flipper/version.rb
CHANGED
|
@@ -3,11 +3,14 @@ require 'active_support/core_ext/string/inflections'
|
|
|
3
3
|
module Flipper
|
|
4
4
|
module Generators
|
|
5
5
|
module TablePrefix
|
|
6
|
+
# Lowercase so the migration file name matches what Rails' migrator accepts.
|
|
7
|
+
FORMAT = /\A[a-z0-9_]*\z/
|
|
8
|
+
|
|
6
9
|
def self.included(generator)
|
|
7
10
|
generator.class_option :table_prefix,
|
|
8
11
|
type: :string,
|
|
9
12
|
default: '',
|
|
10
|
-
desc: 'Prefix for the flipper_features and flipper_gates tables'
|
|
13
|
+
desc: 'Prefix for the flipper_features and flipper_gates tables, such as cross_app_ (lowercase letters, numbers and underscores)'
|
|
11
14
|
end
|
|
12
15
|
|
|
13
16
|
private
|
|
@@ -24,10 +27,6 @@ module Flipper
|
|
|
24
27
|
file_name.sub('flipper', "#{table_prefix}flipper")
|
|
25
28
|
end
|
|
26
29
|
|
|
27
|
-
def migration_class_name(class_name)
|
|
28
|
-
class_name.sub('Flipper', "#{table_prefix.camelize}Flipper")
|
|
29
|
-
end
|
|
30
|
-
|
|
31
30
|
def feature_index_name
|
|
32
31
|
:"index_#{table_prefix}flipper_features_on_key" unless table_prefix.empty?
|
|
33
32
|
end
|
|
@@ -37,7 +36,11 @@ module Flipper
|
|
|
37
36
|
end
|
|
38
37
|
|
|
39
38
|
def table_prefix
|
|
40
|
-
options[:table_prefix].to_s
|
|
39
|
+
prefix = options[:table_prefix].to_s
|
|
40
|
+
unless FORMAT.match?(prefix)
|
|
41
|
+
raise Thor::Error, "--table-prefix must contain only lowercase letters, numbers and underscores (got #{prefix.inspect})"
|
|
42
|
+
end
|
|
43
|
+
prefix
|
|
41
44
|
end
|
|
42
45
|
end
|
|
43
46
|
end
|
data/lib/generators/flipper/templates/update/migrations/02_change_flipper_gates_value_to_text.rb.erb
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
<%
|
|
4
|
-
migration_class = migration_class_name
|
|
4
|
+
migration_class = migration_class_name
|
|
5
5
|
gate_table = gate_table_name
|
|
6
6
|
gate_index = gate_index_name
|
|
7
7
|
%>class <%= migration_class %> < ActiveRecord::Migration<%= migration_version %>
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: flipper
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.5.0
|
|
4
|
+
version: 1.5.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- John Nunemaker
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-11-
|
|
11
|
+
date: 2026-11-28 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: concurrent-ruby
|
|
@@ -194,7 +194,7 @@ metadata:
|
|
|
194
194
|
homepage_uri: https://www.flippercloud.io
|
|
195
195
|
source_code_uri: https://github.com/flippercloud/flipper
|
|
196
196
|
bug_tracker_uri: https://github.com/flippercloud/flipper/issues
|
|
197
|
-
changelog_uri: https://github.com/flippercloud/flipper/releases/tag/v1.5.0
|
|
197
|
+
changelog_uri: https://github.com/flippercloud/flipper/releases/tag/v1.5.0
|
|
198
198
|
funding_uri: https://github.com/sponsors/flippercloud
|
|
199
199
|
post_install_message:
|
|
200
200
|
rdoc_options: []
|