karafka-web 0.2.2 → 0.2.3

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: 7619f1c461afdd16646dfe0d7fff92badad1448de8d40afcc41b42af4ac37dfa
4
- data.tar.gz: c706ae9212b87947630be27d366d0d8a938b2307d8e2e969d7dbddad6488ab4b
3
+ metadata.gz: '069037558ca061c8dd11c4fd48658699814f9904668463a957c7fabeff16fb4c'
4
+ data.tar.gz: 7627bf19b437d6b9e040c7d164a615d6cfcf0777d0294bb5958e4ea8b8e8a20c
5
5
  SHA512:
6
- metadata.gz: 1ee9e33f8a8a358b45ff1e8ad707252eaecc0d3801194ce313e45c3cb0c54e6d8fadf905fac3dc809fbb276a12adc9d29a91285e0f63f6ba09d97803b1c4f198
7
- data.tar.gz: 67a4d2902138aa73689b2c1ccd2f1a76c7d17993ff2584f29ab57a50b1893c01157239d37d7b125b07fce18556354bb88dfb6d87099e0d61cabb7bf5e8ddfaa6
6
+ metadata.gz: 2bbd71a7eb35f534dbd262089651aaa241b481b44cd7e9841954571f47d7c8737c0f9c8dd14f479fec5d8b80315f5317c9177ca4c1a11689b8e973541a9107c4
7
+ data.tar.gz: 4b5100c7fb244bb53e5590b94cf16ef98203295944ffffb44f5e29af912848608e0d514d4eeaca0f47ff9aee85cb86e17712f79ceb698eccd96ea9ddf070fa4d
checksums.yaml.gz.sig CHANGED
Binary file
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Karafka Web changelog
2
2
 
3
+ ## 0.2.3 (2023-03-04)
4
+ - [Improvement] Snapshot current consumer tags upon consumer errors.
5
+ - [Improvement] Optimize exception message extraction from errors.
6
+ - [Improvement] Slightly change error reporting structure (backwards compatible) to collect process tags on errors and to align with other reports.
7
+
3
8
  ## 0.2.2 (2023-02-25)
4
9
  - [Fix] Fix status page reference in Pro.
5
10
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- karafka-web (0.2.2)
4
+ karafka-web (0.2.3)
5
5
  erubi (~> 1.4)
6
6
  karafka (>= 2.0.33, < 3.0.0)
7
7
  karafka-core (>= 2.0.12, < 3.0.0)
@@ -17,7 +17,7 @@ GEM
17
17
  minitest (>= 5.1)
18
18
  tzinfo (~> 2.0)
19
19
  byebug (11.1.3)
20
- concurrent-ruby (1.2.0)
20
+ concurrent-ruby (1.2.2)
21
21
  diff-lcs (1.5.0)
22
22
  docile (1.4.0)
23
23
  erubi (1.12.0)
@@ -70,13 +70,14 @@ GEM
70
70
  tilt (2.1.0)
71
71
  tzinfo (2.0.6)
72
72
  concurrent-ruby (~> 1.0)
73
- waterdrop (2.4.10)
74
- karafka-core (>= 2.0.9, < 3.0.0)
73
+ waterdrop (2.4.11)
74
+ karafka-core (>= 2.0.12, < 3.0.0)
75
75
  zeitwerk (~> 2.3)
76
76
  webrick (1.8.1)
77
77
  zeitwerk (2.6.7)
78
78
 
79
79
  PLATFORMS
80
+ arm64-darwin-21
80
81
  x86_64-linux
81
82
 
82
83
  DEPENDENCIES
@@ -88,4 +89,4 @@ DEPENDENCIES
88
89
  simplecov
89
90
 
90
91
  BUNDLED WITH
91
- 2.4.6
92
+ 2.4.7
@@ -28,7 +28,8 @@ module Karafka
28
28
  error_message: error_message,
29
29
  backtrace: backtrace,
30
30
  details: details,
31
- occurred_at: float_now
31
+ occurred_at: float_now,
32
+ process: sampler.to_report[:process].slice(:name, :tags)
32
33
  }
33
34
 
34
35
  sampler.counters[:errors] += 1
@@ -55,6 +56,13 @@ module Karafka
55
56
 
56
57
  private
57
58
 
59
+ # @return [Object] sampler for the metrics
60
+ # @note We use this sampler to get basic process details that we want to assign
61
+ # to the error
62
+ def consumer_sampler
63
+ @consumer_sampler ||= ::Karafka::Web.config.tracking.consumers.sampler
64
+ end
65
+
58
66
  # @param consumer [::Karafka::BaseConsumer]
59
67
  # @return [Hash] hash with consumer specific info for details of error
