Skip to content

Commit

Permalink
feat(server): server logs to be structured and add more log error #2308
Browse files Browse the repository at this point in the history
… (#9779)

Signed-off-by: Lam Vu <lamvh2812@gmail.com>
Signed-off-by: Lam Vu <lvu@axon.com>
Co-authored-by: Lam Vu <lvu@axon.com>
  • Loading branch information
VUHAILAM and Lam Vu committed Oct 10, 2022
1 parent f27fe08 commit 514aa05
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
15 changes: 8 additions & 7 deletions server/apiserver/argoserver.go
Expand Up @@ -118,7 +118,7 @@ func init() {
var err error
MaxGRPCMessageSize, err = env.GetInt("GRPC_MESSAGE_SIZE", 100*1024*1024)
if err != nil {
log.Fatalf("GRPC_MESSAGE_SIZE environment variable must be set as an integer: %v", err)
log.WithError(err).Fatal("GRPC_MESSAGE_SIZE environment variable must be set as an integer")
}
}

Expand Down Expand Up @@ -212,7 +212,7 @@ func (as *argoServer) Run(ctx context.Context, port int, browserOpenFunc func(st
// like and the controller won't offload newly created workflows, but you can still read them
offloadRepo, err = sqldb.NewOffloadNodeStatusRepo(session, persistence.GetClusterName(), tableName)
if err != nil {
log.Fatal(err)
log.WithError(err).Fatal(err.Error())
}
// we always enable the archive for the Argo Server, as the Argo Server does not write records, so you can
// disable the archiving - and still read old records
Expand All @@ -232,7 +232,7 @@ func (as *argoServer) Run(ctx context.Context, port int, browserOpenFunc func(st
err = wait.ExponentialBackoff(backoff, func() (bool, error) {
conn, listerErr = net.Listen("tcp", address)
if listerErr != nil {
log.Warnf("failed to listen: %v", listerErr)
log.WithError(err).Warn("failed to listen")
return false, nil
}
return true, nil
Expand Down Expand Up @@ -262,7 +262,7 @@ func (as *argoServer) Run(ctx context.Context, port int, browserOpenFunc func(st
log.WithFields(log.Fields{
"GRPC_MESSAGE_SIZE": MaxGRPCMessageSize,
}).Info("GRPC Server Max Message Size, MaxGRPCMessageSize, is set")
log.Infof("Argo Server started successfully on %s", url)
log.WithFields(log.Fields{"url": url}).Infof("Argo Server started successfully on %s", url)
browserOpenFunc(url)

<-as.stopCh
Expand Down Expand Up @@ -413,14 +413,15 @@ func mustRegisterGWHandler(register registerFunc, ctx context.Context, mux *runt

// checkServeErr checks the error from a .Serve() call to decide if it was a graceful shutdown
func (as *argoServer) checkServeErr(name string, err error) {
nameField := log.Fields{"name": name}
if err != nil {
if as.stopCh == nil {
// a nil stopCh indicates a graceful shutdown
log.Infof("graceful shutdown %s: %v", name, err)
log.WithFields(nameField).WithError(err).Info("graceful shutdown with error")
} else {
log.Fatalf("%s: %v", name, err)
log.WithFields(nameField).WithError(err).Fatalf("%s: %v", name, err)
}
} else {
log.Infof("graceful shutdown %s", name)
log.WithFields(nameField).Info("graceful shutdown")
}
}
2 changes: 1 addition & 1 deletion server/artifacts/artifact_server.go
Expand Up @@ -437,7 +437,7 @@ func (a *ArtifactServer) returnArtifact(w http.ResponseWriter, art *wfv1.Artifac

defer func() {
if err := stream.Close(); err != nil {
log.Warningf("Error closing stream[%s]: %v", stream, err)
log.WithFields(log.Fields{"stream": stream}).WithError(err).Warning("Error closing stream")
}
}()

Expand Down
6 changes: 3 additions & 3 deletions server/workflow/workflow_server.go
Expand Up @@ -80,10 +80,10 @@ func (s *workflowServer) CreateWorkflow(ctx context.Context, req *workflowpkg.Wo
if err != nil {
if apierr.IsServerTimeout(err) && req.Workflow.GenerateName != "" && req.Workflow.Name != "" {
errWithHint := fmt.Errorf(`create request failed due to timeout, but it's possible that workflow "%s" already exists. Original error: %w`, req.Workflow.Name, err)
log.Error(errWithHint)
log.WithError(errWithHint).Error(errWithHint.Error())
return nil, errWithHint
}
log.Errorf("Create request failed: %s", err)
log.WithError(err).Error("Create request failed")
return nil, err
}

Expand Down Expand Up @@ -395,7 +395,7 @@ func (s *workflowServer) ResumeWorkflow(ctx context.Context, req *workflowpkg.Wo

err = util.ResumeWorkflow(ctx, wfClient.ArgoprojV1alpha1().Workflows(req.Namespace), s.hydrator, wf.Name, req.NodeFieldSelector)
if err != nil {
log.Warnf("Failed to resume %s: %+v", wf.Name, err)
log.WithFields(log.Fields{"name": wf.Name}).WithError(err).Warn("Failed to resume")
return nil, err
}

Expand Down

0 comments on commit 514aa05

Please sign in to comment.