deimos-ruby 2.0.12 → 2.0.14

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: 20eaca3989afdf592d5c641ccdbd0e566d1f63dfd7076deb1b645f3496e04a82
4
- data.tar.gz: f1924ae8780d4ab9286f489d5bd125ed1437744275083b156857bd18c1ed24d5
3
+ metadata.gz: e8597163d34a0b2afd7ef60bbc2eda8f08c4e441292181dc7d15215ad4b2ebd7
4
+ data.tar.gz: 364899fa4738dd1df44f98cecc67bdc503f1a679a26274f78b49bd8b29c1ee02
5
5
  SHA512:
6
- metadata.gz: f6bcd268cdba8ab1079bde3bae8f0afa5b6a8b69854fdf503c8bd0a5df4e106e2f1935e630c212ee4a499157ec27b53ba0fe42e2be9f17ce65c21e39b8ae3be2
7
- data.tar.gz: 7d4797954f069453f7d9ede429e3961e6f7ff295f9572489ff4c30ddd901357c769a9e7181d7471c05fcf0dce025d2a32fa71e5c62d6b3e87930113d5c870e68
6
+ metadata.gz: 54eff5f5b0f375816b3a25516f602985b00440fe522d5495346fcb873d37fb1a822666ad04623c74002a15c15c3a70ba851099096d72eaba8ab9840a460ddbc2
7
+ data.tar.gz: 9901785951d244c09fc81ca6601c6700149b2f03f8246f167fe594fce778c035a1f81a1a468045930cf94e5787cecffcefdf069132cfe57686ec0172c8a28f5c
data/CHANGELOG.md CHANGED
@@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## UNRELEASED
9
9
 
10
+ ## 2.0.14 - 2025-05-26
11
+
12
+ - Fix: Log actual payloads by default (was logging "null" for the payload).
13
+
14
+ ## 2.0.13 - 2025-05-26
15
+
16
+ - Fix: Outbox producer would crash if no Deimos producer was defined for the topic.
17
+
10
18
  ## 2.0.12 - 2025-05-22
11
19
 
12
20
  - Fix: Allow for hot reloading of producer classes without crashing.
@@ -9,9 +9,10 @@ module Deimos
9
9
  producer: self,
10
10
  message: message
11
11
  ) do
12
+ return message if message.delete(:already_encoded)
13
+
12
14
  config = Deimos.karafka_config_for(topic: message[:topic])
13
15
  return message if config.nil? || config.schema.nil?
14
- return message if message.delete(:already_encoded)
15
16
  return if message[:payload] && !message[:payload].is_a?(Hash) && !message[:payload].is_a?(SchemaClass::Record)
16
17
 
17
18
  m = Deimos::Message.new(message[:payload].to_h,
@@ -42,7 +42,7 @@ module Deimos
42
42
  if m.respond_to?(:payload)
43
43
  m.payload
44
44
  elsif m[:label]
45
- m.dig(:label, :raw_payload)
45
+ m.dig(:label, :original_payload)
46
46
  else
47
47
  m[:payload]
48
48
  end
@@ -98,6 +98,8 @@ module Deimos
98
98
  message_key = Deimos::TestHelpers.normalize_message(key)
99
99
  hash_matcher = RSpec::Matchers::BuiltIn::Match.new(message)
100
100
  Deimos::TestHelpers.sent_messages.any? do |m|
101
+ return m[:payload] == message if message.is_a?(String)
102
+
101
103
  message.delete(:payload_key) if message.respond_to?(:[]) && message[:payload_key].nil?
102
104
  m[:payload].delete(:payload_key) if m.respond_to?(:[]) && m[:payload]&.respond_to?(:[]) && m[:payload][:payload_key].nil?
103
105
  hash_matcher.send(:match, message, m[:payload]) &&
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Deimos
4
- VERSION = '2.0.12'
4
+ VERSION = '2.0.14'
5
5
  end
data/lib/deimos.rb CHANGED
@@ -107,6 +107,8 @@ module Deimos
107
107
  topic = topic.sub(Deimos.config.producers.topic_prefix, '')
108
108
  end
109
109
  config = karafka_config_for(topic: topic)
110
+ return message unless config
111
+
110
112
  message[:payload] = config.deserializers[:payload].decode_message_hash(message[:payload])
111
113
  if message[:key] && config.deserializers[:key].respond_to?(:decode_message_hash)
112
114
  message[:key] = config.deserializers[:key].decode_message_hash(message[:key])
@@ -272,6 +272,50 @@ module ProducerTest
272
272
  }, '456', '4561')
