resolve conversation

formater

Signed-off-by: wanjunlei <wanjunlei@yunify.com>

debug

debug

Signed-off-by: wanjunlei <wanjunlei@yunify.com>
This commit is contained in:
wanjunlei
2020-06-11 17:44:18 +08:00
parent 4cb84de44d
commit 356560ac74
8 changed files with 61 additions and 67 deletions

View File

@@ -12,31 +12,23 @@ func WithAuditing(handler http.Handler, a auditing.Auditing) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
// When auditing level is LevelNone, request should not be auditing.
if !a.Enable() {
// Auditing level can be modified with cr kube-auditing-webhook,
// so it need to judge every time.
if !a.Enabled() {
handler.ServeHTTP(w, req)
return
}
e := a.LogRequestObject(req)
resp := auditing.NewResponseCapture(w)
handler.ServeHTTP(resp, req)
// Create a new goroutine to finish the request, and wait for the response body.
// The advantage of using goroutine is that recording the return value of the
// request will not affect the processing of the request, even if the auditing fails.
go handler.ServeHTTP(resp, req)
select {
case <-req.Context().Done():
klog.Error("Server timeout")
return
case <-resp.StopCh:
info, ok := request.RequestInfoFrom(req.Context())
if !ok {
klog.Error("Unable to retrieve request info from request")
return
}
a.LogResponseObject(e, resp, info)
info, ok := request.RequestInfoFrom(req.Context())
if !ok {
klog.Error("Unable to retrieve request info from request")
return
}
go a.LogResponseObject(e, resp, info)
})
}