Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

Commit

Permalink
agent-client: include log in agent client
Browse files Browse the repository at this point in the history
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 <penny.zheng@arm.com>
  • Loading branch information
Pennyzct committed Jan 30, 2020
1 parent a44d555 commit accab34
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion protocols/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"fmt"
"net"
"net/url"
"os"
"strconv"
"strings"
"time"
Expand All @@ -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"
Expand All @@ -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
Expand Down Expand Up @@ -413,15 +423,19 @@ func HybridVSockDialer(sock string, timeout time.Duration) (net.Conn, error) {
// - [host] CONNECT <port><LF>
// - [guest/success] OK <assigned_host_port><LF>
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
}
Expand Down

0 comments on commit accab34

Please sign in to comment.