hermes-rb 0.7.2 → 0.7.4

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: 04cd997573681cd37e8efc8061173c6aeb7eaf4a9f7310ba74db397b0e80ce2a
4
- data.tar.gz: b5c13fc6d2cd31cfb509f150788db4d6b7104211241ca623e0e378ed90875d1f
3
+ metadata.gz: 94187b0dbacdc8b471962dd95e728a6656b09a700b58d28fb5dbdabb7f8f29e6
4
+ data.tar.gz: fd3a5be4f4f9ab8c15b45398644cb0e88f17e1e2326ffd6156b98883c073fd9c
5
5
  SHA512:
6
- metadata.gz: 43733dc22a8ae84ef2a83d45c31ab32dd5ce747e695864e9d1d4b982a05c9dd67ed266aabb70113585a120526ae5526913c69dcbe88477816a456b23c017be1f
7
- data.tar.gz: 975dfaafd7ed1050e51b032f7c76153c1c50832fae47852360e1e81984b842eef461f37f000f2ad80fdf44f5763313516ae5951a0f7cf203051c722a2e4d8498
6
+ metadata.gz: 631b9f899d6da6843fe5d31ceef76dc722c2dacaa035d8fbc1de2ff09cebe677b0aa5c607bdb104dce8c4407dfb53a53a5bbd5bd05530466b48808e30bc72db0
7
+ data.tar.gz: '0547960e1b5a139f5cc6415a344ccd927b5c2ddd5f4de9b4148d40b307fdd92eff9fd6d817e4a57b2b53c5f97a693b632ba33d76d90a2c12f210c657e038ac87'
@@ -16,6 +16,7 @@ jobs:
16
16
  DISTRIBUTED_TRACING_DATABASE_URI: "postgresql://postgres:postgres@127.0.0.1:5432/hermes-rb-test"
17
17
  HUTCH_URI: "amqp://guest:guest@127.0.0.1:5672"
18
18
  HUTCH_ENABLE_HTTP_API_USE: false
19
+ DD_PROFILING_NO_EXTENSION: true
19
20
  services:
20
21
  postgres:
21
22
  image: postgres:14
data/Changelog.md CHANGED
@@ -2,6 +2,15 @@
2
2
 
3
3
  ## Master
4
4
 
5
+ ## 0.7.4
6
+
7
+ - Make `Hermes::Logger::ParamsFilter` handle case-insensitive matches
8
+
9
+ ## 0.7.3
10
+
11
+ - Handle database reconnection in synchronous flow
12
+ - Improve test coverage of `Hermes::Logger::ParamsFilter` - cover regular expressions
13
+
5
14
  ## 0.7.2
6
15
  - Clear Hermes.origin_headers after calling event handlers
7
16
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- hermes-rb (0.7.2)
4
+ hermes-rb (0.7.4)
5
5
  activerecord (>= 5)
6
6
  activesupport (>= 5)
7
7
  dry-container (~> 0)
@@ -36,24 +36,27 @@ GEM
36
36
  ddtrace (0.45.0)
37
37
  msgpack
38
38
  diff-lcs (1.4.4)
39
- dry-container (0.10.1)
39
+ dry-container (0.11.0)
40
40
  concurrent-ruby (~> 1.0)
41
- dry-core (0.8.1)
41
+ dry-core (1.0.0)
42
42
  concurrent-ruby (~> 1.0)
43
- dry-inflector (0.3.0)
44
- dry-logic (1.2.0)
43
+ zeitwerk (~> 2.6)
44
+ dry-inflector (1.0.0)
45
+ dry-logic (1.5.0)
45
46
  concurrent-ruby (~> 1.0)
46
- dry-core (~> 0.5, >= 0.5)
47
- dry-struct (1.4.0)
48
- dry-core (~> 0.5, >= 0.5)
49
- dry-types (~> 1.5)
47
+ dry-core (~> 1.0, < 2)
48
+ zeitwerk (~> 2.6)
49
+ dry-struct (1.6.0)
50
+ dry-core (~> 1.0, < 2)
51
+ dry-types (>= 1.7, < 2)
50
52
  ice_nine (~> 0.11)
51
- dry-types (1.5.1)
53
+ zeitwerk (~> 2.6)
54
+ dry-types (1.7.0)
52
55
  concurrent-ruby (~> 1.0)
