diff --git a/main.go b/main.go index f7ad03e..8035a88 100644 --- a/main.go +++ b/main.go @@ -67,7 +67,7 @@ func main() { conf.GetConfig().Logs, ) - logger = logs.CreateLogger("oc-monitord") + logger = u.GetLogger() logger.Debug().Msg("Loki URL : " + conf.GetConfig().LokiURL) logger.Debug().Msg("Workflow executed : " + conf.GetConfig().ExecutionID) @@ -124,13 +124,16 @@ func executeInside(execID string, ns string, argo_file_path string, stepMax int) t, err := tools2.NewService(conf.GetConfig().Mode) if err != nil { logger.Error().Msg("Could not create KubernetesTool") + return } + name, err := t.CreateArgoWorkflow(argo_file_path, ns) + if err != nil { logger.Error().Msg("Could not create argo workflow : " + err.Error()) + return } else { - split := strings.Split(argo_file_path, "_") - argoLogs := models.NewArgoLogs(split[0], "argo", stepMax) + argoLogs := models.NewArgoLogs(workflowName, "argo", stepMax) argoLogs.StartStepRecording(argoLogs.NewWatch(), wf_logger) err := t.LogWorkflow(execID, ns, name, argo_file_path, stepMax, argoLogs.NewWatch(), argoLogs.NewWatch(), argoLogs, []string{}, logWorkflow) if err != nil { diff --git a/tools/kubernetes.go b/tools/kubernetes.go index 2b096be..794cbcd 100644 --- a/tools/kubernetes.go +++ b/tools/kubernetes.go @@ -66,6 +66,8 @@ func (k *KubernetesTools) LogWorkflow(execID string, namespace string, workflowN return errors.New("Could not retrieve workflow ID from execution ID " + execID) } if exec.State == enum.DRAFT || exec.State == enum.FAILURE || exec.State == enum.SUCCESS { + l := utils.GetWFLogger("") + l.Error().Msg("The execution's state doesn't meet requirement, state is : " + exec.State.String()) return nil } k.logWorkflow(namespace, workflowName, argoFilePath, stepMax, current_watch, previous_watch, argoLogs, seen, logFunc) @@ -76,6 +78,7 @@ func (k *KubernetesTools) logWorkflow(namespace string, workflowName string, arg seen []string, logFunc func(argoFilePath string, stepMax int, pipe io.ReadCloser, current_watch *models.ArgoWatch, previous_watch *models.ArgoWatch, argoLogs *models.ArgoLogs, seen []string, wg *sync.WaitGroup)) error { // List pods related to the Argo workflow + fmt.Println("\n!!!!!!!! !!!!!!!!!! !!!!!!!! &&&& & STARTING LOG\n\n") labelSelector := fmt.Sprintf("workflows.argoproj.io/workflow=%s", workflowName) for retries := 0; retries < 10; retries++ { // Retry for up to ~20 seconds // List workflow pods diff --git a/utils/utils.go b/utils/utils.go index 1222230..b926e5a 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -2,11 +2,21 @@ package utils import ( "oc-monitord/conf" + "sync" oclib "cloud.o-forge.io/core/oc-lib" + "cloud.o-forge.io/core/oc-lib/logs" "cloud.o-forge.io/core/oc-lib/models/workflow_execution" + "github.com/rs/zerolog" ) +var ( + logger zerolog.Logger + wf_logger zerolog.Logger + pods_logger zerolog.Logger + onceLogger sync.Once + onceWF sync.Once +) func GetExecution(exec_id string) *workflow_execution.WorkflowExecution { res := oclib.NewRequest(oclib.LibDataEnum(oclib.WORKFLOW_EXECUTION), "", conf.GetConfig().PeerID, []string{}, nil).LoadOne(exec_id) if res.Code != 200 { @@ -16,3 +26,17 @@ func GetExecution(exec_id string) *workflow_execution.WorkflowExecution { } return res.ToWorkflowExecution() } + +func GetLogger() zerolog.Logger { + onceLogger.Do(func(){ + logger = logs.CreateLogger("oc-monitord") + }) + return logger +} + +func GetWFLogger(workflowName string) zerolog.Logger { + onceWF.Do(func(){ + wf_logger = logger.With().Str("argo_name", workflowName).Str("workflow_id", conf.GetConfig().WorkflowID).Str("workflow_execution_id", conf.GetConfig().ExecutionID).Logger() + }) + return wf_logger +} \ No newline at end of file