Skip to content

Commit 10c8973

Browse files
committed
UPSTREAM: <carry>: kube-apiserver: Only log each HTTP request once
kube-apiserver now logs each HTTP request twice since there is an extra logging call when finishing the request. This duplicity is now removed.
1 parent 6efb6a9 commit 10c8973

File tree

1 file changed

+4
-5
lines changed
  • staging/src/k8s.io/apiserver/pkg/server/httplog

1 file changed

+4
-5
lines changed

staging/src/k8s.io/apiserver/pkg/server/httplog/httplog.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,16 +131,15 @@ func withLogging(handler http.Handler, stackTracePred StacktracePred, shouldLogR
131131
req = req.WithContext(context.WithValue(ctx, respLoggerContextKey, rl))
132132

133133
var logFunc func()
134-
logFunc = rl.Log
134+
if klog.V(3).Enabled() || (rl.isTerminating && klog.V(1).Enabled()) {
135+
logFunc = rl.Log
136+
}
135137
defer func() {
136138
if logFunc != nil {
137139
logFunc()
138140
}
139141
}()
140142

141-
if klog.V(3).Enabled() || (rl.isTerminating && klog.V(1).Enabled()) {
142-
defer rl.Log()
143-
}
144143
w = responsewriter.WrapForHTTP1Or2(rl)
145144
handler.ServeHTTP(w, req)
146145

@@ -149,7 +148,7 @@ func withLogging(handler http.Handler, stackTracePred StacktracePred, shouldLogR
149148
// WithRoutine handler in the handler chain (i.e. above handler.ServeHTTP()
150149
// would return request is completely responsed), we want the logging to
151150
// happen in that goroutine too, so we append it to the task.
152-
if routine.AppendTask(ctx, &routine.Task{Func: rl.Log}) {
151+
if logFunc != nil && routine.AppendTask(ctx, &routine.Task{Func: logFunc}) {
153152
logFunc = nil
154153
}
155154
})

0 commit comments

Comments
 (0)