prefab-cloud-ruby 0.0.10 → 0.0.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/lib/prefab/config_client.rb +6 -2
- data/lib/prefab/config_loader.rb +13 -5
- data/lib/prefab/feature_flag_client.rb +2 -2
- data/lib/prefab/retry.rb +2 -2
- data/lib/prefab_pb.rb +6 -12
- data/lib/prefab_services_pb.rb +1 -1
- data/prefab-cloud-ruby.gemspec +3 -3
- data/test/test_config_loader.rb +12 -0
- data/test/test_feature_flag_client.rb +19 -19
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 005df99ad579e508b3b7a826ef11884b2b6495a9
|
4
|
+
data.tar.gz: b36bfa20a612c17628c12b57c01cde87dbfa25dc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7a60d508e8469950990c7d79d1095bc4c253f02a467fc50727d8cfd56263db3d5821e0fe6aa6f93e95ae2bb0782b7106a539203b4534b403eb21e4021b4ebe50
|
7
|
+
data.tar.gz: '0944f4059e6b9ec37fd652bd7c457e149a5facfc3426334af8b63001c2988ca3de97ea562dd4c10a3c1022e72c3c4fd35e1730a7fe0e23c29012ad6f426b3bf8'
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.11
|
data/lib/prefab/config_client.rb
CHANGED
@@ -19,12 +19,16 @@ module Prefab
|
|
19
19
|
@config_resolver.get(prop)
|
20
20
|
end
|
21
21
|
|
22
|
-
def
|
22
|
+
def upsert(key, config_value, namespace = nil, previous_key = nil)
|
23
23
|
raise "key must not contain ':' set namespaces separately" if key.include? ":"
|
24
24
|
raise "namespace must not contain ':'" if namespace&.include?(":")
|
25
25
|
config_delta = Prefab::ConfigClient.value_to_delta(key, config_value, namespace)
|
26
|
-
|
26
|
+
upsert_req = Prefab::UpsertRequest.new(config_delta: config_delta)
|
27
|
+
upsert_req.previous_key = previous_key if previous_key&.present?
|
28
|
+
|
29
|
+
Retry.it method(:stub_with_timeout), :upsert, upsert_req, @timeout, method(:reset)
|
27
30
|
@config_loader.set(config_delta)
|
31
|
+
@config_loader.rm(previous_key) if previous_key&.present?
|
28
32
|
end
|
29
33
|
|
30
34
|
def reset
|
data/lib/prefab/config_loader.rb
CHANGED
@@ -18,7 +18,15 @@ module Prefab
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def set(delta)
|
21
|
-
|
21
|
+
if delta.value.nil?
|
22
|
+
@api_config.delete(delta.key)
|
23
|
+
else
|
24
|
+
@api_config[delta.key] = delta
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def rm(key)
|
29
|
+
@api_config.delete key
|
22
30
|
end
|
23
31
|
|
24
32
|
def get_api_deltas
|
@@ -64,13 +72,13 @@ module Prefab
|
|
64
72
|
def value_from(raw)
|
65
73
|
case raw
|
66
74
|
when String
|
67
|
-
{string: raw}
|
75
|
+
{ string: raw }
|
68
76
|
when Integer
|
69
|
-
{int: raw}
|
77
|
+
{ int: raw }
|
70
78
|
when TrueClass, FalseClass
|
71
|
-
{bool: raw}
|
79
|
+
{ bool: raw }
|
72
80
|
when Float
|
73
|
-
{double: raw}
|
81
|
+
{ double: raw }
|
74
82
|
end
|
75
83
|
end
|
76
84
|
end
|
@@ -7,7 +7,7 @@ module Prefab
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def upsert(feature_obj)
|
10
|
-
@base_client.config_client.
|
10
|
+
@base_client.config_client.upsert(feature_config_name(feature_obj.feature), Prefab::ConfigValue.new(feature_flag: feature_obj))
|
11
11
|
end
|
12
12
|
|
13
13
|
def feature_is_on?(feature_name)
|
@@ -46,7 +46,7 @@ module Prefab
|
|
46
46
|
end
|
47
47
|
|
48
48
|
def feature_config_name(feature)
|
49
|
-
|
49
|
+
feature
|
50
50
|
end
|
51
51
|
|
52
52
|
end
|
data/lib/prefab/retry.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
class Retry
|
2
|
-
DEFAULT_TIMEOUT = 10
|
3
2
|
MAX_SLEEP_SEC = 10
|
4
3
|
BASE_SLEEP_SEC = 0.5
|
5
4
|
|
@@ -13,13 +12,14 @@ class Retry
|
|
13
12
|
attempts += 1
|
14
13
|
return stub_factory.call.send(rpc, req)
|
15
14
|
rescue => exception
|
15
|
+
|
16
16
|
if Time.now - start_time > timeout
|
17
17
|
raise exception
|
18
18
|
end
|
19
|
-
|
20
19
|
sleep_seconds = [BASE_SLEEP_SEC * (2 ** (attempts - 1)), MAX_SLEEP_SEC].min
|
21
20
|
sleep_seconds = sleep_seconds * (0.5 * (1 + rand()))
|
22
21
|
sleep_seconds = [BASE_SLEEP_SEC, sleep_seconds].max
|
22
|
+
puts "Sleep #{sleep_seconds} and Reset"
|
23
23
|
sleep sleep_seconds
|
24
24
|
reset.call
|
25
25
|
retry
|
data/lib/prefab_pb.rb
CHANGED
@@ -26,6 +26,11 @@ Google::Protobuf::DescriptorPool.generated_pool.build do
|
|
26
26
|
add_message "prefab.ConfigDeltas" do
|
27
27
|
repeated :deltas, :message, 1, "prefab.ConfigDelta"
|
28
28
|
end
|
29
|
+
add_message "prefab.UpsertRequest" do
|
30
|
+
optional :account_id, :int64, 1
|
31
|
+
optional :config_delta, :message, 2, "prefab.ConfigDelta"
|
32
|
+
optional :previous_key, :string, 3
|
33
|
+
end
|
29
34
|
add_message "prefab.LimitResponse" do
|
30
35
|
optional :passed, :bool, 1
|
31
36
|
optional :expires_at, :int64, 2
|
@@ -61,7 +66,6 @@ Google::Protobuf::DescriptorPool.generated_pool.build do
|
|
61
66
|
value :MAXIMUM, 2
|
62
67
|
end
|
63
68
|
add_message "prefab.FeatureFlag" do
|
64
|
-
optional :feature, :string, 2
|
65
69
|
optional :pct, :double, 3
|
66
70
|
repeated :whitelisted, :string, 4
|
67
71
|
end
|
@@ -87,15 +91,6 @@ Google::Protobuf::DescriptorPool.generated_pool.build do
|
|
87
91
|
repeated :flags, :message, 1, "prefab.FeatureFlag"
|
88
92
|
optional :cache_expiry, :int64, 2
|
89
93
|
end
|
90
|
-
add_message "prefab.BucketWrite" do
|
91
|
-
optional :tokenBucket, :message, 1, "prefab.TokenBucket"
|
92
|
-
optional :bucket, :string, 2
|
93
|
-
end
|
94
|
-
add_message "prefab.TokenBucket" do
|
95
|
-
optional :current_value, :int64, 1
|
96
|
-
optional :time_key, :int64, 2
|
97
|
-
repeated :expiries, :int64, 3
|
98
|
-
end
|
99
94
|
add_message "prefab.BufferedRequest" do
|
100
95
|
optional :account_id, :int64, 1
|
101
96
|
optional :method, :string, 2
|
@@ -127,6 +122,7 @@ module Prefab
|
|
127
122
|
ConfigDelta = Google::Protobuf::DescriptorPool.generated_pool.lookup("prefab.ConfigDelta").msgclass
|
128
123
|
ConfigValue = Google::Protobuf::DescriptorPool.generated_pool.lookup("prefab.ConfigValue").msgclass
|
129
124
|
ConfigDeltas = Google::Protobuf::DescriptorPool.generated_pool.lookup("prefab.ConfigDeltas").msgclass
|
125
|
+
UpsertRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("prefab.UpsertRequest").msgclass
|
130
126
|
LimitResponse = Google::Protobuf::DescriptorPool.generated_pool.lookup("prefab.LimitResponse").msgclass
|
131
127
|
LimitResponse::LimitPolicyNames = Google::Protobuf::DescriptorPool.generated_pool.lookup("prefab.LimitResponse.LimitPolicyNames").enummodule
|
132
128
|
LimitRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("prefab.LimitRequest").msgclass
|
@@ -136,8 +132,6 @@ module Prefab
|
|
136
132
|
LimitDefinition::SafetyLevel = Google::Protobuf::DescriptorPool.generated_pool.lookup("prefab.LimitDefinition.SafetyLevel").enummodule
|
137
133
|
LimitDefinitions = Google::Protobuf::DescriptorPool.generated_pool.lookup("prefab.LimitDefinitions").msgclass
|
138
134
|
FeatureFlags = Google::Protobuf::DescriptorPool.generated_pool.lookup("prefab.FeatureFlags").msgclass
|
139
|
-
BucketWrite = Google::Protobuf::DescriptorPool.generated_pool.lookup("prefab.BucketWrite").msgclass
|
140
|
-
TokenBucket = Google::Protobuf::DescriptorPool.generated_pool.lookup("prefab.TokenBucket").msgclass
|
141
135
|
BufferedRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("prefab.BufferedRequest").msgclass
|
142
136
|
BatchRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("prefab.BatchRequest").msgclass
|
143
137
|
OnFailure = Google::Protobuf::DescriptorPool.generated_pool.lookup("prefab.OnFailure").enummodule
|
data/lib/prefab_services_pb.rb
CHANGED
@@ -29,7 +29,7 @@ module Prefab
|
|
29
29
|
self.service_name = 'prefab.ConfigService'
|
30
30
|
|
31
31
|
rpc :GetConfig, ConfigServicePointer, stream(ConfigDeltas)
|
32
|
-
rpc :Upsert,
|
32
|
+
rpc :Upsert, UpsertRequest, ConfigServicePointer
|
33
33
|
end
|
34
34
|
|
35
35
|
Stub = Service.rpc_stub_class
|
data/prefab-cloud-ruby.gemspec
CHANGED
@@ -2,16 +2,16 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Juwelier::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: prefab-cloud-ruby 0.0.
|
5
|
+
# stub: prefab-cloud-ruby 0.0.11 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "prefab-cloud-ruby".freeze
|
9
|
-
s.version = "0.0.
|
9
|
+
s.version = "0.0.11"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib".freeze]
|
13
13
|
s.authors = ["Jeff Dwyer".freeze]
|
14
|
-
s.date = "2018-
|
14
|
+
s.date = "2018-02-02"
|
15
15
|
s.description = "RateLimits & Config as a service".freeze
|
16
16
|
s.email = "jdwyer@prefab.cloud".freeze
|
17
17
|
s.extra_rdoc_files = [
|
data/test/test_config_loader.rb
CHANGED
@@ -33,6 +33,18 @@ class TestConfigLoader < Minitest::Test
|
|
33
33
|
assert_equal deltas, @loader.get_api_deltas
|
34
34
|
end
|
35
35
|
|
36
|
+
def test_loading_tombstones_removes_entries
|
37
|
+
val = Prefab::ConfigValue.new(int: 456)
|
38
|
+
delta = Prefab::ConfigDelta.new(key: "sample_int", value: val)
|
39
|
+
@loader.set(delta)
|
40
|
+
|
41
|
+
delta = Prefab::ConfigDelta.new(key: "sample_int", value: nil)
|
42
|
+
@loader.set(delta)
|
43
|
+
|
44
|
+
deltas = Prefab::ConfigDeltas.new
|
45
|
+
assert_equal deltas, @loader.get_api_deltas
|
46
|
+
end
|
47
|
+
|
36
48
|
private
|
37
49
|
|
38
50
|
def should_be(type, value, key)
|
@@ -5,60 +5,60 @@ class TestFeatureFlagClient < Minitest::Test
|
|
5
5
|
def test_pct
|
6
6
|
client = Prefab::FeatureFlagClient.new(MockBaseClient.new)
|
7
7
|
Prefab::FeatureFlagClient.send(:public, :is_on?)
|
8
|
-
|
9
|
-
flag = Prefab::FeatureFlag.new(
|
8
|
+
feature = "FlagName"
|
9
|
+
flag = Prefab::FeatureFlag.new( pct: 0.5)
|
10
10
|
|
11
11
|
assert_equal false,
|
12
|
-
client.is_on?(
|
12
|
+
client.is_on?(feature, "hashes high", [], flag)
|
13
13
|
|
14
14
|
assert_equal true,
|
15
|
-
client.is_on?(
|
15
|
+
client.is_on?(feature, "hashes low", [], flag)
|
16
16
|
end
|
17
17
|
|
18
18
|
|
19
19
|
def test_off
|
20
20
|
client = Prefab::FeatureFlagClient.new(MockBaseClient.new)
|
21
21
|
Prefab::FeatureFlagClient.send(:public, :is_on?)
|
22
|
-
|
23
|
-
flag = Prefab::FeatureFlag.new(
|
22
|
+
feature = "FlagName"
|
23
|
+
flag = Prefab::FeatureFlag.new(pct: 0)
|
24
24
|
|
25
25
|
assert_equal false,
|
26
|
-
client.is_on?(
|
26
|
+
client.is_on?(feature, "hashes high", [], flag)
|
27
27
|
|
28
28
|
assert_equal false,
|
29
|
-
client.is_on?(
|
29
|
+
client.is_on?(feature, "hashes low", [], flag)
|
30
30
|
end
|
31
31
|
|
32
32
|
|
33
33
|
def test_on
|
34
34
|
client = Prefab::FeatureFlagClient.new(MockBaseClient.new)
|
35
35
|
Prefab::FeatureFlagClient.send(:public, :is_on?)
|
36
|
-
|
37
|
-
flag = Prefab::FeatureFlag.new(
|
36
|
+
feature = "FlagName"
|
37
|
+
flag = Prefab::FeatureFlag.new(pct: 1)
|
38
38
|
|
39
39
|
assert_equal true,
|
40
|
-
client.is_on?(
|
40
|
+
client.is_on?(feature, "hashes high", [], flag)
|
41
41
|
|
42
42
|
assert_equal true,
|
43
|
-
client.is_on?(
|
43
|
+
client.is_on?(feature, "hashes low", [], flag)
|
44
44
|
end
|
45
45
|
|
46
46
|
def test_whitelist
|
47
47
|
client = Prefab::FeatureFlagClient.new(MockBaseClient.new)
|
48
48
|
Prefab::FeatureFlagClient.send(:public, :is_on?)
|
49
|
-
|
50
|
-
flag = Prefab::FeatureFlag.new(
|
49
|
+
feature = "FlagName"
|
50
|
+
flag = Prefab::FeatureFlag.new(pct: 0, whitelisted: ["beta", "user:1", "user:3"])
|
51
51
|
|
52
52
|
assert_equal false,
|
53
|
-
client.is_on?(
|
53
|
+
client.is_on?(feature, "anything", [], flag)
|
54
54
|
assert_equal true,
|
55
|
-
client.is_on?(
|
55
|
+
client.is_on?(feature, "anything", ["beta"], flag)
|
56
56
|
assert_equal true,
|
57
|
-
client.is_on?(
|
57
|
+
client.is_on?(feature, "anything", ["alpha", "beta"], flag)
|
58
58
|
assert_equal true,
|
59
|
-
client.is_on?(
|
59
|
+
client.is_on?(feature, "anything", ["alpha", "user:1"], flag)
|
60
60
|
assert_equal false,
|
61
|
-
client.is_on?(
|
61
|
+
client.is_on?(feature, "anything", ["alpha", "user:2"], flag)
|
62
62
|
|
63
63
|
end
|
64
64
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: prefab-cloud-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeff Dwyer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-02-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: grpc
|