53
- dry-container (~> 0.3)
54
- dry-core (~> 0.5, >= 0.5)
55
- dry-inflector (~> 0.1, >= 0.1.2)
56
- dry-logic (~> 1.0, >= 1.0.2)
56
+ dry-core (~> 1.0, < 2)
57
+ dry-inflector (~> 1.0, < 2)
58
+ dry-logic (>= 1.4, < 2)
59
+ zeitwerk (~> 2.6)
57
60
  hutch (1.1.1)
58
61
  activesupport (>= 4.2, < 8)
59
62
  bunny (>= 2.19, < 3.0)
@@ -68,7 +71,7 @@ GEM
68
71
  multi_json (1.15.0)
69
72
  newrelic_rpm (6.15.0)
70
73
  pg (1.2.3)
71
- rack (3.0.0)
74
+ rack (3.0.1)
72
75
  rake (13.0.1)
73
76
  rbtree (0.4.5)
74
77
  request_store (1.5.1)
@@ -95,6 +98,7 @@ GEM
95
98
  tzinfo (2.0.5)
96
99
  concurrent-ruby (~> 1.0)
97
100
  vcr (5.0.0)
101
+ zeitwerk (2.6.6)
98
102
 
99
103
  PLATFORMS
100
104
  ruby
@@ -112,4 +116,4 @@ DEPENDENCIES
112
116
  vcr
113
117
 
114
118
  BUNDLED WITH
115
- 2.2.22
119
+ 2.4.3
data/README.md CHANGED
@@ -30,6 +30,7 @@ Rails.application.config.to_prepare do
30
30
  config.adapter = Rails.application.config.async_messaging_adapter
31
31
  config.application_prefix = "my_app"
32
32
  config.background_processor = HermesHandlerJob
33
+ config.database_connection_provider = ActiveRecord::Base.connection
33
34
  config.enqueue_method = :perform_async
34
35
  config.event_handler = event_handler
35
36
  config.clock = Time.zone
@@ -87,14 +88,15 @@ end
87
88
 
88
89
  If you know what you are doing, you don't necessarily have to process things in the background. As long as the class implements the expected interface, you can do anything you want.
89
90
 
90
- 5. `event_handler` - an instance of event handler/storage, just use what is shown in the example. Notice that you can also pass extra consumer config lambda that will be evaluated within the context of Hutch consumer.
91
- 6. `clock` - a clock object that is time-zone aware, implementing `now` method.
92
- 7. `configure_hutch` - a way to configure Hutch:
91
+ 5. `database_connection_provider` - an object responding to `reconnect!`. It is used during synchronous flow to ensure a valid connection. Optional.
92
+ 6. `event_handler` - an instance of event handler/storage, just use what is shown in the example. Notice that you can also pass extra consumer config lambda that will be evaluated within the context of Hutch consumer.
93
+ 7. `clock` - a clock object that is time-zone aware, implementing `now` method.
94
+ 8. `configure_hutch` - a way to configure Hutch:
93
95
  - `uri` - the URI for RabbitMQ, required.
94
96
  - `force_publisher_confirms` - defaults to `true`
95
97
  - `enable_http_api_use` - defaults to `false`
96
98
  - `tracer` - defaults to `Hermes::Tracers::Datadog` if you use Datadog, `Hutch::Tracers::NewRelic` for NewRelic and `Hutch::Tracers::NullTracer` if you use neither Datadog, nor NewRelic. Check APM section for more details if you want to provide a custom tracer.
97
- 8. `event_handler.handle_events` - that's how you declare events and their handlers. The event handler is an object that responds to `call` method and takes `event` as an argument. All events should ideally be subclasses of `Hermes::BaseEvent`
99
+ 9. `event_handler.handle_events` - that's how you declare events and their handlers. The event handler is an object that responds to `call` method and takes `event` as an argument. All events should ideally be subclasses of `Hermes::BaseEvent`
98
100
 
