diff --git a/modules/mesh-delivery-watchman/cmd/mesh-delivery-watchman/consumes.go b/modules/mesh-delivery-watchman/cmd/mesh-delivery-watchman/consumes.go index 7065d307d..55c41ca6e 100644 --- a/modules/mesh-delivery-watchman/cmd/mesh-delivery-watchman/consumes.go +++ b/modules/mesh-delivery-watchman/cmd/mesh-delivery-watchman/consumes.go @@ -173,7 +173,7 @@ func brokerSubject(subject string) bool { return strings.HasPrefix(subject, "mesh.seat."+meshbroker.Seat+".event.") } -// pipelineSubject hands the runner's `step-started` and `step-ended` and the assigner's `step-progress` to the watchman +// pipelineSubject hands the runner's `step-started`, `step-ended`, `wait-held` and `wait-ended` and the assigner's `step-progress` to the watchman // (watch/pipelines.go, watch/steps.go, design 47 G §732, H §741): each step's clock. It says whether the subject was one of them. func pipelineSubject(w *watch.Watchman, subject string, body []byte) bool { switch { @@ -183,6 +183,10 @@ func pipelineSubject(w *watch.Watchman, subject string, body []byte) bool { case strings.HasPrefix(subject, "mesh.seat."+meshpipelinerunner.Seat+".event."+meshpipelinerunner.EventStepEnded+"."): w.StepEvent(body) w.StepEnded(body) + case strings.HasPrefix(subject, "mesh.seat."+meshpipelinerunner.Seat+".event."+meshpipelinerunner.EventWaitHeld+"."): + w.RunnerWaitHeld(body) + case strings.HasPrefix(subject, "mesh.seat."+meshpipelinerunner.Seat+".event."+meshpipelinerunner.EventWaitEnded+"."): + w.RunnerWaitEnded(body) case strings.HasPrefix(subject, "mesh.seat."+meshwants.Seat+".event."+meshwants.EventStepProgress+"."): w.WantsStepProgress(body) default: diff --git a/modules/mesh-delivery-watchman/cmd/mesh-delivery-watchman/integration_test.go b/modules/mesh-delivery-watchman/cmd/mesh-delivery-watchman/integration_test.go index 20275428e..ba515e89d 100644 --- a/modules/mesh-delivery-watchman/cmd/mesh-delivery-watchman/integration_test.go +++ b/modules/mesh-delivery-watchman/cmd/mesh-delivery-watchman/integration_test.go @@ -394,6 +394,38 @@ func TestWatchmanWhole(t *testing.T) { // 1135/AC8 return watch.FindingKey(watch.ScopeDelivery, watch.StepFindingID(seededPipeline+"/"+step+"/"), watch.KindPipelineStands) } until("the seeded composition step with no progress", func() bool { return finding(seeded("composition")) }) + until("the seeded step held for the view past its bound", func() bool { return finding(seeded("validate")) }) + // H-A-611: a wait-held on the revision view is timed by its bound from its clock-from and its wait-ended clears it; an + // approval wait held twice as long raises nothing. + { + heldFrom := time.Now().UTC().Add(-2 * time.Minute) + held := func(step, on string) []byte { + b, _ := json.Marshal(meshpipelinerunner.WaitHeldEvent{V: 1, Pipeline: "main.13.web", Branch: "main", Source: 13, Step: step, On: on, Bound: "1m", + ClockFrom: &heldFrom, Since: heldFrom}) + return b + } + viewFinding := watch.FindingKey(watch.ScopeDelivery, watch.StepFindingID("main.13.web/composition/"), watch.KindPipelineStands) + approvalFinding := watch.FindingKey(watch.ScopeDelivery, watch.StepFindingID("main.13.web/approval/"), watch.KindPipelineStands) + for _, e := range []struct { + subject string + body []byte + }{ + {meshpipelinerunner.SubjectWaitHeld("main", "13"), held("approval", meshpipelinerunner.WaitOnPerson)}, + {meshpipelinerunner.SubjectWaitHeld("main", "13"), held("composition", meshpipelinerunner.WaitOnRevisionView)}, + } { + if _, err := js.Publish(ctx, e.subject, e.body); err != nil { + t.Fatal(err) + } + } + until("the step held for the revision view past its bound", func() bool { return finding(viewFinding) }) + if finding(approvalFinding) { + t.Error("an approval wait held past the bound raised pipeline-stands") + } + if _, err := js.Publish(ctx, meshpipelinerunner.SubjectWaitEnded("main", "13"), held("composition", meshpipelinerunner.WaitOnRevisionView)); err != nil { + t.Fatal(err) + } + until("the wait's end clears it", func() bool { return !finding(viewFinding) }) + } // H-A-709 (2): the step of the stands' second page is seeded as the first page's is. until("the seeded step of the second page", func() bool { return finding(watch.FindingKey(watch.ScopeDelivery, watch.StepFindingID(seededPipeline+"/unit/web:program"), watch.KindPipelineStands)) @@ -748,6 +780,9 @@ const ( // firstPage is the first page of the stand-in runner's stands, which names the next. var firstPage meshpipelinerunner.StandsAnswer +// heldSince is when the stand-in runner's step held for the revision view was held: past its bound of ten minutes. +var heldSince = time.Now().UTC().Add(-11 * time.Minute) + // seededPipeline is the pipeline the stand-in runner's stands names. const seededPipeline = "main.5.web" @@ -767,7 +802,9 @@ func serveCatalogHalf(t *testing.T, nc *nats.Conn) { // waiting on the assigner, a test step reading a run, and an approval waiting on a person. stands := meshpipelinerunner.StandsAnswer{Stands: []meshpipelinerunner.Wait{ {Pipeline: seededPipeline, Step: "composition", Ask: "seeded-ask", Module: "web", Branch: "main", Since: time.Now().UTC(), V: 1}, - {Pipeline: seededPipeline, Step: "approval", On: meshpipelinerunner.WaitOnPerson, Module: "web", Branch: "main", Since: time.Now().UTC(), V: 1}}} + {Pipeline: seededPipeline, Step: "approval", On: meshpipelinerunner.WaitOnPerson, Module: "web", Branch: "main", Since: time.Now().UTC(), V: 1}, + // H-A-611: a step held for the view past its wait's bound is raised from the start, as after a restart. + {Pipeline: seededPipeline, Step: "validate", On: meshpipelinerunner.WaitOnRevisionView, Bound: "10m", ClockFrom: &heldSince, Module: "web", Branch: "main", Since: heldSince, V: 1}}} // H-A-709 (2): the stands answer in two pages: the first names `next`, the second, asked with it, holds one more open step. second := meshpipelinerunner.StandsAnswer{Stands: []meshpipelinerunner.Wait{ {Pipeline: seededPipeline, Step: "unit", Artifact: "web:program", Ask: "seeded-ask-2", Module: "web", Branch: "main", Since: time.Now().UTC(), V: 1}}} diff --git a/modules/mesh-delivery-watchman/internal/watch/steps.go b/modules/mesh-delivery-watchman/internal/watch/steps.go index 27c3be1d9..599622142 100644 --- a/modules/mesh-delivery-watchman/internal/watch/steps.go +++ b/modules/mesh-delivery-watchman/internal/watch/steps.go @@ -28,6 +28,9 @@ type openStep struct { // at is when the clock began; owed says whether the step is owed progress. at time.Time owed bool + // bound is the time the step may stand from at before it is raised: the wait's own `bound` for a step held for the revision + // view (design 47 H2 H-A-599, H-A-611); zero: the progress bound. + bound time.Duration } // stepKey is the key an open step is kept under. @@ -63,6 +66,54 @@ func (w *Watchman) StepStarted(body []byte) { } owed := e.Result.Outcome == meshpipelinerunner.StepResultOutcomeRunning || e.Result.Outcome == "" w.openStep(key, e.Pipeline, e.Result.Step, e.Result.Artifact, e.Result.Ask, sharedAsks(e.Result.Shared), at, owed) + // A step held for the revision view that starts says its own clock (H-A-625 (1)): the wait's bound is no more. + w.steps[key].bound = 0 + w.timeStep(key) +} + +// RunnerWaitHeld hears the runner's `wait-held`: a wait with `on` `revision view` is a step held for the runner's view of its +// revision, timed by the wait's `bound` from its `clock-from` (its `since` where it carries none), raising `pipeline-stands` +// past it (design 47 H2 H-A-599, H-A-611, H-A-625 (1)); a wait on a person, for a build node or for a turn is owed no progress +// and left. +func (w *Watchman) RunnerWaitHeld(body []byte) { + var e meshpipelinerunner.WaitHeldEvent + if err := json.Unmarshal(body, &e); err != nil || e.Pipeline == "" || e.Step == "" { + w.say("a wait-held of the runner does not read, left: %v", err) + return + } + if e.On != meshpipelinerunner.WaitOnRevisionView { + return + } + bound, err := time.ParseDuration(e.Bound) + if err != nil || bound <= 0 { + w.say("the step %s of %s waits on the revision view and says no bound (%q), so it is never late", e.Step, e.Pipeline, e.Bound) + return + } + from := e.Since + if e.ClockFrom != nil && !e.ClockFrom.IsZero() { + from = *e.ClockFrom + } + w.mu.Lock() + defer w.mu.Unlock() + key := stepKey(e.Pipeline, e.Step, e.Artifact) + w.openStep(key, e.Pipeline, e.Step, e.Artifact, e.Ask, sharedAsks(e.Shared), from, true) + w.steps[key].bound = bound + w.timeStep(key) +} + +// RunnerWaitEnded hears the runner's `wait-ended`: the step held for the revision view is no more held, and its finding ends. +func (w *Watchman) RunnerWaitEnded(body []byte) { + var e meshpipelinerunner.WaitEndedEvent + if err := json.Unmarshal(body, &e); err != nil || e.Pipeline == "" || e.Step == "" { + w.say("a wait-ended of the runner does not read, left: %v", err) + return + } + if e.On != meshpipelinerunner.WaitOnRevisionView { + return + } + w.mu.Lock() + defer w.mu.Unlock() + w.closeStep(stepKey(e.Pipeline, e.Step, e.Artifact)) } // StepEnded hears the runner's `step-ended`: the step's clock ends and its finding is cleared. @@ -184,14 +235,18 @@ func (w *Watchman) timeStep(key string) { if s.ask != "" { last = ", last heard of its ask " + s.ask } + bound := w.progressBound + if s.bound > 0 { + bound = s.bound + } f := Finding{Scope: ScopeDelivery, ID: id, Kind: KindPipelineStands, Severity: Warning, Source: stepRow, Since: s.at, Summary: fmt.Sprintf("the step %s has said nothing since %s%s", name, stamp(s.at), last), - Said: "no progress in " + w.progressBound.String(), + Said: "no progress in " + bound.String(), Headline: "A pipeline step has stopped saying it lives", Explanation: "The step " + name + " started and has not ended, and neither it nor the run it reads has said its progress for " + - w.progressBound.String() + " or more" + last + ".", + bound.String() + " or more" + last + ".", Needs: "the part that runs it to say its progress, or the step ended (the runner's verbs mesh-pipeline-runner.stands and mesh-pipeline-runner.cancel)"} - if left := w.progressBound - w.now().Sub(s.at); left > 0 { + if left := bound - w.now().Sub(s.at); left > 0 { w.signal(stepRow, id, left, signalDue{Do: dueFind, Finding: f}) return } @@ -212,6 +267,20 @@ func (w *Watchman) SeedSteps(stands []meshpipelinerunner.Wait) { continue } owed := s.On != meshpipelinerunner.WaitOnPerson && s.On != meshpipelinerunner.WaitOnBuildNode && s.Who == "" - w.openStep(key, s.Pipeline, s.Step, s.Artifact, s.Ask, sharedAsks(s.Shared), w.now(), owed) + at := w.now() + var bound time.Duration + if s.On == meshpipelinerunner.WaitOnRevisionView { + // A step held for the view stands from the time it was held, whatever the watchman's start (H-A-599, H-A-611). + if d, err := time.ParseDuration(s.Bound); err == nil && d > 0 { + bound = d + at = s.Since + if s.ClockFrom != nil && !s.ClockFrom.IsZero() { + at = *s.ClockFrom + } + } + } + w.openStep(key, s.Pipeline, s.Step, s.Artifact, s.Ask, sharedAsks(s.Shared), at, owed) + w.steps[key].bound = bound + w.timeStep(key) } } diff --git a/modules/mesh-delivery-watchman/internal/watch/steps_test.go b/modules/mesh-delivery-watchman/internal/watch/steps_test.go index 41320f5a0..3d7793617 100644 --- a/modules/mesh-delivery-watchman/internal/watch/steps_test.go +++ b/modules/mesh-delivery-watchman/internal/watch/steps_test.go @@ -19,6 +19,12 @@ func stepBody(pipeline, step, artifact, ask, outcome string, at time.Time, share return b } +func heldBody(pipeline, step, artifact, on, bound string, from *time.Time) []byte { + b, _ := json.Marshal(meshpipelinerunner.WaitHeldEvent{V: 1, Pipeline: pipeline, Branch: "main", Step: step, Artifact: artifact, On: on, Bound: bound, + ClockFrom: from, Since: time.Now().UTC()}) + return b +} + func wantsProgress(ask string, at time.Time, shared ...string) []byte { var sh []meshwants.Shared for _, a := range shared { @@ -111,6 +117,33 @@ func TestAStepThatReadsARunIsTimed(t *testing.T) { w.WantsStepProgress(wantsProgress("a1", c.t)) // the composition step lives expire(w, c, key("p", "unit", "m:program"), time.Minute) }, []string{finding("p", "unit", "m:program")}}, + // H-A-599, H-A-611, H-A-625 (1), H-A-736 (1): a step held for the revision view is timed by its wait's bound from its + // clock-from, and an approval waiting on a person, held twice as long, raises nothing. + {"a wait on the revision view is timed by its bound from its clock-from, and its end clears the finding", func(w *Watchman, o *fakeOut, c *clock) { + from := c.t.Add(-40 * time.Second) + w.RunnerWaitHeld(heldBody("p", "unit", "m:program", meshpipelinerunner.WaitOnRevisionView, "1m", &from)) + if o.ttls[key("p", "unit", "m:program")] != 20*time.Second || len(o.findings) != 0 { + t.Fatalf("the bound is counted from clock-from: %v %v", o.ttls, o.findings) + } + expire(w, c, key("p", "unit", "m:program"), 20*time.Second) + if _, ok := o.findings[finding("p", "unit", "m:program")]; !ok { + t.Fatalf("not raised past the wait's bound: %v", o.findings) + } + w.RunnerWaitEnded(heldBody("p", "unit", "m:program", meshpipelinerunner.WaitOnRevisionView, "1m", &from)) + }, nil}, + {"a wait on a person is never timed, a seeded wait on the view is timed from its clock-from", func(w *Watchman, o *fakeOut, c *clock) { + from := c.t.Add(-2 * time.Minute) + w.RunnerWaitHeld(heldBody("p", "approval", "", meshpipelinerunner.WaitOnPerson, "1m", &from)) + c.t = c.t.Add(time.Hour) + if len(o.pulses) != 0 || len(o.findings) != 0 { + t.Fatalf("a wait on a person owes nothing: %v %v", o.pulses, o.findings) + } + late := c.t.Add(-2 * time.Minute) + w.SeedSteps([]meshpipelinerunner.Wait{{Pipeline: "p", Step: "unit", Artifact: "m:program", On: meshpipelinerunner.WaitOnRevisionView, Bound: "1m", ClockFrom: &late}}) + if _, ok := o.findings[finding("p", "unit", "m:program")]; !ok { + t.Fatalf("a seeded wait held past its bound is raised at once: %v", o.findings) + } + }, []string{finding("p", "unit", "m:program")}}, } for _, tc := range cases { t.Run(tc.name, func(t *testing.T) { diff --git a/modules/mesh-delivery-watchman/manifest_test.go b/modules/mesh-delivery-watchman/manifest_test.go index 6a0dd971c..22842bd78 100644 --- a/modules/mesh-delivery-watchman/manifest_test.go +++ b/modules/mesh-delivery-watchman/manifest_test.go @@ -143,7 +143,7 @@ func TestManifestStateAndReads(t *testing.T) { // 1135/AC6 t.Errorf("invokes = %v, want %v", m.Invokes, want) } // DLV-M5 its first views, 1585/T20 the indexer's take-in events, and DLV-W1 (ADR 0595 §4): the accepted verdicts and the bus module's created and refused, durably. - if want := []string{"seat:mesh-wants.views.wants", "seat:mesh-module-assigner.views.seat-holders", "mesh-catalog.registration-changed", "mesh-catalog.catalog-revision", "mesh-delivery-indexer.take-in.pending", "mesh-delivery-indexer.take-in.taken", "mesh-delivery.source-moved", "mesh-delivery.filling", "mesh-delivery.full", "mesh-delivery.room", "mesh-delivery.record-opened", "mesh-delivery.record-ended", "mesh-catalog.filling", "mesh-catalog.full", "mesh-catalog.room", "mesh-wants.filling", "mesh-wants.full", "mesh-wants.room", "mesh-grants.filling", "mesh-grants.full", "mesh-grants.room", "node-build-go.ask-taken", "node-build-go.step-progress", "node-build-go.step-ended", "node-build-image.ask-taken", "node-build-image.step-progress", "node-build-image.step-ended", "node-build-node.ask-taken", "node-build-node.step-progress", "node-build-node.step-ended", "mesh-pipeline-runner.step-started", "mesh-pipeline-runner.step-ended", "mesh-wants.step-progress", "mesh-wants.wait-held", "mesh-wants.wait-ended", "node-engine.wait-held", "node-engine.wait-ended", "node-engine.running", "mesh-broker.created", "mesh-broker.refused", "mesh-broker.recreated", "mesh-broker.dropped", "mesh-conditions.findings-asked"}; !reflect.DeepEqual(m.Consumes, want) { + if want := []string{"seat:mesh-wants.views.wants", "seat:mesh-module-assigner.views.seat-holders", "mesh-catalog.registration-changed", "mesh-catalog.catalog-revision", "mesh-delivery-indexer.take-in.pending", "mesh-delivery-indexer.take-in.taken", "mesh-delivery.source-moved", "mesh-delivery.filling", "mesh-delivery.full", "mesh-delivery.room", "mesh-delivery.record-opened", "mesh-delivery.record-ended", "mesh-catalog.filling", "mesh-catalog.full", "mesh-catalog.room", "mesh-wants.filling", "mesh-wants.full", "mesh-wants.room", "mesh-grants.filling", "mesh-grants.full", "mesh-grants.room", "node-build-go.ask-taken", "node-build-go.step-progress", "node-build-go.step-ended", "node-build-image.ask-taken", "node-build-image.step-progress", "node-build-image.step-ended", "node-build-node.ask-taken", "node-build-node.step-progress", "node-build-node.step-ended", "mesh-pipeline-runner.step-started", "mesh-pipeline-runner.step-ended", "mesh-pipeline-runner.wait-held", "mesh-pipeline-runner.wait-ended", "mesh-wants.step-progress", "mesh-wants.wait-held", "mesh-wants.wait-ended", "node-engine.wait-held", "node-engine.wait-ended", "node-engine.running", "mesh-broker.created", "mesh-broker.refused", "mesh-broker.recreated", "mesh-broker.dropped", "mesh-conditions.findings-asked"}; !reflect.DeepEqual(m.Consumes, want) { t.Errorf("consumes = %v, want %v", m.Consumes, want) // design 47 H §741, §764, H-A-49, H-A-91 (2) } // Design 47 H §744, H-A-94 (2): the setting take-in-bound, 60 minutes by default, reaches the process as a file. diff --git a/modules/mesh-delivery-watchman/module.json b/modules/mesh-delivery-watchman/module.json index 0d0318aa0..a89d14201 100644 --- a/modules/mesh-delivery-watchman/module.json +++ b/modules/mesh-delivery-watchman/module.json @@ -63,6 +63,8 @@ "node-build-node.step-ended", "mesh-pipeline-runner.step-started", "mesh-pipeline-runner.step-ended", + "mesh-pipeline-runner.wait-held", + "mesh-pipeline-runner.wait-ended", "mesh-wants.step-progress", "mesh-wants.wait-held", "mesh-wants.wait-ended",