Pipelines page: one pipeline by tier and stage, and its delivery on each node
The operator read every step of main.417 as passed and took it for delivered while it had failed on one step and no want was written: the page listed a pipeline's steps flat, with no tier, no stage and no delivery. One pipeline now shows a header (outcome, first failure's why, how many movers run their build on every node they are placed on), then a block per tier with a row per mover, a cell per stage (the worst outcome over its artifacts, waited, ran and why on hover) and a cell per node its module is placed on (no want written, wanted, applying, running the pipeline's build, held with why), in the web page and the terminal view. The page reloads on the runner's events and on the wants', haves' and assignments' changes the view already hears. Builds: design 47 H2 H-A-531, H-A-531 addendum (hq 7dc6592b, f870d24b)
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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{
|
||||
`<a href="/pipelines/show?pipeline=main.12">main.12</a>`, `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{
|
||||
`<a href="/pipelines/show?mover=alpha&pipeline=main.12">alpha</a></td><td>src2:aa</td><td>0.1.4</td><td>passed</td>`,
|
||||
"<td>unit beta:program: could not run: no build node</td>", `changes?pipeline=main.12\u0026since=`}},
|
||||
{"a pipeline's page is its header, then a block per tier, a row per mover with a cell per stage and per node", func() string {
|
||||
return web("/pipelines/show?pipeline=main.12")
|
||||
}, []string{
|
||||
"failed; first failure: unit beta:program: could not run: no build node; 1 of 4 movers run their build on every node they are placed on; 1 is placed on none",
|
||||
"<h2>TIER 1</h2>", "<th>MOVER</th><th>OUTCOME</th><th>BUILD</th><th>LINT</th><th>UNIT</th><th>INTEGRATION</th><th>VALIDATE</th><th>COMPOSITION</th><th>CODE REVIEW</th><th>APPROVAL</th><th>n1</th><th>n2</th><th>n3</th>",
|
||||
`<a href="/pipelines/show?mover=alpha&pipeline=main.12">alpha</a></td><td class="passed">passed</td><td class="passed" title="alpha:program: passed`,
|
||||
">passed 2/3</td>", `<td class="passed">running the pipeline's build</td><td class="passed">running the pipeline's build</td><td class="none"></td></tr>`,
|
||||
`<td class="failed" title="beta:program: could not run, waited 2m40s, ran 20s on n1: no build node`, ">could not run 1/2</td>",
|
||||
`<td class="waiting" title="approval: waiting: a person">waiting</td>`,
|
||||
`<td class="wanted">wanted</td><td class="applying">applying</td><td class="not-run">no want written</td>`,
|
||||
`<td class="held">held: connection refused</td><td class="held">held: health failed on n1</td>`,
|
||||
"<h2>TIER 2</h2>", `changes?pipeline=main.12\u0026since=`}},
|
||||
{"a stage's worst outcome follows the runner's step words, an unknown one counting as failed", func() string {
|
||||
at := func(o ...string) string {
|
||||
var ss []seat.StepResult
|
||||
for _, x := range o {
|
||||
ss = append(ss, seat.StepResult{Step: "unit", Outcome: x})
|
||||
}
|
||||
return stageCell(ss, t0).Text()
|
||||
}
|
||||
return strings.Join([]string{at("passed", "running", "waiting for a build node", "not asked", "running"), at("cancelled", "could not run"),
|
||||
at("frobbed", "passed"), at("running", "running"), at("nothing to run"), at()}, "|")
|
||||
}, []string{"not asked 1/5|could not run 1/2|frobbed 1/2|running 2/2|nothing to run|"}},
|
||||
{"a mover's page is its steps, each asked, taken and ended, how long it waited and how long it ran", func() string {
|
||||
return web("/pipelines/show?pipeline=main.12&mover=beta")
|
||||
}, []string{"<th>ASKED</th><th>TAKEN</th><th>ENDED</th><th>WAITED</th><th>RAN</th>",
|
||||
@@ -130,7 +192,7 @@ func TestThePipelinesPage(t *testing.T) {
|
||||
if err != nil {
|
||||
return err.Error()
|
||||
}
|
||||
return text(func(b *bytes.Buffer) { PipelineTable(b, a, "beta") })
|
||||
return text(func(b *bytes.Buffer) { PipelineTable(b, PipelineAnswer{ShowAnswer: a}, "beta") })
|
||||
}, []string{"STEPS OF beta", "OUTCOME ASKED TAKEN ENDED WAITED RAN WHY", "could not run " + since(started) + " " + since(taken) + " " + since(ended) + " 2m40s 20s no build node"}},
|
||||
{"a step still waiting counts its wait to now, one running its run", func() string {
|
||||
now := t0.Add(400e9)
|
||||
@@ -139,13 +201,21 @@ func TestThePipelinesPage(t *testing.T) {
|
||||
w3, r3 := waitedRan(seat.StepResult{Ended: &ended}, now)
|
||||
return fmt.Sprintf("waiting %s/%s; running %s/%s; never asked %q/%q", w1, r1, w2, r2, w3, r3)
|
||||
}, []string{`waiting 6m40s/; running 2m40s/4m0s; never asked ""/""`}},
|
||||
{"the terminal view's pipeline names each mover's fingerprint, version and failed step", func() string {
|
||||
a, err := p.Show("main.12", "", "")
|
||||
if err != nil {
|
||||
{"the terminal view's pipeline is its header and a block per tier, as the page's", func() string {
|
||||
path, sm := served(t)
|
||||
fill(sm, delivery...)
|
||||
sm.SetPipelines(p)
|
||||
var got *PipelineAnswer
|
||||
if err := AskPipelines(path, "", 0, "main.12", "", "", false, func(_ PipelinesPage, a *PipelineAnswer) bool { got = a; return true }); err != nil {
|
||||
return err.Error()
|
||||
}
|
||||
return text(func(b *bytes.Buffer) { PipelineTable(b, a, "") })
|
||||
}, []string{"PIPELINE main.12: failed, source 9, revision 12", "alpha src2:aa 0.1.4 passed", "beta src2:bb failed unit beta:program: could not run: no build node"}},
|
||||
return text(func(b *bytes.Buffer) { PipelineTable(b, *got, "") })
|
||||
}, []string{"PIPELINE main.12: failed; first failure: unit beta:program: could not run: no build node; 1 of 4 movers",
|
||||
"TIER 1 MOVER OUTCOME BUILD LINT UNIT INTEGRATION VALIDATE COMPOSITION CODE REVIEW APPROVAL N1 N2 N3",
|
||||
"alpha passed passed 2/3 - - - - - passed - running the pipeline's build running the pipeline's build -",
|
||||
"delta passed - - - - - - - - - - -", "TIER 2",
|
||||
"beta failed - - could not run 1/2 - - - - waiting wanted applying no want written",
|
||||
"gamma passed - - - - - - - - held: connection refused held: health failed on n1 -"}},
|
||||
{"the web list asks the newest limit of a branch", func() string { return web("/pipelines?branch=" + testBranch + "&limit=1") }, []string{
|
||||
"release.8", `name="limit" value="1"`}},
|
||||
{"the web list is the newest 20 by default", func() string { return web("/pipelines?branch=" + testBranch) }, []string{
|
||||
@@ -224,12 +294,29 @@ func TestThePipelinesPage(t *testing.T) {
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("a want or a have heard tells every pipeline's page, never the lists", func(t *testing.T) {
|
||||
v := p.Version()
|
||||
fill(m, haveFP(t, "n2", "gamma", fpNew, nodeengineclient.HealthOK))
|
||||
if !changedWithin(ctx, p, "main.12", v) {
|
||||
t.Fatal("the page of main.12 is not told of the have")
|
||||
}
|
||||
p.mu.Lock()
|
||||
lists := p.changedSince("", v)
|
||||
p.mu.Unlock()
|
||||
if lists {
|
||||
t.Error("a have tells the lists")
|
||||
}
|
||||
if got := web("/pipelines/show?pipeline=main.12"); !strings.Contains(got, `<td class="held">held: connection refused</td><td class="passed">running the pipeline's build</td>`) {
|
||||
t.Errorf("the page does not show gamma running on n2: %s", got)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("the terminal view follows the list on the socket, again at each event", func(t *testing.T) {
|
||||
path, sm := served(t)
|
||||
sm.SetPipelines(p)
|
||||
var seen []string
|
||||
heard := false
|
||||
err := AskPipelines(path, "", 0, "", "", "", true, func(page PipelinesPage, _ *seat.ShowAnswer) bool {
|
||||
err := AskPipelines(path, "", 0, "", "", "", true, func(page PipelinesPage, _ *PipelineAnswer) bool {
|
||||
seen = append(seen, page.Rows[0].Pipeline)
|
||||
if !heard {
|
||||
heard = true
|
||||
@@ -244,14 +331,14 @@ func TestThePipelinesPage(t *testing.T) {
|
||||
if err != nil || seen[len(seen)-1] != "main.14" {
|
||||
t.Fatalf("followed %v, %v", seen, err)
|
||||
}
|
||||
var show *seat.ShowAnswer
|
||||
if err := AskPipelines(path, "", 0, "main.12", "beta", "", false, func(_ PipelinesPage, a *seat.ShowAnswer) bool { show = a; return true }); err != nil {
|
||||
var show *PipelineAnswer
|
||||
if err := AskPipelines(path, "", 0, "main.12", "beta", "", false, func(_ PipelinesPage, a *PipelineAnswer) bool { show = a; return true }); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(show.Pipeline.Steps) != 2 || show.Pipeline.Steps[0].Node != "n1" {
|
||||
t.Fatalf("the mover's steps on the socket = %+v", show)
|
||||
}
|
||||
if err := AskPipelines(path, "", 0, "main.99", "", "", false, func(PipelinesPage, *seat.ShowAnswer) bool { return true }); err == nil || !strings.Contains(err.Error(), "no pipeline main.99") {
|
||||
if err := AskPipelines(path, "", 0, "main.99", "", "", false, func(PipelinesPage, *PipelineAnswer) bool { return true }); err == nil || !strings.Contains(err.Error(), "no pipeline main.99") {
|
||||
t.Fatalf("a pipeline the runner does not hold = %v", err)
|
||||
}
|
||||
})
|
||||
@@ -293,7 +380,7 @@ func TestThePipelinesPage(t *testing.T) {
|
||||
path, sm := served(t)
|
||||
sm.SetPipelines(up)
|
||||
var seen []PipelinesPage
|
||||
err := AskPipelines(path, "", 0, "", "", "", true, func(page PipelinesPage, _ *seat.ShowAnswer) bool {
|
||||
err := AskPipelines(path, "", 0, "", "", "", true, func(page PipelinesPage, _ *PipelineAnswer) bool {
|
||||
seen = append(seen, page)
|
||||
if len(seen) == 1 {
|
||||
mu.Lock()
|
||||
|
||||
@@ -153,25 +153,61 @@ func PipelinesTable(w io.Writer, p PipelinesPage) {
|
||||
table(w, PipelinesHead, rows)
|
||||
}
|
||||
|
||||
// PipelineTable prints one pipeline as show answered it for mover: its mover rows, or that mover's steps.
|
||||
func PipelineTable(w io.Writer, a seat.ShowAnswer, mover string) {
|
||||
// PipelineAnswer is one pipeline as the socket answers it: show's answer, and naming no mover the pipeline's page by tier
|
||||
// and stage with its nodes (design 47 H2 H-A-531).
|
||||
type PipelineAnswer struct {
|
||||
seat.ShowAnswer
|
||||
View *PipelineView `json:"view,omitempty"`
|
||||
}
|
||||
|
||||
// PipelineTable prints one pipeline for mover: naming none, its page by tier and stage with its nodes (design 47 H2
|
||||
// H-A-531); naming one, that mover's steps.
|
||||
func PipelineTable(w io.Writer, a PipelineAnswer, mover string) {
|
||||
p := a.Pipeline
|
||||
if mover == "" && a.View != nil {
|
||||
ViewTable(w, *a.View)
|
||||
return
|
||||
}
|
||||
fmt.Fprintf(w, "PIPELINE %s: %s, source %d, revision %d, started %s, ended %s\n", p.Pipeline, p.Outcome, p.Source, p.Revision, timeOf(p.Started), timeOf(p.Ended))
|
||||
if p.Why != "" {
|
||||
fmt.Fprintf(w, "why: %s\n", p.Why)
|
||||
}
|
||||
if mover == "" {
|
||||
table(w, MoversHead, MoverRowsText(a))
|
||||
table(w, MoversHead, MoverRowsText(a.ShowAnswer))
|
||||
} else {
|
||||
fmt.Fprintf(w, "STEPS OF %s\n", mover)
|
||||
table(w, StepsHead, StepsText(a))
|
||||
table(w, StepsHead, StepsText(a.ShowAnswer))
|
||||
}
|
||||
if a.Next != "" {
|
||||
fmt.Fprintf(w, "more: -next %s\n", a.Next)
|
||||
}
|
||||
}
|
||||
|
||||
const pipelinesStyle = `<style>body{font:14px sans-serif;margin:1em}table{border-collapse:collapse}td,th{padding:2px 10px;text-align:left}</style>`
|
||||
// ViewTable prints one pipeline's page: its header, then one block per tier, in tier order (design 47 H2 H-A-531).
|
||||
func ViewTable(w io.Writer, v PipelineView) {
|
||||
fmt.Fprintf(w, "PIPELINE %s: %s\n", v.Pipeline, v.Header())
|
||||
for _, u := range v.Unread {
|
||||
fmt.Fprintf(w, "unreadable: %s\n", u)
|
||||
}
|
||||
for _, t := range v.Tiers {
|
||||
fmt.Fprintf(w, "TIER %d\n", t.Tier)
|
||||
var rows [][]string
|
||||
for _, r := range t.Movers {
|
||||
cells := r.Cells()
|
||||
for i, c := range cells {
|
||||
if c == "" {
|
||||
cells[i] = "-"
|
||||
}
|
||||
}
|
||||
rows = append(rows, cells)
|
||||
}
|
||||
table(w, upper(v.TierHead()), rows)
|
||||
}
|
||||
}
|
||||
|
||||
const pipelinesStyle = `<style>body{font:14px sans-serif;margin:1em}table{border-collapse:collapse}td,th{padding:2px 10px;text-align:left}` +
|
||||
`td[title]{cursor:help}.passed{color:#176f2c}.failed,.held{color:#b3261e;font-weight:bold}.waiting,.running,.applying,.wanted{color:#8a5a00}` +
|
||||
`.not-run,.none{color:#777}</style>`
|
||||
|
||||
// changesScript reloads the page when the view says its part changed, on the runner's events (design 47 H2 H-A-467): never
|
||||
// on a timer.
|
||||
@@ -185,6 +221,38 @@ var pipelinesPage = template.Must(template.New("pl").Parse(`<!doctype html><html
|
||||
{{range .Rows}}<tr><td><a href="{{.Link}}">{{index .Cells 0}}</a></td>{{range slice .Cells 1}}<td>{{.}}</td>{{end}}</tr>{{end}}</table>{{end}}
|
||||
` + changesScript + `</body></html>`))
|
||||
|
||||
// pipelineViewPage is one pipeline's page (design 47 H2 H-A-531): its header, then a block per tier, a row per mover, a
|
||||
// cell per stage (each artifact's waited, ran and why on hover) and a cell per node its module is placed on.
|
||||
var pipelineViewPage = template.Must(template.New("pv").Funcs(template.FuncMap{"word": cellWord, "moverLink": PipelineLink}).Parse(`<!doctype html><html><head><meta charset="utf-8">
|
||||
<title>Pipeline {{.Pipeline}}</title>` + pipelinesStyle + `</head>
|
||||
<body><p><a href="/">What each node runs</a> · <a href="{{.Back}}">Pipelines of {{.Branch}}</a></p>
|
||||
<h1>PIPELINE {{.Pipeline}}</h1>
|
||||
{{if .Error}}<p>unreadable: {{.Error}}</p>{{else}}{{with .View}}<p class="{{word .Outcome}}">{{.Header}}</p>
|
||||
{{range .Unread}}<p>unreadable: {{.}}</p>{{end}}{{$v := .}}{{range .Tiers}}<h2>TIER {{.Tier}}</h2>
|
||||
<table><tr>{{range $v.TierHead}}<th>{{.}}</th>{{end}}</tr>
|
||||
{{range .Movers}}<tr><td><a href="{{moverLink $v.Pipeline .Module}}">{{.Module}}</a></td><td class="{{word .Outcome}}">{{.Outcome}}</td>{{range .Stages}}<td class="{{word .Outcome}}"{{with .Hover}} title="{{.}}"{{end}}>{{.Text}}</td>{{end}}{{range .Nodes}}<td class="{{if .Placed}}{{word .State}}{{else}}none{{end}}">{{.Text}}</td>{{end}}</tr>
|
||||
{{end}}</table>{{end}}{{end}}{{end}}
|
||||
` + changesScript + `</body></html>`))
|
||||
|
||||
// cellWord is a cell's class: the runner's step word of an outcome (H-A-531 addendum (2)), or a node's state's.
|
||||
func cellWord(s string) string {
|
||||
switch s {
|
||||
case "":
|
||||
return "none"
|
||||
case NodeRuns, seat.MoverRowOutcomePassed:
|
||||
return "passed"
|
||||
case NodeHeld:
|
||||
return "held"
|
||||
case NodeApplies:
|
||||
return "applying"
|
||||
case NodeWanted:
|
||||
return "wanted"
|
||||
case NodeNoWant:
|
||||
return "not-run"
|
||||
}
|
||||
return [...]string{"passed", "running", "waiting", "not-run", "failed"}[stepRank(s)]
|
||||
}
|
||||
|
||||
var pipelinePage = template.Must(template.New("p1").Parse(`<!doctype html><html><head><meta charset="utf-8">
|
||||
<title>Pipeline {{.Pipeline}}</title>` + pipelinesStyle + `</head>
|
||||
<body><p><a href="/">What each node runs</a> · <a href="{{.Back}}">Pipelines of {{.Branch}}</a>{{if .Mover}} · <a href="{{.Up}}">Pipeline {{.Pipeline}}</a>{{end}}</p>
|
||||
@@ -238,6 +306,21 @@ func webPipelines(m *Model, w http.ResponseWriter, r *http.Request) {
|
||||
v := p.Version()
|
||||
a, err := p.Show(key, mover, q.Get("next"))
|
||||
data := map[string]any{"Pipeline": key, "Mover": mover, "Changes": changesLink(key, v), "Up": PipelineLink(key, "")}
|
||||
if mover == "" && q.Get("next") == "" {
|
||||
if err == nil {
|
||||
pv, verr := m.PipelineView(p, a)
|
||||
data["View"], err = pv, verr
|
||||
}
|
||||
if err != nil {
|
||||
data["Error"] = err.Error()
|
||||
} else {
|
||||
data["Branch"] = a.Pipeline.Branch
|
||||
data["Back"] = "/pipelines?" + url.Values{"branch": {a.Pipeline.Branch}}.Encode()
|
||||
}
|
||||
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||
pipelineViewPage.Execute(w, data)
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
data["Error"] = err.Error()
|
||||
} else {
|
||||
|
||||
@@ -0,0 +1,359 @@
|
||||
package view
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"maps"
|
||||
"slices"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"git.novox.be/novox/mesh-contracts/go/clients/nodeengineclient"
|
||||
"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"
|
||||
)
|
||||
|
||||
// One pipeline as its page shows it (design 47 H2 H-A-531 and its addendum): a header with its outcome, its first failure's
|
||||
// why and how many of its movers run on every node they are placed on; then one block per tier, in tier order, one row per
|
||||
// mover, a cell per stage and a cell per node the mover's module is placed on. The stages are read through the runner's verb
|
||||
// show, the nodes from what the view already reads for "What each node runs" (the seat's assignments, the wants and the
|
||||
// haves); nothing is kept.
|
||||
|
||||
// Stage is one stage a mover passes, by its name on the page and the step kind the runner names it by.
|
||||
type Stage struct {
|
||||
Name string
|
||||
Step string
|
||||
}
|
||||
|
||||
// Stages are the stages in the order a mover passes them (design 47 H2 H-A-531).
|
||||
var Stages = []Stage{{"build", seat.StepResultStepBuild}, {"lint", seat.StepResultStepLint}, {"unit", seat.StepResultStepUnit},
|
||||
{"integration", seat.StepResultStepIntegration}, {"validate", seat.StepResultStepValidate},
|
||||
{"composition", seat.StepResultStepComposition}, {"code review", seat.StepResultStepReview}, {"approval", seat.StepResultStepApproval}}
|
||||
|
||||
// The states of a mover's module on a node it is placed on (design 47 H2 H-A-531).
|
||||
const (
|
||||
NodeNoWant = "no want written"
|
||||
NodeWanted = "wanted"
|
||||
NodeApplies = "applying"
|
||||
NodeRuns = "running the pipeline's build"
|
||||
NodeHeld = "held"
|
||||
)
|
||||
|
||||
// PipelineView is one pipeline's page: its header, its tiers and the nodes its movers' modules are placed on, by name.
|
||||
type PipelineView struct {
|
||||
Pipeline string `json:"pipeline"`
|
||||
Branch string `json:"branch"`
|
||||
Outcome string `json:"outcome"`
|
||||
Failed *seat.FailedStep `json:"failed,omitempty"`
|
||||
Why string `json:"why,omitempty"`
|
||||
Movers int `json:"movers"`
|
||||
// Running is how many movers run the pipeline's build on every node they are placed on, Unplaced how many are placed on
|
||||
// none: those never count as running (H-A-531 addendum (4)).
|
||||
Running int `json:"running"`
|
||||
Unplaced int `json:"unplaced"`
|
||||
Nodes []string `json:"nodes"`
|
||||
Tiers []PipelineTier `json:"tiers"`
|
||||
// Unread says each stage show could not read: its cells are then empty, never shown passed.
|
||||
Unread []string `json:"unread,omitempty"`
|
||||
}
|
||||
|
||||
// PipelineTier is one tier of the pipeline's delivery order, its movers by module.
|
||||
type PipelineTier struct {
|
||||
Tier int64 `json:"tier"`
|
||||
Movers []MoverStage `json:"movers"`
|
||||
}
|
||||
|
||||
// MoverStage is one mover's row: its stages' cells in Stages' order and its cells on the nodes in the view's Nodes' order.
|
||||
type MoverStage struct {
|
||||
Module string `json:"module"`
|
||||
Fingerprint string `json:"fingerprint"`
|
||||
Version string `json:"version,omitempty"`
|
||||
Outcome string `json:"outcome"`
|
||||
Stages []StageCell `json:"stages"`
|
||||
Nodes []NodeCell `json:"nodes"`
|
||||
}
|
||||
|
||||
// StageCell is one stage of one mover: the worst outcome over its artifacts, how many hold it of how many, and each
|
||||
// artifact's waited, ran and why, shown on hover.
|
||||
type StageCell struct {
|
||||
Outcome string `json:"outcome,omitempty"`
|
||||
Count int `json:"count,omitempty"`
|
||||
Of int `json:"of,omitempty"`
|
||||
Steps []string `json:"steps,omitempty"`
|
||||
}
|
||||
|
||||
// Text is the cell's outcome, with the count where the stage has several artifacts (H-A-531 addendum (3)).
|
||||
func (c StageCell) Text() string {
|
||||
if c.Of > 1 {
|
||||
return fmt.Sprintf("%s %d/%d", c.Outcome, c.Count, c.Of)
|
||||
}
|
||||
return c.Outcome
|
||||
}
|
||||
|
||||
// Hover is each artifact's line, one per line.
|
||||
func (c StageCell) Hover() string { return strings.Join(c.Steps, "\n") }
|
||||
|
||||
// NodeCell is the mover's module on one node: empty when it is not placed there.
|
||||
type NodeCell struct {
|
||||
Placed bool `json:"placed,omitempty"`
|
||||
State string `json:"state,omitempty"`
|
||||
Why string `json:"why,omitempty"`
|
||||
}
|
||||
|
||||
// Text is the cell's state, with its why.
|
||||
func (c NodeCell) Text() string {
|
||||
if c.Why != "" {
|
||||
return c.State + ": " + c.Why
|
||||
}
|
||||
return c.State
|
||||
}
|
||||
|
||||
// stepRank is how bad a step's outcome is, by the runner's own step words (H-A-531 addendum (2)): failed, then not run, then
|
||||
// waiting, then running, then passed; an outcome it does not know counts as failed.
|
||||
func stepRank(outcome string) int {
|
||||
switch outcome {
|
||||
case seat.StepResultOutcomePassed, seat.StepResultOutcomeCarried, seat.StepResultOutcomeAccepted,
|
||||
seat.StepResultOutcomeBypassed, seat.StepResultOutcomeNothingToRun:
|
||||
return 0
|
||||
case seat.StepResultOutcomeRunning:
|
||||
return 1
|
||||
case seat.StepResultOutcomeWaiting, seat.StepResultOutcomeWaitingForABuildNode:
|
||||
return 2
|
||||
case seat.StepResultOutcomeNotAsked, seat.StepResultOutcomeDeclined, seat.StepResultOutcomeSuperseded, seat.StepResultOutcomeCancelled:
|
||||
return 3
|
||||
}
|
||||
return 4
|
||||
}
|
||||
|
||||
// stageCell is the cell of one mover's steps of one stage.
|
||||
func stageCell(steps []seat.StepResult, now time.Time) StageCell {
|
||||
var c StageCell
|
||||
worst := -1
|
||||
for _, s := range steps {
|
||||
c.Of++
|
||||
switch r := stepRank(s.Outcome); {
|
||||
case r > worst:
|
||||
worst, c.Outcome, c.Count = r, s.Outcome, 1
|
||||
case s.Outcome == c.Outcome:
|
||||
c.Count++
|
||||
}
|
||||
waited, ran := waitedRan(s, now)
|
||||
line := s.Step
|
||||
if s.Artifact != "" {
|
||||
line = s.Artifact
|
||||
}
|
||||
line += ": " + s.Outcome
|
||||
if waited != "" {
|
||||
line += ", waited " + waited
|
||||
}
|
||||
if ran != "" {
|
||||
line += ", ran " + ran
|
||||
}
|
||||
if s.Node != "" {
|
||||
line += " on " + s.Node
|
||||
}
|
||||
if s.Why != "" {
|
||||
line += ": " + s.Why
|
||||
}
|
||||
c.Steps = append(c.Steps, line)
|
||||
}
|
||||
return c
|
||||
}
|
||||
|
||||
// stageSteps reads every step of one stage through show, page by page.
|
||||
func (p *Pipelines) stageSteps(pipeline, step string) ([]seat.StepResult, error) {
|
||||
var out []seat.StepResult
|
||||
next := ""
|
||||
for {
|
||||
raw, err := p.call(PipelinesShowVerb, seat.ShowInput{Pipeline: pipeline, Step: step, Next: next})
|
||||
a, err := showAnswer(raw, err, pipeline)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
out = append(out, a.Pipeline.Steps...)
|
||||
if a.Next == "" || a.Next == next {
|
||||
return out, nil
|
||||
}
|
||||
next = a.Next
|
||||
}
|
||||
}
|
||||
|
||||
// moverRows reads every mover's row through show, page by page, starting from the answer of the first page.
|
||||
func (p *Pipelines) moverRows(a seat.ShowAnswer) ([]seat.MoverRow, error) {
|
||||
rows := slices.Clone(a.Movers)
|
||||
next := a.Next
|
||||
for next != "" {
|
||||
b, err := p.Show(a.Pipeline.Pipeline, "", next)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
rows = append(rows, b.Movers...)
|
||||
if b.Next == next {
|
||||
break
|
||||
}
|
||||
next = b.Next
|
||||
}
|
||||
return rows, nil
|
||||
}
|
||||
|
||||
// nodeCell is module's state on node for the pipeline's build fp, from the wants, the haves and the holds the view reads.
|
||||
// The caller holds m.mu.
|
||||
func (m *Model) nodeCell(node, module, fp string) NodeCell {
|
||||
c := NodeCell{Placed: true, State: NodeNoWant}
|
||||
hk, err := nodeengineclient.HaveKey(node, module)
|
||||
if err != nil {
|
||||
return c
|
||||
}
|
||||
h, has := m.haves[hk]
|
||||
has = has && h.err == ""
|
||||
w, wanted := m.wants[hk]
|
||||
wanted = wanted && w.err == "" && !w.value.Removed && w.value.Fp == fp
|
||||
ours := has && h.have.Fp == fp
|
||||
switch {
|
||||
case ours && (h.have.Phase == nodeengineclient.PhaseFailed || h.have.Health == nodeengineclient.HealthFailed):
|
||||
// A build that failed, or whose health failed, is held, never running (H-A-531 addendum (1)).
|
||||
c.State, c.Why = NodeHeld, h.have.Detail
|
||||
if c.Why == "" {
|
||||
c.Why = "health " + string(h.have.Health) + ", phase " + string(h.have.Phase)
|
||||
}
|
||||
case ours && h.have.Phase == nodeengineclient.PhaseRunning:
|
||||
c.State = NodeRuns
|
||||
case has && (wanted || ours) && (h.have.Phase == nodeengineclient.PhaseHeld || h.have.Phase == nodeengineclient.PhaseWaitingYes):
|
||||
c.State, c.Why = NodeHeld, h.have.Detail
|
||||
if h.have.Wait != nil && h.have.Wait.Words != "" {
|
||||
c.Why = h.have.Wait.Words
|
||||
}
|
||||
case ours:
|
||||
c.State = NodeApplies
|
||||
case wanted && has && (h.have.Phase == nodeengineclient.PhaseApplying || h.have.Phase == nodeengineclient.PhaseBackingUp ||
|
||||
h.have.Phase == nodeengineclient.PhaseChecking):
|
||||
c.State = NodeApplies
|
||||
case wanted:
|
||||
c.State = NodeWanted
|
||||
default:
|
||||
if key, err := meshwantsclient.HeldKey(module, fp); err == nil {
|
||||
if held, ok := m.holds[key]; ok && held.err == "" {
|
||||
c.State, c.Why = NodeHeld, held.value.Words
|
||||
}
|
||||
}
|
||||
}
|
||||
return c
|
||||
}
|
||||
|
||||
// PipelineView is one pipeline's page from show's answer naming no mover (its movers' rows): its stages read through show
|
||||
// per stage, its nodes from the view's own reading of the assignments, the wants and the haves (design 47 H2 H-A-531).
|
||||
func (m *Model) PipelineView(p *Pipelines, a seat.ShowAnswer) (PipelineView, error) {
|
||||
rows, err := p.moverRows(a)
|
||||
if err != nil {
|
||||
return PipelineView{}, err
|
||||
}
|
||||
pl := a.Pipeline
|
||||
v := PipelineView{Pipeline: pl.Pipeline, Branch: pl.Branch, Outcome: pl.Outcome, Why: pl.Why, Movers: len(pl.Movers), Nodes: []string{}, Tiers: []PipelineTier{}}
|
||||
outcome := map[string]string{}
|
||||
for _, r := range rows {
|
||||
outcome[r.Module] = r.Outcome
|
||||
if v.Failed == nil && r.Failed != nil { // the first failure, in the runner's movers' order
|
||||
v.Failed = r.Failed
|
||||
}
|
||||
}
|
||||
steps := map[string]map[string][]seat.StepResult{} // by stage step, then module
|
||||
for _, s := range Stages {
|
||||
got, err := p.stageSteps(pl.Pipeline, s.Step)
|
||||
if err != nil {
|
||||
v.Unread = append(v.Unread, s.Name+": "+err.Error())
|
||||
continue
|
||||
}
|
||||
steps[s.Step] = map[string][]seat.StepResult{}
|
||||
for _, r := range got {
|
||||
steps[s.Step][r.Module] = append(steps[s.Step][r.Module], r)
|
||||
}
|
||||
}
|
||||
m.mu.Lock()
|
||||
defer m.mu.Unlock()
|
||||
byNode := m.placed.ByNode()
|
||||
placedOn := map[string][]string{}
|
||||
for node, modules := range byNode {
|
||||
for _, mod := range modules {
|
||||
placedOn[mod] = append(placedOn[mod], node)
|
||||
}
|
||||
}
|
||||
nodes := map[string]bool{}
|
||||
for _, mv := range pl.Movers {
|
||||
for _, n := range placedOn[mv.Module] {
|
||||
nodes[n] = true
|
||||
}
|
||||
}
|
||||
v.Nodes = slices.Sorted(maps.Keys(nodes))
|
||||
now := time.Now()
|
||||
tiers := map[int64][]MoverStage{}
|
||||
for _, mv := range pl.Movers {
|
||||
row := MoverStage{Module: mv.Module, Fingerprint: mv.Fingerprint, Version: mv.Version, Outcome: outcome[mv.Module]}
|
||||
for _, s := range Stages {
|
||||
row.Stages = append(row.Stages, stageCell(steps[s.Step][mv.Module], now))
|
||||
}
|
||||
runs := len(placedOn[mv.Module]) > 0
|
||||
for _, n := range v.Nodes {
|
||||
if !slices.Contains(placedOn[mv.Module], n) {
|
||||
row.Nodes = append(row.Nodes, NodeCell{})
|
||||
continue
|
||||
}
|
||||
c := m.nodeCell(n, mv.Module, mv.Fingerprint)
|
||||
runs = runs && c.State == NodeRuns
|
||||
row.Nodes = append(row.Nodes, c)
|
||||
}
|
||||
switch {
|
||||
case len(placedOn[mv.Module]) == 0:
|
||||
v.Unplaced++
|
||||
case runs:
|
||||
v.Running++
|
||||
}
|
||||
tier := max(mv.Tier, 1)
|
||||
tiers[tier] = append(tiers[tier], row)
|
||||
}
|
||||
for _, t := range slices.Sorted(maps.Keys(tiers)) {
|
||||
ms := tiers[t]
|
||||
slices.SortFunc(ms, func(a, b MoverStage) int { return strings.Compare(a.Module, b.Module) })
|
||||
v.Tiers = append(v.Tiers, PipelineTier{Tier: t, Movers: ms})
|
||||
}
|
||||
return v, nil
|
||||
}
|
||||
|
||||
// Header is the page's header line: the outcome, the first failure's why, and how many movers run on every node they are
|
||||
// placed on, those placed on none said apart (H-A-531 addendum (4)).
|
||||
func (v PipelineView) Header() string {
|
||||
s := v.Outcome
|
||||
switch {
|
||||
case v.Failed != nil:
|
||||
s += "; first failure: " + failedText(v.Failed)
|
||||
case v.Why != "":
|
||||
s += "; why: " + v.Why
|
||||
}
|
||||
s += fmt.Sprintf("; %d of %d movers run their build on every node they are placed on", v.Running, v.Movers)
|
||||
switch {
|
||||
case v.Unplaced == 1:
|
||||
s += "; 1 is placed on none"
|
||||
case v.Unplaced > 1:
|
||||
s += fmt.Sprintf("; %d are placed on none", v.Unplaced)
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
// TierHead is a tier block's head: the mover, its outcome, a column per stage, a column per node.
|
||||
func (v PipelineView) TierHead() []string {
|
||||
out := []string{"MOVER", "OUTCOME"}
|
||||
for _, s := range Stages {
|
||||
out = append(out, strings.ToUpper(s.Name))
|
||||
}
|
||||
return append(out, v.Nodes...)
|
||||
}
|
||||
|
||||
// Cells is a mover row's cells in TierHead's order.
|
||||
func (r MoverStage) Cells() []string {
|
||||
out := []string{r.Module, r.Outcome}
|
||||
for _, c := range r.Stages {
|
||||
out = append(out, c.Text())
|
||||
}
|
||||
for _, c := range r.Nodes {
|
||||
out = append(out, c.Text())
|
||||
}
|
||||
return out
|
||||
}
|
||||
@@ -15,8 +15,6 @@ import (
|
||||
"strings"
|
||||
"text/tabwriter"
|
||||
"time"
|
||||
|
||||
seat "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshpipelinerunner"
|
||||
)
|
||||
|
||||
// ListenSocket listens on the unix socket at path, in a directory of mode 0755, with mode 0666 on the socket: the
|
||||
@@ -576,7 +574,16 @@ func answerPipelines(c net.Conn, m *Model, a ask) {
|
||||
} else if sa, serr := p.Show(a.Pipeline, a.Mover, a.Next); serr != nil {
|
||||
err = enc.Encode(pipelinesRefusal{Refused: serr.Error()})
|
||||
} else {
|
||||
err = enc.Encode(sa)
|
||||
pa := PipelineAnswer{ShowAnswer: sa}
|
||||
if a.Mover == "" && a.Next == "" { // the pipeline's page by tier and stage (design 47 H2 H-A-531)
|
||||
pv, verr := m.PipelineView(p, sa)
|
||||
if verr != nil {
|
||||
enc.Encode(pipelinesRefusal{Refused: verr.Error()})
|
||||
return
|
||||
}
|
||||
pa.View = &pv
|
||||
}
|
||||
err = enc.Encode(pa)
|
||||
}
|
||||
if err != nil || !a.Follow || !p.Changed(ctx, what, v) {
|
||||
return
|
||||
@@ -594,7 +601,7 @@ type pipelinesRefusal struct {
|
||||
// AskPipelines asks the socket at path for one branch's newest limit pipelines (the default's below one), or with pipeline
|
||||
// set for that pipeline (of mover when named); with follow, each answers again at each change, handed to each until it
|
||||
// answers false or the view leaves.
|
||||
func AskPipelines(path, branch string, limit int, pipeline, mover, next string, follow bool, each func(PipelinesPage, *seat.ShowAnswer) bool) error {
|
||||
func AskPipelines(path, branch string, limit int, pipeline, mover, next string, follow bool, each func(PipelinesPage, *PipelineAnswer) bool) error {
|
||||
c, err := net.DialTimeout("unix", path, 5*time.Second)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot reach the view at %s: %w", path, err)
|
||||
@@ -625,9 +632,9 @@ func AskPipelines(path, branch string, limit int, pipeline, mover, next string,
|
||||
return errors.New(refused.Refused)
|
||||
}
|
||||
var page PipelinesPage
|
||||
var show *seat.ShowAnswer
|
||||
var show *PipelineAnswer
|
||||
if pipeline != "" {
|
||||
show = &seat.ShowAnswer{}
|
||||
show = &PipelineAnswer{}
|
||||
if err := json.Unmarshal(raw, show); err != nil {
|
||||
return fmt.Errorf("the view's answer is not a pipeline: %w", err)
|
||||
}
|
||||
|
||||
@@ -392,6 +392,7 @@ func (m *Model) Apply(e Entry) {
|
||||
}
|
||||
writes, reached := m.reachNow()
|
||||
say, put := m.deliveredEvent, m.reachPut
|
||||
pipes := m.pipelines
|
||||
sayMotion := m.motionEvent
|
||||
left, w := m.left, m.writer
|
||||
m.left = nil
|
||||
@@ -404,6 +405,9 @@ func (m *Model) Apply(e Entry) {
|
||||
}
|
||||
m.sendReach(put, say, writes, reached)
|
||||
m.sayMotion(sayMotion, motion)
|
||||
if pipes != nil && !e.History && (e.Bucket == WantsBucket || e.Bucket == HaveBucket || e.Bucket == AssignmentsBucket) {
|
||||
pipes.Delivered() // a pipeline's page shows each mover's nodes (design 47 H2 H-A-531)
|
||||
}
|
||||
}
|
||||
|
||||
// deleteAnswers deletes the view's answers to the asks that left asks, after the model's lock is released; one not deleted is
|
||||
|
||||
Reference in New Issue
Block a user