prefab-cloud-ruby 0.21.0 → 0.23.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/.github/workflows/ruby.yml +1 -1
- data/Gemfile +2 -0
- data/Gemfile.lock +9 -1
- data/README.md +11 -9
- data/VERSION +1 -1
- data/lib/prefab/cancellable_interceptor.rb +3 -3
- data/lib/prefab/client.rb +44 -7
- data/lib/prefab/config_client.rb +17 -16
- data/lib/prefab/config_loader.rb +1 -1
- data/lib/prefab/internal_logger.rb +1 -1
- data/lib/prefab/log_path_collector.rb +98 -0
- data/lib/prefab/logger_client.rb +35 -16
- data/lib/prefab/options.rb +22 -3
- data/lib/prefab/yaml_config_parser.rb +2 -2
- data/lib/prefab_pb.rb +21 -0
- data/lib/prefab_services_pb.rb +14 -0
- data/prefab-cloud-ruby.gemspec +8 -3
- data/test/test_client.rb +24 -0
- data/test/test_config_resolver.rb +0 -4
- data/test/test_helper.rb +17 -1
- data/test/test_log_path_collector.rb +56 -0
- data/test/test_logger.rb +253 -15
- data/test/test_options.rb +32 -0
- metadata +19 -2
data/lib/prefab_pb.rb
CHANGED
@@ -181,6 +181,24 @@ Google::Protobuf::DescriptorPool.generated_pool.build do
|
|
181
181
|
optional :sequence_name, :string, 3
|
182
182
|
optional :size, :int64, 4
|
183
183
|
end
|
184
|
+
add_message "prefab.Loggers" do
|
185
|
+
repeated :loggers, :message, 1, "prefab.Logger"
|
186
|
+
optional :start_at, :int64, 2
|
187
|
+
optional :end_at, :int64, 3
|
188
|
+
optional :instance_hash, :string, 4
|
189
|
+
proto3_optional :namespace, :string, 5
|
190
|
+
end
|
191
|
+
add_message "prefab.Logger" do
|
192
|
+
optional :logger_name, :string, 1
|
193
|
+
proto3_optional :traces, :int64, 2
|
194
|
+
proto3_optional :debugs, :int64, 3
|
195
|
+
proto3_optional :infos, :int64, 4
|
196
|
+
proto3_optional :warns, :int64, 5
|
197
|
+
proto3_optional :errors, :int64, 6
|
198
|
+
proto3_optional :fatals, :int64, 7
|
199
|
+
end
|
200
|
+
add_message "prefab.LoggerReportResponse" do
|
201
|
+
end
|
184
202
|
add_enum "prefab.ConfigType" do
|
185
203
|
value :NOT_SET_CONFIG_TYPE, 0
|
186
204
|
value :CONFIG, 1
|
@@ -236,6 +254,9 @@ module Prefab
|
|
236
254
|
CreationResponse = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("prefab.CreationResponse").msgclass
|
237
255
|
IdBlock = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("prefab.IdBlock").msgclass
|
238
256
|
IdBlockRequest = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("prefab.IdBlockRequest").msgclass
|
257
|
+
Loggers = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("prefab.Loggers").msgclass
|
258
|
+
Logger = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("prefab.Logger").msgclass
|
259
|
+
LoggerReportResponse = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("prefab.LoggerReportResponse").msgclass
|
239
260
|
ConfigType = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("prefab.ConfigType").enummodule
|
240
261
|
LogLevel = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("prefab.LogLevel").enummodule
|
241
262
|
OnFailure = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("prefab.OnFailure").enummodule
|
data/lib/prefab_services_pb.rb
CHANGED
@@ -61,6 +61,20 @@ module Prefab
|
|
61
61
|
rpc :GetAll, ::Prefab::Identity, ::Prefab::ConfigEvaluations
|
62
62
|
end
|
63
63
|
|
64
|
+
Stub = Service.rpc_stub_class
|
65
|
+
end
|
66
|
+
module LoggerReportingService
|
67
|
+
class Service
|
68
|
+
|
69
|
+
include ::GRPC::GenericService
|
70
|
+
|
71
|
+
self.marshal_class_method = :encode
|
72
|
+
self.unmarshal_class_method = :decode
|
73
|
+
self.service_name = 'prefab.LoggerReportingService'
|
74
|
+
|
75
|
+
rpc :Send, ::Prefab::Loggers, ::Prefab::LoggerReportResponse
|
76
|
+
end
|
77
|
+
|
64
78
|
Stub = Service.rpc_stub_class
|
65
79
|
end
|
66
80
|
end
|
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.
|
5
|
+
# stub: prefab-cloud-ruby 0.23.0 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "prefab-cloud-ruby".freeze
|
9
|
-
s.version = "0.
|
9
|
+
s.version = "0.23.0"
|
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 = "2023-
|
14
|
+
s.date = "2023-03-28"
|
15
15
|
s.description = "RateLimits & Config as a service".freeze
|
16
16
|
s.email = "jdwyer@prefab.cloud".freeze
|
17
17
|
s.extra_rdoc_files = [
|
@@ -48,6 +48,7 @@ Gem::Specification.new do |s|
|
|
48
48
|
"lib/prefab/feature_flag_client.rb",
|
49
49
|
"lib/prefab/internal_logger.rb",
|
50
50
|
"lib/prefab/local_config_parser.rb",
|
51
|
+
"lib/prefab/log_path_collector.rb",
|
51
52
|
"lib/prefab/logger_client.rb",
|
52
53
|
"lib/prefab/murmer3.rb",
|
53
54
|
"lib/prefab/noop_cache.rb",
|
@@ -74,7 +75,9 @@ Gem::Specification.new do |s|
|
|
74
75
|
"test/test_helper.rb",
|
75
76
|
"test/test_integration.rb",
|
76
77
|
"test/test_local_config_parser.rb",
|
78
|
+
"test/test_log_path_collector.rb",
|
77
79
|
"test/test_logger.rb",
|
80
|
+
"test/test_options.rb",
|
78
81
|
"test/test_weighted_value_resolver.rb"
|
79
82
|
]
|
80
83
|
s.homepage = "http://github.com/prefab-cloud/prefab-cloud-ruby".freeze
|
@@ -93,6 +96,7 @@ Gem::Specification.new do |s|
|
|
93
96
|
s.add_runtime_dependency(%q<google-protobuf>.freeze, [">= 0"])
|
94
97
|
s.add_runtime_dependency(%q<grpc>.freeze, [">= 0"])
|
95
98
|
s.add_runtime_dependency(%q<ld-eventsource>.freeze, [">= 0"])
|
99
|
+
s.add_runtime_dependency(%q<uuid>.freeze, [">= 0"])
|
96
100
|
s.add_development_dependency(%q<benchmark-ips>.freeze, [">= 0"])
|
97
101
|
s.add_development_dependency(%q<bundler>.freeze, [">= 0"])
|
98
102
|
s.add_development_dependency(%q<grpc-tools>.freeze, [">= 0"])
|
@@ -106,6 +110,7 @@ Gem::Specification.new do |s|
|
|
106
110
|
s.add_dependency(%q<google-protobuf>.freeze, [">= 0"])
|
107
111
|
s.add_dependency(%q<grpc>.freeze, [">= 0"])
|
108
112
|
s.add_dependency(%q<ld-eventsource>.freeze, [">= 0"])
|
113
|
+
s.add_dependency(%q<uuid>.freeze, [">= 0"])
|
109
114
|
s.add_dependency(%q<benchmark-ips>.freeze, [">= 0"])
|
110
115
|
s.add_dependency(%q<bundler>.freeze, [">= 0"])
|
111
116
|
s.add_dependency(%q<grpc-tools>.freeze, [">= 0"])
|
data/test/test_client.rb
CHANGED
@@ -84,6 +84,30 @@ class TestClient < Minitest::Test
|
|
84
84
|
assert certs.length > 1
|
85
85
|
end
|
86
86
|
|
87
|
+
def test_initialization_with_an_options_object
|
88
|
+
options_hash = {
|
89
|
+
namespace: 'test-namespace',
|
90
|
+
prefab_datasources: Prefab::Options::DATASOURCES::LOCAL_ONLY
|
91
|
+
}
|
92
|
+
|
93
|
+
options = Prefab::Options.new(options_hash)
|
94
|
+
|
95
|
+
client = Prefab::Client.new(options)
|
96
|
+
|
97
|
+
assert_equal client.namespace, 'test-namespace'
|
98
|
+
end
|
99
|
+
|
100
|
+
def test_initialization_with_a_hash
|
101
|
+
options_hash = {
|
102
|
+
namespace: 'test-namespace',
|
103
|
+
prefab_datasources: Prefab::Options::DATASOURCES::LOCAL_ONLY
|
104
|
+
}
|
105
|
+
|
106
|
+
client = Prefab::Client.new(options_hash)
|
107
|
+
|
108
|
+
assert_equal client.namespace, 'test-namespace'
|
109
|
+
end
|
110
|
+
|
87
111
|
private
|
88
112
|
|
89
113
|
def new_client(overrides = {})
|
data/test/test_helper.rb
CHANGED
@@ -43,7 +43,7 @@ class MockConfigClient
|
|
43
43
|
@config_values = config_values
|
44
44
|
end
|
45
45
|
|
46
|
-
def get(key, default = nil)
|
46
|
+
def get(key, default = nil, _, _)
|
47
47
|
@config_values.fetch(key, default)
|
48
48
|
end
|
49
49
|
|
@@ -93,3 +93,19 @@ def new_client(overrides = {})
|
|
93
93
|
|
94
94
|
Prefab::Client.new(options)
|
95
95
|
end
|
96
|
+
|
97
|
+
def string_list(values)
|
98
|
+
Prefab::ConfigValue.new(string_list: Prefab::StringList.new(values: values))
|
99
|
+
end
|
100
|
+
|
101
|
+
def inject_config(client, config)
|
102
|
+
resolver = client.config_client.instance_variable_get('@config_resolver')
|
103
|
+
store = resolver.instance_variable_get('@local_store')
|
104
|
+
|
105
|
+
store[config.key] = { config: config }
|
106
|
+
end
|
107
|
+
|
108
|
+
def inject_project_env_id(client, project_env_id)
|
109
|
+
resolver = client.config_client.instance_variable_get('@config_resolver')
|
110
|
+
resolver.project_env_id = project_env_id
|
111
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
require 'timecop'
|
5
|
+
|
6
|
+
class TestLogPathCollector < Minitest::Test
|
7
|
+
def test_sync
|
8
|
+
Timecop.freeze do
|
9
|
+
client = new_client(namespace: 'this.is.a.namespace')
|
10
|
+
|
11
|
+
2.times { client.log.info('here is a message') }
|
12
|
+
3.times { client.log.error('here is a message') }
|
13
|
+
|
14
|
+
requests = []
|
15
|
+
|
16
|
+
client.define_singleton_method(:request) do |*params|
|
17
|
+
requests.push(params)
|
18
|
+
end
|
19
|
+
|
20
|
+
client.log_path_collector.send(:sync)
|
21
|
+
|
22
|
+
# let the flush thread run
|
23
|
+
sleep 0.01 while requests.length == 0
|
24
|
+
|
25
|
+
assert_equal requests, [[
|
26
|
+
Prefab::LoggerReportingService,
|
27
|
+
:send,
|
28
|
+
{
|
29
|
+
req_options: {},
|
30
|
+
params: Prefab::Loggers.new(
|
31
|
+
loggers: [Prefab::Logger.new(logger_name: 'test.test_log_path_collector.test_sync',
|
32
|
+
infos: 2, errors: 3)],
|
33
|
+
start_at: (Time.now.utc.to_f * 1000).to_i,
|
34
|
+
end_at: (Time.now.utc.to_f * 1000).to_i,
|
35
|
+
instance_hash: client.instance_hash,
|
36
|
+
namespace: 'this.is.a.namespace'
|
37
|
+
)
|
38
|
+
}
|
39
|
+
]]
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def new_client(overrides = {})
|
46
|
+
options = Prefab::Options.new(**{
|
47
|
+
prefab_config_override_dir: 'none',
|
48
|
+
prefab_config_classpath_dir: 'test',
|
49
|
+
prefab_envs: ['unit_tests'],
|
50
|
+
api_key: '123-development-yourapikey-SDK',
|
51
|
+
collect_sync_interval: 1000 # we'll trigger sync manually in our test
|
52
|
+
}.merge(overrides))
|
53
|
+
|
54
|
+
Prefab::Client.new(options)
|
55
|
+
end
|
56
|
+
end
|
data/test/test_logger.rb
CHANGED
@@ -2,7 +2,22 @@
|
|
2
2
|
|
3
3
|
require 'test_helper'
|
4
4
|
|
5
|
-
class
|
5
|
+
class TestLogger < Minitest::Test
|
6
|
+
TEST_ENV_ID = 2
|
7
|
+
DEFAULT_VALUE = 'FATAL'
|
8
|
+
DEFAULT_ENV_VALUE = 'INFO'
|
9
|
+
DESIRED_VALUE = 'DEBUG'
|
10
|
+
WRONG_ENV_VALUE = 'ERROR'
|
11
|
+
PROJECT_ENV_ID = 1
|
12
|
+
|
13
|
+
DEFAULT_ROW = Prefab::ConfigRow.new(
|
14
|
+
values: [
|
15
|
+
Prefab::ConditionalValue.new(
|
16
|
+
value: Prefab::ConfigValue.new(log_level: DEFAULT_VALUE)
|
17
|
+
)
|
18
|
+
]
|
19
|
+
)
|
20
|
+
|
6
21
|
def setup
|
7
22
|
Prefab::LoggerClient.send(:public, :get_path)
|
8
23
|
Prefab::LoggerClient.send(:public, :get_loc_path)
|
@@ -47,37 +62,37 @@ class TestCLogger < Minitest::Test
|
|
47
62
|
def test_level_of
|
48
63
|
with_env('PREFAB_LOG_CLIENT_BOOTSTRAP_LOG_LEVEL', 'info') do
|
49
64
|
# env var overrides the default level
|
50
|
-
assert_equal Logger::INFO,
|
65
|
+
assert_equal ::Logger::INFO,
|
51
66
|
@logger.level_of('app.models.user'), 'PREFAB_LOG_CLIENT_BOOTSTRAP_LOG_LEVEL is info'
|
52
67
|
|
53
68
|
@logger.set_config_client(MockConfigClient.new({}))
|
54
|
-
assert_equal Logger::WARN,
|
69
|
+
assert_equal ::Logger::WARN,
|
55
70
|
@logger.level_of('app.models.user'), 'default is warn'
|
56
71
|
|
57
72
|
@logger.set_config_client(MockConfigClient.new('log-level.app' => :INFO))
|
58
|
-
assert_equal Logger::INFO,
|
73
|
+
assert_equal ::Logger::INFO,
|
59
74
|
@logger.level_of('app.models.user')
|
60
75
|
|
61
76
|
@logger.set_config_client(MockConfigClient.new('log-level.app' => :DEBUG))
|
62
|
-
assert_equal Logger::DEBUG,
|
77
|
+
assert_equal ::Logger::DEBUG,
|
63
78
|
@logger.level_of('app.models.user')
|
64
79
|
|
65
80
|
@logger.set_config_client(MockConfigClient.new('log-level.app' => :DEBUG,
|
66
81
|
'log-level.app.models' => :ERROR))
|
67
|
-
assert_equal Logger::ERROR,
|
82
|
+
assert_equal ::Logger::ERROR,
|
68
83
|
@logger.level_of('app.models.user'), 'test leveling'
|
69
84
|
end
|
70
85
|
end
|
71
86
|
|
72
87
|
def test_log_internal
|
73
88
|
logger, mock_logdev = mock_logger_expecting(/W, \[.*\] WARN -- cloud.prefab.client.test.path: : test message/)
|
74
|
-
logger.log_internal('test message', 'test.path', '', Logger::WARN)
|
89
|
+
logger.log_internal('test message', 'test.path', '', ::Logger::WARN)
|
75
90
|
mock_logdev.verify
|
76
91
|
end
|
77
92
|
|
78
93
|
def test_log_internal_unknown
|
79
94
|
logger, mock_logdev = mock_logger_expecting(/A, \[.*\] ANY -- cloud.prefab.client.test.path: : test message/)
|
80
|
-
logger.log_internal('test message', 'test.path', '', Logger::UNKNOWN)
|
95
|
+
logger.log_internal('test message', 'test.path', '', ::Logger::UNKNOWN)
|
81
96
|
mock_logdev.verify
|
82
97
|
end
|
83
98
|
|
@@ -85,30 +100,30 @@ class TestCLogger < Minitest::Test
|
|
85
100
|
logger, mock_logdev = mock_logger_expecting(/W, \[.*\] WARN -- cloud.prefab.client.test.path: : should log/,
|
86
101
|
calls: 2)
|
87
102
|
logger.silence do
|
88
|
-
logger.log_internal('should not log', 'test.path', '', Logger::WARN)
|
103
|
+
logger.log_internal('should not log', 'test.path', '', ::Logger::WARN)
|
89
104
|
end
|
90
|
-
logger.log_internal('should log', 'test.path', '', Logger::WARN)
|
105
|
+
logger.log_internal('should log', 'test.path', '', ::Logger::WARN)
|
91
106
|
mock_logdev.verify
|
92
107
|
end
|
93
108
|
|
94
109
|
def test_log
|
95
110
|
logger, mock_logdev = mock_logger_expecting(/W, \[.*\] WARN -- test.path: : test message/)
|
96
|
-
logger.log('test message', 'test.path', '', Logger::WARN)
|
111
|
+
logger.log('test message', 'test.path', '', ::Logger::WARN)
|
97
112
|
mock_logdev.verify
|
98
113
|
end
|
99
114
|
|
100
115
|
def test_log_unknown
|
101
116
|
logger, mock_logdev = mock_logger_expecting(/A, \[.*\] ANY -- test.path: : test message/)
|
102
|
-
logger.log('test message', 'test.path', '', Logger::UNKNOWN)
|
117
|
+
logger.log('test message', 'test.path', '', ::Logger::UNKNOWN)
|
103
118
|
mock_logdev.verify
|
104
119
|
end
|
105
120
|
|
106
121
|
def test_log_silencing
|
107
122
|
logger, mock_logdev = mock_logger_expecting(/W, \[.*\] WARN -- test.path: : should log/, calls: 2)
|
108
123
|
logger.silence do
|
109
|
-
logger.log('should not log', 'test.path', '', Logger::WARN)
|
124
|
+
logger.log('should not log', 'test.path', '', ::Logger::WARN)
|
110
125
|
end
|
111
|
-
logger.log('should log', 'test.path', '', Logger::WARN)
|
126
|
+
logger.log('should log', 'test.path', '', ::Logger::WARN)
|
112
127
|
mock_logdev.verify
|
113
128
|
end
|
114
129
|
|
@@ -160,10 +175,226 @@ class TestCLogger < Minitest::Test
|
|
160
175
|
assert_logged io, 'ERROR', 'MY_PROGNAME test.test_logger.test_logging_with_a_progname_and_no_message', 'MY_PROGNAME'
|
161
176
|
end
|
162
177
|
|
178
|
+
def test_logging_with_criteria_on_top_level_key
|
179
|
+
prefix = 'my.own.prefix'
|
180
|
+
|
181
|
+
config = Prefab::Config.new(
|
182
|
+
key: 'log-level',
|
183
|
+
rows: [
|
184
|
+
DEFAULT_ROW,
|
185
|
+
|
186
|
+
# wrong env
|
187
|
+
Prefab::ConfigRow.new(
|
188
|
+
project_env_id: TEST_ENV_ID,
|
189
|
+
values: [
|
190
|
+
Prefab::ConditionalValue.new(
|
191
|
+
criteria: [
|
192
|
+
Prefab::Criterion.new(
|
193
|
+
operator: Prefab::Criterion::CriterionOperator::PROP_IS_ONE_OF,
|
194
|
+
value_to_match: string_list(['hotmail.com', 'gmail.com']),
|
195
|
+
property_name: 'email_suffix'
|
196
|
+
)
|
197
|
+
],
|
198
|
+
value: Prefab::ConfigValue.new(log_level: WRONG_ENV_VALUE)
|
199
|
+
)
|
200
|
+
]
|
201
|
+
),
|
202
|
+
|
203
|
+
# correct env
|
204
|
+
Prefab::ConfigRow.new(
|
205
|
+
project_env_id: PROJECT_ENV_ID,
|
206
|
+
values: [
|
207
|
+
Prefab::ConditionalValue.new(
|
208
|
+
criteria: [
|
209
|
+
Prefab::Criterion.new(
|
210
|
+
operator: Prefab::Criterion::CriterionOperator::PROP_IS_ONE_OF,
|
211
|
+
value_to_match: string_list(['hotmail.com', 'gmail.com']),
|
212
|
+
property_name: 'email_suffix'
|
213
|
+
)
|
214
|
+
],
|
215
|
+
value: Prefab::ConfigValue.new(log_level: DESIRED_VALUE)
|
216
|
+
),
|
217
|
+
Prefab::ConditionalValue.new(
|
218
|
+
value: Prefab::ConfigValue.new(log_level: DEFAULT_ENV_VALUE)
|
219
|
+
)
|
220
|
+
]
|
221
|
+
)
|
222
|
+
]
|
223
|
+
)
|
224
|
+
|
225
|
+
prefab, io = captured_logger(log_prefix: prefix)
|
226
|
+
|
227
|
+
inject_config(prefab, config)
|
228
|
+
inject_project_env_id(prefab, PROJECT_ENV_ID)
|
229
|
+
|
230
|
+
# without any context, the level should be the default for the env (info)
|
231
|
+
prefab.with_log_context(nil, {}) do
|
232
|
+
prefab.log.debug 'Test debug'
|
233
|
+
refute_logged io, 'Test debug'
|
234
|
+
|
235
|
+
prefab.log.info 'Test info'
|
236
|
+
assert_logged io, 'INFO', "#{prefix}.test.test_logger.test_logging_with_criteria_on_top_level_key", 'Test info'
|
237
|
+
|
238
|
+
prefab.log.error 'Test error'
|
239
|
+
assert_logged io, 'ERROR', "#{prefix}.test.test_logger.test_logging_with_criteria_on_top_level_key", 'Test error'
|
240
|
+
end
|
241
|
+
|
242
|
+
reset_io(io)
|
243
|
+
|
244
|
+
# with the wrong context, the level should be the default for the env (info)
|
245
|
+
prefab.with_log_context('user:1234', email_suffix: 'yahoo.com') do
|
246
|
+
prefab.log.debug 'Test debug'
|
247
|
+
refute_logged io, 'Test debug'
|
248
|
+
|
249
|
+
prefab.log.info 'Test info'
|
250
|
+
assert_logged io, 'INFO', "#{prefix}.test.test_logger.test_logging_with_criteria_on_top_level_key", 'Test info'
|
251
|
+
|
252
|
+
prefab.log.error 'Test error'
|
253
|
+
assert_logged io, 'ERROR', "#{prefix}.test.test_logger.test_logging_with_criteria_on_top_level_key", 'Test error'
|
254
|
+
end
|
255
|
+
|
256
|
+
reset_io(io)
|
257
|
+
|
258
|
+
# with the correct context, the level should be the desired value (debug)
|
259
|
+
prefab.with_log_context('user:1234', email_suffix: 'hotmail.com') do
|
260
|
+
prefab.log.debug 'Test debug'
|
261
|
+
assert_logged io, 'DEBUG', "#{prefix}.test.test_logger.test_logging_with_criteria_on_top_level_key", 'Test debug'
|
262
|
+
|
263
|
+
prefab.log.info 'Test info'
|
264
|
+
assert_logged io, 'INFO', "#{prefix}.test.test_logger.test_logging_with_criteria_on_top_level_key", 'Test info'
|
265
|
+
|
266
|
+
prefab.log.error 'Test error'
|
267
|
+
assert_logged io, 'ERROR', "#{prefix}.test.test_logger.test_logging_with_criteria_on_top_level_key", 'Test error'
|
268
|
+
end
|
269
|
+
end
|
270
|
+
|
271
|
+
def test_logging_with_criteria_on_key_path
|
272
|
+
prefix = 'my.own.prefix'
|
273
|
+
|
274
|
+
config = Prefab::Config.new(
|
275
|
+
key: 'log-level.my.own.prefix.test.test_logger',
|
276
|
+
rows: [
|
277
|
+
DEFAULT_ROW,
|
278
|
+
|
279
|
+
# wrong env
|
280
|
+
Prefab::ConfigRow.new(
|
281
|
+
project_env_id: TEST_ENV_ID,
|
282
|
+
values: [
|
283
|
+
Prefab::ConditionalValue.new(
|
284
|
+
criteria: [
|
285
|
+
Prefab::Criterion.new(
|
286
|
+
operator: Prefab::Criterion::CriterionOperator::PROP_IS_ONE_OF,
|
287
|
+
value_to_match: string_list(['hotmail.com', 'gmail.com']),
|
288
|
+
property_name: 'email_suffix'
|
289
|
+
)
|
290
|
+
],
|
291
|
+
value: Prefab::ConfigValue.new(log_level: WRONG_ENV_VALUE)
|
292
|
+
)
|
293
|
+
]
|
294
|
+
),
|
295
|
+
|
296
|
+
# correct env
|
297
|
+
Prefab::ConfigRow.new(
|
298
|
+
project_env_id: PROJECT_ENV_ID,
|
299
|
+
values: [
|
300
|
+
Prefab::ConditionalValue.new(
|
301
|
+
criteria: [
|
302
|
+
Prefab::Criterion.new(
|
303
|
+
operator: Prefab::Criterion::CriterionOperator::PROP_IS_ONE_OF,
|
304
|
+
value_to_match: string_list(['hotmail.com', 'gmail.com']),
|
305
|
+
property_name: 'email_suffix'
|
306
|
+
)
|
307
|
+
],
|
308
|
+
value: Prefab::ConfigValue.new(log_level: DESIRED_VALUE)
|
309
|
+
),
|
310
|
+
|
311
|
+
Prefab::ConditionalValue.new(
|
312
|
+
criteria: [
|
313
|
+
Prefab::Criterion.new(
|
314
|
+
operator: Prefab::Criterion::CriterionOperator::LOOKUP_KEY_IN,
|
315
|
+
value_to_match: string_list(%w[user:4567]),
|
316
|
+
property_name: Prefab::CriteriaEvaluator::LOOKUP_KEY
|
317
|
+
)
|
318
|
+
],
|
319
|
+
value: Prefab::ConfigValue.new(log_level: DESIRED_VALUE)
|
320
|
+
),
|
321
|
+
|
322
|
+
Prefab::ConditionalValue.new(
|
323
|
+
value: Prefab::ConfigValue.new(log_level: DEFAULT_ENV_VALUE)
|
324
|
+
)
|
325
|
+
]
|
326
|
+
)
|
327
|
+
]
|
328
|
+
)
|
329
|
+
|
330
|
+
prefab, io = captured_logger(log_prefix: prefix)
|
331
|
+
|
332
|
+
inject_config(prefab, config)
|
333
|
+
inject_project_env_id(prefab, PROJECT_ENV_ID)
|
334
|
+
|
335
|
+
# without any context, the level should be the default for the env (info)
|
336
|
+
prefab.with_log_context(nil, {}) do
|
337
|
+
prefab.log.debug 'Test debug'
|
338
|
+
refute_logged io, 'Test debug'
|
339
|
+
|
340
|
+
prefab.log.info 'Test info'
|
341
|
+
assert_logged io, 'INFO', "#{prefix}.test.test_logger.test_logging_with_criteria_on_key_path", 'Test info'
|
342
|
+
|
343
|
+
prefab.log.error 'Test error'
|
344
|
+
assert_logged io, 'ERROR', "#{prefix}.test.test_logger.test_logging_with_criteria_on_key_path", 'Test error'
|
345
|
+
end
|
346
|
+
|
347
|
+
reset_io(io)
|
348
|
+
|
349
|
+
# with the wrong context, the level should be the default for the env (info)
|
350
|
+
prefab.with_log_context('user:1234', email_suffix: 'yahoo.com') do
|
351
|
+
prefab.log.debug 'Test debug'
|
352
|
+
refute_logged io, 'Test debug'
|
353
|
+
|
354
|
+
prefab.log.info 'Test info'
|
355
|
+
assert_logged io, 'INFO', "#{prefix}.test.test_logger.test_logging_with_criteria_on_key_path", 'Test info'
|
356
|
+
|
357
|
+
prefab.log.error 'Test error'
|
358
|
+
assert_logged io, 'ERROR', "#{prefix}.test.test_logger.test_logging_with_criteria_on_key_path", 'Test error'
|
359
|
+
end
|
360
|
+
|
361
|
+
reset_io(io)
|
362
|
+
|
363
|
+
# with the correct context, the level should be the desired value (debug)
|
364
|
+
prefab.with_log_context('user:1234', email_suffix: 'hotmail.com') do
|
365
|
+
prefab.log.debug 'Test debug'
|
366
|
+
assert_logged io, 'DEBUG', "#{prefix}.test.test_logger.test_logging_with_criteria_on_key_path", 'Test debug'
|
367
|
+
|
368
|
+
prefab.log.info 'Test info'
|
369
|
+
assert_logged io, 'INFO', "#{prefix}.test.test_logger.test_logging_with_criteria_on_key_path", 'Test info'
|
370
|
+
|
371
|
+
prefab.log.error 'Test error'
|
372
|
+
assert_logged io, 'ERROR', "#{prefix}.test.test_logger.test_logging_with_criteria_on_key_path", 'Test error'
|
373
|
+
end
|
374
|
+
|
375
|
+
reset_io(io)
|
376
|
+
|
377
|
+
# with the correct lookup key
|
378
|
+
prefab.with_log_context('user:4567', email_suffix: 'example.com') do
|
379
|
+
prefab.log.debug 'Test debug'
|
380
|
+
assert_logged io, 'DEBUG', "#{prefix}.test.test_logger.test_logging_with_criteria_on_key_path", 'Test debug'
|
381
|
+
|
382
|
+
prefab.log.info 'Test info'
|
383
|
+
assert_logged io, 'INFO', "#{prefix}.test.test_logger.test_logging_with_criteria_on_key_path", 'Test info'
|
384
|
+
|
385
|
+
prefab.log.error 'Test error'
|
386
|
+
assert_logged io, 'ERROR', "#{prefix}.test.test_logger.test_logging_with_criteria_on_key_path", 'Test error'
|
387
|
+
end
|
388
|
+
end
|
389
|
+
|
163
390
|
private
|
164
391
|
|
165
392
|
def assert_logged(logged_io, level, path, message)
|
166
|
-
assert_match(/#{level}
|
393
|
+
assert_match(/#{level}\s+\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} [-+]?\d+:\s+#{path}: #{message}\n/, logged_io.string)
|
394
|
+
end
|
395
|
+
|
396
|
+
def refute_logged(logged_io, message)
|
397
|
+
refute_match(/#{message}/, logged_io.string)
|
167
398
|
end
|
168
399
|
|
169
400
|
def mock_logger_expecting(pattern, configs = {}, calls: 1)
|
@@ -192,4 +423,11 @@ class TestCLogger < Minitest::Test
|
|
192
423
|
|
193
424
|
[prefab, io]
|
194
425
|
end
|
426
|
+
|
427
|
+
def reset_io(io)
|
428
|
+
io.close
|
429
|
+
io.reopen
|
430
|
+
|
431
|
+
assert_equal '', io.string
|
432
|
+
end
|
195
433
|
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
|
5
|
+
class TestOptions < Minitest::Test
|
6
|
+
API_KEY = 'abcdefg'
|
7
|
+
|
8
|
+
def test_works_with_named_arguments
|
9
|
+
assert_equal API_KEY, Prefab::Options.new(api_key: API_KEY).api_key
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_works_with_hash
|
13
|
+
assert_equal API_KEY, Prefab::Options.new({ api_key: API_KEY }).api_key
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_collect_max_paths
|
17
|
+
assert_equal 1000, Prefab::Options.new.collect_max_paths
|
18
|
+
assert_equal 100, Prefab::Options.new(collect_max_paths: 100).collect_max_paths
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_collect_max_paths_with_local_only
|
22
|
+
options = Prefab::Options.new(collect_max_paths: 100,
|
23
|
+
prefab_datasources: Prefab::Options::DATASOURCES::LOCAL_ONLY)
|
24
|
+
assert_equal 0, options.collect_max_paths
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_collect_max_paths_with_collect_logs_false
|
28
|
+
options = Prefab::Options.new(collect_max_paths: 100,
|
29
|
+
collect_logs: false)
|
30
|
+
assert_equal 0, options.collect_max_paths
|
31
|
+
end
|
32
|
+
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.
|
4
|
+
version: 0.23.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeff Dwyer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-03-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|
@@ -100,6 +100,20 @@ dependencies:
|
|
100
100
|
- - ">="
|
101
101
|
- !ruby/object:Gem::Version
|
102
102
|
version: '0'
|
103
|
+
- !ruby/object:Gem::Dependency
|
104
|
+
name: uuid
|
105
|
+
requirement: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
type: :runtime
|
111
|
+
prerelease: false
|
112
|
+
version_requirements: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
103
117
|
- !ruby/object:Gem::Dependency
|
104
118
|
name: benchmark-ips
|
105
119
|
requirement: !ruby/object:Gem::Requirement
|
@@ -221,6 +235,7 @@ files:
|
|
221
235
|
- lib/prefab/feature_flag_client.rb
|
222
236
|
- lib/prefab/internal_logger.rb
|
223
237
|
- lib/prefab/local_config_parser.rb
|
238
|
+
- lib/prefab/log_path_collector.rb
|
224
239
|
- lib/prefab/logger_client.rb
|
225
240
|
- lib/prefab/murmer3.rb
|
226
241
|
- lib/prefab/noop_cache.rb
|
@@ -247,7 +262,9 @@ files:
|
|
247
262
|
- test/test_helper.rb
|
248
263
|
- test/test_integration.rb
|
249
264
|
- test/test_local_config_parser.rb
|
265
|
+
- test/test_log_path_collector.rb
|
250
266
|
- test/test_logger.rb
|
267
|
+
- test/test_options.rb
|
251
268
|
- test/test_weighted_value_resolver.rb
|
252
269
|
homepage: http://github.com/prefab-cloud/prefab-cloud-ruby
|
253
270
|
licenses:
|