hanami-events-cloud_pubsub 3.1.0 → 3.1.1

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: 1b625cc3f94218143ebafd31a854fdefb3e4b3ab5d54aa66385784f6560265c8
4
- data.tar.gz: e7eb0b9995c66e2c4610b9eba4913a4ff94e8c89981302b4f736ccc9cdddf6aa
3
+ metadata.gz: 49a7d1c90e1e14b61aed89764e006780686f58394810ed4f58ae2be580325fed
4
+ data.tar.gz: 9839accaae0d4057c2b2acdeb8a88f35958343510f05d16edd97fc41c523bfe4
5
5
  SHA512:
6
- metadata.gz: f3e44b4a055f90493bfafe9cbeb8243ddc2bba0c6eb693f5b29c664f2675546a5415387519fbe9075a110304aa3d8136b8da9b0ce0dddfa793a155fa39aeca98
7
- data.tar.gz: e7107a4d84b881d2522b04002f07395783912d83a3653673650b2947a1e500cf47b4d8282adaaf0aabacbcfb3572a6780e828ff994ffcdffe160805dd30272ec
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.prepend(Middleware::Prometheus.new)
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
@@ -3,7 +3,7 @@
3
3
  module Hanami
4
4
  module Events
5
5
  module CloudPubsub
6
- VERSION = '3.1.0'
6
+ VERSION = '3.1.1'
7
7
  end
8
8
  end
9
9
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hanami-events-cloud_pubsub
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.0
4
+ version: 3.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ian Ker-Seymer