Skip to content

Commit

Permalink
fixup! use context-id instead of pipeline id
Browse files Browse the repository at this point in the history
  • Loading branch information
mvo5 committed Nov 28, 2024
1 parent f09dee0 commit 4fb489f
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 27 deletions.
35 changes: 18 additions & 17 deletions pkg/osbuildmonitor/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,17 @@ type Progress struct {
// jsonseq monitor status messages
func NewStatusScanner(r io.Reader) *StatusScanner {
return &StatusScanner{
scanner: bufio.NewScanner(r),
pipelineContextMap: make(map[string]*contextJSON),
stageContextMap: make(map[string]*stageContextJSON),
scanner: bufio.NewScanner(r),
contextMap: 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
scanner *bufio.Scanner
contextMap map[string]*contextJSON
stageContextMap map[string]*stageContextJSON
}

// Status returns a single status struct from the scanner or nil
Expand All @@ -93,33 +93,33 @@ func (sr *StatusScanner) Status() (*Status, error) {
}
// keep track of the context
// XXX: needs a test
id := status.Context.Pipeline.ID
pipelineContext := sr.pipelineContextMap[id]
if pipelineContext == nil {
sr.pipelineContextMap[id] = &status.Context
pipelineContext = &status.Context
id := status.Context.ID
context := sr.contextMap[id]
if context == nil {
sr.contextMap[id] = &status.Context
context = &status.Context
}
ts := time.UnixMilli(int64(status.Timestamp * 1000))
pipelineName := pipelineContext.Pipeline.Name
pipelineName := context.Pipeline.Name

st := &Status{
Trace: strings.TrimSpace(status.Message),
Progress: &Progress{
Done: status.Progress.Done,
Total: status.Progress.Total,
Message: pipelineName,
Message: fmt.Sprintf("Pipeline %s", pipelineName),
},
Timestamp: ts,
}

// add subprogress
stageID := pipelineContext.Pipeline.Stage.ID
stageID := context.Pipeline.Stage.ID
stageContext := sr.stageContextMap[stageID]
if stageContext == nil {
sr.stageContextMap[id] = &pipelineContext.Pipeline.Stage
stageContext = &pipelineContext.Pipeline.Stage
sr.stageContextMap[id] = &context.Pipeline.Stage
stageContext = &context.Pipeline.Stage
}
stageName := stageContext.Name
stageName := fmt.Sprintf("Stage %s", stageContext.Name)
prog := st.Progress
for subProg := status.Progress.SubProgress; subProg != nil; subProg = subProg.SubProgress {
prog.SubProgress = &Progress{
Expand Down Expand Up @@ -148,6 +148,7 @@ type statusJSON struct {
// was sent to the user from then on it is only referenced by the ID
type contextJSON struct {
Origin string `json:"origin"`
ID string `json:"id"`
Pipeline struct {
ID string `json:"id"`
Name string `json:"name"`
Expand Down
1 change: 1 addition & 0 deletions pkg/osbuildmonitor/monitor_json_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ func TestOsbuildStatusNestingWorks(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, "Top level message", status.Message)
assert.Equal(t, "name", status.Progress.Name)
assert.Equal(t, "69816755441434713b7567970edfdd42d58193f163e1fdd506274d52246e87f2", status.Context.ID)
assert.Equal(t, 4, status.Progress.Total)
assert.Equal(t, "nested-name", status.Progress.SubProgress.Name)
assert.Equal(t, 8, status.Progress.SubProgress.Total)
Expand Down
25 changes: 15 additions & 10 deletions pkg/osbuildmonitor/monitor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ func TestScannerSimple(t *testing.T) {
assert.Equal(t, &osbuildmonitor.Status{
Trace: "source/org.osbuild.curl (org.osbuild.curl): Downloaded https://rpmrepo.osbuild.org/v2/mirror/public/f39/f39-x86_64-fedora-20231109/Packages/k/kpartx-0.9.5-2.fc39.x86_64.rpm",
Progress: &osbuildmonitor.Progress{
Done: 0,
Total: 4,
Done: 0,
Total: 4,
Message: "Pipeline source org.osbuild.curl",
},
Timestamp: time.UnixMilli(int64(ts1)),
}, st)
Expand All @@ -38,8 +39,9 @@ func TestScannerSimple(t *testing.T) {
assert.Equal(t, &osbuildmonitor.Status{
Trace: "source/org.osbuild.curl (org.osbuild.curl): Downloaded https://rpmrepo.osbuild.org/v2/mirror/public/f39/f39-x86_64-fedora-20231109/Packages/l/langpacks-fonts-en-4.0-9.fc39.noarch.rpm",
Progress: &osbuildmonitor.Progress{
Done: 0,
Total: 4,
Done: 0,
Total: 4,
Message: "Pipeline source org.osbuild.curl",
},
Timestamp: time.UnixMilli(int64(ts2)),
}, st)
Expand All @@ -62,14 +64,17 @@ func TestScannerSubprogress(t *testing.T) {
assert.Equal(t, &osbuildmonitor.Status{
Trace: "Starting module org.osbuild.rpm",
Progress: &osbuildmonitor.Progress{
Done: 1,
Total: 4,
Done: 1,
Total: 4,
Message: "Pipeline build",
SubProgress: &osbuildmonitor.Progress{
Done: 2,
Total: 8,
Done: 2,
Total: 8,
Message: "Stage org.osbuild.rpm",
SubProgress: &osbuildmonitor.Progress{
Done: 4,
Total: 16,
Done: 4,
Total: 16,
Message: "Stage org.osbuild.rpm",
},
},
},
Expand Down

0 comments on commit 4fb489f

Please sign in to comment.