From 112ba70490a840529563ef9e325d3e7021c1534b Mon Sep 17 00:00:00 2001 From: Sridhar Seshasayee Date: Tue, 24 Jul 2018 12:15:31 +0530 Subject: [PATCH] Pass original context to trace volume create steps across grpc nodes. Pass the original context to the runStepOn() function so that it can be used by the opensensus grpc plugin to trace the calls on other nodes in the gluster cluster. Also, append the requestID to the span info in addition to the associated function name so that the operation can be identified on the tracing UI application. Signed-off-by: Sridhar Seshasayee --- glusterd2/transaction/rpc-client.go | 4 ++-- glusterd2/transaction/rpc-service.go | 8 ++++++++ glusterd2/transaction/step.go | 2 +- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/glusterd2/transaction/rpc-client.go b/glusterd2/transaction/rpc-client.go index 5a5b8a2d0..373ac901c 100644 --- a/glusterd2/transaction/rpc-client.go +++ b/glusterd2/transaction/rpc-client.go @@ -16,7 +16,7 @@ import ( ) // runStepOn will run the step on the specified node -func runStepOn(step string, node uuid.UUID, c TxnCtx) error { +func runStepOn(origCtx netctx.Context, step string, node uuid.UUID, c TxnCtx) error { // TODO: I'm creating connections on demand. This should be changed so that // we have long term connections. p, err := peer.GetPeerF(node.String()) @@ -73,7 +73,7 @@ func runStepOn(step string, node uuid.UUID, c TxnCtx) error { var rsp *TxnStepResp - rsp, err = client.RunStep(netctx.TODO(), req) + rsp, err = client.RunStep(origCtx, req) if err != nil { logger.WithFields(log.Fields{ "error": err, diff --git a/glusterd2/transaction/rpc-service.go b/glusterd2/transaction/rpc-service.go index e040d7d98..bec886871 100644 --- a/glusterd2/transaction/rpc-service.go +++ b/glusterd2/transaction/rpc-service.go @@ -7,6 +7,7 @@ import ( "github.com/gluster/glusterd2/glusterd2/servers/peerrpc" log "github.com/sirupsen/logrus" + "go.opencensus.io/trace" "golang.org/x/net/context" "google.golang.org/grpc" ) @@ -37,6 +38,13 @@ func (p *txnSvc) RunStep(rpcCtx context.Context, req *TxnStepReq) (*TxnStepResp, logger = ctx.Logger().WithField("stepfunc", req.StepFunc) logger.Debug("RunStep request received") + if rpcCtx != nil { + reqID := ctx.GetTxnReqID() + spanName := req.StepFunc + " ReqID:" + reqID + _, span := trace.StartSpan(rpcCtx, spanName) + defer span.End() + } + f, ok = getStepFunc(req.StepFunc) if !ok { err = errors.New("step function not found in registry") diff --git a/glusterd2/transaction/step.go b/glusterd2/transaction/step.go index 2c8246c94..da2441377 100644 --- a/glusterd2/transaction/step.go +++ b/glusterd2/transaction/step.go @@ -139,7 +139,7 @@ func runStepFuncOnNode(origCtx context.Context, stepName string, ctx TxnCtx, nod err = runStepFuncLocally(origCtx, stepName, ctx) } else { // remote node - err = runStepOn(stepName, node, ctx) + err = runStepOn(origCtx, stepName, node, ctx) } respCh <- stepPeerResp{node, err}