promenade 0.8.0 → 0.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: 69cb441f3ff80fd4e24c3fd1760a2930d5ec57be77d1e8defc7d5c0c91d9526a
4
- data.tar.gz: b29b635ad8c18ad0cd990d764c9fcda51e2b5394818788a43478692a2f9bef09
3
+ metadata.gz: fc0749131d57843e9243eb47058cc0615c73865b92b753772308ceb13cd6b096
4
+ data.tar.gz: 66c5a9376ea0cd02dbd64bd63e67d3178f440a30701646912ef459586e14a1e6
5
5
  SHA512:
6
- metadata.gz: 78899076a32afdabe648eed9c717ca0656880d83343c8101f68529302d232046a7b0659e00f8aa9d0f2c0c98de5f77c75ae9d43a3b0a656816b0cbd70c5e683c
7
- data.tar.gz: 233dea29570f65d4dbed4a33c3da1898d3c41918777610fa5bba95e8f9931003554a1beb2d1ba7326eb113e0e53176f72c2176e80ab236849adfef914c1076c0
6
+ metadata.gz: 5569ffe88cbaf2a0a738b605c15673a6866e51c345fc53a8000f01004dd77b23a8175af32f1242ed2492aa444c6a71e20d760fb1d377b2c02ead531470108f47
7
+ data.tar.gz: b2fe6be44e09a45f9e6cf051971b27140d9af03e436265815ccb0e527d85dfcc890dc271654e3b404ff9cfce8c8a633ff4efe1c17797781ef6751732bb7d92f3
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- promenade (0.8.0)
4
+ promenade (0.9.0)
5
5
  actionpack
6
6
  activesupport (> 6.0, < 8.0)
7
7
  prometheus-client-mmap (~> 0.16.0)
