Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v12] Add connection information to multiplexer logs so it's easier to investigate #32740

Merged
merged 1 commit into from
Oct 2, 2023
Merged
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
15 changes: 12 additions & 3 deletions lib/multiplexer/multiplexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,10 @@ func (m *Mux) detectAndForward(conn net.Conn) {
connWrapper, err := m.detect(conn)
if err != nil {
if trace.Unwrap(err) != io.EOF {
m.logLimiter.Log(m.Entry, log.WarnLevel, trace.DebugReport(err))
m.logLimiter.Log(m.Entry.WithFields(log.Fields{
"src_addr": conn.RemoteAddr(),
"dst_addr": conn.LocalAddr(),
}), log.WarnLevel, trace.DebugReport(err))
}
conn.Close()
return
Expand All @@ -282,9 +285,15 @@ func (m *Mux) detectAndForward(conn net.Conn) {
listener := m.protocolListener(connWrapper.protocol)
if listener == nil {
if connWrapper.protocol == ProtoHTTP {
m.Debug("Detected an HTTP request. If this is for a health check, use an HTTPS request instead.")
m.WithFields(log.Fields{
"src_addr": connWrapper.RemoteAddr(),
"dst_addr": connWrapper.LocalAddr(),
}).Debug("Detected an HTTP request. If this is for a health check, use an HTTPS request instead.")
}
m.Debugf("Closing %[1]s connection: %[1]s listener is disabled.", connWrapper.protocol)
m.WithFields(log.Fields{
"src_addr": connWrapper.RemoteAddr(),
"dst_addr": connWrapper.LocalAddr(),
}).Debugf("Closing %[1]s connection: %[1]s listener is disabled.", connWrapper.protocol)
connWrapper.Close()
return
}
Expand Down
15 changes: 12 additions & 3 deletions lib/multiplexer/tls.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,10 @@ func (l *TLSListener) Serve() error {
tlsConn, ok := conn.(*tls.Conn)
if !ok {
conn.Close()
log.Errorf("Expected tls.Conn, got %T, internal usage error.", conn)
l.log.WithFields(log.Fields{
"src_addr": conn.RemoteAddr(),
"dst_addr": conn.LocalAddr(),
}).Errorf("Expected tls.Conn, got %T, internal usage error.", conn)
continue
}
go l.detectAndForward(tlsConn)
Expand Down Expand Up @@ -141,7 +144,10 @@ func (l *TLSListener) detectAndForward(conn *tls.Conn) {
start := l.cfg.Clock.Now()
if err := conn.Handshake(); err != nil {
if trace.Unwrap(err) != io.EOF {
l.log.WithError(err).Warning("Handshake failed.")
l.log.WithFields(log.Fields{
"src_addr": conn.RemoteAddr(),
"dst_addr": conn.LocalAddr(),
}).WithError(err).Warning("Handshake failed.")
}
conn.Close()
return
Expand All @@ -167,7 +173,10 @@ func (l *TLSListener) detectAndForward(conn *tls.Conn) {
l.httpListener.HandleConnection(l.context, conn)
default:
conn.Close()
l.log.WithError(err).Errorf("unsupported protocol: %v", conn.ConnectionState().NegotiatedProtocol)
l.log.WithFields(log.Fields{
"src_addr": conn.RemoteAddr(),
"dst_addr": conn.LocalAddr(),
}).WithError(err).Errorf("unsupported protocol: %v", conn.ConnectionState().NegotiatedProtocol)
}
}

Expand Down
15 changes: 12 additions & 3 deletions lib/multiplexer/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,10 @@ func (l *WebListener) Serve() error {

tlsConn, ok := conn.(*tls.Conn)
if !ok {
l.log.Errorf("Expected *tls.Conn, got %T.", conn)
l.log.WithFields(logrus.Fields{
"src_addr": conn.RemoteAddr(),
"dst_addr": conn.LocalAddr(),
}).Errorf("Expected *tls.Conn, got %T.", conn)
conn.Close()
continue
}
Expand All @@ -132,7 +135,10 @@ func (l *WebListener) detectAndForward(conn *tls.Conn) {

if err := conn.Handshake(); err != nil {
if trace.Unwrap(err) != io.EOF {
l.log.WithError(err).Warn("Handshake failed.")
l.log.WithFields(logrus.Fields{
"src_addr": conn.RemoteAddr(),
"dst_addr": conn.LocalAddr(),
}).WithError(err).Warn("Handshake failed.")
}
conn.Close()
return
Expand All @@ -151,7 +157,10 @@ func (l *WebListener) detectAndForward(conn *tls.Conn) {
// tls listener.
isDatabaseConnection, err := dbcommon.IsDatabaseConnection(conn.ConnectionState())
if err != nil {
l.log.WithError(err).Debug("Failed to check if connection is database connection.")
l.log.WithFields(logrus.Fields{
"src_addr": conn.RemoteAddr(),
"dst_addr": conn.LocalAddr(),
}).WithError(err).Debug("Failed to check if connection is database connection.")
}
if isDatabaseConnection {
l.dbListener.HandleConnection(l.context, conn)
Expand Down
Loading