60
68
  def extract_consumer_info(consumer)
@@ -65,7 +73,8 @@ module Karafka
65
73
  first_offset: consumer.messages.first.offset,
66
74
  last_offset: consumer.messages.last.offset,
67
75
  comitted_offset: consumer.coordinator.seek_offset - 1,
68
- consumer: consumer.class.to_s
76
+ consumer: consumer.class.to_s,
77
+ tags: consumer.tags
69
78
  }
70
79
  end
71
80
 
@@ -74,12 +83,6 @@ module Karafka
74
83
  # @param error [StandardError] error that occurred
75
84
  # @return [Array<String, String, String>] array with error name, message and backtrace
76
85
  def extract_error_info(error)
77
- error_message = error.message.to_s.dup
78
- error_message.force_encoding('utf-8')
79
- error_message.scrub!
80
-
81
- backtrace = (error.backtrace || [])
82
-
83
86
  app_root = "#{::Karafka.root}/"
84
87
 
85
88
  gem_home = if ENV.key?('GEM_HOME')
@@ -90,15 +93,27 @@ module Karafka
90
93
 
91
94
  gem_home = "#{gem_home}/"
92
95
 
96
+ backtrace = error.backtrace || []
93
97
  backtrace.map! { |line| line.gsub(app_root, '') }
94
98
  backtrace.map! { |line| line.gsub(gem_home, '') }
95
99
 
96
100
  [
97
101
  error.class.name,
98
- error_message,
102
+ extract_exception_message(error),
99
103
  backtrace.join("\n")
100
104
  ]
101
105
  end
106
+
107
+ # @param error [StandardError] error that occurred
108
+ # @return [String] formatted exception message
109
+ def extract_exception_message(error)
110
+ error_message = error.message.to_s[0, 10_000]
111
+ error_message.force_encoding('utf-8')
112
+ error_message.scrub! if error_message.respond_to?(:scrub!)
113
+ error_message
114
+ rescue StandardError
115
+ '!!! Error message extraction failed !!!'
116
+ end
102
117
  end
103
118
  end
104
119
  end
@@ -60,7 +60,7 @@ module Karafka
60
60
  started_at: @started_at,
61
61
  name: process_name,
62
62
  status: ::Karafka::App.config.internal.status.to_s,
63
- listeners: Karafka::Server.listeners.count,
63
+ listeners: listeners,
64
64
  concurrency: concurrency,
65
65
  memory_usage: memory_usage,
66
66
  memory_total_usage: memory_total_usage,
@@ -76,7 +76,7 @@ module Karafka
76
76
  waterdrop: ::WaterDrop::VERSION
77
77
  },
78
78
 
