hanami-events-cloud_pubsub 2.5.1 → 2.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -1
- data/.tool-versions +1 -1
- data/Gemfile.lock +39 -34
- data/README.md +7 -0
- data/hanami-events-cloud_pubsub.gemspec +2 -0
- data/lib/hanami/events/cloud_pubsub/health_check_server.rb +32 -16
- data/lib/hanami/events/cloud_pubsub/middleware/prometheus.rb +32 -0
- data/lib/hanami/events/cloud_pubsub/version.rb +1 -1
- data/lib/hanami/events/cloud_pubsub.rb +6 -1
- metadata +31 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 753a636d5e7a7f4e76eb1865278d0979ad5d338c0c5283f7b22c11a491a42f92
|
4
|
+
data.tar.gz: 43ba31f43a4b5255d10c4682e9859d14d9f79c9d4036786bd947bf1faa77d042
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d1ae226d26f497f50c447784421861e45d99b59624149cecc224d4f6ae9bf2e74f54c9438cfb2ed33c55ab938f4d12913200025d1c40a4b0518d8305ea089762
|
7
|
+
data.tar.gz: a1a1b64ca8dc346484a699a78508e92b9057ee14d599f1097bf9b84defee04e4af35c59aa039ad30659894d0395d890c490725e4989744a39c936525362fbfd2
|
data/.rubocop.yml
CHANGED
data/.tool-versions
CHANGED
@@ -1 +1 @@
|
|
1
|
-
ruby 2.6.
|
1
|
+
ruby 2.6.6
|
data/Gemfile.lock
CHANGED
@@ -8,11 +8,12 @@ GIT
|
|
8
8
|
PATH
|
9
9
|
remote: .
|
10
10
|
specs:
|
11
|
-
hanami-events-cloud_pubsub (2.
|
11
|
+
hanami-events-cloud_pubsub (2.6.0)
|
12
12
|
dry-configurable (>= 0.8)
|
13
13
|
google-cloud-pubsub (>= 0.38.1, < 1.4)
|
14
14
|
hanami-cli (~> 0.2)
|
15
15
|
hanami-events (~> 0.2.0)
|
16
|
+
rack
|
16
17
|
|
17
18
|
GEM
|
18
19
|
remote: https://rubygems.org/
|
@@ -24,7 +25,7 @@ GEM
|
|
24
25
|
concurrent-ruby (1.1.6)
|
25
26
|
diff-lcs (1.3)
|
26
27
|
docile (1.3.2)
|
27
|
-
dry-configurable (0.11.
|
28
|
+
dry-configurable (0.11.5)
|
28
29
|
concurrent-ruby (~> 1.0)
|
29
30
|
dry-core (~> 0.4, >= 0.4.7)
|
30
31
|
dry-equalizer (~> 0.2)
|
@@ -34,13 +35,13 @@ GEM
|
|
34
35
|
dry-core (0.4.9)
|
35
36
|
concurrent-ruby (~> 1.0)
|
36
37
|
dry-equalizer (0.3.0)
|
37
|
-
faraday (0.
|
38
|
+
faraday (1.0.1)
|
38
39
|
multipart-post (>= 1.2, < 3)
|
39
40
|
google-cloud-core (1.5.0)
|
40
41
|
google-cloud-env (~> 1.0)
|
41
42
|
google-cloud-errors (~> 1.0)
|
42
|
-
google-cloud-env (1.3.
|
43
|
-
faraday (
|
43
|
+
google-cloud-env (1.3.1)
|
44
|
+
faraday (>= 0.17.3, < 2.0)
|
44
45
|
google-cloud-errors (1.0.0)
|
45
46
|
google-cloud-pubsub (1.3.1)
|
46
47
|
concurrent-ruby (~> 1.1)
|
@@ -56,25 +57,26 @@ GEM
|
|
56
57
|
grpc (~> 1.24)
|
57
58
|
rly (~> 0.2.3)
|
58
59
|
google-protobuf (3.11.4)
|
59
|
-
googleapis-common-protos (1.3.
|
60
|
-
google-protobuf (~> 3.
|
61
|
-
googleapis-common-protos-types (
|
62
|
-
grpc (~> 1.
|
63
|
-
googleapis-common-protos-types (1.0.
|
64
|
-
google-protobuf (~> 3.
|
65
|
-
googleauth (0.
|
66
|
-
faraday (
|
60
|
+
googleapis-common-protos (1.3.10)
|
61
|
+
google-protobuf (~> 3.11)
|
62
|
+
googleapis-common-protos-types (>= 1.0.5, < 2.0)
|
63
|
+
grpc (~> 1.27)
|
64
|
+
googleapis-common-protos-types (1.0.5)
|
65
|
+
google-protobuf (~> 3.11)
|
66
|
+
googleauth (0.12.0)
|
67
|
+
faraday (>= 0.17.3, < 2.0)
|
67
68
|
jwt (>= 1.4, < 3.0)
|
68
69
|
memoist (~> 0.16)
|
69
70
|
multi_json (~> 1.11)
|
70
71
|
os (>= 0.9, < 2.0)
|
71
|
-
signet (~> 0.
|
72
|
-
grpc (1.
|
72
|
+
signet (~> 0.14)
|
73
|
+
grpc (1.28.0)
|
73
74
|
google-protobuf (~> 3.11)
|
74
75
|
googleapis-common-protos-types (~> 1.0)
|
75
|
-
grpc-google-iam-v1 (0.6.
|
76
|
-
|
77
|
-
|
76
|
+
grpc-google-iam-v1 (0.6.10)
|
77
|
+
google-protobuf (~> 3.11)
|
78
|
+
googleapis-common-protos (>= 1.3.10, < 2.0)
|
79
|
+
grpc (~> 1.27)
|
78
80
|
hanami-cli (0.3.1)
|
79
81
|
concurrent-ruby (~> 1.0)
|
80
82
|
hanami-utils (~> 1.3)
|
@@ -84,17 +86,19 @@ GEM
|
|
84
86
|
jaro_winkler (1.5.4)
|
85
87
|
jwt (2.2.1)
|
86
88
|
memoist (0.16.2)
|
87
|
-
method_source (0.
|
89
|
+
method_source (1.0.0)
|
88
90
|
multi_json (1.14.1)
|
89
91
|
multipart-post (2.1.1)
|
90
|
-
os (1.0
|
92
|
+
os (1.1.0)
|
91
93
|
parallel (1.19.1)
|
92
|
-
parser (2.7.
|
94
|
+
parser (2.7.1.1)
|
93
95
|
ast (~> 2.4.0)
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
96
|
+
prometheus-client (2.0.0)
|
97
|
+
pry (0.13.1)
|
98
|
+
coderay (~> 1.1)
|
99
|
+
method_source (~> 1.0)
|
100
|
+
public_suffix (4.0.4)
|
101
|
+
rack (2.2.2)
|
98
102
|
rainbow (3.0.0)
|
99
103
|
rake (13.0.1)
|
100
104
|
rexml (3.2.4)
|
@@ -105,33 +109,33 @@ GEM
|
|
105
109
|
rspec-mocks (~> 3.9.0)
|
106
110
|
rspec-core (3.9.1)
|
107
111
|
rspec-support (~> 3.9.1)
|
108
|
-
rspec-expectations (3.9.
|
112
|
+
rspec-expectations (3.9.1)
|
109
113
|
diff-lcs (>= 1.2.0, < 2.0)
|
110
114
|
rspec-support (~> 3.9.0)
|
111
115
|
rspec-mocks (3.9.1)
|
112
116
|
diff-lcs (>= 1.2.0, < 2.0)
|
113
117
|
rspec-support (~> 3.9.0)
|
114
118
|
rspec-support (3.9.2)
|
115
|
-
rubocop (0.
|
119
|
+
rubocop (0.82.0)
|
116
120
|
jaro_winkler (~> 1.5.1)
|
117
121
|
parallel (~> 1.10)
|
118
122
|
parser (>= 2.7.0.1)
|
119
123
|
rainbow (>= 2.2.2, < 4.0)
|
120
124
|
rexml
|
121
125
|
ruby-progressbar (~> 1.7)
|
122
|
-
unicode-display_width (>= 1.4.0, <
|
126
|
+
unicode-display_width (>= 1.4.0, < 2.0)
|
123
127
|
ruby-progressbar (1.10.1)
|
124
|
-
signet (0.
|
128
|
+
signet (0.14.0)
|
125
129
|
addressable (~> 2.3)
|
126
|
-
faraday (
|
130
|
+
faraday (>= 0.17.3, < 2.0)
|
127
131
|
jwt (>= 1.5, < 3.0)
|
128
132
|
multi_json (~> 1.10)
|
129
|
-
simplecov (0.18.
|
133
|
+
simplecov (0.18.5)
|
130
134
|
docile (~> 1.1)
|
131
135
|
simplecov-html (~> 0.11)
|
132
|
-
simplecov-html (0.12.
|
136
|
+
simplecov-html (0.12.2)
|
133
137
|
transproc (1.1.1)
|
134
|
-
unicode-display_width (1.
|
138
|
+
unicode-display_width (1.7.0)
|
135
139
|
|
136
140
|
PLATFORMS
|
137
141
|
ruby
|
@@ -140,6 +144,7 @@ DEPENDENCIES
|
|
140
144
|
bundler (~> 1.16)
|
141
145
|
hanami-events!
|
142
146
|
hanami-events-cloud_pubsub!
|
147
|
+
prometheus-client
|
143
148
|
pry
|
144
149
|
rake (~> 13.0)
|
145
150
|
rspec (~> 3.0)
|
@@ -147,4 +152,4 @@ DEPENDENCIES
|
|
147
152
|
simplecov
|
148
153
|
|
149
154
|
BUNDLED WITH
|
150
|
-
1.17.
|
155
|
+
1.17.3
|
data/README.md
CHANGED
@@ -106,6 +106,13 @@ Then, run the worker process:
|
|
106
106
|
bundle exec cloudpubsub run
|
107
107
|
```
|
108
108
|
|
109
|
+
# Prometheus Integration
|
110
|
+
|
111
|
+
If you have the `prometheus-client` gem installed, a `/metrics` endpoint will
|
112
|
+
be available on the health check server which can be scraped.
|
113
|
+
|
114
|
+
All you need to do to activate this is to make sure to `require 'prometheus/client'`.
|
115
|
+
|
109
116
|
# Testing
|
110
117
|
|
111
118
|
If you would like to use an emulator process for testing:
|
@@ -26,8 +26,10 @@ Gem::Specification.new do |spec|
|
|
26
26
|
spec.add_dependency 'google-cloud-pubsub', '>= 0.38.1', '< 1.4'
|
27
27
|
spec.add_dependency 'hanami-cli', '~> 0.2'
|
28
28
|
spec.add_dependency 'hanami-events', '~> 0.2.0'
|
29
|
+
spec.add_dependency 'rack'
|
29
30
|
|
30
31
|
spec.add_development_dependency 'bundler', '~> 1.16'
|
32
|
+
spec.add_development_dependency 'prometheus-client'
|
31
33
|
spec.add_development_dependency 'rake', '~> 13.0'
|
32
34
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
33
35
|
end
|
@@ -14,18 +14,18 @@ module Hanami
|
|
14
14
|
|
15
15
|
def start
|
16
16
|
logger.info 'Starting healthcheck server on port 0.0.0.0:8081'
|
17
|
-
|
17
|
+
start_server
|
18
18
|
end
|
19
19
|
|
20
20
|
def shutdown
|
21
21
|
logger.info 'Shutting down healthcheck server'
|
22
|
-
server.shutdown
|
22
|
+
@server.shutdown
|
23
23
|
end
|
24
24
|
|
25
25
|
def run_in_background(on_shutdown: nil)
|
26
26
|
prom = Concurrent::Promise.execute do
|
27
27
|
start
|
28
|
-
on_shutdown&.call(server)
|
28
|
+
on_shutdown&.call(@server)
|
29
29
|
end
|
30
30
|
|
31
31
|
prom.catch { |err| logger.error(err) }
|
@@ -35,22 +35,38 @@ module Hanami
|
|
35
35
|
|
36
36
|
attr_reader :logger, :runner
|
37
37
|
|
38
|
-
def
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
38
|
+
def start_server
|
39
|
+
require 'rack'
|
40
|
+
|
41
|
+
Rack::Handler::WEBrick.run(
|
42
|
+
rack_app,
|
43
|
+
AccessLog: [],
|
44
|
+
Host: '0.0.0.0',
|
45
|
+
Port: 8081,
|
46
|
+
Logger: WEBrick::Log.new('/dev/null')
|
47
|
+
) do |server|
|
48
|
+
@server = server
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def rack_app
|
53
|
+
health_endpoint_app = method(:health_endpoint)
|
54
|
+
|
55
|
+
Rack::Builder.new do |builder|
|
56
|
+
builder.use Rack::Deflater
|
57
|
+
if defined?(::Prometheus::Client)
|
58
|
+
require 'prometheus/middleware/exporter'
|
59
|
+
builder.use ::Prometheus::Middleware::Exporter
|
47
60
|
end
|
61
|
+
builder.run health_endpoint_app
|
62
|
+
end
|
48
63
|
end
|
49
64
|
|
50
|
-
def health_endpoint(
|
51
|
-
|
52
|
-
|
53
|
-
|
65
|
+
def health_endpoint(_env)
|
66
|
+
headers = { 'Content-Type' => 'text/plain' }
|
67
|
+
status = runner.healthy? ? 200 : 503
|
68
|
+
body = [runner.debug_info]
|
69
|
+
[status, headers, body]
|
54
70
|
end
|
55
71
|
end
|
56
72
|
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Hanami
|
4
|
+
module Events
|
5
|
+
module CloudPubsub
|
6
|
+
module Middleware
|
7
|
+
# Middleware used for logging useful information about an event
|
8
|
+
class Prometheus
|
9
|
+
attr_reader :events_counter
|
10
|
+
|
11
|
+
def initialize
|
12
|
+
require 'prometheus/client'
|
13
|
+
prometheus = ::Prometheus::Client.registry
|
14
|
+
@events_counter = prometheus.counter(
|
15
|
+
:pubsub_events,
|
16
|
+
docstring: 'A counter of received pubsub events',
|
17
|
+
labels: %i[event_name subscription]
|
18
|
+
)
|
19
|
+
end
|
20
|
+
|
21
|
+
def call(msg, opts = {})
|
22
|
+
yield(opts)
|
23
|
+
ensure
|
24
|
+
sub = msg.subscription.subscriber.subscription_name
|
25
|
+
event_name = msg.attributes['event_name']
|
26
|
+
events_counter.increment(labels: { event_name: event_name, subscription: sub })
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -6,6 +6,7 @@ require 'hanami/events/cloud_pubsub/version'
|
|
6
6
|
require 'hanami/events/cloud_pubsub/middleware/stack'
|
7
7
|
require 'hanami/events/cloud_pubsub/middleware/logging'
|
8
8
|
require 'hanami/events/cloud_pubsub/middleware/auto_retry'
|
9
|
+
require 'hanami/events/cloud_pubsub/middleware/prometheus'
|
9
10
|
require 'hanami/events/cloud_pubsub/runner'
|
10
11
|
require 'hanami/events/cloud_pubsub/errors'
|
11
12
|
require 'google/cloud/pubsub'
|
@@ -57,11 +58,15 @@ module Hanami
|
|
57
58
|
end
|
58
59
|
], reader: true
|
59
60
|
|
60
|
-
|
61
|
+
middleware_stack = Middleware::Stack.new(
|
61
62
|
Middleware::Logging.new,
|
62
63
|
Middleware::AutoRetry.new
|
63
64
|
)
|
64
65
|
|
66
|
+
middleware_stack.prepend(Middleware::Prometheus) if defined?(::Prometheus::Client)
|
67
|
+
|
68
|
+
setting :middleware, middleware_stack
|
69
|
+
|
65
70
|
setting :on_shutdown_handlers, [], reader: true
|
66
71
|
|
67
72
|
def self.finalize_settings!
|
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.
|
4
|
+
version: 2.6.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-
|
11
|
+
date: 2020-04-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dry-configurable
|
@@ -72,6 +72,20 @@ dependencies:
|
|
72
72
|
- - "~>"
|
73
73
|
- !ruby/object:Gem::Version
|
74
74
|
version: 0.2.0
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: rack
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
type: :runtime
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
75
89
|
- !ruby/object:Gem::Dependency
|
76
90
|
name: bundler
|
77
91
|
requirement: !ruby/object:Gem::Requirement
|
@@ -86,6 +100,20 @@ dependencies:
|
|
86
100
|
- - "~>"
|
87
101
|
- !ruby/object:Gem::Version
|
88
102
|
version: '1.16'
|
103
|
+
- !ruby/object:Gem::Dependency
|
104
|
+
name: prometheus-client
|
105
|
+
requirement: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
type: :development
|
111
|
+
prerelease: false
|
112
|
+
version_requirements: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
89
117
|
- !ruby/object:Gem::Dependency
|
90
118
|
name: rake
|
91
119
|
requirement: !ruby/object:Gem::Requirement
|
@@ -152,6 +180,7 @@ files:
|
|
152
180
|
- lib/hanami/events/cloud_pubsub/listener.rb
|
153
181
|
- lib/hanami/events/cloud_pubsub/middleware/auto_retry.rb
|
154
182
|
- lib/hanami/events/cloud_pubsub/middleware/logging.rb
|
183
|
+
- lib/hanami/events/cloud_pubsub/middleware/prometheus.rb
|
155
184
|
- lib/hanami/events/cloud_pubsub/middleware/stack.rb
|
156
185
|
- lib/hanami/events/cloud_pubsub/register.rb
|
157
186
|
- lib/hanami/events/cloud_pubsub/runner.rb
|