Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed log message format #263

Merged
merged 2 commits into from
Aug 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions grpc-server/tinkerbell.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package grpcserver

import (
"context"
"fmt"
"strconv"
"time"

"github.com/tinkerbell/tink/db"
Expand All @@ -21,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 @@ -90,7 +92,8 @@ func (s *server) ReportActionStatus(context context.Context, req *pb.WorkflowAct
return nil, status.Errorf(codes.InvalidArgument, errInvalidActionName)
}

logger.Info(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 @@ -130,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(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 Expand Up @@ -218,12 +231,12 @@ func isApplicableToSend(context context.Context, wfContext *pb.WorkflowContext,
}
if wfContext.GetCurrentActionIndex() == 0 {
if actions.ActionList[wfContext.GetCurrentActionIndex()+1].GetWorkerId() == workerID {
logger.Info(msgSendWfContext, wfContext.GetWorkflowId())
logger.Info(fmt.Sprintf(msgSendWfContext, wfContext.GetWorkflowId()))
return true
}
}
} else if actions.ActionList[wfContext.GetCurrentActionIndex()].GetWorkerId() == workerID {
logger.Info(msgSendWfContext, wfContext.GetWorkflowId())
logger.Info(fmt.Sprintf(msgSendWfContext, wfContext.GetWorkflowId()))
return true

}
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
}