deimos-ruby 1.8.2.pre.beta2 → 1.8.2

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: b773de54759babb229e8f3bc6b42931dab7695b7197d601ad4ae08015c0b401f
4
- data.tar.gz: 4af1aa98ffdfc013c4cac02fa316371ad138ec0d807ed58426a7ad57d6c1e719
3
+ metadata.gz: 237cb6cd22b6a057003fedae1caeec81c999a3d9b90d837bb8b0a4add43ca4e2
4
+ data.tar.gz: fab51933cdcd5c5fd10b8c92bbc67854fe56f23cdbec41660579f18b9075e09c
5
5
  SHA512:
6
- metadata.gz: 319d01a4c42c5efe72bd4959fb57548102c3f2b4305f3d94510747fd372d516ebad3e34ff74f9e6744641728efce9eb7a20f2d89c37d6bd90847253698a05238
7
- data.tar.gz: 9e6999cca87ca448167a9e61a0bfa5914b36fd74c053f132bd02ab5200be840984546469affccfd07ce77d4d098a2096b13e42febd4ce7059ec882c436580cd8
6
+ metadata.gz: 193b9b593b4f92edecc6c239eb6106fbe40e0acd1453694508f3fb02525166c39e4f1eba71230362493cd1647ab19e98a63ecf55f5371b844e9d0c38ffa5b2ea
7
+ data.tar.gz: e7d42ec7ec2bc864735c9230a925685935678d2dd0f3918426926dc9f358d5eb810dd5b324bcacaf9201c78bdfbbfa58037a4cac4cf4ca66257737440b3d2c97
@@ -7,6 +7,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## UNRELEASED
9
9
 
