prefab-cloud-ruby 0.16.0 → 0.17.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -1
- data/Gemfile.lock +2 -4
- data/README.md +2 -3
- data/VERSION +1 -1
- data/lib/prefab/auth_interceptor.rb +4 -3
- data/lib/prefab/config_client.rb +1 -2
- data/lib/prefab/config_helper.rb +2 -0
- data/lib/prefab/config_loader.rb +9 -4
- data/lib/prefab/logger_client.rb +17 -11
- data/lib/prefab_pb.rb +11 -1
- data/prefab-cloud-ruby.gemspec +5 -5
- data/test/.prefab.unit_tests.config.yaml +2 -1
- data/test/test_config_client.rb +3 -0
- data/test/test_config_loader.rb +7 -3
- data/test/test_helper.rb +2 -1
- data/test/test_logger.rb +6 -6
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 96a092713ab6a3e93c9597c9457144769d954679877d35cfa21550880fb30251
|
4
|
+
data.tar.gz: 43aaa1cadb70983991ea7f2908d5986c47579e9057574a8cd623f4a12d2e4e3e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8392d08f8bdd0b6bfd89e1b1ad32fb3e1161e60f8b2ad54984d0cc1795b91476061c7b38a770263a48d217072d8562e6d4dd1b348c975f22cab092e25d017806
|
7
|
+
data.tar.gz: c6fc0b30a9f52d850b1e6422932691b47004a29738cf8adeafada21d734392630df00d081b4dc230a8a0ba2148ebf4d12610a4d17d3791eb02104097fce86b96
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -47,7 +47,6 @@ GEM
|
|
47
47
|
http-cookie (1.0.4)
|
48
48
|
domain_name (~> 0.5)
|
49
49
|
http-form_data (2.3.0)
|
50
|
-
json (1.8.6)
|
51
50
|
juwelier (2.4.9)
|
52
51
|
builder
|
53
52
|
bundler
|
@@ -89,8 +88,7 @@ GEM
|
|
89
88
|
rack (2.2.4)
|
90
89
|
rake (13.0.3)
|
91
90
|
rchardet (1.8.0)
|
92
|
-
rdoc (3.
|
93
|
-
json (~> 1.4)
|
91
|
+
rdoc (6.3.3)
|
94
92
|
ruby2_keywords (0.0.4)
|
95
93
|
semver2 (3.4.2)
|
96
94
|
simplecov (0.18.5)
|
@@ -121,7 +119,7 @@ DEPENDENCIES
|
|
121
119
|
juwelier (~> 2.4.9)
|
122
120
|
ld-eventsource
|
123
121
|
minitest
|
124
|
-
rdoc
|
122
|
+
rdoc
|
125
123
|
simplecov
|
126
124
|
thin
|
127
125
|
|
data/README.md
CHANGED
@@ -31,8 +31,7 @@ Many ruby web servers fork. GRPC does not like to be forked. You should manually
|
|
31
31
|
```ruby
|
32
32
|
|
33
33
|
#config/initializers/prefab.rb
|
34
|
-
$prefab = Prefab::Client.new
|
35
|
-
logdev: $stdout)
|
34
|
+
$prefab = Prefab::Client.new
|
36
35
|
Rails.logger = $prefab.log
|
37
36
|
```
|
38
37
|
|
@@ -45,7 +44,7 @@ end
|
|
45
44
|
|
46
45
|
## Logging & Debugging
|
47
46
|
In classpath or ~/.prefab.overrides.config.yaml set
|
48
|
-
```
|
47
|
+
```log-level.prefab: debug```
|
49
48
|
|
50
49
|
To debug issues before this config file has been read, set env var
|
51
50
|
```
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.17.0
|
@@ -1,9 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
module Prefab
|
3
3
|
class AuthInterceptor < GRPC::ClientInterceptor
|
4
|
+
VERSION = File.exist?('VERSION') ? File.read('VERSION').chomp : ""
|
5
|
+
CLIENT = "prefab-cloud-ruby.#{VERSION}".freeze
|
6
|
+
|
4
7
|
def initialize(api_key)
|
5
|
-
version = File.exist?('VERSION') ? File.read('VERSION').chomp : ""
|
6
|
-
@client = "prefab-cloud-ruby.#{version}".freeze
|
7
8
|
@api_key = api_key
|
8
9
|
end
|
9
10
|
|
@@ -25,7 +26,7 @@ module Prefab
|
|
25
26
|
|
26
27
|
def shared(metadata)
|
27
28
|
metadata['auth'] = @api_key
|
28
|
-
metadata['client'] =
|
29
|
+
metadata['client'] = CLIENT
|
29
30
|
yield
|
30
31
|
end
|
31
32
|
end
|
data/lib/prefab/config_client.rb
CHANGED
@@ -149,8 +149,7 @@ module Prefab
|
|
149
149
|
end
|
150
150
|
|
151
151
|
def load_checkpoint_api_cdn
|
152
|
-
|
153
|
-
url = "#{@options.url_for_api_cdn}/api/v1/configs/0/#{key_hash}/0"
|
152
|
+
url = "#{@options.url_for_api_cdn}/api/v1/configs/0"
|
154
153
|
conn = if Faraday::VERSION[0].to_i >= 2
|
155
154
|
Faraday.new(url) do |conn|
|
156
155
|
conn.request :authorization, :basic, AUTH_USER, @base_client.api_key
|
data/lib/prefab/config_helper.rb
CHANGED
data/lib/prefab/config_loader.rb
CHANGED
@@ -102,7 +102,7 @@ module Prefab
|
|
102
102
|
config: Prefab::Config.new(
|
103
103
|
key: k,
|
104
104
|
rows: [
|
105
|
-
Prefab::ConfigRow.new(value: Prefab::ConfigValue.new(value_from(v)))
|
105
|
+
Prefab::ConfigRow.new(value: Prefab::ConfigValue.new(value_from(k, v)))
|
106
106
|
]
|
107
107
|
)
|
108
108
|
}
|
@@ -119,10 +119,15 @@ module Prefab
|
|
119
119
|
end
|
120
120
|
end
|
121
121
|
|
122
|
-
def value_from(raw)
|
122
|
+
def value_from(key, raw)
|
123
123
|
case raw
|
124
124
|
when String
|
125
|
-
|
125
|
+
if key.start_with? Prefab::LoggerClient::BASE_KEY
|
126
|
+
prefab_log_level_resolve = Prefab::LogLevel.resolve(raw.upcase.to_sym) || Prefab::LogLevel::NOT_SET_LOG_LEVEL
|
127
|
+
{ log_level: prefab_log_level_resolve }
|
128
|
+
else
|
129
|
+
{ string: raw }
|
130
|
+
end
|
126
131
|
when Integer
|
127
132
|
{ int: raw }
|
128
133
|
when TrueClass, FalseClass
|
@@ -165,7 +170,7 @@ module Prefab
|
|
165
170
|
match: key,
|
166
171
|
config: Prefab::Config.new(
|
167
172
|
key: key,
|
168
|
-
variants: [Prefab::FeatureFlagVariant.new(value_from(value['value']))],
|
173
|
+
variants: [Prefab::FeatureFlagVariant.new(value_from(key, value['value']))],
|
169
174
|
rows: [row]
|
170
175
|
)
|
171
176
|
}
|
data/lib/prefab/logger_client.rb
CHANGED
@@ -3,12 +3,22 @@ module Prefab
|
|
3
3
|
class LoggerClient < Logger
|
4
4
|
|
5
5
|
SEP = "."
|
6
|
-
|
6
|
+
BASE_KEY = "log-level"
|
7
7
|
UNKNOWN = "unknown"
|
8
8
|
|
9
|
+
LOG_LEVEL_LOOKUPS = {
|
10
|
+
Prefab::LogLevel::NOT_SET_LOG_LEVEL => Logger::DEBUG,
|
11
|
+
Prefab::LogLevel::TRACE => Logger::DEBUG,
|
12
|
+
Prefab::LogLevel::DEBUG => Logger::DEBUG,
|
13
|
+
Prefab::LogLevel::INFO => Logger::INFO,
|
14
|
+
Prefab::LogLevel::WARN => Logger::WARN,
|
15
|
+
Prefab::LogLevel::ERROR => Logger::ERROR,
|
16
|
+
Prefab::LogLevel::FATAL => Logger::FATAL
|
17
|
+
}
|
18
|
+
|
9
19
|
def initialize(logdev, formatter: nil)
|
10
20
|
super(logdev)
|
11
|
-
self.formatter= formatter
|
21
|
+
self.formatter = formatter
|
12
22
|
@config_client = BootstrappingConfigClient.new
|
13
23
|
@silences = Concurrent::Map.new(:initial_capacity => 2)
|
14
24
|
end
|
@@ -109,8 +119,8 @@ module Prefab
|
|
109
119
|
|
110
120
|
# Find the closest match to 'log_level.path' in config
|
111
121
|
def level_of(path)
|
112
|
-
closest_log_level_match = @config_client.get(
|
113
|
-
path.split(SEP).inject([
|
122
|
+
closest_log_level_match = @config_client.get(BASE_KEY, Prefab::LogLevel::WARN)
|
123
|
+
path.split(SEP).inject([BASE_KEY]) do |memo, n|
|
114
124
|
memo << n
|
115
125
|
val = @config_client.get(memo.join(SEP), nil)
|
116
126
|
unless val.nil?
|
@@ -118,7 +128,7 @@ module Prefab
|
|
118
128
|
end
|
119
129
|
memo
|
120
130
|
end
|
121
|
-
|
131
|
+
LOG_LEVEL_LOOKUPS[closest_log_level_match]
|
122
132
|
end
|
123
133
|
|
124
134
|
def get_loc_path(loc)
|
@@ -138,17 +148,13 @@ module Prefab
|
|
138
148
|
path.slice! SEP
|
139
149
|
path
|
140
150
|
end
|
141
|
-
|
142
|
-
def val level
|
143
|
-
return Object.const_get("Logger::#{level.upcase}")
|
144
|
-
end
|
145
151
|
end
|
146
152
|
|
147
153
|
# StubConfigClient to be used while config client initializes
|
148
154
|
# since it may log
|
149
155
|
class BootstrappingConfigClient
|
150
|
-
def get(key, default=nil)
|
151
|
-
ENV["PREFAB_LOG_CLIENT_BOOTSTRAP_LOG_LEVEL"]
|
156
|
+
def get(key, default = nil)
|
157
|
+
ENV["PREFAB_LOG_CLIENT_BOOTSTRAP_LOG_LEVEL"] ? Prefab::LogLevel.resolve(ENV["PREFAB_LOG_CLIENT_BOOTSTRAP_LOG_LEVEL"].upcase.to_sym) : default
|
152
158
|
end
|
153
159
|
end
|
154
160
|
end
|
data/lib/prefab_pb.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
1
|
# Generated by the protocol buffer compiler. DO NOT EDIT!
|
3
2
|
# source: prefab.proto
|
4
3
|
|
@@ -21,6 +20,7 @@ Google::Protobuf::DescriptorPool.generated_pool.build do
|
|
21
20
|
optional :feature_flag, :message, 6, "prefab.FeatureFlag"
|
22
21
|
optional :limit_definition, :message, 7, "prefab.LimitDefinition"
|
23
22
|
optional :segment, :message, 8, "prefab.Segment"
|
23
|
+
optional :log_level, :enum, 9, "prefab.LogLevel"
|
24
24
|
end
|
25
25
|
end
|
26
26
|
add_message "prefab.Configs" do
|
@@ -184,6 +184,15 @@ Google::Protobuf::DescriptorPool.generated_pool.build do
|
|
184
184
|
optional :sequence_name, :string, 3
|
185
185
|
optional :size, :int64, 4
|
186
186
|
end
|
187
|
+
add_enum "prefab.LogLevel" do
|
188
|
+
value :NOT_SET_LOG_LEVEL, 0
|
189
|
+
value :TRACE, 1
|
190
|
+
value :DEBUG, 2
|
191
|
+
value :INFO, 3
|
192
|
+
value :WARN, 5
|
193
|
+
value :ERROR, 6
|
194
|
+
value :FATAL, 9
|
195
|
+
end
|
187
196
|
add_enum "prefab.OnFailure" do
|
188
197
|
value :NOT_SET, 0
|
189
198
|
value :LOG_AND_PASS, 1
|
@@ -222,5 +231,6 @@ module Prefab
|
|
222
231
|
CreationResponse = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("prefab.CreationResponse").msgclass
|
223
232
|
IdBlock = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("prefab.IdBlock").msgclass
|
224
233
|
IdBlockRequest = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("prefab.IdBlockRequest").msgclass
|
234
|
+
LogLevel = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("prefab.LogLevel").enummodule
|
225
235
|
OnFailure = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("prefab.OnFailure").enummodule
|
226
236
|
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.17.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.17.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 = "2022-
|
14
|
+
s.date = "2022-10-11"
|
15
15
|
s.description = "RateLimits & Config as a service".freeze
|
16
16
|
s.email = "jdwyer@prefab.cloud".freeze
|
17
17
|
s.extra_rdoc_files = [
|
@@ -83,7 +83,7 @@ Gem::Specification.new do |s|
|
|
83
83
|
s.add_runtime_dependency(%q<googleapis-common-protos-types>.freeze, [">= 0"])
|
84
84
|
s.add_development_dependency(%q<benchmark-ips>.freeze, [">= 0"])
|
85
85
|
s.add_development_dependency(%q<grpc-tools>.freeze, [">= 0"])
|
86
|
-
s.add_development_dependency(%q<rdoc>.freeze, ["
|
86
|
+
s.add_development_dependency(%q<rdoc>.freeze, [">= 0"])
|
87
87
|
s.add_development_dependency(%q<bundler>.freeze, [">= 0"])
|
88
88
|
s.add_development_dependency(%q<juwelier>.freeze, ["~> 2.4.9"])
|
89
89
|
s.add_development_dependency(%q<simplecov>.freeze, [">= 0"])
|
@@ -97,7 +97,7 @@ Gem::Specification.new do |s|
|
|
97
97
|
s.add_dependency(%q<googleapis-common-protos-types>.freeze, [">= 0"])
|
98
98
|
s.add_dependency(%q<benchmark-ips>.freeze, [">= 0"])
|
99
99
|
s.add_dependency(%q<grpc-tools>.freeze, [">= 0"])
|
100
|
-
s.add_dependency(%q<rdoc>.freeze, ["
|
100
|
+
s.add_dependency(%q<rdoc>.freeze, [">= 0"])
|
101
101
|
s.add_dependency(%q<bundler>.freeze, [">= 0"])
|
102
102
|
s.add_dependency(%q<juwelier>.freeze, ["~> 2.4.9"])
|
103
103
|
s.add_dependency(%q<simplecov>.freeze, [">= 0"])
|
data/test/test_config_client.rb
CHANGED
@@ -16,6 +16,9 @@ class TestConfigClient < Minitest::Test
|
|
16
16
|
def test_load
|
17
17
|
assert_equal "test sample value", @config_client.get("sample")
|
18
18
|
assert_equal 123, @config_client.get("sample_int")
|
19
|
+
assert_equal 12.12, @config_client.get("sample_double")
|
20
|
+
assert_equal true, @config_client.get("sample_bool")
|
21
|
+
assert_equal :ERROR, @config_client.get("log-level.app")
|
19
22
|
end
|
20
23
|
|
21
24
|
def test_initialization_timeout_error
|
data/test/test_config_loader.rb
CHANGED
@@ -21,9 +21,13 @@ class TestConfigLoader < Minitest::Test
|
|
21
21
|
def test_nested
|
22
22
|
should_be :string, "nested value", "nested.values.string"
|
23
23
|
should_be :string, "top level", "nested.values"
|
24
|
-
should_be :
|
25
|
-
should_be :
|
26
|
-
should_be :
|
24
|
+
should_be :log_level, :ERROR, "log-level.app"
|
25
|
+
should_be :log_level, :WARN, "log-level.app.controller.hello"
|
26
|
+
should_be :log_level, :INFO, "log-level.app.controller.hello.index"
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_invalid_log_level
|
30
|
+
should_be :log_level, :NOT_SET_LOG_LEVEL, "log-level.invalid"
|
27
31
|
end
|
28
32
|
|
29
33
|
def test_load_without_unit_test_env
|
data/test/test_helper.rb
CHANGED
data/test/test_logger.rb
CHANGED
@@ -50,18 +50,18 @@ class TestCLogger < Minitest::Test
|
|
50
50
|
assert_equal Logger::WARN,
|
51
51
|
@logger.level_of("app.models.user"), "default is warn"
|
52
52
|
|
53
|
-
@logger.set_config_client(MockConfigClient.new("
|
53
|
+
@logger.set_config_client(MockConfigClient.new("log-level.app" => Prefab::LogLevel::INFO))
|
54
54
|
assert_equal Logger::INFO,
|
55
55
|
@logger.level_of("app.models.user")
|
56
56
|
|
57
|
-
@logger.set_config_client(MockConfigClient.new("
|
57
|
+
@logger.set_config_client(MockConfigClient.new("log-level.app" => Prefab::LogLevel::DEBUG))
|
58
58
|
assert_equal Logger::DEBUG,
|
59
59
|
@logger.level_of("app.models.user")
|
60
60
|
|
61
|
-
@logger.set_config_client(MockConfigClient.new("
|
62
|
-
"
|
63
|
-
assert_equal Logger::
|
64
|
-
@logger.level_of("app.models.user")
|
61
|
+
@logger.set_config_client(MockConfigClient.new("log-level.app" => Prefab::LogLevel::DEBUG,
|
62
|
+
"log-level.app.models" => Prefab::LogLevel::ERROR))
|
63
|
+
assert_equal Logger::ERROR,
|
64
|
+
@logger.level_of("app.models.user"), "test leveling"
|
65
65
|
end
|
66
66
|
end
|
67
67
|
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.17.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: 2022-
|
11
|
+
date: 2022-10-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|
@@ -132,16 +132,16 @@ dependencies:
|
|
132
132
|
name: rdoc
|
133
133
|
requirement: !ruby/object:Gem::Requirement
|
134
134
|
requirements:
|
135
|
-
- - "
|
135
|
+
- - ">="
|
136
136
|
- !ruby/object:Gem::Version
|
137
|
-
version: '
|
137
|
+
version: '0'
|
138
138
|
type: :development
|
139
139
|
prerelease: false
|
140
140
|
version_requirements: !ruby/object:Gem::Requirement
|
141
141
|
requirements:
|
142
|
-
- - "
|
142
|
+
- - ">="
|
143
143
|
- !ruby/object:Gem::Version
|
144
|
-
version: '
|
144
|
+
version: '0'
|
145
145
|
- !ruby/object:Gem::Dependency
|
146
146
|
name: bundler
|
147
147
|
requirement: !ruby/object:Gem::Requirement
|