hanami-events-cloud_pubsub 2.8.1 → 2.9.0

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: 85ed69df79fc8f4c3197cc63e2c70afcc30532dd1dd61de56b40d816ef512633
4
- data.tar.gz: 8b2cd963546a1a051fbb1fdef5c34d69c81c93b928ad7465481fe2e26e0b6415
3
+ metadata.gz: a5ffe95cabc82141bd06ee9514ad0af66aaba9c5ebc719190e7cc9efba855274
4
+ data.tar.gz: 119b219d3294f50b37a13daa36a4a55edf0d85f5ac14e82676fee3cad62f135a
5
5
  SHA512:
6
- metadata.gz: 3c10ba39f6b0c6f3f4ffbd7a5073019821e0ecbdfd30be769a9aee8c61a0d38ff0c9dc3ad5047f1c7ca9aaabf57320a3e9e2d1a682524329eb5991d68bc801fb
7
- data.tar.gz: 9e5855ad6001ab46e7acafb27929f2d3ffdc0f341e31a22752f0e9bb9e0a9e1d24669fc73288481ee17e174018acadb78048f957e5c8a2028d1eb9963dcb7c6e
6
+ metadata.gz: a3475491db3dab17ab2fd423c056dca407977321223bd457903b3773bdbd7ef9080b2446e70305e8e64f136d6bd434c157b90ae72bd48f91bd388cb060005ee3
7
+ data.tar.gz: 93bd30e26d6a85281f21dfd394f6aa7ea41a340459426f8b280f798e56b1fb3dc857390e6384e8d4605a286cbd313174eab2207e971e0c02374663cd91180744
data/Gemfile CHANGED
@@ -11,3 +11,5 @@ gem 'hanami-events', github: 'hanami/events'
11
11
  gem 'pry'
12
12
  gem 'rubocop'
13
13
  gem 'simplecov', require: false
14
+
15
+ gem 'request_id', '~> 0.4.3'
@@ -8,7 +8,7 @@ GIT
8
8
  PATH
9
9
  remote: .
10
10
  specs:
11
- hanami-events-cloud_pubsub (2.8.1)
11
+ hanami-events-cloud_pubsub (2.9.0)
12
12
  dry-configurable (>= 0.8)
13
13
  google-cloud-pubsub (>= 0.38.1, < 1.7)
14
14
  hanami-cli (~> 0.2)
@@ -20,12 +20,12 @@ GEM
20
20
  specs:
21
21
  addressable (2.7.0)
22
22
  public_suffix (>= 2.0.2, < 5.0)
23
- ast (2.4.0)
24
- coderay (1.1.2)
23
+ ast (2.4.1)
24
+ coderay (1.1.3)
25
25
  concurrent-ruby (1.1.6)
26
- diff-lcs (1.3)
26
+ diff-lcs (1.4.4)
27
27
  docile (1.3.2)
28
- dry-configurable (0.11.5)
28
+ dry-configurable (0.11.6)
29
29
  concurrent-ruby (~> 1.0)
30
30
  dry-core (~> 0.4, >= 0.4.7)
31
31
  dry-equalizer (~> 0.2)
@@ -40,7 +40,7 @@ GEM
40
40
  google-cloud-core (1.5.0)
41
41
  google-cloud-env (~> 1.0)
42
42
  google-cloud-errors (~> 1.0)
43
- google-cloud-env (1.3.2)
43
+ google-cloud-env (1.3.3)
44
44
  faraday (>= 0.17.3, < 2.0)
45
45
  google-cloud-errors (1.0.1)
46
46
  google-cloud-pubsub (1.6.1)
@@ -56,22 +56,22 @@ GEM
56
56
  googleauth (~> 0.9)
57
57
  grpc (~> 1.24)
58
58
  rly (~> 0.2.3)
59
- google-protobuf (3.12.2)
59
+ google-protobuf (3.12.4)
60
60
  googleapis-common-protos (1.3.10)
61
61
  google-protobuf (~> 3.11)
62
62
  googleapis-common-protos-types (>= 1.0.5, < 2.0)
63
63
  grpc (~> 1.27)
64
64
  googleapis-common-protos-types (1.0.5)
65
65
  google-protobuf (~> 3.11)
66
- googleauth (0.12.0)
66
+ googleauth (0.13.1)
67
67
  faraday (>= 0.17.3, < 2.0)
68
68
  jwt (>= 1.4, < 3.0)
69
69
  memoist (~> 0.16)
70
70
  multi_json (~> 1.11)
71
71
  os (>= 0.9, < 2.0)
72
72
  signet (~> 0.14)
73
- grpc (1.28.0)
74
- google-protobuf (~> 3.11)
73
+ grpc (1.30.2)
74
+ google-protobuf (~> 3.12)
75
75
  googleapis-common-protos-types (~> 1.0)
76
76
  grpc-google-iam-v1 (0.6.10)
77
77
  google-protobuf (~> 3.11)
@@ -83,47 +83,51 @@ GEM
83
83
  hanami-utils (1.3.6)
