Skip to content

Commit

Permalink
x/ref/runtime/protocols/lib/websocket: reduce log noise due to monito…
Browse files Browse the repository at this point in the history
…ring connections (#134)

Monitoring systems, such as prometheus, rely on establishing connections to services to determine their availability. This PR reduces the log noise that such connections generate by doing two things:

- log a failed connection attempt whereby the client sends no data at all, at log severity 2 rather than 1.
- delay logging the attempted the establishment of a connection (still log level 1) until after an initial byte has been read.

The net effect is to result in log messages for an https connection that sends no data.
  • Loading branch information
cosnicolaou authored Jun 29, 2020
1 parent bb18759 commit 9961769
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions x/ref/runtime/protocols/lib/websocket/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,9 @@ func (ln *wsTCPListener) netAcceptLoop() {
ln.acceptQ <- err
continue
}
logger.Global().VI(1).Infof("New net.Conn accepted from %s (local address: %s)", conn.RemoteAddr(), conn.LocalAddr())
logger.Global().VI(2).Infof("New net.Conn accepted from %s (local address: %s)", conn.RemoteAddr(), conn.LocalAddr())
if err := tcputil.EnableTCPKeepAlive(conn); err != nil {
logger.Global().Errorf("Failed to enable TCP keep alive: %v", err)
logger.Global().Errorf("Failed to enable TCP keep alive for connection from %s (local address %s): %v", conn.RemoteAddr(), conn.LocalAddr(), err)
}
classifications.Add(1)
go ln.classify(conn, &classifications)
Expand All @@ -146,13 +146,14 @@ func (ln *wsTCPListener) classify(conn net.Conn, done *sync.WaitGroup) {
n, err := io.ReadFull(conn, magic[:])
if err != nil {
// Unable to classify, ignore this connection.
logger.Global().VI(1).Infof("Shutting down connection from %v since the magic bytes could not be read: %v", conn.RemoteAddr(), err)
logger.Global().VI(2).Infof("Shutting down connection from %v since the magic bytes could not be read: %v", conn.RemoteAddr(), err)
conn.Close()
return
}
conn = &hybridConn{conn: conn, buffered: magic[:n]}
isHTTP = magic[0] == 'G'
}
logger.Global().VI(1).Infof("New net.Conn accepted from %s (local address: %s), classified: isHTTP %v", conn.RemoteAddr(), conn.LocalAddr(), isHTTP)
if isHTTP {
ln.httpReq.Add(1)
ln.httpQ <- conn
Expand Down

0 comments on commit 9961769

Please sign in to comment.