Skip to content

Commit

Permalink
adding sensible data to logs
Browse files Browse the repository at this point in the history
Signed-off-by: Gaurav Gahlot <[email protected]>
  • Loading branch information
gauravgahlot committed Aug 21, 2020
1 parent cde2736 commit 638dd56
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 12 deletions.
18 changes: 15 additions & 3 deletions grpc-server/tinkerbell.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package grpcserver
import (
"context"
"fmt"
"strconv"
"time"

"github.com/tinkerbell/tink/db"
Expand All @@ -22,7 +23,7 @@ const (
errInvalidActionReported = "reported action name does not match the current action details"

msgReceivedStatus = "received action status: %s"
msgCurrentWfContext = "current workflow context: %s"
msgCurrentWfContext = "current workflow context"
msgSendWfContext = "send workflow context: %s"
)

Expand Down Expand Up @@ -91,7 +92,8 @@ func (s *server) ReportActionStatus(context context.Context, req *pb.WorkflowAct
return nil, status.Errorf(codes.InvalidArgument, errInvalidActionName)
}

logger.Info(fmt.Sprintf(msgReceivedStatus, req.GetActionStatus()))
l := logger.With("actionName", req.GetActionName(), "workflowID", req.GetWorkflowId())
l.Info(fmt.Sprintf(msgReceivedStatus, req.GetActionStatus()))

wfContext, err := s.db.GetWorkflowContexts(context, wfID)
if err != nil {
Expand Down Expand Up @@ -131,7 +133,17 @@ func (s *server) ReportActionStatus(context context.Context, req *pb.WorkflowAct
if err != nil {
return &pb.Empty{}, status.Error(codes.Aborted, err.Error())
}
logger.Info(fmt.Sprintf(msgCurrentWfContext, wfContext))

l = logger.With(
"workflowID", wfContext.GetWorkflowId(),
"currentWorker", wfContext.GetCurrentWorker(),
"currentTask", wfContext.GetCurrentTask(),
"currentAction", wfContext.GetCurrentAction(),
"currentActionIndex", strconv.FormatInt(wfContext.GetCurrentActionIndex(), 10),
"currentActionState", wfContext.GetCurrentActionState(),
"totalNumberOfActions", wfContext.GetTotalNumberOfActions(),
)
l.Info(msgCurrentWfContext)
return &pb.Empty{}, nil
}

Expand Down
28 changes: 19 additions & 9 deletions grpc-server/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"bytes"
"context"
"encoding/json"
"fmt"
"strconv"
"text/template"

"github.com/pkg/errors"
Expand Down Expand Up @@ -34,7 +34,6 @@ func (s *server) CreateWorkflow(ctx context.Context, in *workflow.CreateRequest)
labels["op"] = "createworkflow"
msg = "creating a new workflow"
id := uuid.NewV4()
//var data string
fn := func() error {
wf := db.Workflow{
ID: id.String(),
Expand All @@ -59,7 +58,6 @@ func (s *server) CreateWorkflow(ctx context.Context, in *workflow.CreateRequest)

logger.Info(msg)
err := fn()
logger.Info("done " + msg)
if err != nil {
metrics.CacheErrors.With(labels).Inc()
l := logger
Expand All @@ -69,6 +67,8 @@ func (s *server) CreateWorkflow(ctx context.Context, in *workflow.CreateRequest)
l.Error(err)
return &workflow.CreateResponse{}, err
}
l := logger.With("workflowID", id.String())
l.Info("done " + msg)
return &workflow.CreateResponse{Id: id.String()}, err
}

Expand All @@ -90,7 +90,6 @@ func (s *server) GetWorkflow(ctx context.Context, in *workflow.GetRequest) (*wor

logger.Info(msg)
w, err := fn()
logger.Info("done " + msg)
if err != nil {
metrics.CacheErrors.With(labels).Inc()
l := logger
Expand All @@ -110,6 +109,8 @@ func (s *server) GetWorkflow(ctx context.Context, in *workflow.GetRequest) (*wor
State: state[w.State],
Data: yamlData,
}
l := logger.With("workflowID", w.ID)
l.Info("done " + msg)
return wf, err
}

Expand All @@ -122,6 +123,7 @@ func (s *server) DeleteWorkflow(ctx context.Context, in *workflow.GetRequest) (*

msg := ""
labels["op"] = "delete"
l := logger.With("workflowID", in.GetId())
msg = "deleting a workflow"
fn := func() error {
// update only if not in running state
Expand All @@ -132,9 +134,8 @@ func (s *server) DeleteWorkflow(ctx context.Context, in *workflow.GetRequest) (*
timer := prometheus.NewTimer(metrics.CacheDuration.With(labels))
defer timer.ObserveDuration()

logger.Info(msg)
l.Info(msg)
err := fn()
logger.Info("done " + msg)
if err != nil {
metrics.CacheErrors.With(labels).Inc()
l := logger
Expand All @@ -143,6 +144,7 @@ func (s *server) DeleteWorkflow(ctx context.Context, in *workflow.GetRequest) (*
}
l.Error(err)
}
l.Info("done " + msg)
return &workflow.Empty{}, err
}

Expand Down Expand Up @@ -201,7 +203,6 @@ func (s *server) GetWorkflowContext(ctx context.Context, in *workflow.GetRequest

logger.Info(msg)
w, err := fn()
logger.Info("done " + msg)
if err != nil {
metrics.CacheErrors.With(labels).Inc()
l := logger
Expand All @@ -219,6 +220,16 @@ func (s *server) GetWorkflowContext(ctx context.Context, in *workflow.GetRequest
CurrentActionState: workflow.ActionState(w.CurrentActionState),
TotalNumberOfActions: w.TotalNumberOfActions,
}
l := logger.With(
"workflowID", wf.GetWorkflowId(),
"currentWorker", wf.GetCurrentWorker(),
"currentTask", wf.GetCurrentTask(),
"currentAction", wf.GetCurrentAction(),
"currentActionIndex", strconv.FormatInt(wf.GetCurrentActionIndex(), 10),
"currentActionState", wf.GetCurrentActionState(),
"totalNumberOfActions", wf.GetTotalNumberOfActions(),
)
l.Info("done " + msg)
return wf, err
}

Expand Down Expand Up @@ -257,7 +268,7 @@ func (s *server) ShowWorkflowEvents(req *workflow.GetRequest, stream workflow.Wo
metrics.CacheErrors.With(labels).Inc()
return err
}
logger.Info("Done Listing workflows Events")
logger.Info("done listing workflows events")
metrics.CacheHits.With(labels).Inc()
return nil
}
Expand Down Expand Up @@ -290,6 +301,5 @@ func renderTemplate(tempData string, devices []byte) (string, error) {
if err != nil {
return "", nil
}
fmt.Println(buf.String())
return buf.String(), nil
}

0 comments on commit 638dd56

Please sign in to comment.