Skip to content

Commit

Permalink
fixup! add Message with high level messages
Browse files Browse the repository at this point in the history
  • Loading branch information
mvo5 committed Nov 28, 2024
1 parent 4fb489f commit d6405ac
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 7 deletions.
17 changes: 12 additions & 5 deletions pkg/osbuildmonitor/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,9 @@ 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"
// Message contains a high level user-visible message about
// e.g. a startus change
Message string

// Progress contains the current progress.
Progress *Progress
Expand Down Expand Up @@ -102,8 +101,16 @@ func (sr *StatusScanner) Status() (*Status, error) {
ts := time.UnixMilli(int64(status.Timestamp * 1000))
pipelineName := context.Pipeline.Name

var trace, msg string
if context.Origin == "osbuild.monitor" {
msg = strings.TrimSpace(status.Message)
} else {
trace = strings.TrimSpace(status.Message)
}

st := &Status{
Trace: strings.TrimSpace(status.Message),
Trace: trace,
Message: msg,
Progress: &Progress{
Done: status.Progress.Done,
Total: status.Progress.Total,
Expand Down
23 changes: 21 additions & 2 deletions pkg/osbuildmonitor/monitor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ import (
)

const osbuildMonitorLines_curl = `{"message": "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\n", "context": {"origin": "org.osbuild", "pipeline": {"name": "source org.osbuild.curl", "id": "598849389c35f93efe2412446f5ca6919434417b9bcea040ea5f9203de81db2c", "stage": {}}, "id": "7355d3857aa5c7b3a0c476c13d4b242a625fe190f2e7796df2335f3a34429db3"}, "progress": {"name": "pipelines/sources", "total": 4, "done": 0}, "timestamp": 1731589338.8252223}
{"message": "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\n", "context": {"id": "7355d3857aa5c7b3a0c476c13d4b242a625fe190f2e7796df2335f3a34429db3"}, "progress": {"name": "pipelines/sources", "total": 4, "done": 0}, "timestamp": 1731589338.8256931}`
{"message": "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\n", "context": {"id": "7355d3857aa5c7b3a0c476c13d4b242a625fe190f2e7796df2335f3a34429db3"}, "progress": {"name": "pipelines/sources", "total": 4, "done": 0}, "timestamp": 1731589338.8256931}
{"message": "Starting pipeline build", "context": {"origin": "osbuild.monitor", "pipeline": {"name": "build", "id": "32e87da44d9a519e89770723a33b7ecdd4ab85b872ae6ab8aaa94bdef9a275c7", "stage": {}}, "id": "0020bdf60135d4a03d8db333f66d40386278bf55b39fd06ed18839da11d98f96"}, "progress": {"name": "pipelines/sources", "total": 4, "done": 1, "progress": {"name": "pipeline: build", "total": 2, "done": 0}}, "timestamp": 1731589407.0338647}`

func TestScannerSimple(t *testing.T) {
ts1 := 1731589338.8252223 * 1000
ts2 := 1731589338.8256931 * 1000
ts3 := 1731589407.0338647 * 1000

r := bytes.NewBufferString(osbuildMonitorLines_curl)
scanner := osbuildmonitor.NewStatusScanner(r)
Expand Down Expand Up @@ -45,6 +47,23 @@ func TestScannerSimple(t *testing.T) {
},
Timestamp: time.UnixMilli(int64(ts2)),
}, st)
// third line
st, err = scanner.Status()
assert.NoError(t, err)
assert.Equal(t, &osbuildmonitor.Status{
Message: "Starting pipeline build",
Progress: &osbuildmonitor.Progress{
Done: 1,
Total: 4,
Message: "Pipeline build",
SubProgress: &osbuildmonitor.Progress{
Message: "Stage ",
Done: 0,
Total: 2,
},
},
Timestamp: time.UnixMilli(int64(ts3)),
}, st)
// end
st, err = scanner.Status()
assert.NoError(t, err)
Expand All @@ -62,7 +81,7 @@ func TestScannerSubprogress(t *testing.T) {
st, err := scanner.Status()
assert.NoError(t, err)
assert.Equal(t, &osbuildmonitor.Status{
Trace: "Starting module org.osbuild.rpm",
Message: "Starting module org.osbuild.rpm",
Progress: &osbuildmonitor.Progress{
Done: 1,
Total: 4,
Expand Down

0 comments on commit d6405ac

Please sign in to comment.