karafka-core 2.0.1 → 2.0.2

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: 6bd6d59f81183ea27ea19b3292f17e94928bf8159527521d542e0ca997e3cfef
4
- data.tar.gz: d71e9371eb87e46f3a41468807b0ec66cc817752701ab2ccd9b2b3ffb41d84a3
3
+ metadata.gz: f3932e3ec9d159f2be8ba43d231197c00770409693e712a6a14f7893aa5671fc
4
+ data.tar.gz: 86b27fc05550881f80f7d3db32d4e7cd3fcd48b8792d87413d6887ca19722d3f
5
5
  SHA512:
6
- metadata.gz: 871ccf53e4f17d93ad16ed22484b880ca03a73b96202aa1bf4be1c3cf69b684b0ae63838ff939d4e3503a36a6c62a36dee6ca3757e9255bba272bc74a44777eb
7
- data.tar.gz: 36ae734a39ba0f146926ccbeb84755130dee1966fe1398a94fafbf06da58da051ca546538132db218f03a82ee2a56e53698da89786356b34b71bc06775e93aa4
6
+ metadata.gz: c017f02c04db51ea04a7686a41974622006c0a6eaf07aeaa9edbd7f9e6b32fcca14edf8215da67a9f50d52237c455a3242e900994a9444df833eebf606de74c6
7
+ data.tar.gz: e07af5f18d2f158209afa0c9615cc2d2459edb4d89a5b4534e9424e3d2243decd1bff316fc7a03556478b9f3f2b1afe5d20cf5367eaa93376350005b6711f158
checksums.yaml.gz.sig CHANGED
Binary file
data/CHANGELOG.md CHANGED
@@ -1,7 +1,10 @@
1
1
  # Karafka core changelog
2
2
 
3
- ## 2.0.1
3
+ ## 2.0.2 (2022-08-01)
4
+ - Add extracted statistics decorator (#932)
5
+
6
+ ## 2.0.1 (2022-07-30)
4
7
  - Fix a case where setting would match a method monkey-patched on an object (#1) causing initializers not to build proper accessors on nodes. This is not the core bug, but still worth handling this case.
5
8
 
6
- ## 2.0.0
9
+ ## 2.0.0 (2022-07-28)
7
10
  - Initial extraction of common components used in the Karafka ecosystem from WaterDrop.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- karafka-core (2.0.1)
4
+ karafka-core (2.0.2)
5
5
  concurrent-ruby (>= 1.1)
6
6
 
7
7
  GEM
@@ -0,0 +1,77 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Karafka
4
+ module Core
5
+ module Monitoring
6
+ # Many of the librdkafka statistics are absolute values instead of a gauge.
7
+ # This means, that for example number of messages sent is an absolute growing value
8
+ # instead of being a value of messages sent from the last statistics report.
9
+ # This decorator calculates the diff against previously emited stats, so we get also
10
+ # the diff together with the original values
11
+ class StatisticsDecorator
12
+ def initialize
13
+ @previous = {}.freeze
14
+ end
15
+
16
+ # @param emited_stats [Hash] original emited statistics
17
+ # @return [Hash] emited statistics extended with the diff data
18
+ # @note We modify the emited statistics, instead of creating new. Since we don't expose
19
+ # any API to get raw data, users can just assume that the result of this decoration is
20
+ # the proper raw stats that they can use
21
+ def call(emited_stats)
22
+ diff(
23
+ @previous,
24
+ emited_stats
25
+ )
26
+
27
+ @previous = emited_stats
28
+
29
+ emited_stats.freeze
30
+ end
31
+
32
+ private
33
+
34
+ # Calculates the diff of the provided values and modifies in place the emited statistics
35
+ #
36
+ # @param previous [Object] previous value from the given scope in which
37
+ # we are
38
+ # @param current [Object] current scope from emitted statistics
39
+ # @return [Object] the diff if the values were numerics or the current scope
40
+ def diff(previous, current)
41
+ if current.is_a?(Hash)
42
+ # @note We cannot use #each_key as we modify the content of the current scope
43
+ # in place (in case it's a hash)
44
+ current.keys.each do |key|
45
+ append(
46
+ current,
47
+ key,
48
+ diff((previous || {})[key], (current || {})[key])
49
+ )
50
+ end
51
+ end
52
+
53
+ # Diff can be computed only for numerics
54
+ return current unless current.is_a?(Numeric)
55
+ # If there was no previous value, delta is always zero
56
+ return 0 unless previous
57
+ # Should never happen but just in case, a type changed in between stats
58
+ return current unless previous.is_a?(Numeric)
59
+
60
+ current - previous
61
+ end
62
+
63
+ # Appends the result of the diff to a given key as long as the result is numeric
64
+ #
65
+ # @param current [Hash] current scope
66
+ # @param key [Symbol] key based on which we were diffing
67
+ # @param result [Object] diff result
68
+ def append(current, key, result)
69
+ return unless result.is_a?(Numeric)
70
+ return if current.frozen?
71
+
72
+ current["#{key}_d"] = result
73
+ end
74
+ end
75
+ end
76
+ end
77
+ end
@@ -4,6 +4,6 @@ module Karafka
4
4
  module Core
5
5
  # Current Karafka::Core version
6
6
  # We follow the versioning schema of given Karafka version
7
- VERSION = '2.0.1'
7
+ VERSION = '2.0.2'
8
8
  end
9
9
  end
data/lib/karafka-core.rb CHANGED
@@ -11,6 +11,7 @@
11
11
  karafka/core/monitoring/event
12
12
  karafka/core/monitoring/monitor
13
13
  karafka/core/monitoring/notifications
14
+ karafka/core/monitoring/statistics_decorator
14
15
  karafka/core/configurable
15
16
  karafka/core/configurable/leaf
16
17
  karafka/core/configurable/node
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: karafka-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maciej Mensfeld
@@ -34,7 +34,7 @@ cert_chain:
34
34
  R2P11bWoCtr70BsccVrN8jEhzwXngMyI2gVt750Y+dbTu1KgRqZKp/ECe7ZzPzXj
35
35
  pIy9vHxTANKYVyI4qj8OrFdEM5BQNu8oQpL0iQ==
36
36
  -----END CERTIFICATE-----
37
- date: 2022-07-30 00:00:00.000000000 Z
37
+ date: 2022-08-01 00:00:00.000000000 Z
38
38
  dependencies:
39
39
  - !ruby/object:Gem::Dependency
40
40
  name: concurrent-ruby
@@ -89,6 +89,7 @@ files:
89
89
  - lib/karafka/core/monitoring/event.rb
90
90
  - lib/karafka/core/monitoring/monitor.rb
91
91
  - lib/karafka/core/monitoring/notifications.rb
92
+ - lib/karafka/core/monitoring/statistics_decorator.rb
92
93
  - lib/karafka/core/version.rb
93
94
  - log/.gitkeep
94
95
  homepage: https://karafka.io
metadata.gz.sig CHANGED
Binary file