diff --git a/modules/mesh-delivery-view/cmd/mesh-delivery-cli/main.go b/modules/mesh-delivery-view/cmd/mesh-delivery-cli/main.go index 51404efa5..c5db6c24b 100644 --- a/modules/mesh-delivery-view/cmd/mesh-delivery-cli/main.go +++ b/modules/mesh-delivery-view/cmd/mesh-delivery-cli/main.go @@ -17,7 +17,6 @@ import ( "text/tabwriter" "time" - seat "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshpipelinerunner" "mesh-delivery-view/internal/view" ) @@ -148,8 +147,8 @@ func pipelines(socket string, args []string, next string, limit int, follow, asJ return 0 } -// seatShow is the seat's answer of show, as the view hands it on. -type seatShow = seat.ShowAnswer +// seatShow is the view's answer of one pipeline: show's, with the pipeline's page by tier and stage naming no mover. +type seatShow = view.PipelineAnswer // holds prints every hold: module, fingerprint, node, since, answer, words. func holds(socket string, asJSON bool, out, errOut io.Writer) int { diff --git a/modules/mesh-delivery-view/cmd/mesh-delivery-cli/main_test.go b/modules/mesh-delivery-view/cmd/mesh-delivery-cli/main_test.go index 4d4f61386..d1039d53c 100644 --- a/modules/mesh-delivery-view/cmd/mesh-delivery-cli/main_test.go +++ b/modules/mesh-delivery-view/cmd/mesh-delivery-cli/main_test.go @@ -306,7 +306,8 @@ func rawAsk(t *testing.T, a oc.Ask) json.RawMessage { const testView = "acme-view" -// Design 47 H2 H-A-467: the terminal view's pipelines page: a branch's newest pipelines, and one pipeline's mover rows. +// Design 47 H2 H-A-467, H-A-531: the terminal view's pipelines page: a branch's newest pipelines, and one pipeline by tier and +// stage. func TestThePipelinesCommands(t *testing.T) { m := view.New(testView) call := func(key string, body any) (json.RawMessage, error) { @@ -346,7 +347,8 @@ func TestThePipelinesCommands(t *testing.T) { {[]string{"pipelines", "next"}, "next.3 3 2 passed 1 4 0 0 0 0 0 0 0"}, {[]string{"pipelines", "next"}, "next.2"}, // the newest 20 by default {[]string{"-limit", "1", "pipelines", "next"}, "next.3"}, - {[]string{"pipeline", "next.3"}, "alpha src2:aa 0.2.1 passed"}, + {[]string{"pipeline", "next.3"}, "TIER 1 MOVER OUTCOME BUILD LINT UNIT INTEGRATION VALIDATE COMPOSITION CODE REVIEW APPROVAL alpha passed - - - - - - - -"}, + {[]string{"pipeline", "next.3"}, "PIPELINE next.3: passed; 0 of 1 movers run their build on every node they are placed on; 1 is placed on none"}, {[]string{"-json", "pipeline", "next.3"}, `"fingerprint": "src2:aa"`}, } { var out, errOut bytes.Buffer diff --git a/modules/mesh-delivery-view/cmd/mesh-delivery-view/integration_test.go b/modules/mesh-delivery-view/cmd/mesh-delivery-view/integration_test.go index 55532c3a7..722a418ed 100644 --- a/modules/mesh-delivery-view/cmd/mesh-delivery-view/integration_test.go +++ b/modules/mesh-delivery-view/cmd/mesh-delivery-view/integration_test.go @@ -896,7 +896,7 @@ func TestProcessWholeSaysTheSourceRevisionIsDelivered(t *testing.T) { pipelines.set(pseat.PipelineRow{Pipeline: "release.9", Source: rev, Revision: 9, Outcome: "passed", MoverCount: 1}, pseat.PipelineRow{Pipeline: "release.8", Source: rev, Revision: 8, Outcome: "superseded", MoverCount: 1}) var seen [][]string - err = view.AskPipelines(env["MESH_DELIVERY_SOCKET"], catalogBranch, 0, "", "", "", true, func(page view.PipelinesPage, _ *pseat.ShowAnswer) bool { + err = view.AskPipelines(env["MESH_DELIVERY_SOCKET"], catalogBranch, 0, "", "", "", true, func(page view.PipelinesPage, _ *view.PipelineAnswer) bool { var keys []string for _, r := range page.Rows { keys = append(keys, r.Pipeline) diff --git a/modules/mesh-delivery-view/internal/view/pipelines.go b/modules/mesh-delivery-view/internal/view/pipelines.go index 0428d126f..cc1cfe901 100644 --- a/modules/mesh-delivery-view/internal/view/pipelines.go +++ b/modules/mesh-delivery-view/internal/view/pipelines.go @@ -104,6 +104,11 @@ func (p *Pipelines) List(branch string, limit int) ([]seat.PipelineRow, error) { // (design 47 H2 H-A-467 (2)); next is the cursor of a page show answered. func (p *Pipelines) Show(pipeline, mover, next string) (seat.ShowAnswer, error) { raw, err := p.call(PipelinesShowVerb, seat.ShowInput{Pipeline: pipeline, Mover: mover, Next: next}) + return showAnswer(raw, err, pipeline) +} + +// showAnswer reads an answer of show. +func showAnswer(raw json.RawMessage, err error, pipeline string) (seat.ShowAnswer, error) { if err != nil { return seat.ShowAnswer{}, fmt.Errorf("%s of %s: %w", PipelinesShowVerb, pipeline, err) } @@ -211,6 +216,14 @@ func (p *Pipelines) Hear(data []byte) error { return nil } +// deliveryKey is what heard keeps the last change of the delivery under: a want, a have or an assignment the view heard, +// which every pipeline's page shows (design 47 H2 H-A-531). No pipeline's key holds a NUL. +const deliveryKey = "\x00delivery" + +// Delivered tells every pipeline's page that the delivery changed: a want, a have or an assignment the view heard, on the +// events it already hears for "What each node runs" (design 47 H2 H-A-531), never a timer. The lists are not read again. +func (p *Pipelines) Delivered() { p.notify(deliveryKey) } + // owe has Run read the lists again. func (p *Pipelines) owe() { select { @@ -266,7 +279,7 @@ func (p *Pipelines) Version() uint64 { func (p *Pipelines) Changed(ctx context.Context, what string, since uint64) bool { ch := make(chan string, 1) p.mu.Lock() - if p.heard[what] > since { + if p.changedSince(what, since) { p.mu.Unlock() return true } @@ -283,7 +296,7 @@ func (p *Pipelines) Changed(ctx context.Context, what string, since uint64) bool return false case <-ch: // any change: a note dropped while one waited is read from heard, never lost p.mu.Lock() - changed := p.heard[what] > since + changed := p.changedSince(what, since) p.mu.Unlock() if changed { return true @@ -291,3 +304,9 @@ func (p *Pipelines) Changed(ctx context.Context, what string, since uint64) bool } } } + +// changedSince says whether what changed after since: a pipeline's page changes with the delivery too (design 47 H2 +// H-A-531), the lists do not. The caller holds p.mu. +func (p *Pipelines) changedSince(what string, since uint64) bool { + return p.heard[what] > since || (what != "" && p.heard[deliveryKey] > since) +} diff --git a/modules/mesh-delivery-view/internal/view/pipelines_test.go b/modules/mesh-delivery-view/internal/view/pipelines_test.go index eeba6991b..c41077c6b 100644 --- a/modules/mesh-delivery-view/internal/view/pipelines_test.go +++ b/modules/mesh-delivery-view/internal/view/pipelines_test.go @@ -13,6 +13,9 @@ import ( "testing" "time" + "git.novox.be/novox/mesh-contracts/go/clients/nodeengineclient" + "git.novox.be/novox/mesh-contracts/go/seats/nodeengine" + "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshwantsclient" seat "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshpipelinerunner" ) @@ -22,6 +25,7 @@ type fakeRunner struct { mu sync.Mutex rows map[string][]seat.PipelineRow // by branch shows map[string]seat.ShowAnswer // by pipeline, or pipeline/mover + steps map[string][]seat.StepResult // by pipeline, every mover's steps, which show filtered by a step answers two a page lists int } @@ -39,6 +43,22 @@ func (f *fakeRunner) call(key string, body any) (json.RawMessage, error) { return json.Marshal(seat.ListAnswer{Rows: rows[:min(int(in.Limit), len(rows))]}) case PipelinesShowVerb: in := body.(seat.ShowInput) + if in.Step != "" { + a := f.shows[in.Pipeline] + var held []seat.StepResult + for _, s := range f.steps[in.Pipeline] { + if s.Step == in.Step { + held = append(held, s) + } + } + from := 0 + fmt.Sscan(in.Next, &from) + a.Pipeline.Steps = held[min(from, len(held)):min(from+2, len(held))] + if a.Next = ""; from+2 < len(held) { + a.Next = fmt.Sprint(from + 2) + } + return json.Marshal(a) + } k := in.Pipeline if in.Mover != "" { k += "/" + in.Mover @@ -58,6 +78,13 @@ func (f *fakeRunner) setRows(branch string, rows ...seat.PipelineRow) { f.rows[branch] = rows } +// The builds of the pipeline's movers, in the new form a want names. +var ( + fpA = "src2:" + strings.Repeat("a", 64) + fpB = "src2:" + strings.Repeat("b", 64) + fpB0 = "src2:" + strings.Repeat("0", 64) +) + // changedWithin is p.Changed bounded, so a change never said fails the test instead of hanging it. func changedWithin(ctx context.Context, p *Pipelines, what string, since uint64) bool { ctx, cancel := context.WithTimeout(ctx, 30*time.Second) @@ -65,20 +92,26 @@ func changedWithin(ctx context.Context, p *Pipelines, what string, since uint64) return p.Changed(ctx, what, since) } -// Design 47 H2 H-A-467: the pipelines page reads the runner's list and show, refreshes on its events, never on a timer, -// and links each delivery to its pipeline by its source revision. +// Design 47 H2 H-A-467, H-A-531: the pipelines page reads the runner's list and show, refreshes on its events and on the wants' +// and haves', never on a timer, shows one pipeline by tier and stage with its nodes, and links each delivery to its pipeline. func TestThePipelinesPage(t *testing.T) { started, ended := t0, t0.Add(3*60e9) taken := t0.Add(160e9) // a build node took the step 2m40s after its ask, and it ran 20s (design 47 H2 H-A-516) runner := &fakeRunner{rows: map[string][]seat.PipelineRow{}, shows: map[string]seat.ShowAnswer{ "main.12": {Pipeline: seat.Pipeline{Pipeline: "main.12", Branch: "main", Source: 9, Revision: 12, Outcome: seat.PipelineOutcomeFailed, - Started: &started, Ended: &ended, Movers: []seat.Mover{{Module: "alpha", Fingerprint: "src2:aa", Version: "0.1.4"}, {Module: "beta", Fingerprint: "src2:bb"}}}, + Started: &started, Ended: &ended, Movers: []seat.Mover{{Module: "alpha", Fingerprint: fpA, Version: "0.1.4", Tier: 1}, + {Module: "beta", Fingerprint: fpB, Tier: 2}, {Module: "gamma", Fingerprint: fpNew, Tier: 2}, {Module: "delta", Fingerprint: fpOld}}}, Movers: []seat.MoverRow{{Module: "alpha", Outcome: seat.MoverRowOutcomePassed}, - {Module: "beta", Outcome: seat.MoverRowOutcomeFailed, Failed: &seat.FailedStep{Step: "unit", Artifact: "beta:program", Outcome: "could not run", Why: "no build node"}}}}, + {Module: "beta", Outcome: seat.MoverRowOutcomeFailed, Failed: &seat.FailedStep{Step: "unit", Artifact: "beta:program", Outcome: "could not run", Why: "no build node"}}, + {Module: "gamma", Outcome: seat.MoverRowOutcomePassed}, {Module: "delta", Outcome: seat.MoverRowOutcomePassed}}}, "main.12/beta": {Pipeline: seat.Pipeline{Pipeline: "main.12", Branch: "main", Source: 9, Revision: 12, Outcome: seat.PipelineOutcomeFailed, Steps: []seat.StepResult{{Module: "beta", Step: "unit", Artifact: "beta:program", Seat: "node-build-go", Node: "n1", Outcome: "could not run", AskedAt: &started, Started: &started, TakenAt: &taken, Ended: &ended, Why: "no build node"}, {Module: "beta", Step: "lint", Artifact: "beta:program", Seat: "node-build-go", Outcome: "could not run", AskedAt: &started, Ended: &ended}}}}, - }} + }, steps: map[string][]seat.StepResult{"main.12": { + {Module: "alpha", Step: "build", Artifact: "alpha:program", Outcome: "passed"}, {Module: "alpha", Step: "build", Artifact: "alpha:image", Outcome: "carried"}, + {Module: "alpha", Step: "build", Artifact: "alpha:tool", Outcome: "passed"}, {Module: "alpha", Step: "review", Outcome: "passed"}, + {Module: "beta", Step: "unit", Artifact: "beta:program", Node: "n1", Outcome: "could not run", AskedAt: &started, TakenAt: &taken, Ended: &ended, Why: "no build node"}, + {Module: "beta", Step: "unit", Artifact: "beta:tool", Outcome: "passed"}, {Module: "beta", Step: "approval", Outcome: "waiting", Why: "a person"}}}} runner.setRows("main", seat.PipelineRow{Pipeline: "main.12", Source: 9, Revision: 12, Started: &started, Outcome: seat.PipelineOutcomeFailed, MoverCount: 2, Steps: map[string]int64{"passed": 5, "failed": 1, "could not run": 1, "waiting for a build node": 2}}) runner.setRows(testBranch, seat.PipelineRow{Pipeline: "release.8", Source: 4, Revision: 8, Outcome: seat.PipelineOutcomePassed}, @@ -86,6 +119,15 @@ func TestThePipelinesPage(t *testing.T) { p := NewPipelines(runner.call, func() []string { return []string{testBranch} }, 0, nil) m := New(testView) fill(m, sourceE(t, 4)) + // alpha runs its build on both its nodes; beta is wanted on n1, applying on n2 and has no want on n3; gamma's build failed + // its health on n1 and the assigner holds it; delta is placed on no node (design 47 H2 H-A-531 and its addendum). + applying, _ := nodeengineclient.EncodeHave(nodeengine.HaveByNodeModuleValue{Fp: fpB0, Phase: nodeengineclient.PhaseApplying, Health: nodeengineclient.HealthWaits}) + sick, _ := nodeengineclient.EncodeHave(nodeengine.HaveByNodeModuleValue{Fp: fpNew, Phase: nodeengineclient.PhaseRunning, Health: nodeengineclient.HealthFailed, Detail: "connection refused"}) + delivery := []Entry{place(t, "n1", "alpha", "beta", "gamma"), place(t, "n2", "alpha", "beta", "gamma"), place(t, "n3", "beta"), + haveFP(t, "n1", "alpha", fpA, nodeengineclient.HealthOK), haveFP(t, "n2", "alpha", fpA, nodeengineclient.HealthOK), + wantE(t, "n1", "beta", meshwantsclient.Want{Fp: fpB}), wantE(t, "n2", "beta", meshwantsclient.Want{Fp: fpB}), haveE(t, "n2", "beta", applying, t0), + wantE(t, "n1", "gamma", meshwantsclient.Want{Fp: fpNew}), haveE(t, "n1", "gamma", sick, t0), heldE(t, "gamma", fpNew, "n1", "health failed on n1")} + fill(m, delivery...) m.SetPipelines(p) ctx, cancel := context.WithCancel(context.Background()) defer cancel() @@ -117,9 +159,29 @@ func TestThePipelinesPage(t *testing.T) { "main.12 12 9 2026-10-18", "failed 2 5 1 1 0 0 2 0 0"}}, {"the web list links each pipeline and reloads on the view's changes, never a timer", func() string { return web("/pipelines") }, []string{ `main.12`, `new EventSource("/pipelines/changes?since=`}}, - {"a pipeline's page is its mover rows, each linking its steps", func() string { return web("/pipelines/show?pipeline=main.12") }, []string{ - `alpha