phobos 2.1.0 → 2.1.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: ec66514784d6b38c90a4ca0aaf063e001536d2680732c4afa535b49c2a55cb9c
4
- data.tar.gz: 1d988dd76e39305cfb30d3dd8e8fd926065631e391ed077d7c0459e6760587b4
3
+ metadata.gz: '0956b5ef7d6d1cdd48c4f8fd36a8236d192450eda009f5313ec81d628784ce0b'
4
+ data.tar.gz: 17e608663beea493f386290bb8781f5c540baee9ba00e0fde47fce2504ee9f7d
5
5
  SHA512:
6
- metadata.gz: 07a92fdf61d970a61f98cfb8615568fa48af0550fb473458b6dce67b479b684ce8e280dbd97b20b5c16f84bf14fa18eea47f8bae490c6ac5712b8d21d2c4d037
7
- data.tar.gz: 59bb2c58cfd017b8f9462eb431d2bb62322bdc817a1260816648481abff4ff0a5d6f1df5430f3888a0bad3cb92eeb11ee2ace3ced62df1e8ee02756bb1e8a795
6
+ metadata.gz: 7df8dbd47d916c8d344badce4039598188c5ce53b3d595c9baa5e6d0fa5467482ca5ebdeddb972fcf9aded6f4ac8905add780bc8104b6d7cccdbb71d21c86c23
7
+ data.tar.gz: 6db4a6e57804d373eb055b6ab88cd709b8260e141a5853f4826f927c50912d2224f206c9751bd5186f87bf99aa3463ff3df6e65a536a17ec7f7aee58cffe89a5
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.3] - 2022-05-13
10
+
11
+ - Rescue and log Kafka::HeartbeatError in batch processing
12
+
13
+ ## [2.1.2] - 2022-01-27
14
+
15
+ - Fix packaging error.
16
+
17
+ ## [2.1.1] - 2022-01-26
18
+
19
+ - Fix crash on Ruby 3.1 involving a change to the Psych gem.
20
+
9
21
  ## [2.1.0] - 2021-05-27
10
22
 
11
23
  - Modify config to allow specifying kafka connection information separately for consumers and producers
@@ -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
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.0'
4
+ VERSION = '2.1.3'
5
5
  end
data/lib/phobos.rb CHANGED
@@ -13,7 +13,7 @@ require 'kafka'
13
13
  require 'logging'
14
14
  require 'erb'
15
15
 
16
- require 'phobos/deep_struct'
16
+ require 'phobos/configuration'
17
17
  require 'phobos/version'
18
18
  require 'phobos/constants'
19
19
  require 'phobos/log'
@@ -49,22 +49,11 @@ module Logging
49
49
  end
50
50
 
51
51
  module Phobos
52
+ extend Configuration
52
53
  class << self
53
54
  attr_reader :config, :logger
54
55
  attr_accessor :silence_log
55
56
 
56
- def configure(configuration)
57
- @config = fetch_configuration(configuration)
58
- @config.class.send(:define_method, :producer_hash) do
59
- Phobos.config.producer&.to_hash&.except(:kafka)
60
- end
61
- @config.class.send(:define_method, :consumer_hash) do
62
- Phobos.config.consumer&.to_hash&.except(:kafka)
63
- end
64
- @config.listeners ||= []
65
- configure_logger
66
- end
67
-
68
57
  def add_listeners(configuration)
69
58
  listeners_config = fetch_configuration(configuration)
70
59
  @config.listeners += listeners_config.listeners
@@ -91,85 +80,5 @@ module Phobos
91
80
  location = caller.find { |line| line !~ %r{/phobos/} }
92
81
  warn "DEPRECATION WARNING: #{message}: #{location}"
93
82
  end
94
-
95
- # :nodoc:
96
- def configure_logger
97
- Logging.backtrace(true)
98
- Logging.logger.root.level = silence_log ? :fatal : config.logger.level
99
-
100
- configure_ruby_kafka_logger
101
- configure_phobos_logger
102
-
103
- logger.info do
104
- Hash(message: 'Phobos configured', env: ENV['RAILS_ENV'] || ENV['RACK_ENV'] || 'N/A')
105
- end
106
- end
107
-
108
- private
109
-
110
- def fetch_configuration(configuration)
111
- DeepStruct.new(read_configuration(configuration))
112
- end
113
-
114
- def read_configuration(configuration)
115
- return configuration.to_h if configuration.respond_to?(:to_h)
116
-
117
- YAML.safe_load(
118
- ERB.new(
119
- File.read(File.expand_path(configuration))
120
- ).result,
121
- [Symbol],
122
- [],
123
- true
124
- )
125
- end
126
-
127
- def configure_phobos_logger
128
- if config.custom_logger
129
- @logger = config.custom_logger
130
- else
131
- @logger = Logging.logger[self]
132
- @logger.appenders = logger_appenders
133
- end
134
- end
135
-
136
- def configure_ruby_kafka_logger
137
- if config.custom_kafka_logger
138
- @ruby_kafka_logger = config.custom_kafka_logger
139
- elsif config.logger.ruby_kafka
140
- @ruby_kafka_logger = Logging.logger['RubyKafka']
141
- @ruby_kafka_logger.appenders = logger_appenders
142
- @ruby_kafka_logger.level = silence_log ? :fatal : config.logger.ruby_kafka.level
143
- else
144
- @ruby_kafka_logger = nil
145
- end
146
- end
147
-
148
- def logger_appenders
149
- appenders = [Logging.appenders.stdout(layout: stdout_layout)]
150
-
151
- if log_file
152
- FileUtils.mkdir_p(File.dirname(log_file))
153
- appenders << Logging.appenders.file(log_file, layout: json_layout)
154
- end
155
-
156
- appenders
157
- end
158
-
159
- def log_file
160
- config.logger.file
161
- end
162
-
163
- def json_layout
164
- Logging.layouts.json(date_pattern: Constants::LOG_DATE_PATTERN)
165
- end
166
-
167
- def stdout_layout
168
- if config.logger.stdout_json == true
169
- json_layout
170
- else
171
- Logging.layouts.pattern(date_pattern: Constants::LOG_DATE_PATTERN)
172
- end
173
- end
174
83
  end
175
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.0
4
+ version: 2.1.3
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: 2021-05-27 00:00:00.000000000 Z
18
+ date: 2022-05-13 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.2.16
318
+ rubygems_version: 3.3.5
318
319
  signing_key:
319
320
  specification_version: 4
320
321
  summary: Simplifying Kafka for ruby apps