mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 19:31:44 +00:00
Merge pull request #102435 from AbdulBasitAlvi/hotfix/restore_depth_to_log_calls
hotfix(staging_apiserver_pkg_httplog): restore depth to log calls
This commit is contained in:
commit
6181a2c7d8
@ -97,7 +97,7 @@ func WithLogging(handler http.Handler, pred StacktracePred) http.Handler {
|
|||||||
req = req.WithContext(context.WithValue(ctx, respLoggerContextKey, rl))
|
req = req.WithContext(context.WithValue(ctx, respLoggerContextKey, rl))
|
||||||
|
|
||||||
if klog.V(3).Enabled() {
|
if klog.V(3).Enabled() {
|
||||||
defer func() { klog.InfoS("HTTP", rl.LogArgs()...) }()
|
defer rl.Log()
|
||||||
}
|
}
|
||||||
handler.ServeHTTP(rl, req)
|
handler.ServeHTTP(rl, req)
|
||||||
})
|
})
|
||||||
@ -180,38 +180,33 @@ func AddInfof(ctx context.Context, format string, data ...interface{}) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rl *respLogger) LogArgs() []interface{} {
|
// Log is intended to be called once at the end of your request handler, via defer
|
||||||
|
func (rl *respLogger) Log() {
|
||||||
latency := time.Since(rl.startTime)
|
latency := time.Since(rl.startTime)
|
||||||
auditID := request.GetAuditIDTruncated(rl.req)
|
auditID := request.GetAuditIDTruncated(rl.req)
|
||||||
if rl.hijacked {
|
keysAndValues := []interface{}{
|
||||||
return []interface{}{
|
|
||||||
"verb", rl.req.Method,
|
|
||||||
"URI", rl.req.RequestURI,
|
|
||||||
"latency", latency,
|
|
||||||
"userAgent", rl.req.UserAgent(),
|
|
||||||
"audit-ID", auditID,
|
|
||||||
"srcIP", rl.req.RemoteAddr,
|
|
||||||
"hijacked", true,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
args := []interface{}{
|
|
||||||
"verb", rl.req.Method,
|
"verb", rl.req.Method,
|
||||||
"URI", rl.req.RequestURI,
|
"URI", rl.req.RequestURI,
|
||||||
"latency", latency,
|
"latency", latency,
|
||||||
"userAgent", rl.req.UserAgent(),
|
"userAgent", rl.req.UserAgent(),
|
||||||
"audit-ID", auditID,
|
"audit-ID", auditID,
|
||||||
"srcIP", rl.req.RemoteAddr,
|
"srcIP", rl.req.RemoteAddr,
|
||||||
"resp", rl.status,
|
|
||||||
}
|
|
||||||
if len(rl.statusStack) > 0 {
|
|
||||||
args = append(args, "statusStack", rl.statusStack)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
info := rl.addedInfo.String()
|
if rl.hijacked {
|
||||||
if len(info) > 0 {
|
keysAndValues = append(keysAndValues, "hijacked", true)
|
||||||
args = append(args, "addedInfo", info)
|
} else {
|
||||||
|
keysAndValues = append(keysAndValues, "resp", rl.status)
|
||||||
|
if len(rl.statusStack) > 0 {
|
||||||
|
keysAndValues = append(keysAndValues, "statusStack", rl.statusStack)
|
||||||
|
}
|
||||||
|
info := rl.addedInfo.String()
|
||||||
|
if len(info) > 0 {
|
||||||
|
keysAndValues = append(keysAndValues, "addedInfo", info)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return args
|
|
||||||
|
klog.InfoSDepth(1, "HTTP", keysAndValues...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Header implements http.ResponseWriter.
|
// Header implements http.ResponseWriter.
|
||||||
|
Loading…
Reference in New Issue
Block a user