@@ -0,0 +1,46 @@
1
+ require "promenade/karafka/subscriber"
2
+
3
+ module Promenade
4
+ module Karafka
5
+ class ConsumerSubscriber < Subscriber
6
+ attach_to "consumer.karafka"
7
+
8
+ Promenade.histogram :karafka_consumer_batch_processing_duration_seconds do
9
+ doc "Consumer message processing latency in seconds"
10
+ buckets :network
11
+ end
12
+
13
+ Promenade.counter :karafka_consumer_messages_processed do
14
+ doc "Messages processed by this consumer"
15
+ end
16
+
17
+ def consumed(event)
18
+ consumer = event.payload[:caller]
19
+ messages = consumer.messages
20
+ batch_processing_duration = convert_milliseconds_to_seconds(event.payload[:time])
21
+
22
+ labels = get_labels(consumer)
23
+
24
+ Promenade.metric(:karafka_consumer_messages_processed).increment(labels, messages.size)
25
+ Promenade.metric(:karafka_consumer_batch_processing_duration_seconds).observe(labels, batch_processing_duration)
26
+ end
27
+
28
+ private
29
+
30
+ def get_labels(consumer)
31
+ metadata = consumer.messages.metadata
32
+
33
+ {
34
+ client: consumer.topic.kafka[:"client.id"],
35
+ group: consumer.topic.consumer_group.id,
36
+ topic: metadata.topic,
37
+ partition: metadata.partition,
38
+ }
39
+ end
40
+
41
+ def convert_milliseconds_to_seconds(time_in_milliseconds)
42
+ time_in_milliseconds / 1000.to_f
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,27 @@
1
+ require "promenade/karafka/subscriber"
2
+
3
+ module Promenade
4
+ module Karafka
5
+ class ErrorSubscriber < Subscriber
6
+ attach_to "error.karafka"
7
+
8
+ Promenade.counter :karafka_errors do
9
+ doc "Count of Kafka connection errors"
10
+ end
11
+
12
+ def occurred(event)
13
+ labels = get_labels(event)
14
+
15
+ Promenade.metric(:karafka_errors).increment(labels)
16
+ end
17
+
18
+ private
19
+
20
+ def get_labels(event)
21
+ {
22
+ error_type: event.payload[:type],
23
+ }
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,80 @@
1
+ require "promenade/karafka/subscriber"
2
+ require "active_support/core_ext/hash"
3
+
4
+ module Promenade
5
+ module Karafka
6
+ class StatisticsSubscriber < Subscriber
7
+ attach_to "statistics.karafka"
8
+
9
+ Promenade.histogram :karafka_connection_latency_seconds do
10
+ doc "Request latency (rtt) in seconds"
11
+ buckets :network
12
+ end
13
+
14
+ Promenade.counter :karafka_connection_calls do
15
+ doc "Count of calls made to Kafka broker"
16
+ end
17
+
18
+ Promenade.gauge :karafka_consumer_offset_lag do
19
+ doc "Lag between message create and consume time"
20
+ end
21
+
22
+ def emitted(event)
23
+ group = event.payload[:consumer_group_id]
24
+ statistics = event.payload[:statistics].with_indifferent_access
25
+ client_id = statistics[:client_id]
26
+
27
+ report_topic_metrics(statistics[:topics], group, client_id)
28
+ report_connection_metrics(statistics[:brokers], client_id)
29
+ end
30
+
31
+ private
32
+
33
+ def report_topic_metrics(topics, group, client_id)
34
+ topics.map do |topic_name, topic_values|
35
+ labels = {
36
+ client: client_id,
37
+ topic: topic_name,
38
+ group: group,
39
+ }
40
+ report_partition_metrics(topic_values, labels)
41
+ end
42
+ end
43
+
44
+ def report_partition_metrics(topic_values, labels)
45
+ topic_values[:partitions].map do |partition_name, partition_values|
46
+ next if partition_name == "-1"
47
+ next if partition_values[:consumer_lag_stored] == -1
48
+
49
+ labels = labels.merge(
50
+ partition: partition_name,
51
+ )
52
+
53
+ offset_lag = partition_values[:consumer_lag_stored]
54
+
55
+ Promenade.metric(:karafka_consumer_offset_lag).set(labels, offset_lag)
56
+ end
57
+ end
58
+
59
+ def report_connection_metrics(brokers, client_id)
60
+ labels = {
61
+ client: client_id,
62
+ }
63
+
64
+ brokers.map do |broker_name, broker_values|
65
+ next if broker_values[:nodeid] == -1
66
+
67
+ rtt = convert_microseconds_to_seconds(broker_values[:rtt][:avg])
68
+ connection_calls = broker_values[:connects]
69
+
70
+ Promenade.metric(:karafka_connection_calls).increment(labels.merge(broker: broker_name), connection_calls)
71
+ Promenade.metric(:karafka_connection_latency_seconds).observe(labels.merge(broker: broker_name), rtt)
72
+ end
73
+ end
74
+
75
+ def convert_microseconds_to_seconds(time_in_microseconds)
76
+ time_in_microseconds / 1_000_000.to_f
77
+ end
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,8 @@
1
+ require "active_support/subscriber"
2
+
3
+ module Promenade
4
+ module Karafka
5
+ class Subscriber < ActiveSupport::Subscriber
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,3 @@
1
+ require "promenade/karafka/consumer_subscriber"
2
+ require "promenade/karafka/error_subscriber"
3
+ require "promenade/karafka/statistics_subscriber"
@@ -1,3 +1,3 @@
1
1
  module Promenade
2
- VERSION = "0.8.0".freeze
2
+ VERSION = "0.9.0".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: promenade
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ed Robinson
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-03-02 00:00:00.000000000 Z
11
+ date: 2023-03-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack
@@ -288,6 +288,11 @@ files:
288
288
  - lib/promenade/kafka/fetcher_subscriber.rb
289
289
  - lib/promenade/kafka/producer_subscriber.rb
290
290
  - lib/promenade/kafka/subscriber.rb
291
+ - lib/promenade/karafka.rb
292
+ - lib/promenade/karafka/consumer_subscriber.rb
293
+ - lib/promenade/karafka/error_subscriber.rb
294
+ - lib/promenade/karafka/statistics_subscriber.rb
295
+ - lib/promenade/karafka/subscriber.rb
291
296
  - lib/promenade/prometheus.rb
292
297
  - lib/promenade/railtie.rb
293
298
  - lib/promenade/setup.rb
@@ -313,7 +318,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
313
318
  - !ruby/object:Gem::Version
314
319
  version: '0'
315
320
  requirements: []
316
- rubygems_version: 3.4.6
321
+ rubygems_version: 3.3.7
317
322
  signing_key:
318
323
  specification_version: 4
319
324
  summary: Promenade makes it simple to instrument Ruby apps for prometheus scraping