fn: add context into to logger passed to DialWithBackoff (#1133)

This commit is contained in:
Tolga Ceylan
2018-07-23 13:05:30 -07:00
committed by GitHub
parent 3d60c9c6be
commit fc71208063

View File

@@ -20,7 +20,6 @@ import (
"github.com/fnproject/fn/grpcutil" "github.com/fnproject/fn/grpcutil"
pb_empty "github.com/golang/protobuf/ptypes/empty" pb_empty "github.com/golang/protobuf/ptypes/empty"
"github.com/sirupsen/logrus"
) )
var ( var (
@@ -61,14 +60,17 @@ func (r *gRPCRunner) Close(context.Context) error {
} }
func runnerConnection(address, runnerCertCN string, pki *pool.PKIData) (*grpc.ClientConn, pb.RunnerProtocolClient, error) { func runnerConnection(address, runnerCertCN string, pki *pool.PKIData) (*grpc.ClientConn, pb.RunnerProtocolClient, error) {
ctx := context.Background() ctx := context.Background()
logger := common.Logger(ctx).WithField("runner_addr", address)
ctx = common.WithLogger(ctx, logger)
var creds credentials.TransportCredentials var creds credentials.TransportCredentials
if pki != nil { if pki != nil {
var err error var err error
creds, err = grpcutil.CreateCredentials(pki.Cert, pki.Key, pki.Ca, runnerCertCN) creds, err = grpcutil.CreateCredentials(pki.Cert, pki.Key, pki.Ca, runnerCertCN)
if err != nil { if err != nil {
logrus.WithError(err).Error("Unable to create credentials to connect to runner node") logger.WithError(err).Error("Unable to create credentials to connect to runner node")
return nil, nil, err return nil, nil, err
} }
} }
@@ -76,11 +78,11 @@ func runnerConnection(address, runnerCertCN string, pki *pool.PKIData) (*grpc.Cl
// we want to set a very short timeout to fail-fast if something goes wrong // we want to set a very short timeout to fail-fast if something goes wrong
conn, err := grpcutil.DialWithBackoff(ctx, address, creds, 100*time.Millisecond, grpc.DefaultBackoffConfig) conn, err := grpcutil.DialWithBackoff(ctx, address, creds, 100*time.Millisecond, grpc.DefaultBackoffConfig)
if err != nil { if err != nil {
logrus.WithError(err).Error("Unable to connect to runner node") logger.WithError(err).Error("Unable to connect to runner node")
} }
protocolClient := pb.NewRunnerProtocolClient(conn) protocolClient := pb.NewRunnerProtocolClient(conn)
logrus.WithField("runner_addr", address).Info("Connected to runner") logger.Info("Connected to runner")
return conn, protocolClient, nil return conn, protocolClient, nil
} }