prefab-cloud-ruby 0.24.5 → 1.0.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 +15 -0
- data/VERSION +1 -1
- data/compile_protos.sh +7 -0
- data/lib/prefab/client.rb +20 -46
- data/lib/prefab/config_client.rb +9 -12
- data/lib/prefab/config_resolver.rb +2 -1
- data/lib/prefab/config_value_unwrapper.rb +20 -9
- data/lib/prefab/context.rb +43 -7
- data/lib/prefab/context_shape_aggregator.rb +1 -1
- data/lib/prefab/criteria_evaluator.rb +24 -16
- data/lib/prefab/evaluation.rb +48 -0
- data/lib/prefab/evaluation_summary_aggregator.rb +85 -0
- data/lib/prefab/example_contexts_aggregator.rb +76 -0
- data/lib/prefab/exponential_backoff.rb +5 -0
- data/lib/prefab/feature_flag_client.rb +0 -2
- data/lib/prefab/log_path_aggregator.rb +1 -1
- data/lib/prefab/logger_client.rb +12 -13
- data/lib/prefab/options.rb +52 -43
- data/lib/prefab/periodic_sync.rb +30 -13
- data/lib/prefab/rate_limit_cache.rb +41 -0
- data/lib/prefab/resolved_config_presenter.rb +2 -4
- data/lib/prefab/weighted_value_resolver.rb +1 -1
- data/lib/prefab-cloud-ruby.rb +5 -5
- data/lib/prefab_pb.rb +11 -1
- data/prefab-cloud-ruby.gemspec +14 -9
- data/test/integration_test.rb +1 -3
- data/test/integration_test_helpers.rb +0 -1
- data/test/support/common_helpers.rb +174 -0
- data/test/support/mock_base_client.rb +44 -0
- data/test/support/mock_config_client.rb +19 -0
- data/test/support/mock_config_loader.rb +1 -0
- data/test/test_client.rb +354 -40
- data/test/test_config_client.rb +1 -0
- data/test/test_config_loader.rb +1 -0
- data/test/test_config_resolver.rb +25 -24
- data/test/test_config_value_unwrapper.rb +22 -32
- data/test/test_context.rb +1 -0
- data/test/test_context_shape_aggregator.rb +11 -1
- data/test/test_criteria_evaluator.rb +180 -133
- data/test/test_evaluation_summary_aggregator.rb +162 -0
- data/test/test_example_contexts_aggregator.rb +238 -0
- data/test/test_helper.rb +5 -131
- data/test/test_integration.rb +6 -4
- data/test/test_local_config_parser.rb +2 -2
- data/test/test_log_path_aggregator.rb +9 -1
- data/test/test_logger.rb +6 -5
- data/test/test_options.rb +33 -2
- data/test/test_rate_limit_cache.rb +44 -0
- data/test/test_weighted_value_resolver.rb +13 -7
- metadata +13 -8
- data/lib/prefab/evaluated_configs_aggregator.rb +0 -60
- data/lib/prefab/evaluated_keys_aggregator.rb +0 -41
- data/lib/prefab/noop_cache.rb +0 -15
- data/lib/prefab/noop_stats.rb +0 -8
- data/test/test_evaluated_configs_aggregator.rb +0 -254
- data/test/test_evaluated_keys_aggregator.rb +0 -54
@@ -8,77 +8,67 @@ class TestConfigValueUnwrapper < Minitest::Test
|
|
8
8
|
|
9
9
|
def test_unwrapping_int
|
10
10
|
config_value = PrefabProto::ConfigValue.new(int: 123)
|
11
|
-
assert_equal 123,
|
11
|
+
assert_equal 123, unwrap(config_value, CONFIG_KEY, EMPTY_CONTEXT)
|
12
12
|
end
|
13
13
|
|
14
14
|
def test_unwrapping_string
|
15
15
|
config_value = PrefabProto::ConfigValue.new(string: 'abc')
|
16
|
-
assert_equal 'abc',
|
16
|
+
assert_equal 'abc', unwrap(config_value, CONFIG_KEY, EMPTY_CONTEXT)
|
17
17
|
end
|
18
18
|
|
19
19
|
def test_unwrapping_double
|
20
20
|
config_value = PrefabProto::ConfigValue.new(double: 1.23)
|
21
|
-
assert_equal 1.23,
|
21
|
+
assert_equal 1.23, unwrap(config_value, CONFIG_KEY, EMPTY_CONTEXT)
|
22
22
|
end
|
23
23
|
|
24
24
|
def test_unwrapping_bool
|
25
25
|
config_value = PrefabProto::ConfigValue.new(bool: true)
|
26
|
-
assert_equal true,
|
26
|
+
assert_equal true, unwrap(config_value, CONFIG_KEY, EMPTY_CONTEXT)
|
27
27
|
|
28
28
|
config_value = PrefabProto::ConfigValue.new(bool: false)
|
29
|
-
assert_equal false,
|
29
|
+
assert_equal false, unwrap(config_value, CONFIG_KEY, EMPTY_CONTEXT)
|
30
30
|
end
|
31
31
|
|
32
32
|
def test_unwrapping_log_level
|
33
33
|
config_value = PrefabProto::ConfigValue.new(log_level: :INFO)
|
34
|
-
assert_equal :INFO,
|
34
|
+
assert_equal :INFO, unwrap(config_value, CONFIG_KEY, EMPTY_CONTEXT)
|
35
35
|
end
|
36
36
|
|
37
37
|
def test_unwrapping_string_list
|
38
38
|
config_value = PrefabProto::ConfigValue.new(string_list: PrefabProto::StringList.new(values: %w[a b c]))
|
39
|
-
assert_equal %w[a b c],
|
39
|
+
assert_equal %w[a b c], unwrap(config_value, CONFIG_KEY, EMPTY_CONTEXT)
|
40
40
|
end
|
41
41
|
|
42
42
|
def test_unwrapping_weighted_values
|
43
43
|
# single value
|
44
44
|
config_value = PrefabProto::ConfigValue.new(weighted_values: weighted_values([['abc', 1]]))
|
45
45
|
|
46
|
-
assert_equal 'abc',
|
46
|
+
assert_equal 'abc', unwrap(config_value, CONFIG_KEY, EMPTY_CONTEXT)
|
47
47
|
|
48
48
|
# multiple values, evenly distributed
|
49
49
|
config_value = PrefabProto::ConfigValue.new(weighted_values: weighted_values([['abc', 1], ['def', 1], ['ghi', 1]]))
|
50
|
-
assert_equal 'def',
|
51
|
-
assert_equal 'ghi',
|
52
|
-
assert_equal 'abc',
|
53
|
-
assert_equal 'ghi',
|
50
|
+
assert_equal 'def', unwrap(config_value, CONFIG_KEY, context_with_key('user:000'))
|
51
|
+
assert_equal 'ghi', unwrap(config_value, CONFIG_KEY, context_with_key('user:456'))
|
52
|
+
assert_equal 'abc', unwrap(config_value, CONFIG_KEY, context_with_key('user:789'))
|
53
|
+
assert_equal 'ghi', unwrap(config_value, CONFIG_KEY, context_with_key('user:888'))
|
54
54
|
|
55
55
|
# multiple values, unevenly distributed
|
56
56
|
config_value = PrefabProto::ConfigValue.new(weighted_values: weighted_values([['abc', 1], ['def', 99], ['ghi', 1]]))
|
57
|
-
assert_equal 'def',
|
58
|
-
assert_equal 'def',
|
59
|
-
assert_equal 'def',
|
60
|
-
assert_equal 'def',
|
61
|
-
assert_equal 'ghi',
|
62
|
-
assert_equal 'abc',
|
57
|
+
assert_equal 'def', unwrap(config_value, CONFIG_KEY, context_with_key('user:123'))
|
58
|
+
assert_equal 'def', unwrap(config_value, CONFIG_KEY, context_with_key('user:456'))
|
59
|
+
assert_equal 'def', unwrap(config_value, CONFIG_KEY, context_with_key('user:789'))
|
60
|
+
assert_equal 'def', unwrap(config_value, CONFIG_KEY, context_with_key('user:012'))
|
61
|
+
assert_equal 'ghi', unwrap(config_value, CONFIG_KEY, context_with_key('user:428'))
|
62
|
+
assert_equal 'abc', unwrap(config_value, CONFIG_KEY, context_with_key('user:548'))
|
63
63
|
end
|
64
64
|
|
65
65
|
private
|
66
66
|
|
67
|
-
def weighted_values(values_and_weights, hash_by_property_name: 'user.key')
|
68
|
-
values = values_and_weights.map do |value, weight|
|
69
|
-
weighted_value(value, weight)
|
70
|
-
end
|
71
|
-
|
72
|
-
PrefabProto::WeightedValues.new(weighted_values: values, hash_by_property_name: hash_by_property_name)
|
73
|
-
end
|
74
|
-
|
75
|
-
def weighted_value(string, weight)
|
76
|
-
PrefabProto::WeightedValue.new(
|
77
|
-
value: PrefabProto::ConfigValue.new(string: string), weight: weight
|
78
|
-
)
|
79
|
-
end
|
80
|
-
|
81
67
|
def context_with_key(key)
|
82
68
|
Prefab::Context.new(user: { key: key })
|
83
69
|
end
|
70
|
+
|
71
|
+
def unwrap(config_value, config_key, context)
|
72
|
+
Prefab::ConfigValueUnwrapper.deepest_value(config_value, config_key, context).unwrap
|
73
|
+
end
|
84
74
|
end
|
data/test/test_context.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'test_helper'
|
4
|
+
require 'timecop'
|
4
5
|
|
5
6
|
class TestContextShapeAggregator < Minitest::Test
|
6
7
|
DOB = Date.new
|
@@ -49,6 +50,8 @@ class TestContextShapeAggregator < Minitest::Test
|
|
49
50
|
|
50
51
|
assert_equal [['user', 'name', 2], ['user', 'email', 2], ['user', 'age', 4], ['subscription', 'plan', 2], ['subscription', 'free', 5], ['user', 'dob', 2], ['device', 'name', 2], ['device', 'os', 2], ['device', 'version', 1]],
|
51
52
|
aggregator.data.to_a
|
53
|
+
|
54
|
+
assert_only_expected_logs
|
52
55
|
end
|
53
56
|
|
54
57
|
def test_prepare_data
|
@@ -82,6 +85,7 @@ class TestContextShapeAggregator < Minitest::Test
|
|
82
85
|
}
|
83
86
|
|
84
87
|
assert_equal [], aggregator.data.to_a
|
88
|
+
assert_only_expected_logs
|
85
89
|
end
|
86
90
|
|
87
91
|
def test_sync
|
@@ -117,6 +121,12 @@ class TestContextShapeAggregator < Minitest::Test
|
|
117
121
|
])
|
118
122
|
]
|
119
123
|
], requests
|
124
|
+
|
125
|
+
|
126
|
+
assert_logged [
|
127
|
+
"WARN 2023-08-09 15:18:12 -0400: cloud.prefab.client No success loading checkpoints",
|
128
|
+
"WARN 2023-08-09 15:18:12 -0400: cloud.prefab.client Couldn't Initialize In 0. Key some.key. Returning what we have"
|
129
|
+
]
|
120
130
|
end
|
121
131
|
|
122
132
|
private
|
@@ -127,7 +137,7 @@ class TestContextShapeAggregator < Minitest::Test
|
|
127
137
|
initialization_timeout_sec: 0,
|
128
138
|
on_init_failure: Prefab::Options::ON_INITIALIZATION_FAILURE::RETURN,
|
129
139
|
api_key: '123-development-yourapikey-SDK',
|
130
|
-
|
140
|
+
context_upload_mode: :shape_only
|
131
141
|
}.merge(overrides))
|
132
142
|
end
|
133
143
|
|