[release-11.6.8] Log TLS handshake EOF error as DEBUG instead INFO (#113097)

Log TLS handshake EOF error as DEBUG instead INFO (#112294)

* Log TLS handshake EOF error as DEBUG instead INFO



---------


(cherry picked from commit a75b01907d)

Signed-off-by: Maicon Costa <maiconscosta@gmail.com>
Co-authored-by: maicon <maiconscosta@gmail.com>
This commit is contained in:
grafana-delivery-bot[bot]
2025-10-28 16:05:34 -03:00
committed by GitHub
co-authored by maicon
parent 46b9094c20
commit 0e676de335
+27
View File
@@ -12,6 +12,7 @@ import (
"encoding/pem"
"errors"
"fmt"
stdlog "log"
"math/big"
"net"
"net/http"
@@ -401,6 +402,26 @@ func (hs *HTTPServer) AddNamedMiddleware(middleware routing.RegisterNamedMiddlew
hs.namedMiddlewares = append(hs.namedMiddlewares, middleware)
}
type customErrorLogger struct {
log log.Logger
}
const tlsHandshakeErrorPrefix = "http: TLS handshake error from"
const tlsHandshakeErrorSuffix = "EOF"
func (w *customErrorLogger) Write(msg []byte) (int, error) {
// checks if the error is a TLS handshake error that ends with EOF
if strings.Contains(string(msg), tlsHandshakeErrorPrefix) && strings.Contains(string(msg), tlsHandshakeErrorSuffix) {
// log at debug level and remove new lines
w.log.Debug(strings.ReplaceAll(string(msg), "\n", ""))
} else {
// log the error as is using the standard logger (the same way as the default http server does)
stdlog.Print(string(msg))
}
return len(msg), nil
}
func (hs *HTTPServer) Run(ctx context.Context) error {
hs.context = ctx
@@ -413,6 +434,12 @@ func (hs *HTTPServer) Run(ctx context.Context) error {
Handler: hs.web,
ReadTimeout: hs.Cfg.ReadTimeout,
}
customErrorLogger := &customErrorLogger{
log: hs.log,
}
hs.httpSrv.ErrorLog = stdlog.New(customErrorLogger, "", 0)
switch hs.Cfg.Protocol {
case setting.HTTP2Scheme, setting.HTTPSScheme:
if err := hs.configureTLS(); err != nil {