logs for pods are better formatted

This commit is contained in:
pb 2025-04-10 11:10:16 +02:00
parent c31184e2ec
commit 27fd603e36
3 changed files with 31 additions and 9 deletions

View File

@ -147,7 +147,7 @@ func executeOutside(argo_file_path string, stepMax int, workflow workflow_builde
var wg sync.WaitGroup
var err error
logger.Debug().Msg("executing :" + "argo submit --watch " + argo_file_path + " --serviceaccount sa-" + conf.GetConfig().ExecutionID + " -n " + conf.GetConfig().ExecutionID)
logger.Debug().Msg("executing :" + "argo submit --watch " + argo_file_path + " --serviceaccount sa-" + conf.GetConfig().ExecutionID + " -n " + conf.GetConfig().ExecutionID )
cmdSubmit := exec.Command("argo", "submit", "--watch", argo_file_path, "--serviceaccount", "sa-"+conf.GetConfig().ExecutionID, "-n", conf.GetConfig().ExecutionID)
if stdoutSubmit, err = cmdSubmit.StdoutPipe(); err != nil {
@ -169,14 +169,14 @@ func executeOutside(argo_file_path string, stepMax int, workflow workflow_builde
steps = append(steps, template.Name)
}
cmdLogs := exec.Command("argo", "logs", "oc-monitor-"+workflowName, "-n", conf.GetConfig().ExecutionID, "--follow")
cmdLogs := exec.Command("argo", "logs", "oc-monitor-"+workflowName, "-n", conf.GetConfig().ExecutionID, "--follow","--no-color")
if stdoutLogs, err = cmdLogs.StdoutPipe(); err != nil {
wf_logger.Error().Msg("Could not retrieve stdoutpipe for 'argo logs'" + err.Error())
return
}
go models.LogLocalWorkflow(workflowName, stdoutSubmit, &wg)
go models.LogPods(stdoutLogs, steps, &wg)
go models.LogPods(workflowName, stdoutLogs, steps, &wg)
fmt.Println("Starting argo submit")
if err := cmdSubmit.Start(); err != nil {
@ -189,7 +189,8 @@ func executeOutside(argo_file_path string, stepMax int, workflow workflow_builde
fmt.Println("Running argo logs")
if err := cmdLogs.Run(); err != nil {
wf_logger.Error().Msg("Could not run 'argo logs oc-monitor-" + workflowName + " -n " + conf.GetConfig().ExecutionID + " --follow")
wf_logger.Error().Msg("Could not run '" + strings.Join(cmdLogs.Args, " ") + "'")
wf_logger.Fatal().Msg(err.Error() + bufio.NewScanner(stderrLogs).Text())
}

View File

@ -145,3 +145,17 @@ func (a *ArgoLogs) StopStepRecording(current *ArgoWatch) *ArgoWatch {
current.Status = status
return current
}
type ArgoPodLog struct {
PodName string
Step string
Message string
}
func NewArgoPodLog(name string, step string, msg string) ArgoPodLog {
return ArgoPodLog{
PodName: name,
Step: step,
Message: msg,
}
}

View File

@ -18,7 +18,7 @@ var wfLogger zerolog.Logger
// Take the slice of string that make up one round of stderr outputs from the --watch option in argo submit
func NewLocalArgoLogs(inputs []string) *ArgoWatch {
func NewLocalArgoWatch(inputs []string) *ArgoWatch {
var workflow ArgoWatch
for _, input := range inputs {
@ -84,7 +84,7 @@ func LogLocalWorkflow(wfName string, pipe io.ReadCloser, wg *sync.WaitGroup) {
// Log the progress of the WF
if strings.HasPrefix(log, "Progress:") {
current_watch = *NewLocalArgoLogs(watch_output)
current_watch = *NewLocalArgoWatch(watch_output)
workflowName := current_watch.Name
if !current_watch.Equals(&previous_watch) {
wg.Add(1)
@ -106,17 +106,24 @@ func LogLocalWorkflow(wfName string, pipe io.ReadCloser, wg *sync.WaitGroup) {
}
// Debug, no logs sent
func LogPods(pipe io.ReadCloser, steps []string, wg *sync.WaitGroup) {
func LogPods(wfName string, pipe io.ReadCloser, steps []string, wg *sync.WaitGroup) {
scanner := bufio.NewScanner(pipe)
for scanner.Scan() {
var podLogger zerolog.Logger
fmt.Println("new line")
wg.Add(1)
var podLogger zerolog.Logger
line := scanner.Text()
podName := strings.Split(line, ":")[0]
podLogger = wfLogger.With().Str("step_name", getStepName(podName, steps)).Logger()
log := strings.Split(line,podName+":")[1]
podLogger.Info().Msg(log)
podLog := NewArgoPodLog(wfName,podName,log)
jsonifiedLog, err := json.Marshal(podLog)
if err != nil {
podLogger.Fatal().Msg(err.Error())
}
podLogger.Info().Msg(string(jsonifiedLog))
wg.Done()
}