prefab-cloud-ruby 1.6.0.pre1 → 1.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -1
- data/Gemfile +1 -1
- data/README.md +37 -6
- data/VERSION +1 -1
- data/lib/prefab/client.rb +4 -14
- data/lib/prefab/options.rb +2 -0
- data/prefab-cloud-ruby.gemspec +4 -4
- data/test/support/common_helpers.rb +16 -9
- data/test/test_integration.rb +6 -0
- data/test/test_log_path_aggregator.rb +6 -6
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f8cd1347e930a4820b28ae3943e100a09765efeb56ca423dc4e4f26b51e3543b
|
4
|
+
data.tar.gz: 783119a33360850c31c425558735d356202e5365aa9f3ae3e88f776a22c7e231
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 04b84fcdebab292f086d7909428ea8b77f0d7a53a2dfe5943716ba988ea778ddef0f3c0f09ed4ccddae048097e17f358699633213059ab3062ae04ae287acc99
|
7
|
+
data.tar.gz: 2f65bdf10b36016e397413774bc676b20ed40d42f4ea4abcb7984bdd16afcbefd313e05a28505630cc9a818bcca950e60dcb41774d15e353d08f1e4d8d028966
|
data/CHANGELOG.md
CHANGED
@@ -1,11 +1,15 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
-
##
|
3
|
+
## 1.6.0 - 2024-03-27
|
4
4
|
|
5
5
|
- Use semantic_logger for internal logging (#173)
|
6
6
|
- Remove Prefab::LoggerClient as a logger for end users (#173)
|
7
7
|
- Provide log_filter for end users (#173)
|
8
8
|
|
9
|
+
## 1.5.1 - 2024-02-22
|
10
|
+
|
11
|
+
- Fix: Send context shapes by default (#174)
|
12
|
+
|
9
13
|
## 1.5.0 - 2024-02-12
|
10
14
|
|
11
15
|
- Fix potential inconsistent Context behavior (#172)
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -34,7 +34,7 @@ Many ruby web servers fork. When the process is forked, the current realtime upd
|
|
34
34
|
|
35
35
|
```ruby
|
36
36
|
#config/application.rb
|
37
|
-
Prefab.init # reads PREFAB_API_KEY env var
|
37
|
+
Prefab.init # reads PREFAB_API_KEY env var by default
|
38
38
|
```
|
39
39
|
|
40
40
|
```ruby
|
@@ -53,22 +53,51 @@ end
|
|
53
53
|
|
54
54
|
## Logging & Debugging
|
55
55
|
|
56
|
-
To use dynamic logging
|
56
|
+
To use dynamic logging, we recommend [semantic logger]. Add semantic_logger to your Gemfile and then we'll configure our app to use it.
|
57
57
|
|
58
|
+
### Plain ol' Ruby
|
59
|
+
|
60
|
+
```ruby
|
61
|
+
# Gemfile
|
62
|
+
gem "semantic_logger"
|
63
|
+
```
|
64
|
+
|
65
|
+
```ruby
|
66
|
+
require "semantic_logger"
|
67
|
+
require "prefab"
|
68
|
+
|
69
|
+
Prefab.init
|
70
|
+
|
71
|
+
SemanticLogger.sync!
|
72
|
+
SemanticLogger.default_level = :trace # Prefab will take over the filtering
|
73
|
+
SemanticLogger.add_appender(
|
74
|
+
io: $stdout,
|
75
|
+
formatter: :json,
|
76
|
+
filter: Prefab.log_filter,
|
77
|
+
)
|
58
78
|
```
|
79
|
+
|
80
|
+
### With Rails
|
81
|
+
|
82
|
+
```ruby
|
83
|
+
# Gemfile
|
59
84
|
gem "amazing_print"
|
60
85
|
gem "rails_semantic_logger"
|
61
86
|
```
|
87
|
+
|
62
88
|
```ruby
|
63
|
-
#application.rb
|
89
|
+
# config/application.rb
|
90
|
+
Prefab.init
|
91
|
+
|
92
|
+
# config/initializers/logging.rb
|
93
|
+
SemanticLogger.sync!
|
64
94
|
SemanticLogger.default_level = :trace # Prefab will take over the filtering
|
65
95
|
SemanticLogger.add_appender(
|
66
96
|
io: $stdout,
|
67
|
-
formatter: Rails.env.development? ? :
|
97
|
+
formatter: Rails.env.development? ? :color : :json,
|
68
98
|
filter: Prefab.log_filter,
|
69
99
|
)
|
70
|
-
|
71
|
-
````
|
100
|
+
```
|
72
101
|
|
73
102
|
```ruby
|
74
103
|
#puma.rb
|
@@ -101,3 +130,5 @@ REMOTE_BRANCH=main LOCAL_BRANCH=main bundle exec rake release
|
|
101
130
|
## Copyright
|
102
131
|
|
103
132
|
Copyright (c) 2024 Prefab, Inc. See LICENSE.txt for further details.
|
133
|
+
|
134
|
+
[semantic logger]: https://logger.rocketjob.io/
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.6.0
|
1
|
+
1.6.0
|
data/lib/prefab/client.rb
CHANGED
@@ -51,6 +51,7 @@ module Prefab
|
|
51
51
|
|
52
52
|
def log_path_aggregator
|
53
53
|
return nil if @options.collect_max_paths <= 0
|
54
|
+
|
54
55
|
@log_path_aggregator ||= LogPathAggregator.new(client: self, max_paths: @options.collect_max_paths,
|
55
56
|
sync_interval: @options.collect_sync_interval)
|
56
57
|
end
|
@@ -87,14 +88,7 @@ module Prefab
|
|
87
88
|
end
|
88
89
|
|
89
90
|
def set_rails_loggers
|
90
|
-
|
91
|
-
ActionView::Base.logger = log
|
92
|
-
ActionController::Base.logger = log
|
93
|
-
ActiveJob::Base.logger = log if defined?(ActiveJob)
|
94
|
-
ActiveRecord::Base.logger = log
|
95
|
-
ActiveStorage.logger = log if defined?(ActiveStorage)
|
96
|
-
|
97
|
-
LogSubscribers::ActionControllerSubscriber.attach_to :action_controller unless @options.disable_action_controller_logging
|
91
|
+
warn '[DEPRECATION] `set_rails_loggers` is deprecated since 1.6. Please use semantic_logger or `Prefab.log_filter` instead.'
|
98
92
|
end
|
99
93
|
|
100
94
|
def on_update(&block)
|
@@ -127,14 +121,10 @@ module Prefab
|
|
127
121
|
|
128
122
|
# When starting a forked process, use this to re-use the options
|
129
123
|
# on_worker_boot do
|
130
|
-
#
|
131
|
-
# $prefab.set_rails_loggers
|
124
|
+
# Prefab.fork
|
132
125
|
# end
|
133
126
|
def fork
|
134
|
-
|
135
|
-
Prefab::Client.new(@options.for_fork).tap do |client|
|
136
|
-
client.log.add_context_keys(*log_options)
|
137
|
-
end
|
127
|
+
Prefab::Client.new(@options.for_fork)
|
138
128
|
end
|
139
129
|
|
140
130
|
private
|
data/lib/prefab/options.rb
CHANGED
@@ -94,6 +94,8 @@ module Prefab
|
|
94
94
|
when :periodic_example
|
95
95
|
@collect_example_contexts = true
|
96
96
|
@collect_max_example_contexts = context_max_size
|
97
|
+
@collect_shapes = true
|
98
|
+
@collect_max_shapes = context_max_size
|
97
99
|
when :shape_only
|
98
100
|
@collect_shapes = true
|
99
101
|
@collect_max_shapes = context_max_size
|
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 1.6.0
|
5
|
+
# stub: prefab-cloud-ruby 1.6.0 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "prefab-cloud-ruby".freeze
|
9
|
-
s.version = "1.6.0
|
9
|
+
s.version = "1.6.0"
|
10
10
|
|
11
|
-
s.required_rubygems_version = Gem::Requirement.new("
|
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 = "2024-
|
14
|
+
s.date = "2024-03-27"
|
15
15
|
s.description = "Feature Flags, Live Config, and Dynamic Log Levels as a service".freeze
|
16
16
|
s.email = "jdwyer@prefab.cloud".freeze
|
17
17
|
s.executables = ["console".freeze]
|
@@ -6,12 +6,24 @@ module CommonHelpers
|
|
6
6
|
def setup
|
7
7
|
$oldstderr, $stderr = $stderr, StringIO.new
|
8
8
|
|
9
|
-
$logs
|
10
|
-
SemanticLogger.add_appender(io: $logs)
|
9
|
+
$logs = StringIO.new
|
10
|
+
SemanticLogger.add_appender(io: $logs, filter: Prefab.log_filter)
|
11
|
+
SemanticLogger.sync!
|
11
12
|
Timecop.freeze('2023-08-09 15:18:12 -0400')
|
12
13
|
end
|
13
14
|
|
14
15
|
def teardown
|
16
|
+
if $logs && !$logs.string.empty?
|
17
|
+
log_lines = $logs.string.split("\n").reject do |line|
|
18
|
+
line.match(/Prefab::ConfigClient -- No success loading checkpoints/)
|
19
|
+
end
|
20
|
+
|
21
|
+
if log_lines.size > 0
|
22
|
+
$logs = nil
|
23
|
+
raise "Unexpected logs. Handle logs with assert_logged\n\n#{log_lines}"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
15
27
|
if $stderr != $oldstderr && !$stderr.string.empty?
|
16
28
|
# we ignore 2.X because of the number of `instance variable @xyz not initialized` warnings
|
17
29
|
if !RUBY_VERSION.start_with?('2.')
|
@@ -41,7 +53,6 @@ module CommonHelpers
|
|
41
53
|
}.freeze
|
42
54
|
|
43
55
|
def new_client(overrides = {})
|
44
|
-
|
45
56
|
config = overrides.delete(:config)
|
46
57
|
project_env_id = overrides.delete(:project_env_id)
|
47
58
|
|
@@ -140,12 +151,6 @@ module CommonHelpers
|
|
140
151
|
Prefab::Context.new(properties)
|
141
152
|
end
|
142
153
|
|
143
|
-
def assert_only_expected_logs
|
144
|
-
# assert_equal "WARN 2023-08-09 15:18:12 -0400: cloud.prefab.client.configclient No success loading checkpoints\n", $logs.string
|
145
|
-
# mark nil to indicate we handled it
|
146
|
-
$logs = nil
|
147
|
-
end
|
148
|
-
|
149
154
|
def assert_logged(expected)
|
150
155
|
# we do a uniq here because logging can happen in a separate thread so the
|
151
156
|
# number of times a log might happen could be slightly variable.
|
@@ -159,6 +164,8 @@ module CommonHelpers
|
|
159
164
|
|
160
165
|
assert(matched, "expectation: #{expectation}, got: #{actuals}")
|
161
166
|
end
|
167
|
+
# mark nil to indicate we handled it
|
168
|
+
$logs = nil
|
162
169
|
end
|
163
170
|
|
164
171
|
def assert_stderr(expected)
|
data/test/test_integration.rb
CHANGED
@@ -50,6 +50,12 @@ class TestIntegration < Minitest::Test
|
|
50
50
|
else
|
51
51
|
raise "Unknown test type: #{it.test_type}"
|
52
52
|
end
|
53
|
+
|
54
|
+
if test_case["name"].match(/doesn't raise on init timeout/)
|
55
|
+
assert_logged [
|
56
|
+
"Prefab::ConfigClient -- Couldn't Initialize In 0.01. Key any-key. Returning what we have"
|
57
|
+
]
|
58
|
+
end
|
53
59
|
end
|
54
60
|
end
|
55
61
|
end
|
@@ -8,7 +8,7 @@ class TestLogPathAggregator < Minitest::Test
|
|
8
8
|
SLEEP_TIME = 0.01
|
9
9
|
|
10
10
|
def test_push
|
11
|
-
client = new_client
|
11
|
+
client = new_client(prefab_datasources: Prefab::Options::DATASOURCES::ALL,)
|
12
12
|
aggregator = Prefab::LogPathAggregator.new(client: client, max_paths: 2, sync_interval: 1000)
|
13
13
|
|
14
14
|
aggregator.push('test.test_log_path_aggregator.test_push.1', ::Logger::INFO)
|
@@ -19,16 +19,14 @@ class TestLogPathAggregator < Minitest::Test
|
|
19
19
|
# we've reached the limit, so no more
|
20
20
|
aggregator.push('test.test_log_path_aggregator.test_push.3', ::Logger::INFO)
|
21
21
|
assert_equal 2, aggregator.data.size
|
22
|
-
|
23
|
-
assert_only_expected_logs
|
24
22
|
end
|
25
23
|
|
26
24
|
def test_sync
|
27
25
|
Timecop.freeze do
|
28
26
|
client = new_client(namespace: 'this.is.a.namespace', allow_telemetry_in_local_mode: true)
|
29
27
|
|
30
|
-
2.times { client.log.should_log? 1, "test.test_log_path_aggregator.test_sync"}
|
31
|
-
3.times { client.log.should_log? 3, "test.test_log_path_aggregator.test_sync"}
|
28
|
+
2.times { client.log.should_log? 1, "test.test_log_path_aggregator.test_sync" }
|
29
|
+
3.times { client.log.should_log? 3, "test.test_log_path_aggregator.test_sync" }
|
32
30
|
|
33
31
|
requests = wait_for_post_requests(client) do
|
34
32
|
client.log_path_aggregator.send(:sync)
|
@@ -40,7 +38,9 @@ class TestLogPathAggregator < Minitest::Test
|
|
40
38
|
assert_equal Prefab::TimeHelpers.now_in_ms, sent_logger.start_at
|
41
39
|
assert_equal Prefab::TimeHelpers.now_in_ms, sent_logger.end_at
|
42
40
|
assert_equal client.instance_hash, sent_logger.instance_hash
|
43
|
-
assert_includes sent_logger.loggers,
|
41
|
+
assert_includes sent_logger.loggers,
|
42
|
+
PrefabProto::Logger.new(logger_name: 'test.test_log_path_aggregator.test_sync', infos: 2,
|
43
|
+
errors: 3)
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
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: 1.6.0
|
4
|
+
version: 1.6.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: 2024-
|
11
|
+
date: 2024-03-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|
@@ -327,9 +327,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
327
327
|
version: '0'
|
328
328
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
329
329
|
requirements:
|
330
|
-
- - "
|
330
|
+
- - ">="
|
331
331
|
- !ruby/object:Gem::Version
|
332
|
-
version:
|
332
|
+
version: '0'
|
333
333
|
requirements: []
|
334
334
|
rubygems_version: 3.2.32
|
335
335
|
signing_key:
|