Skip to content

Commit

Permalink
align async dispatch logger messages
Browse files Browse the repository at this point in the history
  • Loading branch information
mensfeld committed Sep 13, 2024
1 parent 5421559 commit d09a315
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ This release contains **BREAKING** changes. Make sure to read and apply upgrade
- **[Breaking]** License changed from MIT to LGPL with an additional commercial option. Note: there is no commercial code in this repository. The commercial license is available for companies unable to use LGPL-licensed software for legal reasons.
- [Enhancement] Make variants fiber safe.
- [Enhancement] In transactional mode do not return any `dispatched` messages as none will be dispatched due to rollback.
- [Enhancement] Align the `LoggerListener` async messages to reflect, that messages are delegated to the internal queue and not dispatched.
- [Fix] Ensure, that `:dispatched` key for `#produce_many_sync` always contains delivery handles (final) and not delivery reports.

### Upgrade Notes
Expand Down
7 changes: 5 additions & 2 deletions lib/waterdrop/instrumentation/logger_listener.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def initialize(logger, log_messages: true)
def on_message_produced_async(event)
message = event[:message]

info(event, "Async producing of a message to '#{message[:topic]}' topic")
info(event, "Message to '#{message[:topic]}' topic was delegated to a dispatch queue")

return unless log_messages?

Expand All @@ -49,7 +49,10 @@ def on_messages_produced_async(event)
messages = event[:messages]
topics_count = messages.map { |message| "'#{message[:topic]}'" }.uniq.count

info(event, "Async producing of #{messages.size} messages to #{topics_count} topics")
info(
event,
"#{messages.size} messages to #{topics_count} topics were delegated to a dispatch queue"
)

return unless log_messages?

Expand Down
10 changes: 6 additions & 4 deletions spec/lib/waterdrop/instrumentation/logger_listener_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

it { expect(logged_data[0]).to include(producer.id) }
it { expect(logged_data[0]).to include('INFO') }
it { expect(logged_data[0]).to include('Async producing of a message to') }
it { expect(logged_data[0]).to include('topic was delegated to a dispatch queue') }
it { expect(logged_data[0]).to include(message[:topic]) }
it { expect(logged_data[1]).to include(producer.id) }
it { expect(logged_data[1]).to include('DEBUG') }
Expand All @@ -39,7 +39,7 @@

it { expect(logged_data[0]).to include(producer.id) }
it { expect(logged_data[0]).to include('INFO') }
it { expect(logged_data[0]).to include('Async producing of a message to') }
it { expect(logged_data[0]).to include('topic was delegated to a dispatch queue') }
it { expect(logged_data[0]).to include(message[:topic]) }
it { expect(logged_data[1]).to eq(nil) }
end
Expand Down Expand Up @@ -68,11 +68,13 @@
end

describe '#on_messages_produced_async' do
let(:dispatched_msg) { '2 messages to 2 topics were delegated to a dispatch queue' }

before { listener.on_messages_produced_async(event) }

it { expect(logged_data[0]).to include(producer.id) }
it { expect(logged_data[0]).to include('INFO') }
it { expect(logged_data[0]).to include('Async producing of 2 messages to 2 topics') }
it { expect(logged_data[0]).to include(dispatched_msg) }
it { expect(logged_data[1]).to include(producer.id) }
it { expect(logged_data[1]).to include('DEBUG') }
it { expect(logged_data[1]).to include(message.to_s) }
Expand All @@ -82,7 +84,7 @@

it { expect(logged_data[0]).to include(producer.id) }
it { expect(logged_data[0]).to include('INFO') }
it { expect(logged_data[0]).to include('Async producing of 2 messages to 2 topics') }
it { expect(logged_data[0]).to include(dispatched_msg) }
it { expect(logged_data[1]).to eq(nil) }
end
end
Expand Down

0 comments on commit d09a315

Please sign in to comment.