prefab-cloud-ruby 1.5.1 → 1.6.0.pre1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +4 -2
  3. data/Gemfile +2 -0
  4. data/Gemfile.lock +3 -0
  5. data/README.md +24 -15
  6. data/VERSION +1 -1
  7. data/lib/prefab/client.rb +2 -7
  8. data/lib/prefab/config_client.rb +12 -16
  9. data/lib/prefab/config_loader.rb +1 -1
  10. data/lib/prefab/config_value_unwrapper.rb +1 -1
  11. data/lib/prefab/context_shape_aggregator.rb +1 -2
  12. data/lib/prefab/criteria_evaluator.rb +3 -3
  13. data/lib/prefab/evaluation_summary_aggregator.rb +1 -2
  14. data/lib/prefab/example_contexts_aggregator.rb +1 -2
  15. data/lib/prefab/feature_flag_client.rb +2 -1
  16. data/lib/prefab/internal_logger.rb +36 -10
  17. data/lib/prefab/log_path_aggregator.rb +1 -2
  18. data/lib/prefab/logger_client.rb +34 -213
  19. data/lib/prefab/options.rb +0 -44
  20. data/lib/prefab/periodic_sync.rb +2 -1
  21. data/lib/prefab/prefab.rb +23 -1
  22. data/lib/prefab/yaml_config_parser.rb +1 -1
  23. data/lib/prefab-cloud-ruby.rb +2 -5
  24. data/prefab-cloud-ruby.gemspec +6 -8
  25. data/test/support/common_helpers.rb +14 -13
  26. data/test/support/mock_base_client.rb +0 -1
  27. data/test/test_client.rb +1 -10
  28. data/test/test_config_client.rb +1 -2
  29. data/test/test_context_shape_aggregator.rb +2 -5
  30. data/test/test_criteria_evaluator.rb +0 -4
  31. data/test/test_integration.rb +1 -1
  32. data/test/test_internal_logger.rb +25 -0
  33. data/test/test_log_path_aggregator.rb +5 -10
  34. data/test/test_logger.rb +57 -453
  35. data/test/test_logger_initialization.rb +1 -1
  36. metadata +18 -8
  37. data/lib/prefab/log_subscribers/action_controller_subscriber.rb +0 -55
  38. data/lib/prefab/logging/formatter_base.rb +0 -21
  39. data/lib/prefab/sse_logger.rb +0 -14
  40. data/lib/prefab/static_logger.rb +0 -29
  41. data/test/test_action_controller.rb +0 -81
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prefab-cloud-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.1
4
+ version: 1.6.0.pre1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Dwyer
@@ -128,6 +128,20 @@ dependencies:
128
128
  - - ">="
129
129
  - !ruby/object:Gem::Version
130
130
  version: '4'
131
+ - !ruby/object:Gem::Dependency
132
+ name: semantic_logger
133
+ requirement: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - ">="
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ type: :runtime
139
+ prerelease: false
140
+ version_requirements: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ version: '0'
131
145
  - !ruby/object:Gem::Dependency
132
146
  name: benchmark-ips
133
147
  requirement: !ruby/object:Gem::Requirement
@@ -252,17 +266,13 @@ files:
252
266
  - lib/prefab/internal_logger.rb
253
267
  - lib/prefab/local_config_parser.rb
254
268
  - lib/prefab/log_path_aggregator.rb
255
- - lib/prefab/log_subscribers/action_controller_subscriber.rb
256
269
  - lib/prefab/logger_client.rb
257
- - lib/prefab/logging/formatter_base.rb
258
270
  - lib/prefab/murmer3.rb
259
271
  - lib/prefab/options.rb
260
272
  - lib/prefab/periodic_sync.rb
261
273
  - lib/prefab/prefab.rb
262
274
  - lib/prefab/rate_limit_cache.rb
263
275
  - lib/prefab/resolved_config_presenter.rb
264
- - lib/prefab/sse_logger.rb
265
- - lib/prefab/static_logger.rb
266
276
  - lib/prefab/time_helpers.rb
267
277
  - lib/prefab/weighted_value_resolver.rb
268
278
  - lib/prefab/yaml_config_parser.rb
@@ -276,7 +286,6 @@ files:
276
286
  - test/support/mock_base_client.rb
277
287
  - test/support/mock_config_client.rb