99
101
  This class inherits from `Dry::Struct`, so getting familiar with [dry-struct gem](https://dry-rb.org/gems/dry-struct/) would be beneficial. Here is an example event:
100
102
 
@@ -122,9 +124,9 @@ To avoid unexpected problems, don't use restricted names for attribtes such as `
122
124
 
123
125
  You can also specify whether the event should be processed asynchronously using `background_processor` (default behavior) or synchronously. If you want the event to be processed synchronously, e.g. when doing RPC, use `async: false` option.
124
126
 
125
- 9. `rpc_call_timeout` - a timeout for RPC calls, defaults to 10 seconds. Can be also customized per instance of RPC Client (covered later). Optional.
127
+ 10. `rpc_call_timeout` - a timeout for RPC calls, defaults to 10 seconds. Can be also customized per instance of RPC Client (covered later). Optional.
126
128
 
127
- 10. `instrumenter` - instrumenter object responding to `instrument` method taking one string argument, one optional hash argument and a block.
129
+ 11. `instrumenter` - instrumenter object responding to `instrument` method taking one string argument, one optional hash argument and a block.
128
130
 
129
131
  For example:
130
132
 
@@ -144,21 +146,21 @@ end
144
146
 
145
147
  If you don't care about it, you can leave it empty.
146
148
 
147
- 11. `distributed_tracing_database_uri` - If you want to enable distributed tracing, specify Postgres database URI. Optional.
149
+ 12. `distributed_tracing_database_uri` - If you want to enable distributed tracing, specify Postgres database URI. Optional.
148
150
 
149
- 12. `distributed_tracing_database_table` - Table name for storing traces, by default it's `hermes_distributed_traces`. Optional.
151
+ 13. `distributed_tracing_database_table` - Table name for storing traces, by default it's `hermes_distributed_traces`. Optional.
150
152
 
151
- 13. `distributes_tracing_mapper` - an object responding to `call` method taking one argument (a hash of attributes) which must return a hash as well. This hash will be used for assigning attributes when creating `Hermes::DistributedTrace`. It defaults to `Hermes::DistributedTrace::Mapper`, which uses `logger_params_filter` to remove sensitive info (this config option is covered below). You can either provide a custom mapper or pass a custom params filter, for example: `Hermes::DistributedTrace::Mapper.new(params_filter: custom_params_filter)`
153
+ 14. `distributes_tracing_mapper` - an object responding to `call` method taking one argument (a hash of attributes) which must return a hash as well. This hash will be used for assigning attributes when creating `Hermes::DistributedTrace`. It defaults to `Hermes::DistributedTrace::Mapper`, which uses `logger_params_filter` to remove sensitive info (this config option is covered below). You can either provide a custom mapper or pass a custom params filter, for example: `Hermes::DistributedTrace::Mapper.new(params_filter: custom_params_filter)`
152
154
 
153
- 14. `error_notification_service` - an object responding to `capture_exception` method taking one argument (error). Its interface is based on `Raven` from [Sentry Raven](https://github.com/getsentry/sentry-ruby/tree/master/sentry-raven). By default `Hermes::NullErrorNotificationService` is used, which does nothing. Optional.
155
+ 15. `error_notification_service` - an object responding to `capture_exception` method taking one argument (error). Its interface is based on `Raven` from [Sentry Raven](https://github.com/getsentry/sentry-ruby/tree/master/sentry-raven). By default `Hermes::NullErrorNotificationService` is used, which does nothing. Optional.
154
156
 
155
- 15. `database_error_handler` - `an object responding to `call` method taking one argument (error). Used when storing distributed traces. By default it uses `Hermes::DatabaseErrorHandler` which depends on `error_notification_service`, so in most cases, you will probably want to just configure `error_notification_service`. Optional.
157
+ 16. `database_error_handler` - `an object responding to `call` method taking one argument (error). Used when storing distributed traces. By default it uses `Hermes::DatabaseErrorHandler` which depends on `error_notification_service`, so in most cases, you will probably want to just configure `error_notification_service`. Optional.
156
158
 
157
- 16. `enable_safe_producer` - a method requiring a job class implementing `enqueue` method that will be responsible for retrying delivery of the event later in case it fails. Check `Safe Event Producer` section for more details.
159
+ 17. `enable_safe_producer` - a method requiring a job class implementing `enqueue` method that will be responsible for retrying delivery of the event later in case it fails. Check `Safe Event Producer` section for more details.
158
160
 
159
- 17. `producer_retryable` - used when `safe_producer` was enabled via (`enable_safe_producer`). By default, it is a method retrying delivery 3 times rescuing from `StandardError` each time. The object responsible for this behavior by default is: `Hermes::Retryable.new(times: 3, errors: [StandardError])`.
161
+ 18. `producer_retryable` - used when `safe_producer` was enabled via (`enable_safe_producer`). By default, it is a method retrying delivery 3 times rescuing from `StandardError` each time. The object responsible for this behavior by default is: `Hermes::Retryable.new(times: 3, errors: [StandardError])`.
160
162
 
161
- 18. `logger_params_filter` - a service used as params filter for logger, to make sure no sensitive data will be logged. It defaults to `Hermes::Logger::ParamsFilter` which already performs some filtering but it might not be enough in your case. If you are not satisfied with the defaults, you have 2 options, which are especially simple in Rails apps:
163
+ 19. `logger_params_filter` - a service used as params filter for logger, to make sure no sensitive data will be logged. It defaults to `Hermes::Logger::ParamsFilter` which already performs some filtering but it might not be enough in your case. If you are not satisfied with the defaults, you have 2 options, which are especially simple in Rails apps:
162
164
  - provide custom array of sensitive attributes and still use a default filter: `Hermes::Logger::ParamsFilter.new(sensitive_keywords: Rails.application.config.filter_parameters)`.
163
165
  - provide custom filter object, which responds to `call` method and takes 2 arguments: attribute name and its value and performs mutation by using `gsub!` (don't worry, the entire body is cloned before passing it to the filter, so nothing unexpected will happen). This is compatible with the interface of `Rails.application.config.filter_parameters` when you use a custom filter there. In such case, you can do something like this: `Rails.application.config.filter_parameters = [Proc.new { |k, v| do_something_custom_here(k, v) }]` and then just assign `Rails.application.config.filter_parameters.first` in the Hermes config.
164
166
  ## RPC
@@ -4,7 +4,7 @@ module Hermes
4
4
  :background_processor, :enqueue_method, :event_handler, :rpc_call_timeout,
5
5
  :instrumenter, :distributed_tracing_database_uri, :distributed_tracing_database_table,
6
6
  :distributes_tracing_mapper, :database_error_handler, :error_notification_service, :producer_error_handler,
7
- :producer_error_handler_job_class, :producer_retryable, :logger_params_filter, :tracer
7
+ :producer_error_handler_job_class, :producer_retryable, :logger_params_filter, :tracer, :database_connection_provider
8
8
 
9
9
  def configure_hutch
10
10
  yield hutch
@@ -25,6 +25,7 @@ module Hermes
25
25
  config.background_processor.public_send(config.enqueue_method, event_class.to_s, body, headers)
26
26
  logger.log_enqueued(event_class, body, headers, config.clock.now)
27
27
  else
28
+ ensure_database_connection!
28
29
  result = event_processor.call(event_class.to_s, body, headers)
29
30
  event = result.event
30
31
  response = result.response
@@ -58,6 +59,10 @@ module Hermes
58
59
  def event_processor
59
60
  Hermes::DependenciesContainer["event_processor"]
60
61
  end
62
+
63
+ def ensure_database_connection!
64
+ config.database_connection_provider.reconnect! if config.database_connection_provider
65
+ end
61
66
  end
62
67
 
63
68
  register_consumer(consumer_name, consumer)
@@ -16,7 +16,7 @@ module Hermes
16
16
  end
17
17
 
18
18
  def call(attribute, value)
19
- if sensitive_keywords.any? { |sensitive_attribute| attribute.to_s.match(sensitive_attribute) } && value.respond_to?(:to_str)
19
+ if sensitive_keywords.any? { |sensitive_attribute| attribute.to_s.downcase.match(sensitive_attribute.to_s.downcase) } && value.respond_to?(:to_str)
20
20
  value.gsub!(value, stripped_value)
21
21
  end
22
22
  end
@@ -1,5 +1,5 @@
1
1
  module Hermes
2
2
  module Rb
3
- VERSION = "0.7.2"
3
+ VERSION = "0.7.4"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hermes-rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.2
4
+ version: 0.7.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Karol Galanciak
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-09-14 00:00:00.000000000 Z
11
+ date: 2023-01-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-struct