diff --git a/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline-tools/testruns.go b/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline-tools/testruns.go index 398007500..f106da6c8 100644 --- a/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline-tools/testruns.go +++ b/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline-tools/testruns.go @@ -10,11 +10,11 @@ import ( ) // TestRunsTools are runner_test_runs and runner_test_runs_drop (design 47 G §728; A-469f, A-469u): each calls its seat verb -// over the bus, both answered by the runner's process, which holds test-runs-cap-mib (A-469g, A-470i). +// over the bus, both answered by the runner's process, which reads test-runs' fill against its bucket's max bytes (A-469g, A-470i, H-A-510). func TestRunsTools(ask func(key string, body any) (json.RawMessage, error)) []stdio.Tool { return []stdio.Tool{ {Name: Prefix + "_test_runs", - Description: "The pipeline runner's test runs, one per candidate, level and tested packages (the state test-runs): each with its packages read from its output object, its ask, node, readers, outcome and counts, and the state's fill against its cap setting test-runs-cap-mib; filtered by a candidate, a level, a digest or a module, or none.", + Description: "The pipeline runner's test runs, one per candidate, level and tested packages (the state test-runs): each with its packages read from its output object, its ask, node, readers, outcome and counts, and the state's fill against its cap, the bucket's max bytes (the manifest's max-mib); filtered by a candidate, a level, a digest or a module, or none.", Input: map[string]any{"type": "object", "properties": map[string]any{ "candidate": map[string]any{"type": "string"}, "level": map[string]any{"type": "string"}, "digest": map[string]any{"type": "string"}, "module": map[string]any{"type": "string"}}}, diff --git a/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/testruns.go b/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/testruns.go index 02f416a70..364512a1c 100644 --- a/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/testruns.go +++ b/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/testruns.go @@ -7,7 +7,6 @@ import ( "fmt" "io/fs" "os" - "strconv" "strings" "sync" "time" @@ -283,7 +282,8 @@ func (o *runObjects) Delete(name string) error { return nil } -// runsFill reads test-runs' fill, its key-value stream's bytes (A-469d): judged by the process against its cap setting. +// runsFill reads test-runs' fill, its key-value stream's bytes, against its cap, the stream's max bytes (A-469d, H-A-510 +// addendum): the bucket on the bus is the one truth of the manifest's max-mib, so the runner keeps no second number. func runsFill(ctx context.Context, js jetstream.JetStream, module string, now func() time.Time) func() (seat.Fill, error) { return func() (seat.Fill, error) { st, err := js.Stream(ctx, "KV_"+ownBucket(module, TestRunsState)) @@ -301,7 +301,6 @@ func runsFill(ctx context.Context, js jetstream.JetStream, module string, now fu // The files the manifest writes each setting of the test runs into, `${config:}`, named by the environment (A-469x). const ( - envRunsCap = "MESH_RUNNER_TEST_RUNS_CAP_FILE" envRunsKept = "MESH_RUNNER_TEST_RUNS_KEPT_FILE" envStepBound = "MESH_RUNNER_TEST_STEP_BOUND_FILE" envUntakenBound = "MESH_RUNNER_RUN_UNTAKEN_BOUND_FILE" @@ -310,20 +309,11 @@ const ( // maxRunsKept is test-runs-kept's maximum (A-470a): the pipeline naming a run's key is kept at least that long. const maxRunsKept = 168 * time.Hour -// runSettings reads the settings of the test runs at the start (§725; A-469x): test-runs-cap-mib a whole number of MiB, -// test-runs-kept, test-step-bound and run-untaken-bound Go durations. A setting whose file is missing or empty is its +// runSettings reads the settings of the test runs at the start (§725; A-469x): test-runs-kept, test-step-bound and +// run-untaken-bound Go durations. A setting whose file is missing or empty is its // default; a content that is neither is an error naming the file. func runSettings(getenv func(string) string) (pipeline.RunSettings, error) { s := pipeline.DefaultRunSettings - if v, err := settingText(getenv(envRunsCap)); err != nil { - return s, err - } else if v != "" { - n, err := strconv.Atoi(v) - if err != nil || n < 1 { - return s, fmt.Errorf("%s holds %q, which is not a positive whole number", getenv(envRunsCap), v) - } - s.CapBytes = int64(n) << 20 - } for _, d := range []struct { env string to *time.Duration @@ -445,7 +435,8 @@ func openTestRuns(ctx context.Context, js jetstream.JetStream, cred process.Acco hearer.RunOutputs = objects if hearer.Ager != nil { hearer.Ager.Runs, hearer.Ager.RunOutputs, hearer.Ager.RunsKept, hearer.Ager.Clock = runs, objects.Delete, settings.Kept, runs + hearer.Ager.RunsFill = starter.TestRunsFill } - logf("test runs: cap %d bytes, kept %s, step bound %s, untaken bound %s", settings.CapBytes, settings.Kept, settings.StepBound, settings.Untaken) + logf("test runs: the cap is the bucket's max bytes, kept %s, step bound %s, untaken bound %s", settings.Kept, settings.StepBound, settings.Untaken) return kv, objects, nil } diff --git a/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/testruns_integration_test.go b/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/testruns_integration_test.go index 463f0cb1a..adcbc736f 100644 --- a/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/testruns_integration_test.go +++ b/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/testruns_integration_test.go @@ -40,8 +40,9 @@ import ( // a run that keeps saying its progress past its bound is not ended, // and a taken ask silent for its bound ends could not run with its readers, its ask dropped; a second revision with the // same digests asks its own runs; a seat the seat-holders view names no holder for ends its pipeline failed at once, its -// other steps not asked (A-470g, A-470h); the process answers test-runs with its fill against test-runs-cap-mib and -// test-runs-drop deletes the key and its output object (A-470i); at the cap a step ends could not run, naming the fill. +// other steps not asked (A-470g, A-470h); the process answers test-runs with its fill against the bucket's max bytes and +// test-runs-drop deletes the key and its output object (A-470i); at nine tenths of the bucket a step's end ages the oldest +// ended runs, said in one journal line (H-A-510). // The step bound is two seconds here, as the setting test-step-bound names it, where the mesh's is 30 minutes. func TestTestRunsAreAskedOncePerLevelAndMoveEveryReader(t *testing.T) { url := testbus.URL(t) @@ -63,8 +64,9 @@ func TestTestRunsAreAskedOncePerLevelAndMoveEveryReader(t *testing.T) { t.Fatal(err) } } - for _, state := range []string{"bounds", TestRunsState} { - if _, err := js.CreateKeyValue(ctx, jetstream.KeyValueConfig{Bucket: module + "_" + state, History: 1, LimitMarkerTTL: time.Minute}); err != nil { + // test-runs is 1 MiB here, as the manifest's max-mib makes its bucket: its cap (H-A-510 addendum). + for state, max := range map[string]int64{"bounds": 0, TestRunsState: 1 << 20} { + if _, err := js.CreateKeyValue(ctx, jetstream.KeyValueConfig{Bucket: module + "_" + state, History: 1, LimitMarkerTTL: time.Minute, MaxBytes: max}); err != nil { t.Fatal(err) } } @@ -204,10 +206,10 @@ func TestTestRunsAreAskedOncePerLevelAndMoveEveryReader(t *testing.T) { return out } - // The settings, as the manifest's resources write them (A-469x): a cap of 1 MiB, a step bound of two seconds; the + // The settings, as the manifest's resources write them (A-469x): a step bound of two seconds; the // candidates' pipelines run side by side, so pipelines-at-once is its most, 8 (§748). dir := t.TempDir() - files := map[string]string{envRunsCap: "1", envStepBound: "2s", envPipelinesAtOnce: "8"} + files := map[string]string{envStepBound: "2s", envPipelinesAtOnce: "8"} env := map[string]string{} for name, content := range files { path := filepath.Join(dir, name) @@ -552,7 +554,7 @@ func TestTestRunsAreAskedOncePerLevelAndMoveEveryReader(t *testing.T) { } } - // test-runs is answered by the process, its fill against test-runs-cap-mib (A-470i), each run's packages from its output + // test-runs is answered by the process, its fill against the bucket's max bytes (A-470i, H-A-510), each run's packages from its output // object; test-runs-drop deletes the key and its object (§728). var runs seat.TestRunsAnswer if e := call(seat.VerbTestRuns, seat.TestRunsInput{Candidate: "main.1"}, &runs); e != "" || len(runs.Runs) != 2 || runs.Fill.Cap != 1<<20 || runs.Fill.Store != TestRunsState { @@ -576,8 +578,8 @@ func TestTestRunsAreAskedOncePerLevelAndMoveEveryReader(t *testing.T) { t.Error("the dropped run's output object is kept") } - // At the cap a step ends could not run, naming the fill (§725, A-469d). - pad := make([]byte, 600<<10) + // At nine tenths of the bucket a step's end ages the oldest ended runs, said in one journal line (H-A-510). + pad := make([]byte, 470<<10) for _, k := range []string{"pad.a", "pad.b"} { if _, err := runsKV.Put(ctx, k, pad); err != nil { t.Fatal(err) @@ -587,10 +589,9 @@ func TestTestRunsAreAskedOncePerLevelAndMoveEveryReader(t *testing.T) { publish(catalog.SubjectCatalogRevision("main"), catalog.CatalogRevisionEvent{V: 1, Revision: 4, Kind: "trunk", Branch: "main", Source: 6}) const p6 = "main.4" takeIn("app", "c1", "src2:aa", 6, 4) - waitFor(t, ctx, logs, func() bool { - s := step(read(p6), "app:program", "unit") - return s.Outcome == seat.StepResultOutcomeCouldNotRun && strings.Contains(s.Why, "test-runs-cap-mib") - }) + placed(p6) + passBuild(p6, "app", "c1", "src2:aa") + waitFor(t, ctx, logs, func() bool { return strings.Contains(logs.String(), "of its 1048576 bytes, nine tenths or more") }) } func mustJSON(v any) []byte { diff --git a/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/testruns_test.go b/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/testruns_test.go index c8f14d81f..da0a023ee 100644 --- a/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/testruns_test.go +++ b/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/testruns_test.go @@ -8,8 +8,8 @@ import ( ) // The test runs' settings reach the process through the files the manifest writes (design 47 G §725; A-469x, A-470a): the -// cap a whole number of MiB, the times Go durations, a missing file its default, a content that is neither, or a kept time -// past 168h, an error naming the file. +// times Go durations, test-runs-kept 48h by default (H-A-510), a missing file its default, a content that is no duration, +// or a kept time past 168h, an error naming the file. The cap is no setting: a cap file is not read (H-A-510 addendum). func TestTheTestRunsSettingsAreReadFromTheirFiles(t *testing.T) { dir := t.TempDir() write := func(name, content string) string { @@ -23,20 +23,20 @@ func TestTheTestRunsSettingsAreReadFromTheirFiles(t *testing.T) { name string files map[string]string ok bool - check func(t *testing.T, cap int64, kept, step, untaken time.Duration) + check func(t *testing.T, kept, step, untaken time.Duration) }{ - {"defaults", nil, true, func(t *testing.T, cap int64, kept, step, untaken time.Duration) { - if cap != 16<<20 || kept != 168*time.Hour || step != 30*time.Minute || untaken != 24*time.Hour { - t.Errorf("defaults = %d %s %s %s", cap, kept, step, untaken) + {"defaults", nil, true, func(t *testing.T, kept, step, untaken time.Duration) { + if kept != 48*time.Hour || step != 30*time.Minute || untaken != 24*time.Hour { + t.Errorf("defaults = %s %s %s", kept, step, untaken) } }}, - {"set", map[string]string{envRunsCap: "8\n", envRunsKept: "48h", envStepBound: "2s", envUntakenBound: "1m"}, true, - func(t *testing.T, cap int64, kept, step, untaken time.Duration) { - if cap != 8<<20 || kept != 48*time.Hour || step != 2*time.Second || untaken != time.Minute { - t.Errorf("settings = %d %s %s %s", cap, kept, step, untaken) + {"set", map[string]string{envRunsKept: "72h\n", envStepBound: "2s", envUntakenBound: "1m"}, true, + func(t *testing.T, kept, step, untaken time.Duration) { + if kept != 72*time.Hour || step != 2*time.Second || untaken != time.Minute { + t.Errorf("settings = %s %s %s", kept, step, untaken) } }}, - {"a cap that is no whole number", map[string]string{envRunsCap: "8.5"}, false, nil}, + {"a cap file is not read", map[string]string{"MESH_RUNNER_TEST_RUNS_CAP_FILE": "8.5"}, true, nil}, {"a time that is no duration", map[string]string{envStepBound: "30"}, false, nil}, {"kept past its maximum", map[string]string{envRunsKept: "169h"}, false, nil}, } @@ -51,7 +51,7 @@ func TestTheTestRunsSettingsAreReadFromTheirFiles(t *testing.T) { t.Fatalf("runSettings = %+v, %v", s, err) } if r.check != nil { - r.check(t, s.CapBytes, s.Kept, s.StepBound, s.Untaken) + r.check(t, s.Kept, s.StepBound, s.Untaken) } }) } diff --git a/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/verbs.go b/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/verbs.go index 154938655..cc02ba9c5 100644 --- a/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/verbs.go +++ b/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/verbs.go @@ -59,7 +59,7 @@ func writeHandlers(v pipeline.Verbs) map[string]process.SeatHandler { seat.VerbAskAgain: verbOf(func(c string, in seat.AskAgainInput) (any, error) { return v.AskAgain(c, in) }), // §728, A-469g: a test run's drop is answered by the process, the only writer of pipelines and test-runs. seat.VerbTestRunsDrop: verbOf(func(c string, in seat.TestRunsDropInput) (any, error) { return v.TestRunsDrop(c, in) }), - // A-470i: test-runs too, since the process holds test-runs-cap-mib, the cap its fill is said against. + // A-470i: test-runs too, since the process reads its fill against the bucket's max bytes (H-A-510). seat.VerbTestRuns: verbOf(func(_ string, in seat.TestRunsInput) (any, error) { return v.Runs.TestRuns(in) }), } } diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/aged.go b/modules/mesh-delivery-pipeline/internal/pipeline/aged.go index 6699631f7..204139ded 100644 --- a/modules/mesh-delivery-pipeline/internal/pipeline/aged.go +++ b/modules/mesh-delivery-pipeline/internal/pipeline/aged.go @@ -57,6 +57,9 @@ type Ager struct { Runs TestRuns RunOutputs func(name string) error RunsKept time.Duration + // RunsFill is test-runs' fill against its bucket's max bytes (Starter.TestRunsFill): at nine tenths of it the oldest + // ended runs are deleted, their outputs with them, until it is under eight tenths (H-A-510); nil ages by time only. + RunsFill func() (seat.Fill, error) // Clock is test-runs' bound and ask keys: a run's ask keys are deleted with the run (H-A-500 addendum (1)); nil keeps them. Clock RunClock Now func() time.Time @@ -84,13 +87,97 @@ func (a *Ager) Age() { } retentions = append([]Retention{{RetentionTestRuns, kept}}, retentions...) } - for _, r := range retentions { + for i, r := range retentions { if err := a.ageAt(r); err != nil { a.logf("aged: the data past %s are not aged: %v", r.Name, err) } + // By fill after by time, before the pipelines age, so the pipeline that names a run's key is still kept. + if i == 0 && a.Runs != nil { + if err := a.ageByFill(); err != nil { + a.logf("aged: the test runs are not aged by their fill: %v", err) + } + } } } +// The fill of test-runs, in tenths of its cap, at which the Ager deletes its oldest ended runs and under which it stops +// (H-A-510). +const ( + runsFillAgeTenths = 9 + runsFillUnderTenths = 8 +) + +// ageByFill deletes the oldest ended test runs, with their output objects, once test-runs holds nine tenths of its cap, +// until it holds under eight tenths (H-A-510): in the step log's order onward from the test runs' retention, as the Ager +// ages by time (§330), so nothing is scanned whole; a run not ended is never deleted. It says how many and how old in one +// journal line. +func (a *Ager) ageByFill() error { + if a.RunsFill == nil { + return nil + } + f, err := a.RunsFill() + if err != nil { + return err + } + if f.Cap <= 0 || f.Bytes*10 < f.Cap*runsFillAgeTenths { + return nil + } + now := time.Now().UTC() + if a.Now != nil { + now = a.Now().UTC() + } + held := f.Bytes + last, err := a.Aged.Get(RetentionTestRuns) + if err != nil { + return err + } + moved, deleted := last, 0 + var oldest, newest time.Time + defer func() { + if moved != last { + if err := a.Aged.Put(RetentionTestRuns, moved); err != nil { + a.logf("aged: the test runs' retention is not moved to %d: %v", moved, err) + } + } + }() + for f.Bytes*10 >= f.Cap*runsFillUnderTenths { + entries, err := a.Log(moved+1, AgedPerStep) + if err != nil { + return err + } + if len(entries) == 0 { + break + } + for _, e := range entries { + moved = e.Sequence + _, ended, ok := a.deleteRun(e.Entry) + if !ok { + continue + } + deleted++ + if oldest.IsZero() || ended.Before(oldest) { + oldest = ended + } + if ended.After(newest) { + newest = ended + } + if f, err = a.RunsFill(); err != nil { + return err + } + if f.Bytes*10 < f.Cap*runsFillUnderTenths { + break + } + } + } + if deleted == 0 { + a.logf("aged: the state test-runs holds %d of its %d bytes, nine tenths or more, and no ended test run is left to delete in the step log", held, f.Cap) + return nil + } + a.logf("aged: the state test-runs held %d of its %d bytes, nine tenths or more, so %d ended test runs and their outputs were deleted, ended %s to %s ago; it holds %d bytes now", + held, f.Cap, deleted, now.Sub(oldest).Round(time.Second), now.Sub(newest).Round(time.Second), f.Bytes) + return nil +} + func (a *Ager) ageAt(r Retention) error { now := time.Now().UTC() if a.Now != nil { @@ -122,14 +209,21 @@ func (a *Ager) ageAt(r Retention) error { const RetentionTestRuns = "test-runs" // ageRun deletes the test run the ended step of e read, and its output object, once its kept time has passed since the -// step's end, in the step log's order (§725, A-470a): the run's key is read from e's pipeline, its step's Shared run. +// step's end, in the step log's order (§725, A-470a), said in a line. func (a *Ager) ageRun(r Retention, e seat.LogEntry) { - if e.What != seat.LogEntryWhatEnded { - return + if run, _, ok := a.deleteRun(e); ok { + a.logf("aged: deleted the test run %s and its output (%s after its end)", run, r.Age) } - p, _, err := a.Pipelines.Get(e.Pipeline) +} + +// runOfEntry is the run the ended step of e read: its step's Shared run in e's pipeline, empty when it reads none. +func runOfEntry(pipelines Updater, e seat.LogEntry) string { + if e.What != seat.LogEntryWhatEnded { + return "" + } + p, _, err := pipelines.Get(e.Pipeline) if err != nil { - return + return "" } run := "" for _, s := range p.Steps { @@ -137,20 +231,27 @@ func (a *Ager) ageRun(r Retention, e seat.LogEntry) { run = sharedRun(s) } } + return run +} + +// deleteRun deletes the ended test run the ended step of e read, and its output object, and answers its end: the run's key +// is read from e's pipeline, its step's Shared run. A run not ended is kept, and so is one whose output is not deleted. +func (a *Ager) deleteRun(e seat.LogEntry) (string, time.Time, bool) { + run := runOfEntry(a.Pipelines, e) if run == "" { - return + return run, time.Time{}, false } for { t, rev, err := a.Runs.Get(run) // The entry is past the retention (ageAt), and a run ends no later than the reader's end it was read at: a run not // ended yet is aged at a later reader's end. if err != nil || t.Ended == nil { - return + return run, time.Time{}, false } if t.Output != "" && a.RunOutputs != nil { if err := a.RunOutputs(t.Output); err != nil { a.logf("aged: the output %s of the test run %s is not deleted, so the run is kept: %v", t.Output, run, err) - return + return run, time.Time{}, false } } // Deleted at the revision read: a rerun that wrote the key again since is read again, and a run it started is kept. @@ -158,11 +259,10 @@ func (a *Ager) ageRun(r Retention, e seat.LogEntry) { continue } else if err != nil { a.logf("aged: the test run %s is not deleted: %v", run, err) - return + return run, time.Time{}, false } - a.logf("aged: deleted the test run %s and its output (%s after its end)", run, r.Age) unmarkAsks(a.Clock, run, a.logf) - return + return run, *t.Ended, true } } diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/runends.go b/modules/mesh-delivery-pipeline/internal/pipeline/runends.go index 7a68b1e83..3b3a869cc 100644 --- a/modules/mesh-delivery-pipeline/internal/pipeline/runends.go +++ b/modules/mesh-delivery-pipeline/internal/pipeline/runends.go @@ -10,18 +10,17 @@ import ( seat "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshpipelinerunner" ) -// RunSettings are the runner's settings of its test runs (design 47 G §725; A-469d, A-469w, A-469x): the cap of test-runs -// the process judges a write by, how long an ended run is kept, the bound of a taken run's owed progress and the bound of -// an ask never taken. +// RunSettings are the runner's settings of its test runs (design 47 G §725; A-469d, A-469w, A-469x): how long an ended run +// is kept, the bound of a taken run's owed progress and the bound of an ask never taken. test-runs' cap is no setting: it +// is its bucket's max bytes, read from the bus (H-A-510 addendum). type RunSettings struct { - CapBytes int64 Kept time.Duration StepBound time.Duration Untaken time.Duration } -// The settings' defaults (§725; A-466n, A-466s): 16 MiB, 7 days, 30 minutes, 24 hours. -var DefaultRunSettings = RunSettings{CapBytes: 16 << 20, Kept: 7 * 24 * time.Hour, StepBound: 30 * time.Minute, Untaken: 24 * time.Hour} +// The settings' defaults (§725; A-466n, A-466s, H-A-510): 48 hours, 30 minutes, 24 hours. +var DefaultRunSettings = RunSettings{Kept: 48 * time.Hour, StepBound: 30 * time.Minute, Untaken: 24 * time.Hour} // The two bound keys of a test run in test-runs, each with its own time to live (§725; A-468b, A-470): `bound.`, // written at the build seat's ask-taken of the run's ask and again at each step-progress of it, and `untaken.`, @@ -407,9 +406,6 @@ func (h *Hearer) TakeUp() (int, error) { func (h *Hearer) runSettings() RunSettings { s := h.Runs d := DefaultRunSettings - if s.CapBytes <= 0 { - s.CapBytes = d.CapBytes - } if s.Kept <= 0 { s.Kept = d.Kept } diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/testruns.go b/modules/mesh-delivery-pipeline/internal/pipeline/testruns.go index a46e85e85..f72c4b600 100644 --- a/modules/mesh-delivery-pipeline/internal/pipeline/testruns.go +++ b/modules/mesh-delivery-pipeline/internal/pipeline/testruns.go @@ -206,27 +206,20 @@ func (s *Starter) share(key string, asks []Asked) []Asked { type fullErr struct{ fill seat.Fill } func (e *fullErr) Error() string { - return fmt.Sprintf("the state %s holds %d of its %d bytes, so no test run is asked (test-runs-cap-mib)", e.fill.Store, e.fill.Bytes, e.fill.Cap) + return fmt.Sprintf("the state %s holds %d of its %d bytes, so no test run is asked (its bucket's max-mib)", e.fill.Store, e.fill.Bytes, e.fill.Cap) } -// TestRunsFill is test-runs' fill against its cap setting test-runs-cap-mib, the cap that refuses a new run (A-469d, A-470i), -// never the manifest's ceiling. +// TestRunsFill is test-runs' fill against its cap, the bucket's max bytes as the bus says it, the max-mib of the manifest +// the runner runs from and never a second number (A-469d, A-470i, H-A-510 and its addendum). func (s *Starter) TestRunsFill() (seat.Fill, error) { if s.RunsFill == nil { return seat.Fill{}, errors.New("the runner reads no fill of test-runs") } - f, err := s.RunsFill() - if err != nil { - return seat.Fill{}, err - } - f.Cap = s.Runs.CapBytes - if f.Cap <= 0 { - f.Cap = DefaultRunSettings.CapBytes - } - return f, nil + return s.RunsFill() } -// atCap is the error of test-runs at its cap setting, nil below it or when its fill is not read (said). +// atCap is the error of test-runs full by its bucket's max bytes, nil below it, when its bucket has no cap or when its +// fill is not read (said). func (s *Starter) atCap() error { if s.RunsFill == nil { return nil @@ -236,7 +229,7 @@ func (s *Starter) atCap() error { s.logf("the fill of test-runs is not read, so its cap is not judged: %v", err) return nil } - if f.Bytes >= f.Cap { + if f.Cap > 0 && f.Bytes >= f.Cap { return &fullErr{fill: f} } return nil diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/testruns_test.go b/modules/mesh-delivery-pipeline/internal/pipeline/testruns_test.go index 60a47cb9a..5446491fa 100644 --- a/modules/mesh-delivery-pipeline/internal/pipeline/testruns_test.go +++ b/modules/mesh-delivery-pipeline/internal/pipeline/testruns_test.go @@ -112,6 +112,7 @@ type runFixture struct { said []seat.StepEvent logged []string fill int64 + cap int64 s *Starter h *Hearer // mu guards drops and logged, written also by the drops DropOpen asks side by side (H-A-506). @@ -142,7 +143,7 @@ func newRunFixture() *runFixture { }} f.s = &Starter{Pipelines: memCreated{f.store}, Store: f.store, TestRuns: f.runs, Clock: f.clock, Say: say, Steps: f.asks, Name: "the-runner", Registration: func(string) (catalog.Registration, bool) { return reg, true }, EndReaders: f.h.EndReaders, - RunsFill: func() (seat.Fill, error) { return seat.Fill{Store: "test-runs", Bytes: f.fill}, nil }, Logf: f.h.Logf} + RunsFill: func() (seat.Fill, error) { return seat.Fill{Store: "test-runs", Bytes: f.fill, Cap: f.cap}, nil }, Logf: f.h.Logf} return f } @@ -260,7 +261,7 @@ func TestATestRunHasOneClockACapAndAnAge(t *testing.T) { }) t.Run("cap", func(t *testing.T) { f := newRunFixture() - f.s.Runs.CapBytes, f.fill = 1<<20, 1<<20 + f.cap, f.fill = 1<<20, 1<<20 p := f.start(t, 4, 9) for _, a := range f.asks.ids { if a == stepNamed(p, "app:program", "unit").Ask { @@ -282,14 +283,15 @@ func TestATestRunHasOneClockACapAndAnAge(t *testing.T) { _ = f.h.EndRun(run, seat.TestRun{Outcome: seat.StepResultOutcomePassed, Output: "out-1"}, nil) f.objects["out-1"] = []byte("ok") now := agedNow - a := &Ager{Runs: f.runs, RunOutputs: f.objects.Delete, RunsKept: 7 * 24 * time.Hour, Pipelines: agedDeleter{f.store}, + // test-runs-kept unset is its default, 48h (H-A-510). + a := &Ager{Runs: f.runs, RunOutputs: f.objects.Delete, Pipelines: agedDeleter{f.store}, Clock: f.clock, Aged: agedState{}, Now: func() time.Time { return now }, Log: func(from uint64, limit int) ([]LoggedEntry, error) { if from > 1 { return nil, nil } return []LoggedEntry{{Sequence: 1, Entry: seat.LogEntry{Pipeline: p.Pipeline, Step: "unit", Artifact: "app:tools", - What: seat.LogEntryWhatEnded, At: agedNow.Add(-6 * 24 * time.Hour)}}}, nil + What: seat.LogEntryWhatEnded, At: agedNow.Add(-46 * time.Hour)}}}, nil }} a.Age() if _, _, err := f.runs.Get(run); err != nil { @@ -300,7 +302,7 @@ func TestATestRunHasOneClockACapAndAnAge(t *testing.T) { t.Fatalf("the ask key of %s holds %q after its run ended, want it deleted with the end", unit.Ask, held) } _ = f.clock.MarkAsk(unit.Ask, AskMark{Run: run}) // a key written before the addendum, holding its run alone - now = now.Add(2 * 24 * time.Hour) + now = now.Add(3 * time.Hour) a.Age() if _, _, err := f.runs.Get(run); err != ErrNoRun || len(f.objects) != 0 { t.Errorf("the run past test-runs-kept is %v, objects %v; want both deleted", err, f.objects) @@ -310,6 +312,74 @@ func TestATestRunHasOneClockACapAndAnAge(t *testing.T) { t.Errorf("the ask key of %s outlives its aged run", unit.Ask) } }) + t.Run("age by fill", func(t *testing.T) { + // H-A-510: at nine tenths of the bucket's max bytes the oldest ended runs go with their outputs, in the step log's + // order, until the fill is under eight tenths, said in one line; a run not ended is never aged by fill. + store, runs, objects := memStore{}, testRunsMem{}, objectsMem{} + var steps []seat.StepResult + var log []LoggedEntry + for i := range 5 { + run, step := sprintf("r%d", i), sprintf("unit%d", i) + steps = append(steps, seat.StepResult{Artifact: "app:program", Step: step, Shared: []seat.Shared{{Run: run}}}) + r := Run{TestRun: seat.TestRun{Output: "o" + run}} + if i > 0 { // r0 has not ended + ended := agedNow.Add(-time.Duration(6-i) * time.Hour) + r.Ended = &ended + } + _ = runs.Create(run, r) + objects["o"+run] = []byte("out") + log = append(log, LoggedEntry{Sequence: uint64(i + 1), Entry: seat.LogEntry{Pipeline: "main.1", Step: step, + Artifact: "app:program", What: seat.LogEntryWhatEnded, At: agedNow.Add(-time.Hour)}}) + } + store["main.1"] = struct { + p seat.Pipeline + rev uint64 + }{seat.Pipeline{Pipeline: "main.1", Branch: "main", Outcome: seat.PipelineOutcomePassed, Steps: steps}, 1} + var logged []string + cap := int64(60) + aged := agedState{} + a := &Ager{Runs: runs, RunOutputs: objects.Delete, Pipelines: agedDeleter{store}, Aged: aged, + Now: func() time.Time { return agedNow }, + Logf: func(format string, v ...any) { logged = append(logged, sprintf(format, v...)) }, + RunsFill: func() (seat.Fill, error) { + return seat.Fill{Store: "test-runs", Bytes: int64(10 * len(runs)), Cap: cap}, nil + }, + Log: func(from uint64, limit int) ([]LoggedEntry, error) { + var out []LoggedEntry + for _, e := range log { + if e.Sequence >= from && len(out) < limit { + out = append(out, e) + } + } + return out, nil + }} + kept := func() []string { + var out []string + for k := range runs { + out = append(out, k) + } + slices.Sort(out) + return out + } + a.Age() // 50 of 60 bytes, under nine tenths; and no run is past test-runs-kept's 48h + if got := kept(); len(got) != 5 || len(logged) != 0 { + t.Fatalf("under nine tenths the runs are %v, said %q; want all five kept, nothing said", got, logged) + } + cap = 50 + a.Age() + if got := kept(); !slices.Equal(got, []string{"r0", "r3", "r4"}) || objects["or1"] != nil || objects["or2"] != nil || objects["or0"] == nil { + t.Fatalf("at the cap the runs are %v, objects %v; want r1 and r2 deleted with their outputs, the unended r0 kept", got, objects) + } + if len(logged) != 1 || !strings.Contains(logged[0], "50 of its 50 bytes") || !strings.Contains(logged[0], "2 ended test runs") || + !strings.Contains(logged[0], "ended 5h0m0s to 4h0m0s ago") || !strings.Contains(logged[0], "holds 30 bytes now") || aged[RetentionTestRuns] != 3 { + t.Fatalf("the fill's ageing said %q, retention at %d; want one line of how many and how old, at the log's third entry", logged, aged[RetentionTestRuns]) + } + cap, logged = 10, nil + a.Age() // past the cap: every ended run left goes, the log runs out, and the unended r0 stays + if got := kept(); !slices.Equal(got, []string{"r0"}) || len(logged) != 1 || !strings.Contains(logged[0], "2 ended test runs") { + t.Fatalf("the runs are %v, said %q; want only the unended r0 kept, said in one line", got, logged) + } + }) } // agedDeleter is a memStore with the delete the ager makes. @@ -547,15 +617,13 @@ func TestTheTestRunsAreReadAndDroppedByTheirVerbs(t *testing.T) { for k, e := range f.runs { put(t, pipes, k, e.r) } - // The fill is said against the cap setting that refuses, never the bucket's 64 MiB ceiling (A-470g, A-470i). - f.s.Runs.CapBytes, f.fill = 1<<20, 9 - bucket := f.s.RunsFill - f.s.RunsFill = func() (seat.Fill, error) { fl, err := bucket(); fl.Cap = 64 << 20; return fl, err } + // The fill is said against the bucket's max bytes, the cap that refuses, never a second number (A-470i, H-A-510). + f.cap, f.fill = 1<<20, 9 read := RunsRead{Runs: pipes, Object: f.objects.Get, Fill: f.s.TestRunsFill} a, err := read.TestRuns(seat.TestRunsInput{Level: "unit", Module: "app"}) if err != nil || len(a.Runs) != 1 || len(a.Runs[0].Packages) != 1 || a.Runs[0].Packages[0] != (seat.TestRunPackage{Package: "app/x", Digest: "d1"}) || a.Runs[0].Key != unit.Shared[0].Run || len(a.Runs[0].Readers) != 2 || a.Fill.Cap != 1<<20 || a.Fill.Bytes != 9 { - t.Fatalf("test-runs = %+v, %v; want the unit run with its package and readers, and the fill against the cap setting", a, err) + t.Fatalf("test-runs = %+v, %v; want the unit run with its package and readers, and the fill against the bucket's max bytes", a, err) } delete(f.objects, unit.Shared[0].Run) // gone, whatever step-outputs' age: the run answers without its packages if a, _ := read.TestRuns(seat.TestRunsInput{Level: "unit"}); len(a.Runs) != 1 || a.Runs[0].Gone != Gone || len(a.Runs[0].Packages) != 0 { diff --git a/modules/mesh-delivery-pipeline/manifest_test.go b/modules/mesh-delivery-pipeline/manifest_test.go index 07d0dbfad..a26fd0c81 100644 --- a/modules/mesh-delivery-pipeline/manifest_test.go +++ b/modules/mesh-delivery-pipeline/manifest_test.go @@ -208,8 +208,9 @@ func equalSets(a, b []string) bool { return slices.Equal(x, y) } -// runSettingsOf says whether the manifest holds the test runs' four settings (design 47 G §725; A-469w, A-469x): the cap a -// whole number of at most 64, the three times Go durations, each written into the file its environment names. +// runSettingsOf says whether the manifest holds the test runs' three settings (design 47 G §725; A-469w, A-469x), Go +// durations, test-runs-kept 48h by default, each written into the file its environment names, and no cap setting: the cap is +// the state's max-mib (H-A-510 and its addendum). func runSettingsOf(raw []byte) bool { var m struct { Config map[string]map[string]any `json:"config"` @@ -223,7 +224,7 @@ func runSettingsOf(raw []byte) bool { if json.Unmarshal(raw, &m) != nil { return false } - want := map[string]string{"test-runs-cap-mib": "number", "test-runs-kept": "string", "test-step-bound": "string", "run-untaken-bound": "string", "ask-unanswered-bound": "string", "widens-read-bound": "string", "revisions-kept": "number", + want := map[string]string{"test-runs-kept": "string", "test-step-bound": "string", "run-untaken-bound": "string", "ask-unanswered-bound": "string", "widens-read-bound": "string", "revisions-kept": "number", "pipelines-at-once": "number", "pipelines-waiting-cap": "number"} // design 47 H2 §790, §781: stalled-bound is read through mesh-sdk's settings reader, by the process and the tools // program alike, from the words the node-engine composes: no file of its own. @@ -235,7 +236,7 @@ func runSettingsOf(raw []byte) bool { return false } } - if len(m.Config) != len(want)+len(words) || m.Config["test-runs-cap-mib"]["maximum"] != float64(64) || m.Config["test-runs-cap-mib"]["default"] != float64(16) || + if len(m.Config) != len(want)+len(words) || m.Config["test-runs-kept"]["default"] != "48h" || m.Config["pipelines-at-once"]["minimum"] != float64(1) || m.Config["pipelines-at-once"]["maximum"] != float64(8) || m.Config["pipelines-at-once"]["default"] != float64(1) || m.Config["pipelines-waiting-cap"]["default"] != float64(64) || m.Config["widens-read-bound"]["default"] != "30s" { @@ -247,6 +248,11 @@ func runSettingsOf(raw []byte) bool { env[v] = true } } + for _, r := range m.Resources { + if strings.Contains(r.Path, "test-runs-cap") { + return false + } + } for key, kind := range want { if m.Config[key]["type"] != kind { return false diff --git a/modules/mesh-delivery-pipeline/module.json b/modules/mesh-delivery-pipeline/module.json index e1e2bae21..5296680b9 100644 --- a/modules/mesh-delivery-pipeline/module.json +++ b/modules/mesh-delivery-pipeline/module.json @@ -116,19 +116,11 @@ "operator-channel" ], "config": { - "test-runs-cap-mib": { - "type": "number", - "description": "MiB of the state test-runs at which the runner asks no new test run and ends the step could not run, naming the fill (design 47 G section 725, A-469d); the manifest's max-mib is the ceiling.", - "minimum": 1, - "maximum": 64, - "trusted": false, - "default": 16 - }, "test-runs-kept": { "type": "string", - "description": "how long an ended test run and its output object are kept after its end, a Go duration such as 168h (design 47 G section 725, A-469x, A-470a); at most 168h, so the pipeline naming its key is still kept.", + "description": "how long an ended test run and its output object are kept after its end, a Go duration such as 48h (design 47 G section 725, A-469x, A-470a, H-A-510); at most 168h, so the pipeline naming its key is still kept. Past nine tenths of the state's max-mib the oldest ended runs go sooner, until it is under eight tenths.", "trusted": false, - "default": "168h" + "default": "48h" }, "test-step-bound": { "type": "string", @@ -301,14 +293,6 @@ "place": ".", "unknown": "program" }, - { - "id": "test-runs-cap", - "type": "file", - "path": "${dir:state}/test-runs-cap-mib", - "owner": "mesh-delivery-pipeline", - "mode": "0600", - "content": "${config:test-runs-cap-mib}" - }, { "id": "test-runs-kept", "type": "file", @@ -383,7 +367,6 @@ ], "env": { "MESH_BROKER_FILE": "${dir:state}/broker", - "MESH_RUNNER_TEST_RUNS_CAP_FILE": "${dir:state}/test-runs-cap-mib", "MESH_RUNNER_TEST_RUNS_KEPT_FILE": "${dir:state}/test-runs-kept", "MESH_RUNNER_TEST_STEP_BOUND_FILE": "${dir:state}/test-step-bound", "MESH_RUNNER_WIDENS_READ_BOUND_FILE": "${dir:state}/widens-read-bound",