prefab-cloud-ruby 1.6.0.pre2 → 1.6.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +4 -2
- data/CHANGELOG.md +10 -1
- data/Gemfile +1 -2
- data/Gemfile.lock +69 -82
- data/README.md +36 -6
- data/Rakefile +35 -32
- data/VERSION +1 -1
- data/dev/allocation_stats +60 -0
- data/dev/benchmark +40 -0
- data/lib/prefab/client.rb +5 -8
- data/lib/prefab/config_client.rb +2 -2
- data/lib/prefab/config_resolver.rb +5 -6
- data/lib/prefab/context.rb +90 -37
- data/lib/prefab/evaluation.rb +2 -1
- data/lib/prefab/options.rb +5 -3
- data/lib/prefab-cloud-ruby.rb +0 -1
- data/prefab-cloud-ruby.gemspec +7 -8
- data/test/support/common_helpers.rb +17 -10
- data/test/test_config_resolver.rb +41 -0
- data/test/test_context.rb +40 -44
- data/test/test_example_contexts_aggregator.rb +1 -4
- data/test/test_helper.rb +1 -1
- data/test/test_integration.rb +6 -0
- data/test/test_log_path_aggregator.rb +6 -6
- metadata +8 -21
- /data/{bin → dev}/console +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e0cc90e8b5acc15676a5101e6cbd902e37e38781ebb6d6fb33c892f938df3bbc
|
4
|
+
data.tar.gz: 68e1dbb144273aa9c54fb11efdf9333f2260a8805705d2aff47885719d995b7f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9518b4ab1b19e6f7532fd29146b26bd0fd4e3527dbc4fde041b61b712a843db95f6f9355d8afb0b2496436aab711ec5f4a57075dbaf80c7afd4bb85c35d92b53
|
7
|
+
data.tar.gz: d2f4806025b4c965792653149ac9976b47ed4f687bbbb9b73cf58af091a55d4ad03affe49e6cd55aba132fa1a49f422f73900a2d295abb3afb2867cf204bb533
|
data/.github/workflows/ruby.yml
CHANGED
@@ -22,7 +22,7 @@ jobs:
|
|
22
22
|
runs-on: ubuntu-latest
|
23
23
|
strategy:
|
24
24
|
matrix:
|
25
|
-
ruby-version: ['2.7', '3.0', '3.
|
25
|
+
ruby-version: ['2.7', '3.0', '3.3']
|
26
26
|
|
27
27
|
steps:
|
28
28
|
- uses: actions/checkout@v3
|
@@ -36,7 +36,9 @@ jobs:
|
|
36
36
|
uses: ruby/setup-ruby@v1
|
37
37
|
with:
|
38
38
|
ruby-version: ${{ matrix.ruby-version }}
|
39
|
-
bundler-cache:
|
39
|
+
bundler-cache: false # runs 'bundle install' and caches installed gems automatically
|
40
|
+
- name: Install dependencies
|
41
|
+
run: bundle install --without development --jobs 4 --retry 3
|
40
42
|
- name: Run tests
|
41
43
|
run: bundle exec rake
|
42
44
|
env:
|
data/CHANGELOG.md
CHANGED
@@ -1,11 +1,20 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
-
##
|
3
|
+
## 1.6.1 - 2024-03-28
|
4
|
+
|
5
|
+
- Performance optimizations (#178)
|
6
|
+
- Global context (#182)
|
7
|
+
|
8
|
+
## 1.6.0 - 2024-03-27
|
4
9
|
|
5
10
|
- Use semantic_logger for internal logging (#173)
|
6
11
|
- Remove Prefab::LoggerClient as a logger for end users (#173)
|
7
12
|
- Provide log_filter for end users (#173)
|
8
13
|
|
14
|
+
## 1.5.1 - 2024-02-22
|
15
|
+
|
16
|
+
- Fix: Send context shapes by default (#174)
|
17
|
+
|
9
18
|
## 1.5.0 - 2024-02-12
|
10
19
|
|
11
20
|
- Fix potential inconsistent Context behavior (#172)
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,23 +1,7 @@
|
|
1
1
|
GEM
|
2
2
|
remote: https://rubygems.org/
|
3
3
|
specs:
|
4
|
-
|
5
|
-
actionview (= 7.1.2)
|
6
|
-
activesupport (= 7.1.2)
|
7
|
-
nokogiri (>= 1.8.5)
|
8
|
-
racc
|
9
|
-
rack (>= 2.2.4)
|
10
|
-
rack-session (>= 1.0.1)
|
11
|
-
rack-test (>= 0.6.3)
|
12
|
-
rails-dom-testing (~> 2.2)
|
13
|
-
rails-html-sanitizer (~> 1.6)
|
14
|
-
actionview (7.1.2)
|
15
|
-
activesupport (= 7.1.2)
|
16
|
-
builder (~> 3.1)
|
17
|
-
erubi (~> 1.11)
|
18
|
-
rails-dom-testing (~> 2.2)
|
19
|
-
rails-html-sanitizer (~> 1.6)
|
20
|
-
activesupport (7.1.2)
|
4
|
+
activesupport (7.1.3.2)
|
21
5
|
base64
|
22
6
|
bigdecimal
|
23
7
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
@@ -27,34 +11,48 @@ GEM
|
|
27
11
|
minitest (>= 5.1)
|
28
12
|
mutex_m
|
29
13
|
tzinfo (~> 2.0)
|
30
|
-
addressable (2.8.
|
31
|
-
public_suffix (>= 2.0.2, <
|
14
|
+
addressable (2.8.6)
|
15
|
+
public_suffix (>= 2.0.2, < 6.0)
|
32
16
|
ansi (1.5.0)
|
33
17
|
base64 (0.2.0)
|
34
|
-
benchmark-ips (2.
|
35
|
-
bigdecimal (3.1.
|
18
|
+
benchmark-ips (2.13.0)
|
19
|
+
bigdecimal (3.1.7)
|
36
20
|
builder (3.2.4)
|
37
|
-
concurrent-ruby (1.
|
21
|
+
concurrent-ruby (1.2.3)
|
38
22
|
connection_pool (2.4.1)
|
39
|
-
crass (1.0.6)
|
40
23
|
descendants_tracker (0.0.4)
|
41
24
|
thread_safe (~> 0.3, >= 0.3.1)
|
42
|
-
docile (1.
|
43
|
-
domain_name (0.
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
25
|
+
docile (1.4.0)
|
26
|
+
domain_name (0.6.20240107)
|
27
|
+
drb (2.2.1)
|
28
|
+
faraday (1.10.3)
|
29
|
+
faraday-em_http (~> 1.0)
|
30
|
+
faraday-em_synchrony (~> 1.0)
|
31
|
+
faraday-excon (~> 1.1)
|
32
|
+
faraday-httpclient (~> 1.0)
|
33
|
+
faraday-multipart (~> 1.0)
|
49
34
|
faraday-net_http (~> 1.0)
|
50
|
-
|
51
|
-
|
35
|
+
faraday-net_http_persistent (~> 1.0)
|
36
|
+
faraday-patron (~> 1.0)
|
37
|
+
faraday-rack (~> 1.0)
|
38
|
+
faraday-retry (~> 1.0)
|
39
|
+
ruby2_keywords (>= 0.0.4)
|
40
|
+
faraday-em_http (1.0.0)
|
41
|
+
faraday-em_synchrony (1.0.0)
|
42
|
+
faraday-excon (1.1.0)
|
43
|
+
faraday-httpclient (1.0.1)
|
44
|
+
faraday-multipart (1.0.4)
|
45
|
+
multipart-post (~> 2)
|
52
46
|
faraday-net_http (1.0.1)
|
53
|
-
|
54
|
-
|
55
|
-
|
47
|
+
faraday-net_http_persistent (1.2.0)
|
48
|
+
faraday-patron (1.0.0)
|
49
|
+
faraday-rack (1.0.0)
|
50
|
+
faraday-retry (1.0.3)
|
51
|
+
ffi (1.16.3)
|
52
|
+
ffi-compiler (1.3.2)
|
53
|
+
ffi (>= 1.15.5)
|
56
54
|
rake
|
57
|
-
git (1.
|
55
|
+
git (1.19.1)
|
58
56
|
addressable (~> 2.8)
|
59
57
|
rchardet (~> 1.8)
|
60
58
|
github_api (0.19.0)
|
@@ -63,20 +61,21 @@ GEM
|
|
63
61
|
faraday (>= 0.8, < 2)
|
64
62
|
hashie (~> 3.5, >= 3.5.2)
|
65
63
|
oauth2 (~> 1.0)
|
66
|
-
google-protobuf (3.
|
67
|
-
googleapis-common-protos-types (1.
|
68
|
-
google-protobuf (~> 3.
|
64
|
+
google-protobuf (3.25.3)
|
65
|
+
googleapis-common-protos-types (1.14.0)
|
66
|
+
google-protobuf (~> 3.18)
|
69
67
|
hashie (3.6.0)
|
70
|
-
highline (
|
71
|
-
http (5.0
|
72
|
-
addressable (~> 2.
|
68
|
+
highline (3.0.1)
|
69
|
+
http (5.2.0)
|
70
|
+
addressable (~> 2.8)
|
71
|
+
base64 (~> 0.1)
|
73
72
|
http-cookie (~> 1.0)
|
74
73
|
http-form_data (~> 2.2)
|
75
|
-
llhttp-ffi (~> 0.
|
76
|
-
http-cookie (1.0.
|
74
|
+
llhttp-ffi (~> 0.5.0)
|
75
|
+
http-cookie (1.0.5)
|
77
76
|
domain_name (~> 0.5)
|
78
77
|
http-form_data (2.3.0)
|
79
|
-
i18n (1.14.
|
78
|
+
i18n (1.14.4)
|
80
79
|
concurrent-ruby (~> 1.0)
|
81
80
|
juwelier (2.4.9)
|
82
81
|
builder
|
@@ -90,34 +89,32 @@ GEM
|
|
90
89
|
rake
|
91
90
|
rdoc
|
92
91
|
semver2
|
93
|
-
jwt (2.
|
92
|
+
jwt (2.8.1)
|
93
|
+
base64
|
94
94
|
kamelcase (0.0.2)
|
95
95
|
semver2 (~> 3)
|
96
|
-
ld-eventsource (2.2.
|
96
|
+
ld-eventsource (2.2.2)
|
97
97
|
concurrent-ruby (~> 1.0)
|
98
98
|
http (>= 4.4.1, < 6.0.0)
|
99
|
-
llhttp-ffi (0.
|
99
|
+
llhttp-ffi (0.5.0)
|
100
100
|
ffi-compiler (~> 1.0)
|
101
101
|
rake (~> 13.0)
|
102
|
-
loofah (2.21.4)
|
103
|
-
crass (~> 1.0.2)
|
104
|
-
nokogiri (>= 1.12.0)
|
105
102
|
macaddr (1.7.2)
|
106
103
|
systemu (~> 2.6.5)
|
107
|
-
mini_portile2 (2.8.
|
108
|
-
minitest (5.
|
109
|
-
minitest-focus (1.
|
104
|
+
mini_portile2 (2.8.5)
|
105
|
+
minitest (5.22.3)
|
106
|
+
minitest-focus (1.4.0)
|
110
107
|
minitest (>= 4, < 6)
|
111
|
-
minitest-reporters (1.
|
108
|
+
minitest-reporters (1.6.1)
|
112
109
|
ansi
|
113
110
|
builder
|
114
111
|
minitest (>= 5.0)
|
115
112
|
ruby-progressbar
|
116
113
|
multi_json (1.15.0)
|
117
114
|
multi_xml (0.6.0)
|
118
|
-
multipart-post (2.
|
115
|
+
multipart-post (2.4.0)
|
119
116
|
mutex_m (0.2.0)
|
120
|
-
nokogiri (1.
|
117
|
+
nokogiri (1.16.3)
|
121
118
|
mini_portile2 (~> 2.8.2)
|
122
119
|
racc (~> 1.4)
|
123
120
|
oauth2 (1.4.11)
|
@@ -126,41 +123,32 @@ GEM
|
|
126
123
|
multi_json (~> 1.3)
|
127
124
|
multi_xml (~> 0.5)
|
128
125
|
rack (>= 1.2, < 4)
|
129
|
-
psych (
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
rack
|
134
|
-
|
135
|
-
rack-test (2.1.0)
|
136
|
-
rack (>= 1.3)
|
137
|
-
rails-dom-testing (2.2.0)
|
138
|
-
activesupport (>= 5.0.0)
|
139
|
-
minitest
|
140
|
-
nokogiri (>= 1.6)
|
141
|
-
rails-html-sanitizer (1.6.0)
|
142
|
-
loofah (~> 2.21)
|
143
|
-
nokogiri (~> 1.14)
|
144
|
-
rake (13.0.6)
|
126
|
+
psych (5.1.2)
|
127
|
+
stringio
|
128
|
+
public_suffix (5.0.4)
|
129
|
+
racc (1.7.3)
|
130
|
+
rack (3.0.10)
|
131
|
+
rake (13.1.0)
|
145
132
|
rchardet (1.8.0)
|
146
|
-
rdoc (6.3.
|
147
|
-
|
148
|
-
|
133
|
+
rdoc (6.6.3.1)
|
134
|
+
psych (>= 4.0.0)
|
135
|
+
ruby-progressbar (1.13.0)
|
136
|
+
ruby2_keywords (0.0.5)
|
149
137
|
semantic_logger (4.15.0)
|
150
138
|
concurrent-ruby (~> 1.0)
|
151
139
|
semver2 (3.4.2)
|
152
|
-
simplecov (0.
|
140
|
+
simplecov (0.22.0)
|
153
141
|
docile (~> 1.1)
|
154
142
|
simplecov-html (~> 0.11)
|
143
|
+
simplecov_json_formatter (~> 0.1)
|
155
144
|
simplecov-html (0.12.3)
|
145
|
+
simplecov_json_formatter (0.1.4)
|
146
|
+
stringio (3.1.0)
|
156
147
|
systemu (2.6.5)
|
157
148
|
thread_safe (0.3.6)
|
158
|
-
timecop (0.9.
|
149
|
+
timecop (0.9.8)
|
159
150
|
tzinfo (2.0.6)
|
160
151
|
concurrent-ruby (~> 1.0)
|
161
|
-
unf (0.1.4)
|
162
|
-
unf_ext
|
163
|
-
unf_ext (0.0.8)
|
164
152
|
uuid (2.3.9)
|
165
153
|
macaddr (~> 1.0)
|
166
154
|
|
@@ -168,7 +156,6 @@ PLATFORMS
|
|
168
156
|
ruby
|
169
157
|
|
170
158
|
DEPENDENCIES
|
171
|
-
actionpack (>= 4)
|
172
159
|
activesupport (>= 4)
|
173
160
|
benchmark-ips
|
174
161
|
bundler
|
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,23 +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"
|
58
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
|
+
)
|
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
|
64
93
|
SemanticLogger.sync!
|
65
94
|
SemanticLogger.default_level = :trace # Prefab will take over the filtering
|
66
95
|
SemanticLogger.add_appender(
|
67
96
|
io: $stdout,
|
68
|
-
formatter: Rails.env.development? ? :
|
97
|
+
formatter: Rails.env.development? ? :color : :json,
|
69
98
|
filter: Prefab.log_filter,
|
70
99
|
)
|
71
|
-
|
72
|
-
````
|
100
|
+
```
|
73
101
|
|
74
102
|
```ruby
|
75
103
|
#puma.rb
|
@@ -102,3 +130,5 @@ REMOTE_BRANCH=main LOCAL_BRANCH=main bundle exec rake release
|
|
102
130
|
## Copyright
|
103
131
|
|
104
132
|
Copyright (c) 2024 Prefab, Inc. See LICENSE.txt for further details.
|
133
|
+
|
134
|
+
[semantic logger]: https://logger.rocketjob.io/
|
data/Rakefile
CHANGED
@@ -9,42 +9,45 @@ rescue Bundler::BundlerError => e
|
|
9
9
|
warn 'Run `bundle install` to install missing gems'
|
10
10
|
exit e.status_code
|
11
11
|
end
|
12
|
+
|
12
13
|
require 'rake'
|
13
|
-
|
14
|
-
Juwelier::Tasks.new do |gem|
|
15
|
-
# gem is a Gem::Specification... see http://guides.rubygems.org/specification-reference/ for more options
|
16
|
-
gem.name = 'prefab-cloud-ruby'
|
17
|
-
gem.homepage = 'http://github.com/prefab-cloud/prefab-cloud-ruby'
|
18
|
-
gem.license = 'MIT'
|
19
|
-
gem.summary = %(Prefab Ruby Infrastructure)
|
20
|
-
gem.description = %(Feature Flags, Live Config, and Dynamic Log Levels as a service)
|
21
|
-
gem.email = 'jdwyer@prefab.cloud'
|
22
|
-
gem.authors = ['Jeff Dwyer']
|
14
|
+
task default: :test
|
23
15
|
|
24
|
-
|
25
|
-
|
26
|
-
Juwelier::
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
16
|
+
unless ENV['CI']
|
17
|
+
require 'juwelier'
|
18
|
+
Juwelier::Tasks.new do |gem|
|
19
|
+
# gem is a Gem::Specification... see http://guides.rubygems.org/specification-reference/ for more options
|
20
|
+
gem.name = 'prefab-cloud-ruby'
|
21
|
+
gem.homepage = 'http://github.com/prefab-cloud/prefab-cloud-ruby'
|
22
|
+
gem.license = 'MIT'
|
23
|
+
gem.summary = %(Prefab Ruby Infrastructure)
|
24
|
+
gem.description = %(Feature Flags, Live Config, and Dynamic Log Levels as a service)
|
25
|
+
gem.email = 'jdwyer@prefab.cloud'
|
26
|
+
gem.authors = ['Jeff Dwyer']
|
33
27
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
28
|
+
# dependencies defined in Gemfile
|
29
|
+
end
|
30
|
+
Juwelier::RubygemsDotOrgTasks.new
|
31
|
+
require 'rake/testtask'
|
32
|
+
Rake::TestTask.new(:test) do |test|
|
33
|
+
test.libs << 'lib' << 'test'
|
34
|
+
test.pattern = 'test/**/test_*.rb'
|
35
|
+
test.verbose = true
|
36
|
+
end
|
39
37
|
|
40
|
-
|
38
|
+
desc 'Code coverage detail'
|
39
|
+
task :simplecov do
|
40
|
+
ENV['COVERAGE'] = 'true'
|
41
|
+
Rake::Task['test'].execute
|
42
|
+
end
|
41
43
|
|
42
|
-
require 'rdoc/task'
|
43
|
-
Rake::RDocTask.new do |rdoc|
|
44
|
-
|
44
|
+
require 'rdoc/task'
|
45
|
+
Rake::RDocTask.new do |rdoc|
|
46
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ''
|
45
47
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
48
|
+
rdoc.rdoc_dir = 'rdoc'
|
49
|
+
rdoc.title = "prefab-cloud-ruby #{version}"
|
50
|
+
rdoc.rdoc_files.include('README*')
|
51
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
52
|
+
end
|
50
53
|
end
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.6.
|
1
|
+
1.6.1
|
@@ -0,0 +1,60 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'bundler/setup'
|
5
|
+
|
6
|
+
gemspec = Dir.glob(File.expand_path("../../*.gemspec", __FILE__)).first
|
7
|
+
spec = Gem::Specification.load(gemspec)
|
8
|
+
|
9
|
+
# Add the require paths to the $LOAD_PATH
|
10
|
+
spec.require_paths.each do |path|
|
11
|
+
full_path = File.expand_path("../" + path, __dir__)
|
12
|
+
$LOAD_PATH.unshift(full_path) unless $LOAD_PATH.include?(full_path)
|
13
|
+
end
|
14
|
+
|
15
|
+
spec.require_paths.each do |path|
|
16
|
+
require "./lib/prefab-cloud-ruby"
|
17
|
+
end
|
18
|
+
|
19
|
+
require 'prefab-cloud-ruby'
|
20
|
+
|
21
|
+
$prefab = Prefab::Client.new(collect_logger_counts: false, collect_evaluation_summaries: false,
|
22
|
+
context_upload_mode: :none)
|
23
|
+
$prefab.get('prefab.auth.allowed_origins')
|
24
|
+
|
25
|
+
puts '-' * 80
|
26
|
+
|
27
|
+
require 'allocation_stats'
|
28
|
+
|
29
|
+
$runs = 100
|
30
|
+
|
31
|
+
def measure(description)
|
32
|
+
puts "Measuring #{description}..."
|
33
|
+
stats = $prefab.with_context(user: { email_suffix: 'yahoo.com' }) do
|
34
|
+
AllocationStats.trace do
|
35
|
+
$runs.times do
|
36
|
+
yield
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
allocations = stats.allocations(alias_paths: true).group_by(:sourcefile, :sourceline, :class)
|
42
|
+
|
43
|
+
if ENV['TOP']
|
44
|
+
puts allocations.sort_by_size.to_text.split("\n").first(20)
|
45
|
+
end
|
46
|
+
|
47
|
+
puts "Total allocations: #{allocations.all.values.map(&:size).sum}"
|
48
|
+
puts "Total memory: #{allocations.all.values.flatten.map(&:memsize).sum}"
|
49
|
+
puts stats.gc_profiler_report
|
50
|
+
end
|
51
|
+
|
52
|
+
measure "no-JIT context (#{$runs} runs)" do
|
53
|
+
$prefab.get('prefab.auth.allowed_origins')
|
54
|
+
end
|
55
|
+
|
56
|
+
puts "\n\n"
|
57
|
+
|
58
|
+
measure "with JIT context (#{$runs} runs)" do
|
59
|
+
$prefab.get('prefab.auth.allowed_origins', { a: { b: "c" } })
|
60
|
+
end
|
data/dev/benchmark
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'bundler/setup'
|
5
|
+
|
6
|
+
gemspec = Dir.glob(File.expand_path("../../*.gemspec", __FILE__)).first
|
7
|
+
spec = Gem::Specification.load(gemspec)
|
8
|
+
|
9
|
+
# Add the require paths to the $LOAD_PATH
|
10
|
+
spec.require_paths.each do |path|
|
11
|
+
full_path = File.expand_path("../" + path, __dir__)
|
12
|
+
$LOAD_PATH.unshift(full_path) unless $LOAD_PATH.include?(full_path)
|
13
|
+
end
|
14
|
+
|
15
|
+
spec.require_paths.each do |path|
|
16
|
+
require "./lib/prefab-cloud-ruby"
|
17
|
+
end
|
18
|
+
|
19
|
+
require 'prefab-cloud-ruby'
|
20
|
+
require 'benchmark/ips'
|
21
|
+
|
22
|
+
prefab = Prefab::Client.new(collect_logger_counts: false, collect_evaluation_summaries: false,
|
23
|
+
context_upload_mode: :none)
|
24
|
+
|
25
|
+
prefab.get('prefab.auth.allowed_origins')
|
26
|
+
|
27
|
+
prefab.with_context(user: { email_suffix: 'yahoo.com' }) do
|
28
|
+
Benchmark.ips do |x|
|
29
|
+
x.report("noop") do
|
30
|
+
end
|
31
|
+
|
32
|
+
x.report('prefab.get') do
|
33
|
+
prefab.get('prefab.auth.allowed_origins')
|
34
|
+
end
|
35
|
+
|
36
|
+
x.report('prefab.get with jit context') do
|
37
|
+
prefab.get('prefab.auth.allowed_origins', { a: { b: "c" } })
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/lib/prefab/client.rb
CHANGED
@@ -29,6 +29,9 @@ module Prefab
|
|
29
29
|
end
|
30
30
|
|
31
31
|
context.clear
|
32
|
+
|
33
|
+
Prefab::Context.global_context = @options.global_context
|
34
|
+
|
32
35
|
# start config client
|
33
36
|
config_client
|
34
37
|
end
|
@@ -51,6 +54,7 @@ module Prefab
|
|
51
54
|
|
52
55
|
def log_path_aggregator
|
53
56
|
return nil if @options.collect_max_paths <= 0
|
57
|
+
|
54
58
|
@log_path_aggregator ||= LogPathAggregator.new(client: self, max_paths: @options.collect_max_paths,
|
55
59
|
sync_interval: @options.collect_sync_interval)
|
56
60
|
end
|
@@ -87,14 +91,7 @@ module Prefab
|
|
87
91
|
end
|
88
92
|
|
89
93
|
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
|
94
|
+
warn '[DEPRECATION] `set_rails_loggers` is deprecated since 1.6. Please use semantic_logger or `Prefab.log_filter` instead.'
|
98
95
|
end
|
99
96
|
|
100
97
|
def on_update(&block)
|
data/lib/prefab/config_client.rb
CHANGED
@@ -60,7 +60,7 @@ module Prefab
|
|
60
60
|
@base_client.example_contexts_aggregator.record(context)
|
61
61
|
end
|
62
62
|
|
63
|
-
evaluation = _get(key,
|
63
|
+
evaluation = _get(key, properties)
|
64
64
|
|
65
65
|
@base_client.context_shape_aggregator&.push(context)
|
66
66
|
|
@@ -168,7 +168,7 @@ module Prefab
|
|
168
168
|
]
|
169
169
|
end.to_h
|
170
170
|
|
171
|
-
|
171
|
+
Prefab::Context.default_context = default_contexts || {}
|
172
172
|
|
173
173
|
configs.configs.each do |config|
|
174
174
|
@config_loader.set(config, source)
|
@@ -5,8 +5,6 @@ module Prefab
|
|
5
5
|
attr_accessor :project_env_id # this will be set by the config_client when it gets an API response
|
6
6
|
attr_reader :local_store
|
7
7
|
|
8
|
-
attr_accessor :default_context
|
9
|
-
|
10
8
|
def initialize(base_client, config_loader)
|
11
9
|
@lock = Concurrent::ReadWriteLock.new
|
12
10
|
@local_store = {}
|
@@ -14,7 +12,6 @@ module Prefab
|
|
14
12
|
@project_env_id = 0 # we don't know this yet, it is set from the API results
|
15
13
|
@base_client = base_client
|
16
14
|
@on_update = nil
|
17
|
-
@default_context = {}
|
18
15
|
make_local
|
19
16
|
end
|
20
17
|
|
@@ -59,11 +56,13 @@ module Prefab
|
|
59
56
|
end
|
60
57
|
|
61
58
|
def make_context(properties)
|
62
|
-
if properties
|
59
|
+
if properties.is_a?(Context)
|
60
|
+
properties
|
61
|
+
elsif properties == NO_DEFAULT_PROVIDED || properties.nil?
|
63
62
|
Context.current
|
64
63
|
else
|
65
|
-
Context.
|
66
|
-
end
|
64
|
+
Context.join(parent: Context.current, hash: properties, id: :jit)
|
65
|
+
end
|
67
66
|
end
|
68
67
|
|
69
68
|
private
|