phobos 2.1.1 → 2.1.4

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: 6ec70d6f78852088846db2f5cee6673e9889962379bd82934758aa936886f1df
4
- data.tar.gz: f0d5a40fb1acbf02e0ac6cae4121571eb72689bc13076505153f33cef48f2362
3
+ metadata.gz: 02e1b97b3d44dffefffea99da0c15393997043598697d88fe3f7c7ab83549193
4
+ data.tar.gz: 4e3ec45a1db997825ace585a1535ac5c1504105afabe0470c0c676f8f301c66a
5
5
  SHA512:
6
- metadata.gz: c7192c98b0e3f3b22ab3aa4ef4f28bf3227410120012d3b77a66f018960f0e72309f72d47a00e505355d906826dc89bdc327ceea50a99ea7e28d233602bd8ec6
7
- data.tar.gz: b1dab967fb374559b98d976b0628140692f9c080d3de55d17edaa2a885a4ef17a1bbf7555a380ef00199e62a002f0bdd6d56486e77fbe4f2176eb39756c4f185
6
+ metadata.gz: b249c05f44dfe0dcb0f81b8177dd27a129e4364e0dbcbf8492295d9823473a7de66ee913c088945346a4e1943b3f2226c8106083cf5502d90341b8bb8fbac0eb
7
+ data.tar.gz: f6725f584a75f099bb2b4624338e424f7ba44859ace5c660bfc20d8f5681d663a1cd051381d18f832659f87bd1406d5c8aea3098112876a1f119649b56645be6
data/CHANGELOG.md CHANGED
@@ -6,6 +6,18 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
6
6
  ``
7
7
  ## UNRELEASED
8
8
 
9
+ ## [2.1.4] - 2022-06-15
10
+
11
+ - Re-raise consuming errors so that threads don't die forever and are retried
12
+
13
+ ## [2.1.3] - 2022-05-13
14
+
15
+ - Rescue and log Kafka::HeartbeatError in batch processing
16
+
17
+ ## [2.1.2] - 2022-01-27
18
+
19
+ - Fix packaging error.
20
+
9
21
  ## [2.1.1] - 2022-01-26
10
22
 
11
23
  - Fix crash on Ruby 3.1 involving a change to the Psych gem.
@@ -4,6 +4,7 @@ module Phobos
4
4
  module Actions
5
5
  class ProcessBatch
6
6
  include Phobos::Instrumentation
7
+ include Phobos::Log
7
8
 
8
9
  attr_reader :metadata
9
10
 
@@ -26,7 +27,11 @@ module Phobos
26
27
  message: message,
27
28
  listener_metadata: @listener_metadata
28
29
  ).execute
29
- @listener.consumer.trigger_heartbeat
30
+ begin
31
+ @listener.consumer.trigger_heartbeat
32
+ rescue Kafka::HeartbeatError => e
33
+ log_warn("Error sending Heartbeat #{e.class.name}-#{e}")
34
+ end
30
35
  end
31
36
  end
32
37
  end