84
84
  concurrent-ruby (~> 1.0)
85
85
  transproc (~> 1.0)
86
- jaro_winkler (1.5.4)
87
86
  jwt (2.2.1)
88
87
  memoist (0.16.2)
89
88
  method_source (1.0.0)
90
- multi_json (1.14.1)
89
+ multi_json (1.15.0)
91
90
  multipart-post (2.1.1)
92
- os (1.1.0)
93
- parallel (1.19.1)
94
- parser (2.7.1.1)
95
- ast (~> 2.4.0)
96
- prometheus-client (2.0.0)
91
+ os (1.1.1)
92
+ parallel (1.19.2)
93
+ parser (2.7.1.4)
94
+ ast (~> 2.4.1)
95
+ prometheus-client (2.1.0)
97
96
  pry (0.13.1)
98
97
  coderay (~> 1.1)
99
98
  method_source (~> 1.0)
100
99
  public_suffix (4.0.5)
101
- rack (2.2.2)
100
+ rack (2.2.3)
102
101
  rainbow (3.0.0)
103
102
  rake (13.0.1)
103
+ regexp_parser (1.7.1)
104
+ request_id (0.4.3)
104
105
  rexml (3.2.4)
105
106
  rly (0.2.3)
106
107
  rspec (3.9.0)
107
108
  rspec-core (~> 3.9.0)
108
109
  rspec-expectations (~> 3.9.0)
109
110
  rspec-mocks (~> 3.9.0)
110
- rspec-core (3.9.1)
111
- rspec-support (~> 3.9.1)
112
- rspec-expectations (3.9.1)
111
+ rspec-core (3.9.2)
112
+ rspec-support (~> 3.9.3)
113
+ rspec-expectations (3.9.2)
113
114
  diff-lcs (>= 1.2.0, < 2.0)
114
115
  rspec-support (~> 3.9.0)
115
116
  rspec-mocks (3.9.1)
116
117
  diff-lcs (>= 1.2.0, < 2.0)
117
118
  rspec-support (~> 3.9.0)
118
- rspec-support (3.9.2)
119
- rubocop (0.82.0)
120
- jaro_winkler (~> 1.5.1)
119
+ rspec-support (3.9.3)
120
+ rubocop (0.89.0)
121
121
  parallel (~> 1.10)
122
- parser (>= 2.7.0.1)
122
+ parser (>= 2.7.1.1)
123
123
  rainbow (>= 2.2.2, < 4.0)
124
+ regexp_parser (>= 1.7)
124
125
  rexml
126
+ rubocop-ast (>= 0.1.0, < 1.0)
125
127
  ruby-progressbar (~> 1.7)
126
128
  unicode-display_width (>= 1.4.0, < 2.0)
129
+ rubocop-ast (0.3.0)
130
+ parser (>= 2.7.1.4)
127
131
  ruby-progressbar (1.10.1)
128
132
  signet (0.14.0)
129
133
  addressable (~> 2.3)
@@ -147,6 +151,7 @@ DEPENDENCIES
147
151
  prometheus-client
148
152
  pry
149
153
  rake (~> 13.0)
154
+ request_id (~> 0.4.3)
150
155
  rspec (~> 3.0)
151
156
  rubocop
152
157
  simplecov
data/README.md CHANGED
@@ -106,6 +106,19 @@ Then, run the worker process:
106
106
  bundle exec cloudpubsub run
