pkg/kubelet/server: migrate to structured logs

This commit is contained in:
chenyw1990
2021-02-01 10:47:38 +08:00
parent 765249c524
commit db5de9169f
8 changed files with 19 additions and 21 deletions

View File

@@ -259,7 +259,7 @@ func (h *handler) handleSystemContainer(request *restful.Request, response *rest
if err != nil {
if _, ok := stats[containerName]; ok {
// If the failure is partial, log it and return a best-effort response.
klog.Errorf("Partial failure issuing GetRawContainerInfo(%v): %v", query, err)
klog.ErrorS(err, "Partial failure issuing GetRawContainerInfo", "query", query)
} else {
handleError(response, fmt.Sprintf("/stats/container %v", query), err)
return
@@ -295,7 +295,7 @@ func (h *handler) handlePodContainer(request *restful.Request, response *restful
pod, ok := h.provider.GetPodByName(params["namespace"], params["podName"])
if !ok {
klog.V(4).Infof("Container not found: %v", params)
klog.V(4).InfoS("Container not found", "pod", klog.KRef(params["namespace"], params["podName"]))
response.WriteError(http.StatusNotFound, kubecontainer.ErrContainerNotFound)
return
}
@@ -314,7 +314,7 @@ func (h *handler) handlePodContainer(request *restful.Request, response *restful
func writeResponse(response *restful.Response, stats interface{}) {
if err := response.WriteAsJson(stats); err != nil {
klog.Errorf("Error writing response: %v", err)
klog.ErrorS(err, "Error writing response")
}
}
@@ -326,7 +326,7 @@ func handleError(response *restful.Response, request string, err error) {
response.WriteError(http.StatusNotFound, err)
default:
msg := fmt.Sprintf("Internal Error: %v", err)
klog.Errorf("HTTP InternalServerError serving %s: %s", request, msg)
klog.ErrorS(err, "HTTP InternalServerError serving", "request", request)
response.WriteErrorString(http.StatusInternalServerError, msg)
}
}