From 38f5024ed04401c2ecb93a489e968bed79fc2c71 Mon Sep 17 00:00:00 2001 From: Romain Date: Tue, 31 Jan 2023 16:00:10 +0100 Subject: [PATCH] Differentiate UDP stream and TCP connection in logs --- pkg/tcp/proxy.go | 14 +++++++------- pkg/udp/proxy.go | 8 ++++---- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/pkg/tcp/proxy.go b/pkg/tcp/proxy.go index 8887bb91d..9f91c49b3 100644 --- a/pkg/tcp/proxy.go +++ b/pkg/tcp/proxy.go @@ -48,14 +48,14 @@ func NewProxy(address string, terminationDelay time.Duration, proxyProtocol *dyn // ServeTCP forwards the connection to a service. func (p *Proxy) ServeTCP(conn WriteCloser) { - log.WithoutContext().Debugf("Handling connection from %s to %s", conn.RemoteAddr(), p.address) + log.WithoutContext().Debugf("Handling TCP connection from %s to %s", conn.RemoteAddr(), p.address) // needed because of e.g. server.trackedConnection defer conn.Close() connBackend, err := p.dialBackend() if err != nil { - log.WithoutContext().Errorf("Error while connecting to backend: %v", err) + log.WithoutContext().Errorf("Error while dialing backend: %v", err) return } @@ -66,7 +66,7 @@ func (p *Proxy) ServeTCP(conn WriteCloser) { if p.proxyProtocol != nil && p.proxyProtocol.Version > 0 && p.proxyProtocol.Version < 3 { header := proxyproto.HeaderProxyFromAddrs(byte(p.proxyProtocol.Version), conn.RemoteAddr(), conn.LocalAddr()) if _, err := header.WriteTo(connBackend); err != nil { - log.WithoutContext().Errorf("Error while writing proxy protocol headers to backend connection: %v", err) + log.WithoutContext().Errorf("Error while writing TCP proxy protocol headers to backend connection: %v", err) return } } @@ -80,9 +80,9 @@ func (p *Proxy) ServeTCP(conn WriteCloser) { // This allows to not report an RST packet sent by the peer as an error, // as it is an abrupt but possible end for the TCP session if isReadConnResetError(err) { - log.WithoutContext().Debugf("Error during connection: %v", err) + log.WithoutContext().Debugf("Error while handling TCP connection: %v", err) } else { - log.WithoutContext().Errorf("Error during connection: %v", err) + log.WithoutContext().Errorf("Error while handling TCP connection: %v", err) } } @@ -119,7 +119,7 @@ func (p Proxy) connCopy(dst, src WriteCloser, errCh chan error) { // In that case, logging the error is superfluous, // as in the first place we should not have needed to call CloseWrite. if !isSocketNotConnectedError(errClose) { - log.WithoutContext().Debugf("Error while terminating connection: %v", errClose) + log.WithoutContext().Debugf("Error while terminating TCP connection: %v", errClose) } return @@ -128,7 +128,7 @@ func (p Proxy) connCopy(dst, src WriteCloser, errCh chan error) { if p.terminationDelay >= 0 { err := dst.SetReadDeadline(time.Now().Add(p.terminationDelay)) if err != nil { - log.WithoutContext().Debugf("Error while setting deadline: %v", err) + log.WithoutContext().Debugf("Error while setting TCP connection deadline: %v", err) } } } diff --git a/pkg/udp/proxy.go b/pkg/udp/proxy.go index 8ccbfda4b..79edcc163 100644 --- a/pkg/udp/proxy.go +++ b/pkg/udp/proxy.go @@ -20,14 +20,14 @@ func NewProxy(address string) (*Proxy, error) { // ServeUDP implements the Handler interface. func (p *Proxy) ServeUDP(conn *Conn) { - log.WithoutContext().Debugf("Handling connection from %s to %s", conn.rAddr, p.target) + log.WithoutContext().Debugf("Handling UDP stream from %s to %s", conn.rAddr, p.target) // needed because of e.g. server.trackedConnection defer conn.Close() connBackend, err := net.Dial("udp", p.target) if err != nil { - log.WithoutContext().Errorf("Error while connecting to backend: %v", err) + log.WithoutContext().Errorf("Error while dialing backend: %v", err) return } @@ -40,7 +40,7 @@ func (p *Proxy) ServeUDP(conn *Conn) { err = <-errChan if err != nil { - log.WithoutContext().Errorf("Error while serving UDP: %v", err) + log.WithoutContext().Errorf("Error while handling UDP stream: %v", err) } <-errChan @@ -55,6 +55,6 @@ func connCopy(dst io.WriteCloser, src io.Reader, errCh chan error) { errCh <- err if err := dst.Close(); err != nil { - log.WithoutContext().Debugf("Error while terminating connection: %v", err) + log.WithoutContext().Debugf("Error while terminating UDP stream: %v", err) } }