prefab-cloud-ruby 1.6.1 → 1.6.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e0cc90e8b5acc15676a5101e6cbd902e37e38781ebb6d6fb33c892f938df3bbc
4
- data.tar.gz: 68e1dbb144273aa9c54fb11efdf9333f2260a8805705d2aff47885719d995b7f
3
+ metadata.gz: f938b850265077b3ea456a8cab3d93eda3eadcba2d7807af03bae5be36b9c625
4
+ data.tar.gz: 5219784f5f6e30a0bddc1376ef102e3f2431639278c9225aa8000ac53cc9c4fa
5
5
  SHA512:
6
- metadata.gz: 9518b4ab1b19e6f7532fd29146b26bd0fd4e3527dbc4fde041b61b712a843db95f6f9355d8afb0b2496436aab711ec5f4a57075dbaf80c7afd4bb85c35d92b53
7
- data.tar.gz: d2f4806025b4c965792653149ac9976b47ed4f687bbbb9b73cf58af091a55d4ad03affe49e6cd55aba132fa1a49f422f73900a2d295abb3afb2867cf204bb533
6
+ metadata.gz: 16c8a0d94d3c267cc3ea7ff4be436e0dfe7a2b7124e8f7d5500194379d0a06e8f8985f790dbc128e70b8960f61c8ce56bc15025ed8872722ce6b9b729a36a760
7
+ data.tar.gz: 1eb81d70d7728b1f900a7a96ae344b7c2fc85a248eecc17ddb662ff1aec80c7704321e1b7e9fb8926090736ae3fe12f2a8f1d378c625900a94031b390cfcfba6
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.6.2 - 2024-03-29
4
+
5
+ - Fix context telemetry when JIT and Block contexts are combined (#185)
6
+ - Remove logger prefix (#186)
7
+
3
8
  ## 1.6.1 - 2024-03-28
4
9
 
5
10
  - Performance optimizations (#178)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.6.1
1
+ 1.6.2
@@ -31,7 +31,7 @@ module Prefab
31
31
  end
32
32
 
33
33
  THREAD_KEY = :prefab_context
34
- attr_reader :contexts, :seen_at
34
+ attr_reader :contexts, :seen_at, :id, :parent
35
35
 
36
36
  class << self
37
37
  def global_context=(context)
@@ -173,6 +173,7 @@ module Prefab
173
173
 
174
174
  def clear
175
175
  @contexts = {}
176
+ @flattened = {}
176
177
  end
177
178
 
178
179
  def context(name)
@@ -187,6 +188,18 @@ module Prefab
187
188
  self
188
189
  end
189
190
 
191
+ def reportable_tree
192
+ ctx = self
193
+ reportables = []
194
+
195
+ while ctx
196
+ reportables.unshift(ctx)
197
+ ctx = ctx.parent
198
+ end
199
+
200
+ reportables
201
+ end
202
+
190
203
  def to_proto(namespace)
191
204
  prefab_context = {
192
205
  'current-time' => ConfigValueWrapper.wrap(Prefab::TimeHelpers.now_in_ms)
@@ -194,8 +207,16 @@ module Prefab
194
207
 
195
208
  prefab_context['namespace'] = ConfigValueWrapper.wrap(namespace) if namespace&.length&.positive?
196
209
 
210
+ reportable_contexts = {}
211
+
212
+ reportable_tree.each do |ctx|
213
+ ctx.contexts.each do |name, context|
214
+ reportable_contexts[name] = context
215
+ end
216
+ end
217
+
197
218
  PrefabProto::ContextSet.new(
198
- contexts: contexts.map do |name, context|
219
+ contexts: reportable_contexts.map do |name, context|
199
220
  context.to_proto
200
221
  end.concat([PrefabProto::Context.new(type: 'prefab',
201
222
  values: prefab_context)])
@@ -224,9 +245,5 @@ module Prefab
224
245
  super
225
246
  end
226
247
  end
227
-
228
- def id
229
- @id
230
- end
231
248
  end
232
249
  end
@@ -28,13 +28,11 @@ module Prefab
28
28
 
29
29
  def semantic_filter(log)
30
30
  class_path = class_path_name(log.name)
31
- lookup_path = "#{logger_prefix}.#{class_path}"
32
31
  level = SemanticLogger::Levels.index(log.level)
33
- log.named_tags.merge!({ path: lookup_path })
34
- should_log? level, lookup_path
32
+ log.named_tags.merge!({ path: class_path })
33
+ should_log? level, class_path
35
34
  end
36
35
 
37
-
38
36
  def config_client=(config_client)
39
37
  @config_client = config_client
40
38
  end
@@ -50,10 +48,6 @@ module Prefab
50
48
  end.gsub(/[^a-z_]/i, '.')
51
49
  end
52
50
 
53
- def logger_prefix
54
- Context.current.get("application.key") || "prefab-cloud-ruby"
55
- end
56
-
57
51
  # Find the closest match to 'log_level.path' in config
58
52
  def level_of(path)
59
53
  closest_log_level_match = nil
@@ -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.1 ruby lib
5
+ # stub: prefab-cloud-ruby 1.6.2 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "prefab-cloud-ruby".freeze
9
- s.version = "1.6.1"
9
+ s.version = "1.6.2"
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 = "2024-03-28"
14
+ s.date = "2024-03-29"
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.extra_rdoc_files = [
@@ -7,6 +7,8 @@ module CommonHelpers
7
7
  $oldstderr, $stderr = $stderr, StringIO.new
8
8
 
9
9
  $logs = StringIO.new
10
+ Prefab::Context.global_context.clear
11
+ Prefab::Context.default_context.clear
10
12
  SemanticLogger.add_appender(io: $logs, filter: Prefab.log_filter)
11
13
  SemanticLogger.sync!
12
14
  Timecop.freeze('2023-08-09 15:18:12 -0400')
@@ -449,6 +449,37 @@ class TestConfigResolver < Minitest::Test
449
449
  end
450
450
  end
451
451
 
452
+ def test_context_lookup_with_no_local_context
453
+ global_context = { cpu: { count: 4, speed: '2.4GHz' }, clock: { timezone: 'UTC' } }
454
+ default_context = { 'prefab-api-key' => { 'user-id' => 123 } }
455
+ jit_context = { user: { name: 'Frank' } }
456
+
457
+ config = PrefabProto::Config.new( key: 'example', rows: [ PrefabProto::ConfigRow.new( values: [ PrefabProto::ConditionalValue.new( value: PrefabProto::ConfigValue.new(string: 'valueB2')) ]) ])
458
+
459
+ client = new_client(global_context: global_context, config: [config])
460
+
461
+ # we fake getting the default context from the API
462
+ Prefab::Context.default_context = default_context
463
+
464
+ resolver = client.resolver
465
+
466
+ context = resolver.get("example", jit_context).context
467
+
468
+ # This digs all the way to the global context
469
+ assert_equal 4, context.get('cpu.count')
470
+ assert_equal '2.4GHz', context.get('cpu.speed')
471
+ assert_equal 'UTC', context.get('clock.timezone')
472
+
473
+ # This digs to the default context
474
+ assert_equal 123, context.get('prefab-api-key.user-id')
475
+
476
+ # This uses the jit context
477
+ assert_equal 'Frank', context.get('user.name')
478
+
479
+ # This is nil in the jit context because `user` was clobbered
480
+ assert_nil context.get('user.email')
481
+ end
482
+
452
483
  private
453
484
 
454
485
  def resolver_for_namespace(namespace, loader, project_env_id: TEST_ENV_ID)
data/test/test_context.rb CHANGED
@@ -154,6 +154,93 @@ class TestContext < Minitest::Test
154
154
  ), contexts.to_proto(namespace)
155
155
  end
156
156
 
157
+ def test_to_proto_with_parent
158
+ global_context = { cpu: { count: 4, speed: '2.4GHz' }, clock: { timezone: 'UTC' }, magic: { key: "global-key" } }
159
+ default_context = { 'prefab-api-key' => { 'user-id' => 123 } }
160
+
161
+ Prefab::Context.global_context = global_context
162
+ Prefab::Context.default_context = default_context
163
+
164
+ Prefab::Context.current = {
165
+ user: { id: 2, email: 'parent-email' },
166
+ magic: { key: 'parent-key', rabbits: 3 },
167
+ clock: { timezone: 'PST' }
168
+ }
169
+
170
+ contexts = Prefab::Context.join(hash: {
171
+ user: {
172
+ id: 1,
173
+ email: 'user-email'
174
+ },
175
+ team: {
176
+ id: 2,
177
+ name: 'team-name'
178
+ }
179
+ }, id: :jit, parent: Prefab::Context.current)
180
+
181
+ expected = PrefabProto::ContextSet.new(
182
+ contexts: [
183
+ # Via global
184
+ PrefabProto::Context.new(
185
+ type: "cpu",
186
+ values: {
187
+ "count" => PrefabProto::ConfigValue.new(int: 4),
188
+ "speed" => PrefabProto::ConfigValue.new(string: "2.4GHz")
189
+ }
190
+ ),
191
+ # Via default
192
+ PrefabProto::Context.new(
193
+ type: "clock",
194
+ values: {
195
+ "timezone" => PrefabProto::ConfigValue.new(string: 'PST'),
196
+ }
197
+ ),
198
+ # via current
199
+ PrefabProto::Context.new(
200
+ type: "magic",
201
+ values: {
202
+ "key" => PrefabProto::ConfigValue.new(string: 'parent-key'),
203
+ "rabbits" => PrefabProto::ConfigValue.new(int: 3)
204
+ }
205
+ ),
206
+ # via default
207
+ PrefabProto::Context.new(
208
+ type: "prefab-api-key",
209
+ values: {
210
+ "user-id" => PrefabProto::ConfigValue.new(int: 123)
211
+ }
212
+ ),
213
+ # via jit
214
+ PrefabProto::Context.new(
215
+ type: "user",
216
+ values: {
217
+ "id" => PrefabProto::ConfigValue.new(int: 1),
218
+ "email" => PrefabProto::ConfigValue.new(string: "user-email")
219
+ }
220
+ ),
221
+ # via jit
222
+ PrefabProto::Context.new(
223
+ type: "team",
224
+ values: {
225
+ "id" => PrefabProto::ConfigValue.new(int: 2),
226
+ "name" => PrefabProto::ConfigValue.new(string: "team-name")
227
+ }
228
+ ),
229
+ # via to_proto
230
+ PrefabProto::Context.new(
231
+ type: "prefab",
232
+ values: {
233
+ 'current-time' => PrefabProto::ConfigValue.new(int: Prefab::TimeHelpers.now_in_ms),
234
+ }
235
+ )
236
+ ]
237
+ )
238
+
239
+ actual = contexts.to_proto("")
240
+
241
+ assert_equal expected, actual
242
+ end
243
+
157
244
  def test_parent_lookup
158
245
  global_context = { cpu: { count: 4, speed: '2.4GHz' }, clock: { timezone: 'UTC' } }
159
246
  default_context = { 'prefab-api-key' => { 'user-id' => 123 } }
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.1
4
+ version: 1.6.2
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-03-28 00:00:00.000000000 Z
11
+ date: 2024-03-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby