diff --git a/pkg/osbuildmonitor/monitor.go b/pkg/osbuildmonitor/monitor.go index adbbf48d61..963ac5914a 100644 --- a/pkg/osbuildmonitor/monitor.go +++ b/pkg/osbuildmonitor/monitor.go @@ -26,6 +26,11 @@ type Status struct { // running osbuild on a terminal Trace string + // XXX: add message and only add stuff that does not come + // directly from a stage? E.g. osbuild sends us + // "origin":"osbuild.monitor" message with nice context like + // "start foo" + // Progress contains the current progress. Progress *Progress @@ -62,6 +67,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 +75,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 +97,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 +149,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 {