273
273
  end
274
274
 
275
+ describe 'payload logging' do
276
+ context 'with default / full' do
277
+ it 'should log full payload' do
278
+ allow(Karafka.logger).to receive(:info)
279
+ MyProducerWithID.publish_list(
280
+ [
281
+ { 'test_id' => 'foo', 'some_int' => 123, :payload_key => 'key' },
282
+ { 'test_id' => 'foo2', 'some_int' => 123, :payload_key => 'key2' },
283
+ ]
284
+ )
285
+ expect(Karafka.logger).to have_received(:info).with(match_message({
286
+ 'message' => 'Publishing Messages:',
287
+ 'payloads' => [
288
+ {
289
+ 'payload' => { 'test_id' => 'foo', 'some_int' => 123 },
290
+ 'key' => 'key'
291
+ },
292
+ {
293
+ 'payload' => { 'test_id' => 'foo2', 'some_int' => 123 },
294
+ 'key' => 'key2'
295
+ }
296
+ ]
297
+ }))
298
+ end
299
+ end
300
+
301
+ context 'with count' do
302
+ it 'should log only count' do
303
+ Deimos.karafka_config_for(topic: 'my-topic-with-id').payload_log :count
304
+ allow(Karafka.logger).to receive(:info)
305
+ MyProducerWithID.publish_list(
306
+ [
307
+ { 'test_id' => 'foo', 'some_int' => 123, :payload_key => 'key' },
308
+ { 'test_id' => 'foo2', 'some_int' => 123, :payload_key => 'key' }
309
+ ]
310
+ )
311
+ expect(Karafka.logger).to have_received(:info).with(match_message({
312
+ 'message' => 'Publishing Messages:',
313
+ 'payloads_count' => 2
314
+ }))
315
+ end
316
+ end
317
+ end
318
+
275
319
  context 'with Schema Class payloads' do
276
320
  it 'should fail on invalid message with error handler' do
277
321
  expect(Deimos::ProducerMiddleware).to receive(:call).and_raise('OH NOES')
data/spec/spec_helper.rb CHANGED
@@ -343,3 +343,18 @@ RSpec.shared_context('with publish_backend') do
343
343
  end
344
344
  end
345
345
  end
346
+
347
+ RSpec::Matchers.define :match_message do |msg|
348
+ match do |actual|
349
+ begin
350
+ parsed = JSON.parse(actual)
351
+ parsed['payloads']&.each do |p|
352
+ p['payload'].delete('timestamp')
353
+ p['payload'].delete('message_id')
354
+ end
355
+ expect(parsed).to match(a_hash_including(msg))
356
+ rescue JSON::ParserError
357
+ false
358
+ end
359
+ end
360
+ end
@@ -340,6 +340,17 @@ each_db_config(Deimos::Utils::OutboxProducer) do
340
340
  end
341
341
 
342
342
  example 'Full integration test' do
343
+ Deimos::KafkaMessage.create!(topic: "topic1",
344
+ message: "mess1",
345
+ partition_key: "key1")
346
+ producer.process_next_messages
347
+ expect(Deimos::KafkaTopicInfo.count).to eq(1)
348
+ expect(Deimos::KafkaTopicInfo.first.topic).to eq('topic1')
349
+ expect(Deimos::KafkaMessage.count).to eq(0)
350
+ expect('topic1').to have_sent('mess1')
351
+ end
352
+
353
+ example 'Integration test - batching' do
343
354
  (1..4).each do |i|
344
355
  (1..2).each do |j|
345
356
  Deimos::KafkaMessage.create!(topic: "topic#{j}",
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: 2.0.12
4
+ version: 2.0.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Orner
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-05-22 00:00:00.000000000 Z
11
+ date: 2025-05-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: avro_turf