mirror of
https://github.com/minio/minio.git
synced 2025-02-03 18:06:00 -05:00
fix(AuditLog): panic while st is nil (#13510)
This commit is contained in:
parent
939fbb3c38
commit
d158607f8e
@ -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.
|
||||
|
Loading…
x
Reference in New Issue
Block a user