From 024ce9a843fc821b74bd699bc5abeb08f95ad23f Mon Sep 17 00:00:00 2001 From: JunYang Date: Fri, 12 Feb 2021 09:58:33 +0800 Subject: [PATCH] Structured Logging migration: modify cri part logs of kubelet. Signed-off-by: JunYang --- .../cri/streaming/portforward/httpstream.go | 24 +++++++++---------- .../cri/streaming/portforward/websocket.go | 4 ++-- .../cri/streaming/remotecommand/httpstream.go | 4 ++-- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/pkg/kubelet/cri/streaming/portforward/httpstream.go b/pkg/kubelet/cri/streaming/portforward/httpstream.go index 41911305487..bd707decb16 100644 --- a/pkg/kubelet/cri/streaming/portforward/httpstream.go +++ b/pkg/kubelet/cri/streaming/portforward/httpstream.go @@ -42,7 +42,7 @@ func handleHTTPStreams(req *http.Request, w http.ResponseWriter, portForwarder P } streamChan := make(chan httpstream.Stream, 1) - klog.V(5).Infof("Upgrading port forward response") + klog.V(5).InfoS("Upgrading port forward response") upgrader := spdy.NewResponseUpgrader() conn := upgrader.UpgradeResponse(w, req, httpStreamReceived(streamChan)) if conn == nil { @@ -50,7 +50,7 @@ func handleHTTPStreams(req *http.Request, w http.ResponseWriter, portForwarder P } defer conn.Close() - klog.V(5).Infof("(conn=%p) setting port forwarding streaming connection idle timeout to %v", conn, idleTimeout) + klog.V(5).InfoS("Connection setting port forwarding streaming connection idle timeout", "connection", conn, "idleTimeout", idleTimeout) conn.SetIdleTimeout(idleTimeout) h := &httpStreamHandler{ @@ -121,11 +121,11 @@ func (h *httpStreamHandler) getStreamPair(requestID string) (*httpStreamPair, bo defer h.streamPairsLock.Unlock() if p, ok := h.streamPairs[requestID]; ok { - klog.V(5).Infof("(conn=%p, request=%s) found existing stream pair", h.conn, requestID) + klog.V(5).InfoS("Connection request found existing stream pair", "connection", h.conn, "request", requestID) return p, false } - klog.V(5).Infof("(conn=%p, request=%s) creating new stream pair", h.conn, requestID) + klog.V(5).InfoS("Connection request creating new stream pair", "connection", h.conn, "request", requestID) p := newPortForwardPair(requestID) h.streamPairs[requestID] = p @@ -143,7 +143,7 @@ func (h *httpStreamHandler) monitorStreamPair(p *httpStreamPair, timeout <-chan utilruntime.HandleError(err) p.printError(err.Error()) case <-p.complete: - klog.V(5).Infof("(conn=%v, request=%s) successfully received error and data streams", h.conn, p.requestID) + klog.V(5).InfoS("Connection request successfully received error and data streams", "connection", h.conn, "request", p.requestID) } h.removeStreamPair(p.requestID) } @@ -170,7 +170,7 @@ func (h *httpStreamHandler) removeStreamPair(requestID string) { func (h *httpStreamHandler) requestID(stream httpstream.Stream) string { requestID := stream.Headers().Get(api.PortForwardRequestIDHeader) if len(requestID) == 0 { - klog.V(5).Infof("(conn=%p) stream received without %s header", h.conn, api.PortForwardRequestIDHeader) + klog.V(5).InfoS("Connection stream received without requestID header", "connection", h.conn) // If we get here, it's because the connection came from an older client // that isn't generating the request id header // (https://github.com/kubernetes/kubernetes/blob/843134885e7e0b360eb5441e85b1410a8b1a7a0c/pkg/client/unversioned/portforward/portforward.go#L258-L287) @@ -197,7 +197,7 @@ func (h *httpStreamHandler) requestID(stream httpstream.Stream) string { requestID = strconv.Itoa(int(stream.Identifier()) - 2) } - klog.V(5).Infof("(conn=%p) automatically assigning request ID=%q from stream type=%s, stream ID=%d", h.conn, requestID, streamType, stream.Identifier()) + klog.V(5).InfoS("Connection automatically assigning request ID from stream type and stream ID", "connection", h.conn, "request", requestID, "streamType", streamType, "stream", stream.Identifier()) } return requestID } @@ -206,17 +206,17 @@ func (h *httpStreamHandler) requestID(stream httpstream.Stream) string { // streams, invoking portForward for each complete stream pair. The loop exits // when the httpstream.Connection is closed. func (h *httpStreamHandler) run() { - klog.V(5).Infof("(conn=%p) waiting for port forward streams", h.conn) + klog.V(5).InfoS("Connection waiting for port forward streams", "connection", h.conn) Loop: for { select { case <-h.conn.CloseChan(): - klog.V(5).Infof("(conn=%p) upgraded connection closed", h.conn) + klog.V(5).InfoS("Connection upgraded connection closed", "connection", h.conn) break Loop case stream := <-h.streamChan: requestID := h.requestID(stream) streamType := stream.Headers().Get(api.StreamType) - klog.V(5).Infof("(conn=%p, request=%s) received new stream of type %s", h.conn, requestID, streamType) + klog.V(5).InfoS("Connection request received new type of stream", "connection", h.conn, "request", requestID, "streamType", streamType) p, created := h.getStreamPair(requestID) if created { @@ -242,9 +242,9 @@ func (h *httpStreamHandler) portForward(p *httpStreamPair) { portString := p.dataStream.Headers().Get(api.PortHeader) port, _ := strconv.ParseInt(portString, 10, 32) - klog.V(5).Infof("(conn=%p, request=%s) invoking forwarder.PortForward for port %s", h.conn, p.requestID, portString) + klog.V(5).InfoS("Connection request invoking forwarder.PortForward for port", "connection", h.conn, "request", p.requestID, "port", portString) err := h.forwarder.PortForward(h.pod, h.uid, int32(port), p.dataStream) - klog.V(5).Infof("(conn=%p, request=%s) done invoking forwarder.PortForward for port %s", h.conn, p.requestID, portString) + klog.V(5).InfoS("Connection request done invoking forwarder.PortForward for port", "connection", h.conn, "request", p.requestID, "port", portString) if err != nil { msg := fmt.Errorf("error forwarding port %d to pod %s, uid %v: %v", port, h.pod, h.uid, err) diff --git a/pkg/kubelet/cri/streaming/portforward/websocket.go b/pkg/kubelet/cri/streaming/portforward/websocket.go index 8b5428cb6d8..d62d9d3f05f 100644 --- a/pkg/kubelet/cri/streaming/portforward/websocket.go +++ b/pkg/kubelet/cri/streaming/portforward/websocket.go @@ -185,9 +185,9 @@ func (h *websocketStreamHandler) portForward(p *websocketStreamPair) { defer p.dataStream.Close() defer p.errorStream.Close() - klog.V(5).Infof("(conn=%p) invoking forwarder.PortForward for port %d", h.conn, p.port) + klog.V(5).InfoS("Connection invoking forwarder.PortForward for port", "connection", h.conn, "port", p.port) err := h.forwarder.PortForward(h.pod, h.uid, p.port, p.dataStream) - klog.V(5).Infof("(conn=%p) done invoking forwarder.PortForward for port %d", h.conn, p.port) + klog.V(5).InfoS("Connection done invoking forwarder.PortForward for port", "connection", h.conn, "port", p.port) if err != nil { msg := fmt.Errorf("error forwarding port %d to pod %s, uid %v: %v", p.port, h.pod, h.uid, err) diff --git a/pkg/kubelet/cri/streaming/remotecommand/httpstream.go b/pkg/kubelet/cri/streaming/remotecommand/httpstream.go index 9be6c4345e2..c1054152d35 100644 --- a/pkg/kubelet/cri/streaming/remotecommand/httpstream.go +++ b/pkg/kubelet/cri/streaming/remotecommand/httpstream.go @@ -54,7 +54,7 @@ func NewOptions(req *http.Request) (*Options, error) { stderr := req.FormValue(api.ExecStderrParam) == "1" if tty && stderr { // TODO: make this an error before we reach this method - klog.V(4).Infof("Access to exec with tty and stderr is not supported, bypassing stderr") + klog.V(4).InfoS("Access to exec with tty and stderr is not supported, bypassing stderr") stderr = false } @@ -155,7 +155,7 @@ func createHTTPStreamStreams(req *http.Request, w http.ResponseWriter, opts *Opt case remotecommandconsts.StreamProtocolV2Name: handler = &v2ProtocolHandler{} case "": - klog.V(4).Infof("Client did not request protocol negotiation. Falling back to %q", remotecommandconsts.StreamProtocolV1Name) + klog.V(4).InfoS("Client did not request protocol negotiation. Falling back", "protocol", remotecommandconsts.StreamProtocolV1Name) fallthrough case remotecommandconsts.StreamProtocolV1Name: handler = &v1ProtocolHandler{}