Skip to content

Commit

Permalink
fixup! wip to add progress context for messages
Browse files Browse the repository at this point in the history
  • Loading branch information
mvo5 committed Nov 26, 2024
1 parent e2beeb8 commit f09dee0
Showing 1 changed file with 30 additions and 10 deletions.
40 changes: 30 additions & 10 deletions pkg/osbuildmonitor/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -62,13 +67,15 @@ func NewStatusScanner(r io.Reader) *StatusScanner {
return &StatusScanner{
scanner: bufio.NewScanner(r),
pipelineContextMap: make(map[string]*contextJSON),
stageContextMap: make(map[string]*stageContextJSON),
}
}

// StatusScanner scan scan the osbuild jsonseq monitor output
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
Expand All @@ -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
}
Expand All @@ -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 {
Expand Down

0 comments on commit f09dee0

Please sign in to comment.