79
- stats: Karafka::Server.jobs_queue.statistics.merge(
79
+ stats: jobs_queue_statistics.merge(
80
80
  utilization: utilization
81
81
  ).merge(total: @counters),
82
82
 
@@ -112,6 +112,12 @@ module Karafka
112
112
  times[:total].sum / 1_000 / concurrency / timefactor * 100
113
113
  end
114
114
 
115
+ # @return [Integer] number of listeners
116
+ def listeners
117
+ # This can be zero before the server starts
118
+ Karafka::Server.listeners&.count.to_i
119
+ end
120
+
115
121
  # @return [String] Unique process name
116
122
  def process_name
117
123
  @process_name ||= "#{Socket.gethostname}:#{::Process.pid}:#{SecureRandom.hex(6)}"
@@ -142,6 +148,12 @@ module Karafka
142
148
  end
143
149
  end
144
150
 
151
+ # @return [Hash] job queue statistics
152
+ def jobs_queue_statistics
153
+ # We return empty stats in case jobs queue is not yet initialized
154
+ Karafka::Server.jobs_queue&.statistics || { busy: 0, enqueued: 0 }
155
+ end
156
+
145
157
  # Total memory used in the OS
146
158
  def memory_total_usage
147
159
  case RUBY_PLATFORM
@@ -44,12 +44,14 @@ module Karafka
44
44
 
45
45
  @consumer_contract.validate!(consumer_report)
46
46
 
47
+ process_name = consumer_report[:process][:name]
48
+
47
49
  # Report consumers statuses
48
50
  messages = [
49
51
  {
50
52
  topic: ::Karafka::Web.config.topics.consumers.reports,
51
53
  payload: consumer_report.to_json,
52
- key: consumer_report[:process][:name],
54
+ key: process_name,
53
55
  partition: 0
54
56
  }
55
57
  ]
@@ -58,12 +60,9 @@ module Karafka
58
60
  messages += consumer_sampler.errors.map do |error|
59
61
  {
60
62
  topic: Karafka::Web.config.topics.errors,
61
- # Inject process name into the error details for easier tracing
62
- payload: error.merge(
63
- process_name: consumer_report[:process][:name]
64
- ).to_json,
63
+ payload: error.to_json,
65
64
  # Always dispatch errors from the same process to the same partition
66
- key: consumer_report[:process][:name]
65
+ key: process_name
67
66
  }
68
67
  end
69
68
 
@@ -74,6 +74,16 @@ module Karafka
74
74
  bg
75
75
  end
76
76
 
77
+ # Renders tags one after another
78
+ #
79
+ # @param tags_array [Array<String>]
80
+ # @return [String] tags badges
81
+ def tags(tags_array)
82
+ tags_array
83
+ .map { |tag| %(<span class="badge bg-info">#{tag}</span>) }
84
+ .join(' ')
85
+ end
86
+
77
87
  # Takes a kafka report state and recommends background style color
78
88
  # @param state [String] state
79
89
  # @return [String] background style
@@ -20,11 +20,7 @@
20
20
  </p>
21
21
 
22
22
  <p class="mt-0 mb-1">
23
- <% process.tags.each do |tag| %>
24
- <span class="badge bg-info badge-topic">
25
- <%= tag %>
26
- </span>
27
- <% end %>
23
+ <%== tags(process.tags) %>
28
24
  </p>
29
25
  </td>
30
26
 
@@ -30,11 +30,7 @@
30
30
 
31
31
  <% unless @process.tags.empty? %>
32
32
  <p class="mb-0 text-end">
33
- <% @process.tags.each do |tag| %>
34
- <span class="badge bg-info badge-topic">
35
- <%= tag %>
36
- </span>
37
- <% end %>
33
+ <%== tags(@process.tags) %>
38
34
  </p>
39
35
  <% end %>
40
36
  </div>
@@ -7,6 +7,8 @@
7
7
  <td>
8
8
  <% if k2.to_s.include?('ssl') %>
9
9
  ***
10
+ <% elsif k2.to_s == 'tags' %>
11
+ <%== tags(v2) %>
10
12
  <% else %>
11
13
  <%= v2 %>
12
14
  <% end %>
@@ -13,9 +13,7 @@
13
13
  <td>
14
14
  <code><%= job.consumer %></code>
15
15
 
16
- <% job.tags.each do |tag| %>
17
- <span class="badge bg-info"><%= tag %></span>
18
- <% end %>
16
+ <%== tags(job.tags) %>
19
17
  </td>
20
18
  <td>
21
19
  <code>#<%= job.type %></code>
@@ -20,11 +20,7 @@
20
20
  </p>
21
21
 
22
22
  <p class="mt-0 mb-1">
23
- <% process.tags.each do |tag| %>
24
- <span class="badge bg-info badge-topic">
25
- <%= tag %>
26
- </span>
27
- <% end %>
23
+ <%== tags(process.tags) %>
28
24
  </p>
29
25
  </td>
30
26
 
@@ -7,6 +7,8 @@
7
7
  <td>
8
8
  <% if k2.to_s.include?('ssl') %>
9
9
  ***
10
+ <% elsif k2.to_s == 'tags' %>
11
+ <%== tags(v2) %>
10
12
  <% else %>
11
13
  <%= v2 %>
12
14
  <% end %>
@@ -13,9 +13,7 @@
13
13
  <td>
14
14
  <code><%= job.consumer %></code>
15
15
 
16
- <% job.tags.each do |tag| %>
17
- <span class="badge bg-info"><%= tag %></span>
18
- <% end %>
16
+ <%== tags(job.tags) %>
19
17
  </td>
20
18
  <td>
21
19
  <code>#<%= job.type %></code>
@@ -3,6 +3,6 @@
3
3
  module Karafka
4
4
  module Web
5
5
  # Current gem version
6
- VERSION = '0.2.2'
6
+ VERSION = '0.2.3'
7
7
  end
8
8
  end
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: karafka-web
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maciej Mensfeld
@@ -35,7 +35,7 @@ cert_chain:
35
35
  Qf04B9ceLUaC4fPVEz10FyobjaFoY4i32xRto3XnrzeAgfEe4swLq8bQsR3w/EF3
36
36
  MGU0FeSV2Yj7Xc2x/7BzLK8xQn5l7Yy75iPF+KP3vVmDHnNl
37
37
  -----END CERTIFICATE-----
38
- date: 2023-02-25 00:00:00.000000000 Z
38
+ date: 2023-03-04 00:00:00.000000000 Z
39
39
  dependencies:
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: erubi
metadata.gz.sig CHANGED
Binary file