Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion lib/puma/plugin/telemetry/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,14 @@ def enabled?
end

def socket_telemetry!
@socket_telemetry = true
# These structs are platform specific, and not available on macOS,
# for example. If they're undefined, then we cannot capture socket
# telemetry. We'll warn in that case.
if defined?(Socket::SOL_TCP) && defined?(Socket::TCP_INFO)
@socket_telemetry = true
else
warn("Cannot capture socket telemetry on this platform (#{RUBY_PLATFORM}); socket_telemetry is disabled.")
end
end

def socket_telemetry?
Expand Down
6 changes: 5 additions & 1 deletion spec/integration/plugin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ def make_request
end

it 'logs socket telemetry' do
unless defined?(Socket::SOL_TCP) && defined?(Socket::TCP_INFO)
skip("Socket::SOL_TCP not defined on #{RUBY_PLATFORM}")
end

threads = Array.new(2) { make_request }

sleep 0.1
Expand All @@ -123,7 +127,7 @@ def make_request
possible_lines = ['queue.backlog=1 sockets.backlog=5',
'queue.backlog=0 sockets.backlog=6']

expect(possible_lines.include?(line)).to eq(true)
expect(possible_lines).to include(line)
Comment on lines -126 to +130
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will result in a more useful error message if the line doesn't match.


total = line.split.sum { |kv| kv.split('=').last.to_i }
expect(total).to eq 6
Expand Down