hanami-events-cloud_pubsub 3.1.0 → 3.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 49a7d1c90e1e14b61aed89764e006780686f58394810ed4f58ae2be580325fed
|
|
4
|
+
data.tar.gz: 9839accaae0d4057c2b2acdeb8a88f35958343510f05d16edd97fc41c523bfe4
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1fcf93deb007707ebb82693a764cffa7d866056a28c56dd0c74b653ee80a29ca4e9ab71e6e9f35a6c883bfa45c7f87572eff63902ce27139807fc53345c72d65
|
|
7
|
+
data.tar.gz: 3ea0abe9e5bbab02d93c6ad649c29a7e091abdb22cfae66b50fcbee1735cc044966280664ef69475f47bcf1ac254c1406f8fed855ee38f87939a2baf0c83b51a
|
|
@@ -63,7 +63,7 @@ module Hanami
|
|
|
63
63
|
if defined?(Yabeda::Prometheus::Exporter)
|
|
64
64
|
begin
|
|
65
65
|
require 'hanami/events/cloud_pubsub/middleware/prometheus'
|
|
66
|
-
middleware_stack
|
|
66
|
+
middleware_stack << Middleware::Prometheus.new
|
|
67
67
|
rescue LoadError
|
|
68
68
|
# ok
|
|
69
69
|
end
|
|
@@ -6,15 +6,27 @@ module Hanami
|
|
|
6
6
|
module Middleware
|
|
7
7
|
# Middleware used for logging useful information about an event
|
|
8
8
|
class Prometheus
|
|
9
|
+
LONG_RUNNING_JOB_RUNTIME_BUCKETS = [
|
|
10
|
+
0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10, # standard (from Prometheus)
|
|
11
|
+
30, 60, 120, 300, 1800, 3600, 21_600 # Tasks may be very long-running
|
|
12
|
+
].freeze
|
|
13
|
+
|
|
9
14
|
Yabeda.configure do
|
|
10
15
|
counter(
|
|
11
16
|
:received_pubsub_events,
|
|
12
17
|
tags: %i[event_name subscription status],
|
|
13
18
|
comment: 'A counter of received pubsub events'
|
|
14
19
|
)
|
|
20
|
+
|
|
21
|
+
histogram :subscriber_runtime, comment: 'A histogram of the subscriber execution time.',
|
|
22
|
+
unit: :seconds,
|
|
23
|
+
per: :message,
|
|
24
|
+
tags: %i[event_name subscription status],
|
|
25
|
+
buckets: LONG_RUNNING_JOB_RUNTIME_BUCKETS
|
|
15
26
|
end
|
|
16
27
|
|
|
17
28
|
def call(msg, **opts)
|
|
29
|
+
start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
|
18
30
|
status = :running
|
|
19
31
|
|
|
20
32
|
begin
|
|
@@ -26,16 +38,18 @@ module Hanami
|
|
|
26
38
|
raise
|
|
27
39
|
end
|
|
28
40
|
ensure
|
|
29
|
-
record_metrics(msg, status)
|
|
41
|
+
record_metrics(msg, status, start)
|
|
30
42
|
end
|
|
31
43
|
|
|
32
44
|
private
|
|
33
45
|
|
|
34
|
-
def record_metrics(msg, status)
|
|
46
|
+
def record_metrics(msg, status, start)
|
|
47
|
+
elapsed = (Process.clock_gettime(Process::CLOCK_MONOTONIC) - start).round(3)
|
|
35
48
|
sub = msg.subscription.subscriber.subscription_name
|
|
36
49
|
event_name = msg.attributes['event_name']
|
|
37
50
|
labels = { event_name: event_name, subscription: sub, status: status }
|
|
38
51
|
Yabeda.received_pubsub_events.increment(labels, by: 1)
|
|
52
|
+
Yabeda.subscriber_runtime.measure(labels, elapsed)
|
|
39
53
|
rescue StandardError
|
|
40
54
|
# ok
|
|
41
55
|
end
|