view: keep the pipeline runner's pipelines and serve view_pipelines
The view hears the seat mesh-pipeline-runner's pipeline-started, step-started, step-ended and pipeline-ended and the build seats' step-progress, keeps each pipeline whole in its own state pipelines (newest 500) and the latest progress per running ask in pipeline-progress (200), and view_pipelines reads them. Builds: the lead's handover of 2026-11-16 (part 1 of the delivery view through its own pipeline); design 47 G, Pipelines per module (no milestone line cited by the handover)
This commit is contained in:
@@ -130,6 +130,27 @@ func Tools(r view.Reader, u view.UsageReader) []stdio.Tool {
|
||||
module, _ := args["module"].(string)
|
||||
return r.Reach(repository, module)
|
||||
}},
|
||||
{Name: view.PipelinesReadTool,
|
||||
Description: "The pipeline runner's pipelines as the view keeps them from its events (the newest " + fmt.Sprint(view.MaxPipelines) + "), newest first, " +
|
||||
"each whole: its module, branch, source and catalog revision, commit, group or run, fingerprint, outcome (running, passed, failed, refused, superseded, " +
|
||||
"cancelled) and why, when it started and ended, its test counts, and each step with its status in the policy, its outcome, why, what it waits on, " +
|
||||
"its ask and the node and times; a running step carries the latest progress its build seat said of its ask (phase fetch, build, run or report, " +
|
||||
"and when it was said). Narrow by branch, module, outcome and since (an RFC 3339 time: only pipelines the view kept an event of at or after it); " +
|
||||
"at most limit (default " + fmt.Sprint(view.DefaultPipelinesLimit) + ", at most " + fmt.Sprint(view.MaxPipelinesLimit) + "); matching says how many fit and cut that the limit cut them. " +
|
||||
"The runner's step log lines are not here. Read-only.",
|
||||
Input: map[string]any{"type": "object", "properties": map[string]any{
|
||||
"branch": map[string]any{"type": "string", "description": "only this branch's pipelines"},
|
||||
"module": map[string]any{"type": "string", "description": "only this module's pipelines"},
|
||||
"outcome": map[string]any{"type": "string", "description": "only pipelines with this outcome"},
|
||||
"since": map[string]any{"type": "string", "description": "RFC 3339 time: only pipelines kept an event of at or after it"},
|
||||
"limit": map[string]any{"type": "integer", "description": "at most this many pipelines, newest first"}}},
|
||||
Run: func(args map[string]any) (any, error) {
|
||||
q, err := view.ParsePipelinesQuery(args)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return r.Pipelines(q)
|
||||
}},
|
||||
{Name: view.TiersTool,
|
||||
Description: "A source revision's tiers, worked out now and never stored (novox/hq ADR 0603 §6): the modules the revision moves " +
|
||||
"(each whose fingerprint last changed at it), ordered by the module graph (a module after the bases, the providers " +
|
||||
@@ -488,6 +509,7 @@ func main() {
|
||||
r.Builds, r.HavesState = read(stdio.State("mesh-delivery-builder.builds")), read(stdio.State("node-engine.have"))
|
||||
r.ReachState = read(stdio.State("reach"))
|
||||
r.WaitsState = read(stdio.State(viewstate.WaitsState))
|
||||
r.PipelinesState, r.ProgressState = read(stdio.State(viewstate.PipelinesState)), read(stdio.State(viewstate.PipelineProgressState))
|
||||
r.SignersState = seatStateRead(holderOf(stdio.Ask), func(name string) view.StateRead { return read(stdio.State(name)) }, view.VaultSeat, view.SignersState)
|
||||
r.ConditionsState, r.AttemptsState = read(stdio.State(view.StatusConditionsState)), read(stdio.State(view.StatusAttemptsState))
|
||||
r.PresenceState, r.StuckState = read(stdio.State(view.StatusPresenceState)), read(stdio.State(view.StatusStuckState))
|
||||
|
||||
@@ -66,6 +66,7 @@ const (
|
||||
func TestModuleToolAnswersTheStoredValue(t *testing.T) {
|
||||
t.Run("indexer_packages answers the published modules", packagesToolAnswersThePublishedModules)
|
||||
t.Run("view_tiers names each module's wait", tiersToolSaysEachModulesWait)
|
||||
t.Run("view_pipelines reads the kept pipelines", pipelinesToolReadsThePipelines)
|
||||
t.Run("each tool answers through the owners' read tools as before", ownersAnswerTheToolsAsBefore)
|
||||
t.Run("node_manifest_reads asks every node's engine in one call", manifestReadsAsksEveryNode)
|
||||
r := fake{"a": withFP2, "b": withNone}.reader()
|
||||
@@ -696,3 +697,27 @@ func TestBuildSeatStatesAreReadInTheHoldersState(t *testing.T) {
|
||||
t.Errorf("the provisions read %v, %v; want acme-mesh-provisioner.provisions", named, err)
|
||||
}
|
||||
}
|
||||
|
||||
// view_pipelines answers the view's kept pipelines with their steps and the progress of a running step, narrowed by its arguments, and
|
||||
// refuses a since that is no time.
|
||||
func pipelinesToolReadsThePipelines(t *testing.T) {
|
||||
r := view.Reader{
|
||||
PipelinesState: fake{
|
||||
"main.9.web": `{"pipeline":"main.9.web","module":"web","branch":"main","commit":"c","outcome":"running","heard":"2026-11-16T03:00:00Z","started":"2026-11-16T02:00:00Z",` +
|
||||
`"steps":[{"step":"build","artifact":"web:program","status":"required","outcome":"running","ask":"a1"}]}`,
|
||||
"feat.8.db": `{"pipeline":"feat.8.db","module":"db","branch":"feat","commit":"d","outcome":"passed","heard":"2026-11-16T01:00:00Z","steps":[]}`,
|
||||
}.reader().State,
|
||||
ProgressState: fake{"a1": `{"ask":"a1","phase":"fetch","at":"2026-11-16T03:00:00Z","seat":"node-build-go","node":"ace"}`}.reader().State,
|
||||
}
|
||||
out, err := run(t, r, view.PipelinesReadTool, map[string]any{"branch": "main", "since": "2026-11-16T02:30:00Z", "limit": float64(5)})
|
||||
a, ok := out.(view.PipelinesAnswer)
|
||||
if err != nil || !ok || len(a.Pipelines) != 1 || a.Pipelines[0].Module != "web" || a.Pipelines[0].Steps[0].Progress == nil || a.Pipelines[0].Steps[0].Progress.Phase != "fetch" {
|
||||
t.Fatalf("%+v %v", out, err)
|
||||
}
|
||||
if out, _ := run(t, r, view.PipelinesReadTool, map[string]any{}); len(out.(view.PipelinesAnswer).Pipelines) != 2 {
|
||||
t.Errorf("no arguments gives every pipeline: %+v", out)
|
||||
}
|
||||
if _, err := run(t, r, view.PipelinesReadTool, map[string]any{"since": "soon"}); err == nil {
|
||||
t.Error("a since that is no time was answered")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -191,6 +191,9 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
|
||||
if err := hearWaits(ctx, hub, js, own.Waits, logger.Printf); err != nil {
|
||||
return fmt.Errorf("the waits' events are not handled: %w", err)
|
||||
}
|
||||
if err := hearPipelines(ctx, hub, js, own.Pipelines, own.Progress, time.Now, logger.Printf); err != nil {
|
||||
return fmt.Errorf("the pipelines' events are not handled: %w", err)
|
||||
}
|
||||
if err := hub.StartUntilBound(ctx, js, cred, nil, nil); err != nil {
|
||||
logger.Printf("the consumer is not heard yet (tried again until it is): %v", err)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,108 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
view "mesh-delivery-view/internal/view"
|
||||
|
||||
"git.novox.be/novox/mesh-sdk/go/process"
|
||||
"github.com/nats-io/nats.go/jetstream"
|
||||
)
|
||||
|
||||
// bucketStore is a key-value bucket of the view's own as view.PipelineStore: a put over a revision is a compare-and-set.
|
||||
type bucketStore struct {
|
||||
ctx context.Context
|
||||
js jetstream.JetStream
|
||||
bucket string
|
||||
}
|
||||
|
||||
func (s bucketStore) kv() (jetstream.KeyValue, error) { return s.js.KeyValue(s.ctx, s.bucket) }
|
||||
|
||||
func (s bucketStore) Get(key string) ([]byte, uint64, error) {
|
||||
kv, err := s.kv()
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
e, err := kv.Get(s.ctx, key)
|
||||
if errors.Is(err, jetstream.ErrKeyNotFound) {
|
||||
return nil, 0, view.ErrNotKept
|
||||
}
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
if e.Operation() != jetstream.KeyValuePut {
|
||||
return nil, 0, view.ErrNotKept
|
||||
}
|
||||
return e.Value(), e.Revision(), nil
|
||||
}
|
||||
|
||||
func (s bucketStore) Put(key string, value []byte, revision uint64) error {
|
||||
kv, err := s.kv()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if revision == 0 {
|
||||
_, err = kv.Create(s.ctx, key, value)
|
||||
return err
|
||||
}
|
||||
_, err = kv.Update(s.ctx, key, value, revision)
|
||||
return err
|
||||
}
|
||||
|
||||
func (s bucketStore) Delete(key string) error {
|
||||
kv, err := s.kv()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := kv.Delete(s.ctx, key); errors.Is(err, jetstream.ErrKeyNotFound) {
|
||||
return view.ErrNotKept
|
||||
} else {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
func (s bucketStore) Keys() ([]string, error) {
|
||||
kv, err := s.kv()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
keys, err := kv.Keys(s.ctx)
|
||||
if errors.Is(err, jetstream.ErrNoKeysFound) {
|
||||
return nil, nil
|
||||
}
|
||||
return keys, err
|
||||
}
|
||||
|
||||
// hearPipelines registers the handlers for the pipeline runner's pipeline and step events and the build seats' step-progress on the
|
||||
// process's hub, each kept in the view's states pipelines and pipeline-progress; one that could not be kept is not acknowledged, so
|
||||
// the bus gives it again (design 47 G *Pipelines per module*).
|
||||
func hearPipelines(ctx context.Context, hub *process.EventHub, js jetstream.JetStream, pipelines, progress string, now func() time.Time, logf func(string, ...any)) error {
|
||||
ps, gs := bucketStore{ctx, js, pipelines}, bucketStore{ctx, js, progress}
|
||||
for _, subject := range view.PipelineSubjects() {
|
||||
if err := hub.Handle(subject, func(m jetstream.Msg) {
|
||||
if err := view.ApplyPipelineEvent(m.Subject(), m.Data(), ps, gs, now()); err != nil {
|
||||
logf("the pipeline event %s is not kept (the bus gives it again): %v", m.Subject(), err)
|
||||
_ = m.Nak()
|
||||
return
|
||||
}
|
||||
_ = m.Ack()
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
for _, subject := range view.ProgressSubjects() {
|
||||
if err := hub.Handle(subject, func(m jetstream.Msg) {
|
||||
if err := view.ApplyProgress(m.Subject(), m.Data(), gs); err != nil {
|
||||
logf("the step progress %s is not kept (the bus gives it again): %v", m.Subject(), err)
|
||||
_ = m.Nak()
|
||||
return
|
||||
}
|
||||
_ = m.Ack()
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
//go:build integration
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"mesh-delivery-view/internal/view"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-view/viewstate"
|
||||
"github.com/nats-io/nats-server/v2/server"
|
||||
"github.com/nats-io/nats.go"
|
||||
"github.com/nats-io/nats.go/jetstream"
|
||||
)
|
||||
|
||||
// The pipelines are kept in the view's own buckets of a real bus: a compare-and-set that loses is refused, a key not there reads as not
|
||||
// kept, and the events fill them whole.
|
||||
func TestPipelinesAreKeptInTheViewsBucketsOnTheBus(t *testing.T) {
|
||||
srv, err := server.NewServer(&server.Options{Host: "127.0.0.1", Port: -1, JetStream: true, StoreDir: t.TempDir(), NoLog: true, NoSigs: true})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
go srv.Start()
|
||||
if !srv.ReadyForConnections(10 * time.Second) {
|
||||
t.Fatal("the bus did not come up")
|
||||
}
|
||||
t.Cleanup(srv.Shutdown)
|
||||
nc, err := nats.Connect(srv.ClientURL())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Cleanup(nc.Close)
|
||||
js, err := jetstream.New(nc)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||
defer cancel()
|
||||
b := viewstate.BucketsOf(testView)
|
||||
for _, name := range []string{b.Pipelines, b.Progress} {
|
||||
if _, err := js.CreateKeyValue(ctx, jetstream.KeyValueConfig{Bucket: name, History: 1}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
ps, gs := bucketStore{ctx, js, b.Pipelines}, bucketStore{ctx, js, b.Progress}
|
||||
if _, _, err := ps.Get("nothing"); !errors.Is(err, view.ErrNotKept) {
|
||||
t.Fatalf("a key not there: %v", err)
|
||||
}
|
||||
now := time.Now()
|
||||
const sub = "mesh.seat.mesh-pipeline-runner.event."
|
||||
if err := view.ApplyPipelineEvent(sub+"pipeline-started.m.main.c1", []byte(`{"v":1,"pipeline":"main.1.m","module":"m","branch":"main","commit":"c1","steps":[{"step":"build","artifact":"m:program","status":"required"}]}`), ps, gs, now); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := view.ApplyPipelineEvent(sub+"step-started.m.main.c1", []byte(`{"v":1,"pipeline":"main.1.m","module":"m","branch":"main","commit":"c1","result":{"step":"build","artifact":"m:program","status":"required","outcome":"running","ask":"a1"}}`), ps, gs, now); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := view.ApplyProgress("mesh.seat.node-build-go.event.step-progress.ace", []byte(`{"asker":"r","ask":"a1","phase":"run","at":"2026-11-16T03:01:00Z"}`), gs); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
_, rev, err := ps.Get("main.1.m")
|
||||
if err != nil || rev == 0 {
|
||||
t.Fatalf("the pipeline is kept: %d %v", rev, err)
|
||||
}
|
||||
if err := ps.Put("main.1.m", []byte(`{}`), rev-1); err == nil {
|
||||
t.Error("a write over a stale revision was kept")
|
||||
}
|
||||
if err := ps.Put("main.1.m", []byte(`{}`), 0); err == nil {
|
||||
t.Error("a create over a kept key was kept")
|
||||
}
|
||||
read := func(s bucketStore) view.StateRead {
|
||||
return view.StateRead{Keys: s.Keys, Get: func(k string) (json.RawMessage, error) { v, _, err := s.Get(k); return v, err }}
|
||||
}
|
||||
a, err := (view.Reader{PipelinesState: read(ps), ProgressState: read(gs)}).Pipelines(view.PipelinesQuery{})
|
||||
if err != nil || len(a.Pipelines) != 1 || a.Pipelines[0].Steps[0].Progress == nil || a.Pipelines[0].Steps[0].Progress.Phase != "run" {
|
||||
t.Fatalf("%+v %v", a, err)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
view "mesh-delivery-view/internal/view"
|
||||
|
||||
"git.novox.be/novox/mesh-sdk/go/process"
|
||||
"github.com/nats-io/nats.go/jetstream"
|
||||
)
|
||||
|
||||
// The pipelines' and the progress's subjects overlap none of the waits' nor each other: the hub gives a message one taker.
|
||||
func TestPipelineSubjectsOverlapNoOtherHandler(t *testing.T) {
|
||||
hub := process.NewEventHub(func(string, ...any) {})
|
||||
patterns := append(append(waitPatterns(), view.PipelineSubjects()...), view.ProgressSubjects()...)
|
||||
if len(patterns) != len(waitPatterns())+4+3 {
|
||||
t.Fatalf("patterns %v", patterns)
|
||||
}
|
||||
for _, p := range patterns {
|
||||
if err := hub.Handle(p, func(jetstream.Msg) {}); err != nil {
|
||||
t.Fatalf("the pattern %s overlaps another: %v", p, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user