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

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:07:06 -03:00
committed by GitHub
parent 0f6741ff29
commit 6751fadc01
+27
View File
@@ -12,6 +12,7 @@ import (
"encoding/pem"
"errors"
"fmt"
stdlog "log"
"math/big"
"net"
"net/http"
@@ -399,6 +400,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
@@ -411,6 +432,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 {