Skip to content

Commit

Permalink
[statsd receiver] rename Statsd.UDPlistener => UDPConn
Browse files Browse the repository at this point in the history
Summary:

Later in this stack of diffs, I rename `TCPlistener` to `Listener` because it becomes a generic listener for all networks supported by `net.Listen`. That makes `UDPlistener`'s naming stand out because:

- It isn't a listener. It's a `*net.UDPConn`.
- It isn't the UDP counterpart to `Listener`.

This diff renames it to `UDPConn` to improve clarity.

Test Plan:

Unit tests pass.
  • Loading branch information
James Ribe committed Jan 21, 2025
1 parent 5a4b0c5 commit cd85850
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 5 additions & 5 deletions plugins/inputs/statsd/statsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ type Statsd struct {
distributions []cacheddistributions

// Protocol listeners
UDPlistener *net.UDPConn
UDPConn *net.UDPConn
TCPlistener *net.TCPListener

// track current connections so we can close them in Stop()
Expand Down Expand Up @@ -296,7 +296,7 @@ func (s *Statsd) Start(ac telegraf.Accumulator) error {
}

s.Log.Infof("UDP listening on %q", conn.LocalAddr().String())
s.UDPlistener = conn
s.UDPConn = conn

s.wg.Add(1)
go func() {
Expand Down Expand Up @@ -450,8 +450,8 @@ func (s *Statsd) Stop() {
s.Log.Infof("Stopping the statsd service")
close(s.done)
if s.isUDP() {
if s.UDPlistener != nil {
s.UDPlistener.Close()
if s.UDPConn != nil {
s.UDPConn.Close()
}
} else {
if s.TCPlistener != nil {
Expand Down Expand Up @@ -530,7 +530,7 @@ func (s *Statsd) tcpListen(listener *net.TCPListener) error {
// udpListen starts listening for UDP packets on the configured port.
func (s *Statsd) udpListen(conn *net.UDPConn) error {
if s.ReadBufferSize > 0 {
if err := s.UDPlistener.SetReadBuffer(s.ReadBufferSize); err != nil {
if err := s.UDPConn.SetReadBuffer(s.ReadBufferSize); err != nil {
return err
}
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/inputs/statsd/statsd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2168,7 +2168,7 @@ func TestUdpFillQueue(t *testing.T) {
var acc testutil.Accumulator
require.NoError(t, plugin.Start(&acc))

conn, err := net.Dial("udp", plugin.UDPlistener.LocalAddr().String())
conn, err := net.Dial("udp", plugin.UDPConn.LocalAddr().String())
require.NoError(t, err)
numberToSend := plugin.AllowedPendingMessages
for i := 0; i < numberToSend; i++ {
Expand Down

0 comments on commit cd85850

Please sign in to comment.