diff --git a/handler/setup.go b/handler/setup.go index d599732..ce81cd5 100644 --- a/handler/setup.go +++ b/handler/setup.go @@ -18,9 +18,12 @@ import ( "github.com/harness/harness-docker-runner/engine/docker" "github.com/harness/harness-docker-runner/engine/spec" "github.com/harness/harness-docker-runner/executor" + "github.com/harness/harness-docker-runner/livelog" "github.com/harness/harness-docker-runner/logger" "github.com/harness/harness-docker-runner/pipeline" prruntime "github.com/harness/harness-docker-runner/pipeline/runtime" + + "github.com/sirupsen/logrus" ) // random generator function @@ -56,6 +59,28 @@ func HandleSetup() http.HandlerFunc { // s.LogConfig.URL = "http://localhost:8079" state.Set(s.Volumes, s.Secrets, s.LogConfig, s.TIConfig, s.SetupRequestConfig.Network.ID) + log := logrus.New() + var logr *logrus.Entry + if s.LogConfig.URL == "" { + log.Out = os.Stdout + } else { + client := state.GetLogStreamClient() + wc := livelog.New(client, s.LogKey, id, nil) + defer func() { + if err := wc.Close(); err != nil { + logrus.WithError(err).Debugln("failed to close log stream") + } + }() + + log.Out = wc + log.SetLevel(logrus.TraceLevel) + } + logr = log.WithField("id", s.ID). + WithField("correlation_id", s.CorrelationID) + + logr.Traceln("starting setup execution") + logger.FromRequest(r).Traceln("starting the setup process") + if s.MountDockerSocket == nil || *s.MountDockerSocket { // required to support m1 where docker isn't installed. s.Volumes = append(s.Volumes, getDockerSockVolume()) } @@ -89,8 +114,6 @@ func HandleSetup() http.HandlerFunc { return } - logger.FromRequest(r).Traceln("starting the setup process") - if err := engine.Setup(r.Context(), cfg); err != nil { logger.FromRequest(r).WithError(err). WithField("latency", time.Since(st)). @@ -101,13 +124,14 @@ func HandleSetup() http.HandlerFunc { return } - logger.FromRequest(r).Traceln("completed the setup process") - WriteJSON(w, api.SetupResponse{IPAddress: "127.0.0.1"}, http.StatusOK) logger.FromRequest(r). WithField("latency", time.Since(st)). WithField("time", time.Now().Format(time.RFC3339)). Infoln("api: successfully completed the stage setup") + + logger.FromRequest(r).Traceln("completed the setup process") + logr.Traceln("completed the setup process") } } diff --git a/handler/step.go b/handler/step.go index ca51432..8657758 100644 --- a/handler/step.go +++ b/handler/step.go @@ -80,7 +80,8 @@ func HandleStartStep() http.HandlerFunc { pollResp, err := stageData.StepExecutor.PollStep(ctx, &api.PollStepRequest{ID: s.ID}) logger.FromRequest(r).WithField("stage_id", s.StageRuntimeID). - WithField("step_id", s.ID).Traceln("received polling response") + WithField("step_id", s.ID).WithField("poll_response", pollResp). + Traceln("received polling response") if err != nil { WriteJSON(w, convert(err), http.StatusOK) return diff --git a/server/server.go b/server/server.go index c1e7079..669401c 100644 --- a/server/server.go +++ b/server/server.go @@ -37,6 +37,7 @@ func (s *Server) Start(ctx context.Context) error { logrus.Infof("Runner version: %s", version.Version) var tlsConfig *tls.Config + logrus.Infof("Runner version: %s", version.Version) if s.Insecure { tlsConfig = nil logrus.Warnln("RUNNING IN INSECURE MODE")