From d6405ac28cb5bb1fa20303b1a59d87e7b94f45c0 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Thu, 28 Nov 2024 17:23:05 +0100 Subject: [PATCH] fixup! add Message with high level messages --- pkg/osbuildmonitor/monitor.go | 17 ++++++++++++----- pkg/osbuildmonitor/monitor_test.go | 23 +++++++++++++++++++++-- 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/pkg/osbuildmonitor/monitor.go b/pkg/osbuildmonitor/monitor.go index 8236251b7c..a995c07bdc 100644 --- a/pkg/osbuildmonitor/monitor.go +++ b/pkg/osbuildmonitor/monitor.go @@ -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 @@ -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, diff --git a/pkg/osbuildmonitor/monitor_test.go b/pkg/osbuildmonitor/monitor_test.go index ba4bb27975..a5b42ab139 100644 --- a/pkg/osbuildmonitor/monitor_test.go +++ b/pkg/osbuildmonitor/monitor_test.go @@ -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) @@ -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) @@ -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,