278
288
  - test/support/mock_config_loader.rb
279
- - test/test_action_controller.rb
280
289
  - test/test_client.rb
281
290
  - test/test_config_client.rb
282
291
  - test/test_config_loader.rb
@@ -294,6 +303,7 @@ files:
294
303
  - test/test_feature_flag_client.rb
295
304
  - test/test_helper.rb
296
305
  - test/test_integration.rb
306
+ - test/test_internal_logger.rb
297
307
  - test/test_local_config_parser.rb
298
308
  - test/test_log_path_aggregator.rb
299
309
  - test/test_logger.rb
@@ -317,9 +327,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
317
327
  version: '0'
318
328
  required_rubygems_version: !ruby/object:Gem::Requirement
319
329
  requirements:
320
- - - ">="
330
+ - - ">"
321
331
  - !ruby/object:Gem::Version
322
- version: '0'
332
+ version: 1.3.1
323
333
  requirements: []
324
334
  rubygems_version: 3.2.32
325
335
  signing_key:
@@ -1,55 +0,0 @@
1
- # Modified from https://github.com/reidmorrison/rails_semantic_logger/blob/master/lib/rails_semantic_logger/action_controller/log_subscriber.rb
2
- #
3
- # Copyright 2012, 2013, 2014, 2015 Reid Morrison
4
- #
5
- # Licensed under the Apache License, Version 2.0 (the "License");
6
- # you may not use this file except in compliance with the License.
7
- # You may obtain a copy of the License at
8
- #
9
- # http://www.apache.org/licenses/LICENSE-2.0
10
- #
11
- # Unless required by applicable law or agreed to in writing, software
12
- # distributed under the License is distributed on an "AS IS" BASIS,
13
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- # See the License for the specific language governing permissions and
15
- # limitations under the License.
16
- #
17
- module Prefab
18
- module LogSubscribers
19
- class ActionControllerSubscriber < ActiveSupport::LogSubscriber
20
-
21
- INTERNAL_PARAMS = %w[controller action format _method only_path].freeze
22
-
23
- LOG = Prefab::StaticLogger.new("rails.controller.request")
24
-
25
- # With great debt to https://github.com/reidmorrison/rails_semantic_logger/blob/master/lib/rails_semantic_logger/action_controller/log_subscriber.rb
26
- def process_action(event)
27
- payload = event.payload.dup
28
- payload.delete(:headers)
29
- payload.delete(:request)
30
- payload.delete(:response)
31
- payload[:req_path] = payload.delete(:path)
32
- params = payload[:params]
33
-
34
- if params.kind_of?(Hash) || params.kind_of?(::ActionController::Parameters)
35
- payload[:params] = params.to_unsafe_h unless params.is_a?(Hash)
36
- payload[:params] = params.except(*INTERNAL_PARAMS)
37
-
38
- if payload[:params].empty?
39
- payload.delete(:params)
40
- elsif params["file"]
41
- # When logging to JSON the entire tempfile is logged, so convert it to a string.
42
- payload[:params]["file"] = params["file"].inspect
43
- end
44
- end
45
-
46
- # Rounds off the runtimes. For example, :view_runtime, :mongo_runtime, etc.
47
- payload.keys.each do |key|
48
- payload[key] = payload[key].to_f.round(2) if key.to_s =~ /(.*)_runtime/
49
- end
50
-
51
- LOG.info "#{payload[:status]} #{payload[:controller]}##{payload[:action]}", **payload
52
- end
53
- end
54
- end
55
- end
@@ -1,21 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Prefab
4
- module Logging
5
- # Shim class to quack like a Rails TaggedLogger
6
- class FormatterBase < ::Logger
7
- def initialize(formatter_proc:, logger_client:)
8
- @formatter_proc = formatter_proc
9
- @logger_client = logger_client
10
- end
11
-
12
- def call_proc(data)
13
- @formatter_proc.call(data)
14
- end
15
-
16
- def current_tags
17
- @logger_client.current_tags
18
- end
19
- end
20
- end
21
- end
@@ -1,14 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Prefab
4
- class SseLogger < InternalLogger
5
- def initialize()
6
- super("sse")
7
- end
8
-
9
- # The SSE::Client warns on a perfectly normal stream disconnect, recast to info
10
- def warn(msg = nil,**log_context, &block)
11
- Prefab::LoggerClient.instance.log_internal ::Logger::INFO, msg, @path, log_context, &block
12
- end
13
- end
14
- end
@@ -1,29 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Prefab
4
- class StaticLogger < ::Logger
5
- def initialize(path)
6
- @path = path
7
- end
8
-
9
- def debug(msg = nil, **log_context, &block)
10
- Prefab::LoggerClient.instance.log_internal ::Logger::DEBUG, msg, @path, log_context, &block
11
- end
12
-
13
- def info(msg = nil, **log_context, &block)
14
- Prefab::LoggerClient.instance.log_internal ::Logger::INFO, msg, @path, log_context, &block
15
- end
16
-
17
- def warn(msg = nil, **log_context, &block)
18
- Prefab::LoggerClient.instance.log_internal ::Logger::WARN, msg, @path, log_context, &block
19
- end
20
-
21
- def error(msg = nil, **log_context, &block)
22
- Prefab::LoggerClient.instance.log_internal ::Logger::ERROR, msg, @path, log_context, &block
23
- end
24
-
25
- def fatal(msg = nil, **log_context, &block)
26
- Prefab::LoggerClient.instance.log_internal ::Logger::FATAL, msg, @path, log_context, &block
27
- end
28
- end
29
- end
@@ -1,81 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
-
5
- class TestActionController < Minitest::Test
6
- def setup
7
- super
8
- end
9
-
10
- def test_load
11
- new_client(config: log_level_config("log-level.rails.controller", "INFO"))
12
- @subscriber = Prefab::LogSubscribers::ActionControllerSubscriber.new
13
- @subscriber.process_action(event)
14
- assert_logged ['INFO 2023-08-09 15:18:12 -0400: rails.controller.request 200 MyController#index action=index controller=MyController db_runtime=0.05 format=application/html method=GET params={"p1"=>"v1"} req_path=/my?p1=v1 status=200 view_runtime=0.02']
15
- end
16
-
17
- def test_json
18
- new_client(config: log_level_config("log-level.rails.controller", "INFO"), log_formatter: Prefab::Options::JSON_LOG_FORMATTER)
19
- @subscriber = Prefab::LogSubscribers::ActionControllerSubscriber.new
20
- event = ActiveSupport::Notifications::Event.new(
21
- 'process_action.action_controller',
22
- Time.now,
23
- Time.now,
24
- 99,
25
- path: '/original_path',
26
- )
27
- @subscriber.process_action(event)
28
- assert_logged ["{\"severity\":\"INFO\",\"datetime\":\"2023-08-09 15:18:12 -0400\",\"path\":\"rails.controller.request\",\"message\":\" #\",\"req_path\":\"/original_path\"}"]
29
-
30
- end
31
-
32
- def test_funny_params
33
- new_client(config: log_level_config("log-level.rails.controller", "INFO"))
34
- @subscriber = Prefab::LogSubscribers::ActionControllerSubscriber.new
35
- event = ActiveSupport::Notifications::Event.new(
36
- 'process_action.action_controller',
37
- Time.now,
38
- Time.now,
39
- 99,
40
- params: "foo"
41
- )
42
- @subscriber.process_action(event)
43
- assert_logged ['INFO 2023-08-09 15:18:12 -0400: rails.controller.request # params=foo']
44
- end
45
-
46
-
47
- def event
48
- ActiveSupport::Notifications::Event.new(
49
- 'process_action.action_controller',
50
- Time.now,
51
- Time.now,
52
- 99,
53
- status: 200,
54
- controller: 'MyController',
55
- action: 'index',
56
- format: 'application/html',
57
- method: 'GET',
58
- path: '/my?p1=v1',
59
- params: { 'p1' => 'v1' },
60
- db_runtime: 0.051123,
61
- view_runtime: 0.024555
62
- )
63
- end
64
-
65
- def log_level_config(path, level)
66
- PrefabProto::Config.new(
67
- id: 123,
68
- key: path,
69
- config_type: PrefabProto::ConfigType::LOG_LEVEL,
70
- rows: [
71
- PrefabProto::ConfigRow.new(
72
- values: [
73
- PrefabProto::ConditionalValue.new(
74
- value: PrefabProto::ConfigValue.new(log_level: level)
75
- )
76
- ]
77
- )
78
- ]
79
- )
80
- end
81
- end