From 1b72324f050b41f416c3d56d597dbef7731ac3a1 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 26 Nov 2024 12:17:53 +0100 Subject: [PATCH] fixup! wip to add progress context for messages --- pkg/osbuildmonitor/monitor.go | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/pkg/osbuildmonitor/monitor.go b/pkg/osbuildmonitor/monitor.go index adbbf48d61..2b7c24f5c4 100644 --- a/pkg/osbuildmonitor/monitor.go +++ b/pkg/osbuildmonitor/monitor.go @@ -62,6 +62,7 @@ func NewStatusScanner(r io.Reader) *StatusScanner { return &StatusScanner{ scanner: bufio.NewScanner(r), pipelineContextMap: make(map[string]*contextJSON), + stageContextMap: make(map[string]*stageContextJSON), } } @@ -69,6 +70,7 @@ func NewStatusScanner(r io.Reader) *StatusScanner { type StatusScanner struct { scanner *bufio.Scanner pipelineContextMap map[string]*contextJSON + stageContextMap map[string]*stageContextJSON } // Status returns a single status struct from the scanner or nil @@ -90,24 +92,35 @@ func (sr *StatusScanner) Status() (*Status, error) { pipelineContext := sr.pipelineContextMap[id] if pipelineContext == nil { sr.pipelineContextMap[id] = &status.Context + pipelineContext = &status.Context } ts := time.UnixMilli(int64(status.Timestamp * 1000)) + pipelineName := pipelineContext.Pipeline.Name st := &Status{ Trace: strings.TrimSpace(status.Message), Progress: &Progress{ - Done: status.Progress.Done, - Total: status.Progress.Total, + Done: status.Progress.Done, + Total: status.Progress.Total, + Message: pipelineName, }, Timestamp: ts, } // add subprogress + stageID := pipelineContext.Pipeline.Stage.ID + stageContext := sr.stageContextMap[stageID] + if stageContext == nil { + sr.stageContextMap[id] = &pipelineContext.Pipeline.Stage + stageContext = &pipelineContext.Pipeline.Stage + } + stageName := stageContext.Name prog := st.Progress for subProg := status.Progress.SubProgress; subProg != nil; subProg = subProg.SubProgress { prog.SubProgress = &Progress{ - Done: subProg.Done, - Total: subProg.Total, + Done: subProg.Done, + Total: subProg.Total, + Message: stageName, } prog = prog.SubProgress } @@ -131,15 +144,17 @@ type statusJSON struct { type contextJSON struct { Origin string `json:"origin"` Pipeline struct { - ID string `json:"id"` - Name string `json:"name"` - Stage struct { - Name string `json:"name"` - ID string `json:"id"` - } `json:"stage"` + ID string `json:"id"` + Name string `json:"name"` + Stage stageContextJSON `json:"stage"` } `json:"pipeline"` } +type stageContextJSON struct { + Name string `json:"name"` + ID string `json:"id"` +} + // progress is the progress information associcated with a given status. // The details about nesting are the same as for "Progress" above. type progressJSON struct {