@@ -0,0 +1,101 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'phobos/deep_struct'
4
+
5
+ module Phobos
6
+ module Configuration
7
+ def configure(configuration)
8
+ @config = fetch_configuration(configuration)
9
+ @config.class.send(:define_method, :producer_hash) do
10
+ Phobos.config.producer&.to_hash&.except(:kafka)
11
+ end
12
+ @config.class.send(:define_method, :consumer_hash) do
13
+ Phobos.config.consumer&.to_hash&.except(:kafka)
14
+ end
15
+ @config.listeners ||= []
16
+ configure_logger
17
+ end
18
+
19
+ # :nodoc:
20
+ def configure_logger
21
+ Logging.backtrace(true)
22
+ Logging.logger.root.level = silence_log ? :fatal : config.logger.level
23
+
24
+ configure_ruby_kafka_logger
25
+ configure_phobos_logger
26
+
27
+ logger.info do
28
+ Hash(message: 'Phobos configured', env: ENV['RAILS_ENV'] || ENV['RACK_ENV'] || 'N/A')
29
+ end
30
+ end
31
+
32
+ private
33
+
34
+ def fetch_configuration(configuration)
35
+ DeepStruct.new(read_configuration(configuration))
36
+ end
37
+
38
+ def read_configuration(configuration)
39
+ return configuration.to_h if configuration.respond_to?(:to_h)
40
+
41
+ config_erb = ERB.new(File.read(File.expand_path(configuration))).result
42
+
43
+ YAML.safe_load(
44
+ config_erb,
45
+ permitted_classes: [Symbol],
46
+ permitted_symbols: [],
47
+ aliases: true
48
+ )
49
+ rescue ArgumentError
50
+ YAML.safe_load(config_erb, [Symbol], [], true)
51
+ end
52
+
53
+ def configure_phobos_logger
54
+ if config.custom_logger
55
+ @logger = config.custom_logger
56
+ else
57
+ @logger = Logging.logger[self]
58
+ @logger.appenders = logger_appenders
59
+ end
60
+ end
61
+
62
+ def configure_ruby_kafka_logger
63
+ if config.custom_kafka_logger
64
+ @ruby_kafka_logger = config.custom_kafka_logger
65
+ elsif config.logger.ruby_kafka
66
+ @ruby_kafka_logger = Logging.logger['RubyKafka']
67
+ @ruby_kafka_logger.appenders = logger_appenders
68
+ @ruby_kafka_logger.level = silence_log ? :fatal : config.logger.ruby_kafka.level
69
+ else
70
+ @ruby_kafka_logger = nil
71
+ end
72
+ end
73
+
74
+ def logger_appenders
75
+ appenders = [Logging.appenders.stdout(layout: stdout_layout)]
76
+
77
+ if log_file
78
+ FileUtils.mkdir_p(File.dirname(log_file))
79
+ appenders << Logging.appenders.file(log_file, layout: json_layout)
80
+ end
81
+
82
+ appenders
83
+ end
84
+
85
+ def log_file
86
+ config.logger.file
87
+ end
88
+
89
+ def json_layout
90
+ Logging.layouts.json(date_pattern: Constants::LOG_DATE_PATTERN)
91
+ end
92
+
93
+ def stdout_layout
94
+ if config.logger.stdout_json == true
95
+ json_layout
96
+ else
97
+ Logging.layouts.pattern(date_pattern: Constants::LOG_DATE_PATTERN)
98
+ end
99
+ end
100
+ end
101
+ end
@@ -42,12 +42,11 @@ module Phobos
42
42
 
43
43
  def start
44
44
  @signal_to_stop = false
45
-
46
45
  start_listener
47
46
 
48
47
  begin
49
48
  start_consumer_loop
50
- rescue Kafka::ProcessingError, Phobos::AbortError
49
+ rescue Kafka::ProcessingError, Phobos::AbortError => e
51
50
  # Abort is an exception to prevent the consumer from committing the offset.
52
51
  # Since "listener" had a message being retried while "stop" was called
53
52
  # it's wise to not commit the batch offset to avoid data loss. This will
@@ -55,6 +54,7 @@ module Phobos
55
54
  instrument('listener.retry_aborted', listener_metadata) do
56
55
  log_info('Retry loop aborted, listener is shutting down', listener_metadata)
57
56
  end
57
+ raise e if e.is_a?(Kafka::ProcessingError)
58
58
  end
59
59
  ensure
60
60
  stop_listener
data/lib/phobos/log.rb CHANGED
@@ -13,6 +13,10 @@ module Phobos
13
13
  def log_error(msg, metadata)
14
14
  LoggerHelper.log(:error, msg, metadata)
15
15
  end
16
+
17
+ def log_warn(msg, metadata = {})
18
+ LoggerHelper.log(:warn, msg, metadata)
19
+ end
16
20
  end
17
21
 
18
22
  module LoggerHelper
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Phobos
4
- VERSION = '2.1.1'
4
+ VERSION = '2.1.4'
5
5
  end
data/lib/phobos.rb CHANGED
@@ -80,6 +80,5 @@ module Phobos
80
80
  location = caller.find { |line| line !~ %r{/phobos/} }
81
81
  warn "DEPRECATION WARNING: #{message}: #{location}"
82
82
  end
83
-
84
83
  end
85
84
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: phobos
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.1
4
+ version: 2.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Túlio Ornelas
@@ -15,7 +15,7 @@ authors:
15
15
  autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
- date: 2022-01-26 00:00:00.000000000 Z
18
+ date: 2022-06-15 00:00:00.000000000 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: bundler
@@ -277,6 +277,7 @@ files:
277
277
  - lib/phobos/cli.rb
278
278
  - lib/phobos/cli/runner.rb
279
279
  - lib/phobos/cli/start.rb
280
+ - lib/phobos/configuration.rb
280
281
  - lib/phobos/constants.rb
281
282
  - lib/phobos/deep_struct.rb
282
283
  - lib/phobos/echo_handler.rb
@@ -314,7 +315,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
314
315
  - !ruby/object:Gem::Version
315
316
  version: '0'
316
317
  requirements: []
317
- rubygems_version: 3.3.3
318
+ rubygems_version: 3.3.5
318
319
  signing_key:
319
320
  specification_version: 4
320
321
  summary: Simplifying Kafka for ruby apps