From accab34f3713c8449a1c01bda69533ada0e6e0ca Mon Sep 17 00:00:00 2001 From: Penny Zheng Date: Mon, 6 Jan 2020 02:16:38 +0000 Subject: [PATCH] agent-client: include log in agent client This file is mainly used by kata-runtime and missing logging part. We add one new "agent-client" log field here, and Plz notice that, you should turn on the `kata-runtime` debug option to see the output. Fixes: #705 Depends-on: github.com/kata-containers/runtime#2379 Signed-off-by: Penny Zheng --- protocols/client/client.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/protocols/client/client.go b/protocols/client/client.go index fc77516fde..fb04cbab2b 100644 --- a/protocols/client/client.go +++ b/protocols/client/client.go @@ -12,6 +12,7 @@ import ( "fmt" "net" "net/url" + "os" "strconv" "strings" "time" @@ -20,6 +21,7 @@ import ( "github.com/hashicorp/yamux" "github.com/mdlayher/vsock" opentracing "github.com/opentracing/opentracing-go" + "github.com/sirupsen/logrus" "google.golang.org/grpc" "google.golang.org/grpc/codes" grpcStatus "google.golang.org/grpc/status" @@ -38,6 +40,14 @@ var defaultCloseTimeout = 5 * time.Second var hybridVSockPort uint32 +var agentClientFields = logrus.Fields{ + "name": "agent-client", + "pid": os.Getpid(), + "source": "agent-client", +} + +var agentClientLog = logrus.WithFields(agentClientFields) + // AgentClient is an agent gRPC client connection wrapper for agentgrpc.AgentServiceClient type AgentClient struct { agentgrpc.AgentServiceClient @@ -413,15 +423,19 @@ func HybridVSockDialer(sock string, timeout time.Duration) (net.Conn, error) { // - [host] CONNECT // - [guest/success] OK reader := bufio.NewReader(conn) - if response, err := reader.ReadString('\n'); err != nil { + response, err := reader.ReadString('\n') + if err != nil { conn.Close() + agentClientLog.WithField("Error", err).Debug("HybridVsock trivial handshake failed") // for now, we temporarily rely on the backoff strategy from GRPC for more stable CI. return conn, nil } else if !strings.Contains(response, "OK") { conn.Close() + agentClientLog.WithField("response", response).Debug("HybridVsock trivial handshake failed with malformd response code") // for now, we temporarily rely on the backoff strategy from GRPC for more stable CI. return conn, nil } + agentClientLog.WithField("response", response).Debug("HybridVsock trivial handshake") return conn, nil }