10
+ ## 1.8.2 - 2020-09-25
11
+
12
+ ### Features :star:
13
+ - Add "disabled" config field to consumers to allow disabling
14
+ individual consumers without having to comment out their
15
+ entries and possibly affecting unit tests.
16
+
17
+ ### Fixes :wrench:
18
+ - Prepend topic_prefix while encoding messages
19
+ (fixes [#37](https://github.com/flipp-oss/deimos/issues/37))
20
+ - Raise error if producing without a topic
21
+ (fixes [#50](https://github.com/flipp-oss/deimos/issues/50))
22
+ - Don't try to load producers/consumers when running rake tasks involving webpacker or assets
23
+
10
24
  ## 1.8.2-beta2 - 2020-09-15
11
25
 
12
26
  ### Features :star:
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- deimos-ruby (1.8.2.pre.beta2)
4
+ deimos-ruby (1.8.2)
5
5
  avro_turf (~> 0.11)
6
6
  phobos (~> 1.9)
7
7
  ruby-kafka (~> 0.7)
@@ -79,6 +79,7 @@ topic|nil|Topic to produce to.
79
79
  schema|nil|This is optional but strongly recommended for testing purposes; this will validate against a local schema file used as the reader schema, as well as being able to write tests against this schema. This is recommended since it ensures you are always getting the values you expect.
80
80
  namespace|nil|Namespace of the schema to use when finding it locally.
81
81
  key_config|nil|Configuration hash for message keys. See [Kafka Message Keys](../README.md#installation)
82
+ disabled|false|Set to true to skip starting an actual listener for this consumer on startup.
82
83
  group_id|nil|ID of the consumer group.
83
84
  max_concurrency|1|Number of threads created for this listener. Each thread will behave as an independent consumer. They don't share any state.
84
85
  start_from_beginning|true|Once the consumer group has checkpointed its progress in the topic's partitions, the consumers will always start from the checkpointed offsets, regardless of config. As such, this setting only applies when the consumer initially starts consuming from a topic
@@ -245,6 +245,13 @@ module Deimos
245
245
 
246
246
  # Configure the settings with values.
247
247
  def configure(&block)
248
+ if defined?(Rake) && defined?(Rake.application)
249
+ tasks = Rake.application.top_level_tasks
250
+ if tasks.any? { |t| %w(assets webpacker yarn).include?(t.split(':').first) }
251
+ puts 'Skipping Deimos configuration since we are in JS/CSS compilation'
252
+ return
253
+ end
254
+ end
248
255
  config.run_callbacks(:configure) do
249
256
  config.instance_eval(&block)
250
257
  end
@@ -319,6 +319,10 @@ module Deimos
319
319
  # Key configuration (see docs).
320
320
  # @return [Hash]
321
321
  setting :key_config
322
+ # Set to true to ignore the consumer in the Phobos config and not actually start up a
323
+ # listener.
324
+ # @return [Boolean]
325
+ setting :disabled, false
322
326
 
323
327
  # These are the phobos "listener" configs. See CONFIGURATION.md for more
324
328
  # info.
@@ -63,8 +63,10 @@ module Deimos
63
63
  }
64
64
 
65
65
  p_config[:listeners] = self.consumer_objects.map do |consumer|
66
+ next nil if consumer.disabled
67
+
66
68
  hash = consumer.to_h.reject do |k, _|
67
- %i(class_name schema namespace key_config backoff).include?(k)
69
+ %i(class_name schema namespace key_config backoff disabled).include?(k)
68
70
  end
69
71
  hash = hash.map { |k, v| [k, v.is_a?(Symbol) ? v.to_s : v] }.to_h
70
72
  hash[:handler] = consumer.class_name
@@ -73,6 +75,7 @@ module Deimos
73
75
  end
74
76
  hash
75
77
  end
78
+ p_config[:listeners].compact!
76
79
 
77
80
  if self.kafka.ssl.enabled
78
81
  %w(ca_cert client_cert client_cert_key).each do |key|
@@ -104,6 +104,8 @@ module Deimos
104
104
  Deimos.config.producers.disabled ||
105
105
  Deimos.producers_disabled?(self)
106
106
 
107
+ raise 'Topic not specified. Please specify the topic.' if topic.blank?
108
+
107
109
  backend_class = determine_backend_class(sync, force_send)
108
110
  Deimos.instrument(
109
111
  'encode_messages',
@@ -183,7 +185,7 @@ module Deimos
183
185
  nil
184
186
  else
185
187
  encoder.encode(message.payload,
186
- topic: "#{config[:topic]}-value")
188
+ topic: "#{Deimos.config.producers.topic_prefix}#{config[:topic]}-value")
187
189
  end
188
190
  end
189
191
 
@@ -201,9 +203,9 @@ module Deimos
201
203
  end
202
204
 
203
205
  if config[:key_field]
204
- encoder.encode_key(config[:key_field], key, topic: "#{config[:topic]}-key")
206
+ encoder.encode_key(config[:key_field], key, topic: "#{Deimos.config.producers.topic_prefix}#{config[:topic]}-key")
205
207
  elsif config[:key_schema]
206
- key_encoder.encode(key, topic: "#{config[:topic]}-key")
208
+ key_encoder.encode(key, topic: "#{Deimos.config.producers.topic_prefix}#{config[:topic]}-key")
207
209
  else
208
210
  key
209
211
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Deimos
4
- VERSION = '1.8.2-beta2'
4
+ VERSION = '1.8.2'
5
5
  end
@@ -6,6 +6,14 @@ class MyConfigConsumer < Deimos::Consumer
6
6
  def consume
7
7
  end
8
8
  end
9
+
10
+ # Mock consumer 2
11
+ class MyConfigConsumer2 < Deimos::Consumer
12
+ # :no-doc:
13
+ def consume
14
+ end
15
+ end
16
+
9
17
  describe Deimos, 'configuration' do
10
18
  it 'should configure with deprecated fields' do
11
19
  logger = Logger.new(nil)
@@ -171,6 +179,13 @@ describe Deimos, 'configuration' do
171
179
  offset_retention_time 13
172
180
  heartbeat_interval 13
173
181
  end
182
+ consumer do
183
+ disabled true
184
+ class_name 'MyConfigConsumer2'
185
+ schema 'blah2'
186
+ topic 'blah2'
187
+ group_id 'myconsumerid2'
188
+ end
174
189
  end
175
190
 
176
191
  expect(described_class.config.phobos_config).
@@ -64,6 +64,14 @@ module ProducerTest
64
64
  end
65
65
  stub_const('MyErrorProducer', producer_class)
66
66
 
67
+ producer_class = Class.new(Deimos::Producer) do
68
+ schema 'MySchema'
69
+ namespace 'com.my-namespace'
70
+ topic nil
71
+ key_config none: true
72
+ end
73
+ stub_const('MyNoTopicProducer', producer_class)
74
+
67
75
  end
68
76
 
69
77
  it 'should fail on invalid message with error handler' do
@@ -228,6 +236,7 @@ module ProducerTest
228
236
  end
229
237
 
230
238
  it 'should encode the key' do
239
+ Deimos.configure { |c| c.producers.topic_prefix = nil }
231
240
  expect(MyProducer.encoder).to receive(:encode_key).with('test_id', 'foo', topic: 'my-topic-key')
232
241
  expect(MyProducer.encoder).to receive(:encode_key).with('test_id', 'bar', topic: 'my-topic-key')
233
242
  expect(MyProducer.encoder).to receive(:encode).with({
@@ -245,6 +254,21 @@ module ProducerTest
245
254
  )
246
255
  end
247
256
 
257
+ it 'should encode the key with topic prefix' do
258
+ Deimos.configure { |c| c.producers.topic_prefix = 'prefix.' }
259
+ expect(MyProducer.encoder).to receive(:encode_key).with('test_id', 'foo', topic: 'prefix.my-topic-key')
260
+ expect(MyProducer.encoder).to receive(:encode_key).with('test_id', 'bar', topic: 'prefix.my-topic-key')
261
+ expect(MyProducer.encoder).to receive(:encode).with({ 'test_id' => 'foo',
262
+ 'some_int' => 123 },
263
+ { topic: 'prefix.my-topic-value' })
264
+ expect(MyProducer.encoder).to receive(:encode).with({ 'test_id' => 'bar',
265
+ 'some_int' => 124 },
266
+ { topic: 'prefix.my-topic-value' })
267
+
268
+ MyProducer.publish_list([{ 'test_id' => 'foo', 'some_int' => 123 },
269
+ { 'test_id' => 'bar', 'some_int' => 124 }])
270
+ end
271
+
248
272
  it 'should not encode with plaintext key' do
249
273
  expect(MyNonEncodedProducer.key_encoder).not_to receive(:encode_key)
250
274
 
@@ -296,6 +320,31 @@ module ProducerTest
296
320
  )
297
321
  end
298
322
 
323
+ it 'should raise error if blank topic is passed in explicitly' do
324
+ expect {
325
+ MyProducer.publish_list(
326
+ [{ 'test_id' => 'foo',
327
+ 'some_int' => 123 },
328
+ { 'test_id' => 'bar',
329
+ 'some_int' => 124 }],
330
+ topic: ''
331
+ )
332
+ }.to raise_error(RuntimeError,
333
+ 'Topic not specified. Please specify the topic.')
334
+ end
335
+
336
+ it 'should raise error if the producer has not been initialized with a topic' do
337
+ expect {
338
+ MyNoTopicProducer.publish_list(
339
+ [{ 'test_id' => 'foo',
340
+ 'some_int' => 123 },
341
+ { 'test_id' => 'bar',
342
+ 'some_int' => 124 }]
343
+ )
344
+ }.to raise_error(RuntimeError,
345
+ 'Topic not specified. Please specify the topic.')
346
+ end
347
+
299
348
  it 'should error with nothing set' do
300
349
  expect {
301
350
  MyErrorProducer.publish_list(
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: deimos-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.2.pre.beta2
4
+ version: 1.8.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Orner
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-09-15 00:00:00.000000000 Z
11
+ date: 2020-09-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: avro_turf
@@ -486,11 +486,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
486
486
  version: '0'
487
487
  required_rubygems_version: !ruby/object:Gem::Requirement
488
488
  requirements:
489
- - - ">"
489
+ - - ">="
490
490
  - !ruby/object:Gem::Version
491
- version: 1.3.1
491
+ version: '0'
492
492
  requirements: []
493
- rubygems_version: 3.1.2
493
+ rubygems_version: 3.1.3
494
494
  signing_key:
495
495
  specification_version: 4
496
496
  summary: Kafka libraries for Ruby.