107
107
  ```
108
108
 
109
+ # `RequestId` Integration
110
+
111
+ To gem has an integration with [request_id](https://github.com/remind101/request_id), so you can trace interactions between various components in your app. To make it work properly, make sure the `request_id` is added to your Gemfile, then require the middleware:
112
+
113
+ ```ruby
114
+ require 'hanami/events/cloud_pubsub/middleware/request_id'
115
+
116
+ Hanami::Events::CloudPubsub.configure do |config|
117
+ # ...
118
+ end
119
+ ```
120
+
121
+
109
122
  # Prometheus Integration
110
123
 
111
124
  If you have the `prometheus-client` gem installed, a `/metrics` endpoint will
@@ -11,7 +11,7 @@ module Hanami
11
11
  #
12
12
  # @api private
13
13
  class CloudPubsub
14
- attr_reader :subscribers, :listeners, :topic_registry
14
+ attr_reader :subscribers, :listeners, :topic_registry, :middleware
15
15
 
16
16
  def initialize(params)
17
17
  @pubsub = params[:pubsub]
@@ -22,6 +22,7 @@ module Hanami
22
22
  @serializer_type = params.fetch(:serializer, :json).to_sym
23
23
  @topic_registry = {}
24
24
  @mutex = Mutex.new
25
+ @middleware = ::Hanami::Events::CloudPubsub.config.client_middleware
25
26
  end
26
27
 
27
28
  # Brodcasts event to all subscribes
@@ -34,8 +35,10 @@ module Hanami
34
35
  payload = serializer.serialize(payload)
35
36
  attributes = { id: SecureRandom.uuid, event_name: event_name }
36
37
 
37
- topic.publish_async(payload, **attributes, **message_opts) do |result|
38
- logger.info "Published event #{result.inspect}"
38
+ middleware.invoke(payload, **attributes, **message_opts) do |*args|
39
+ topic.publish_async(*args) do |result|
40
+ logger.info "Published event #{result.inspect}"
41
+ end
39
42
  end
40
43
  end
41
44
 
@@ -72,6 +72,21 @@ module Hanami
72
72
 
73
73
  setting :middleware, middleware_stack
74
74
 
75
+ client_middleware_stack = Middleware::Stack.new
76
+
77
+ begin
78
+ require 'request_id'
79
+ require 'hanami/events/cloud_pubsub/middleware/client/request_id'
80
+ require 'hanami/events/cloud_pubsub/middleware/request_id'
81
+
82
+ client_middleware_stack.prepend(Middleware::Client::RequestId.new)
83
+ middleware_stack.prepend(Middleware::RequestId.new)
84
+ rescue LoadError
85
+ # ok
86
+ end
87
+
88
+ setting :client_middleware, client_middleware_stack
89
+
75
90
  setting :on_shutdown_handlers, [], reader: true
76
91
 
77
92
  def self.finalize_settings!
@@ -36,7 +36,7 @@ module Hanami
36
36
  def register
37
37
  subscription = subscription_for(subscriber_id)
38
38
 
39
- listener = subscription.listen(subscriber_opts) do |message|
39
+ listener = subscription.listen(**subscriber_opts) do |message|
40
40
  handle_message(message)
41
41
  end
42
42
 
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Hanami
4
+ module Events
5
+ module CloudPubsub
6
+ module Middleware
7
+ module Client
8
+ # Broadcasts events with current request id
9
+ class RequestId
10
+ def call(payload, attributes = {})
11
+ attributes.merge!(
12
+ request_id: ::RequestId.request_id || SecureRandom.uuid
13
+ )
14
+
15
+ yield(payload, **attributes)
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ begin
4
+ require 'request_id'
5
+ rescue LoadError
6
+ abort 'Please add "request_id" to your Gemfile to use this middleware'
7
+ end
8
+
9
+ module Hanami
10
+ module Events
11
+ module CloudPubsub
12
+ module Middleware
13
+ # Middleware used for logging useful information about an event
14
+ class RequestId
15
+ def call(msg, **opts)
16
+ setup_request_id(msg)
17
+ yield(**opts)
18
+ ensure
19
+ clear_request_id(msg)
20
+ end
21
+
22
+ private
23
+
24
+ def setup_request_id(msg)
25
+ id = msg.attributes['request_id'] || msg.attributes[:request_id]
26
+
27
+ ::RequestId.request_id = id || SecureRandom.uuid
28
+ rescue StandardError => e
29
+ warn "Could not set request_id (#{e.message})"
30
+ end
31
+
32
+ def clear_request_id(_msg)
33
+ ::RequestId.request_id = nil
34
+ rescue StandardError => e
35
+ warn "Could not clear request_id (#{e.message})"
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -40,14 +40,14 @@ module Hanami
40
40
  @entries.shift
41
41
  end
42
42
 
43
- def invoke(message)
43
+ def invoke(*args)
44
44
  stack = entries.dup
45
45
 
46
46
  traverse_stack = proc do |**opts|
47
47
  if stack.empty?
48
- yield(message)
48
+ yield(*args)
49
49
  else
50
- stack.shift.call(message, **opts, &traverse_stack)
50
+ stack.shift.call(*args, **opts, &traverse_stack)
51
51
  end
52
52
  end
53
53
 
@@ -3,7 +3,7 @@
3
3
  module Hanami
4
4
  module Events
5
5
  module CloudPubsub
6
- VERSION = '2.8.1'
6
+ VERSION = '2.9.0'
7
7
  end
8
8
  end
9
9
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hanami-events-cloud_pubsub
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.8.1
4
+ version: 2.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ian Ker-Seymer
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-06-01 00:00:00.000000000 Z
11
+ date: 2020-08-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-configurable
@@ -179,8 +179,10 @@ files:
179
179
  - lib/hanami/events/cloud_pubsub/integration.rb
180
180
  - lib/hanami/events/cloud_pubsub/listener.rb
181
181
  - lib/hanami/events/cloud_pubsub/middleware/auto_retry.rb
182
+ - lib/hanami/events/cloud_pubsub/middleware/client/request_id.rb
182
183
  - lib/hanami/events/cloud_pubsub/middleware/logging.rb
183
184
  - lib/hanami/events/cloud_pubsub/middleware/prometheus.rb
185
+ - lib/hanami/events/cloud_pubsub/middleware/request_id.rb
184
186
  - lib/hanami/events/cloud_pubsub/middleware/stack.rb
185
187
  - lib/hanami/events/cloud_pubsub/register.rb
186
188
  - lib/hanami/events/cloud_pubsub/runner.rb