Compare commits

...

3 Commits

Author SHA1 Message Date
Anis Elleuch 33c950d256 Avoid using http.Fluster in cluster replication API 2021-10-27 23:43:52 +02:00
Anis Elleuch ddcfe03b04 Enable http server logs to print handler crash 2021-10-27 23:19:50 +02:00
moon bd4ddccd20 fix(AuditLog): panic while st is nil (#13510) 2021-10-27 19:15:46 +02:00
3 changed files with 22 additions and 10 deletions

View File

@ -265,12 +265,13 @@ func (a adminAPIHandlers) SiteReplicationInfo(w http.ResponseWriter, r *http.Req
return
}
if err = json.NewEncoder(w).Encode(info); err != nil {
jsonBytes, err := json.Marshal(info)
if err != nil {
writeErrorResponseJSON(ctx, w, toAdminAPIErr(ctx, err), r.URL)
return
}
w.(http.Flusher).Flush()
writeSuccessResponseJSON(w, jsonBytes)
}
func (a adminAPIHandlers) SRInternalGetIDPSettings(w http.ResponseWriter, r *http.Request) {
@ -284,12 +285,14 @@ func (a adminAPIHandlers) SRInternalGetIDPSettings(w http.ResponseWriter, r *htt
}
idpSettings := globalSiteReplicationSys.GetIDPSettings(ctx)
if err := json.NewEncoder(w).Encode(idpSettings); err != nil {
jsonBytes, err := json.Marshal(idpSettings)
if err != nil {
writeErrorResponseJSON(ctx, w, toAdminAPIErr(ctx, err), r.URL)
return
}
w.(http.Flusher).Flush()
writeSuccessResponseJSON(w, jsonBytes)
}
func readJSONBody(ctx context.Context, body io.Reader, v interface{}, encryptionKey string) APIErrorCode {

View File

@ -23,7 +23,6 @@ import (
"errors"
"fmt"
"io"
"log"
"math/rand"
"net"
"os"
@ -515,8 +514,6 @@ func serverMain(ctx *cli.Context) {
httpServer.BaseContext = func(listener net.Listener) context.Context {
return GlobalContext
}
// Turn-off random logging by Go internally
httpServer.ErrorLog = log.New(&nullWriter{}, "", 0)
go func() {
globalHTTPServerErrorCh <- httpServer.Start(GlobalContext)
}()

View File

@ -26,6 +26,7 @@ import (
"strconv"
"time"
"github.com/klauspost/compress/gzhttp"
"github.com/minio/minio/internal/logger/message/audit"
)
@ -183,13 +184,24 @@ func AuditLog(ctx context.Context, w http.ResponseWriter, r *http.Request, reqCl
statusCode int
timeToResponse time.Duration
timeToFirstByte time.Duration
outputBytes int64 = -1 // -1: unknown output bytes
)
st, ok := w.(*ResponseWriter)
if ok {
var st *ResponseWriter
switch v := w.(type) {
case *ResponseWriter:
st = v
case *gzhttp.GzipResponseWriter:
// the writer may be obscured by gzip response writer
if rw, ok := v.ResponseWriter.(*ResponseWriter); ok {
st = rw
}
}
if st != nil {
statusCode = st.StatusCode
timeToResponse = time.Now().UTC().Sub(st.StartTime)
timeToFirstByte = st.TimeToFirstByte
outputBytes = int64(st.Size())
}
entry.API.Name = reqInfo.API
@ -198,7 +210,7 @@ func AuditLog(ctx context.Context, w http.ResponseWriter, r *http.Request, reqCl
entry.API.Status = http.StatusText(statusCode)
entry.API.StatusCode = statusCode
entry.API.InputBytes = r.ContentLength
entry.API.OutputBytes = int64(st.Size())
entry.API.OutputBytes = outputBytes
entry.API.TimeToResponse = strconv.FormatInt(timeToResponse.Nanoseconds(), 10) + "ns"
entry.Tags = reqInfo.GetTagsMap()
// ttfb will be recorded only for GET requests, Ignore such cases where ttfb will be empty.