Warn when enabling socket_telemetry on unsupported platform#23
Warn when enabling socket_telemetry on unsupported platform#23stevenharman wants to merge 1 commit intobabbel:mainfrom
Conversation
9e6a3cd to
5746684
Compare
| expect(possible_lines.include?(line)).to eq(true) | ||
| expect(possible_lines).to include(line) |
There was a problem hiding this comment.
This will result in a more useful error message if the line doesn't match.
5746684 to
04b2f10
Compare
|
Anyone opposed to this one? It's a nice experience improvement - certainly better than blowing up! |
04b2f10 to
469ccaf
Compare
|
@unsign3d Thoughts on getting this one in as well? It's a nice quality of life improvement for folks running on macOS locally, while being fully compatible with how things work now. |
c1d08a7 to
0ae608f
Compare
|
👋 Hello. I've rebased this little nice-to-have atop the latest. I'm not sure who to tag as it's unclear who's maintaining this repo (and the published Gem). So I'll try a few of the folks who seem to have been active lately - @unsign3d @stoyanzhekov @jtsaito @amrrbakry We've been running it in production for over a year now. We are very interested in the future of this plugin and I would be happy to help with maintenance if you need a hand. Thank you! |
|
Oh, and I should note - without this change, it's impossible to successfully run the test suite on macOS. You have to skip the |
0ae608f to
2e8c736
Compare
The structs we depend on for collecting socket telemetry (`SOL_TCP` and
`TCP_INFO`) don't exist on all platforms. In such cases, these constants
won't be defined, and so we should WARN users and not enabled the
`socket_telemetry` option.
NOTE: On macOS, similar structs do exist: `Socket::IPPROTO_TCP` and
`Socket::TCP_CONNECTION_INFO`, respectively, and we can unpack the
binary info thusly:
```ruby
require 'socket'
sock = TCPSocket.new('example.com', 80)
info = sock.getsockopt(Socket::IPPROTO_TCP, Socket::TCP_CONNECTION_INFO)
# Struct: 2x uint8 (C2), 26x uint32 (L26)
fields = info.unpack("C2L26")
tcp_connection_info = {
tcpi_state: fields[0],
tcpi_snd_wscale: fields[1] >> 4,
tcpi_rcv_wscale: fields[1] & 0x0F,
tcpi_options: fields[2],
tcpi_flags: fields[3],
tcpi_rto: fields[4],
tcpi_maxseg: fields[5],
tcpi_snd_ssthresh: fields[6],
tcpi_snd_cwnd: fields[7],
tcpi_snd_wnd: fields[8],
tcpi_rcv_wnd: fields[9],
tcpi_rttcur: fields[10],
tcpi_srtt: fields[11],
tcpi_rttvar: fields[12],
tcpi_txpackets: fields[13],
tcpi_rxpackets: fields[14],
tcpi_txbytes: fields[15],
tcpi_rxbytes: fields[16],
tcpi_last_data_recv: fields[17],
tcpi_last_ack_recv: fields[18],
tcpi_last_data_sent: fields[19],
tcpi_last_ack_sent: fields[20],
tcpi_pmtu: fields[21],
tcpi_rcv_ssthresh: fields[22],
tcpi_snd_rexmitpack: fields[23],
tcpi_rcv_ooopack: fields[24],
tcpi_snd_zerowin: fields[25],
# add more fields as needed
}
puts tcp_connection_info
```
However, macOS doesn't expose the number of unacked connections like
various Linux kernels do. There is, as of now, to my knowledge, no way
to get this info without using some other OS level tool.
2e8c736 to
f591323
Compare
The structs we depend on for collecting socket telemetry (
SOL_TCPandTCP_INFO) don't exist on all platforms. In such cases, these constants won't be defined, and so we should WARN users and not enabled thesocket_telemetryoption.NOTE: On macOS, similar structs do exist:
Socket::IPPROTO_TCPandSocket::TCP_CONNECTION_INFO, respectively, and we can unpack the binary info thusly:However, macOS doesn't expose the number of unacked connections like various Linux kernels do. There is, as of now, to my knowledge, no way to get this info without using some other OS level tool.