host: size changes nudge the activator; status carries the size in force and the committed figure
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
7 files changed,
+477
−7
internal/host/agent.go+16 −3internal/host/layoutleg.go+5 −1internal/host/sizestatus.go+144 −0internal/host/sizestatus_test.go+258 −0internal/status/contract_test.go+9 −2internal/status/snapshot.go+17 −1internal/status/snapshot_test.go+28 −0
diff --git a/internal/host/agent.go b/internal/host/agent.go| index b52983b07..3b64d07e3 100644 |
| --- a/internal/host/agent.go |
| +++ b/internal/host/agent.go |
| @@ -511,6 +511,10 @@ func runAgent(args []string, buildClaims ClaimFactory) { |
| Exec: eb, |
| Unit: &activator.UnitBackend{OptDir: release.OptDir()}, |
| }, reg) // the registry satisfies activator.DueStore directly |
| + // Sizes (#329): the provisioning passes' PolicyChanged tells this |
| + // Service a row's size column moved, and the status tick reads each |
| + // awake instance's size through it and the box's cgroupfs. |
| + armSizeSource(svc, "/sys/fs/cgroup") |
| // doWake's own re-read of the committed row before it spawns |
| // (design §6.8). The registry satisfies RouteLookup with its own |
| // Get, exactly as DueStore above. |
| @@ -3461,13 +3465,18 @@ func provisionTickConfig(getenv func(string) string) provision.ReconcileConfig { |
| // boxProvisionConfig is one reconcile pass's Config on this box, from |
| // either provisioning loop (fastConvergeLoop's full pass, instancesLoop): |
| // provisionTickConfig from the environment, the claim configuration, the |
| -// box's lifetime judge (newBoxJudge; nil with host claims on) and the |
| -// process's one app policy cache (armPolicyCache). Pinned by |
| -// TestProvisioningLoopsShareThePolicyCache. |
| +// box's lifetime judge (newBoxJudge; nil with host claims on), the |
| +// process's one app policy cache (armPolicyCache) and the size nudge |
| +// (noteSizeChanged). Pinned by TestProvisioningLoopsShareThePolicyCache |
| +// and TestPolicyChangedNotesTheSize. |
| func boxProvisionConfig(judge *provision.LifetimeJudge, configure []func(*provision.ReconcileConfig)) provision.ReconcileConfig { |
| cfg := configuredClaimProvision(provisionTickConfig(os.Getenv), configure) |
| cfg.Judge = judge |
| cfg.Policies = armedPolicyCache.Load() |
| + // A converge that moved a row's policy columns tells the activator, so |
| + // a new size applies live on the next sweep (#329); nil-safe before |
| + // the activator is armed. |
| + cfg.PolicyChanged = noteSizeChanged |
| return cfg |
| } |
| @@ -4254,6 +4263,10 @@ func statusLoop(reg *registry.Registry, svc *activator.Service, buildStates func |
| // local socket and an in-memory map: no store request. Private |
| // Metrics only: hosts. |
| p.Egress = egressStatusProbe(egressStatus, routes, provision.PolicyReadStates()) |
| + // The sum of the awake instances' sizes (#329, spec §5.5), from the |
| + // activator's memory: no store request, no root call. nil with no |
| + // activator. Private Metrics only. |
| + p.SizeCommittedMiB = sizeCommittedMiB(armedSizeSource.Load(), routes) |
| // A fleet box (CARLOS_FLEET set) never gets here as a contender: it |
| // self-reports only, never attempting the election at all — no |
diff --git a/internal/host/layoutleg.go b/internal/host/layoutleg.go| index 37d3b88b5..5974e697f 100644 |
| --- a/internal/host/layoutleg.go |
| +++ b/internal/host/layoutleg.go |
| @@ -189,6 +189,7 @@ func layoutStatusReport(routes []registry.Route) *status.LayoutReport { |
| mode = "none" |
| } |
| def := lastLayoutDefault() |
| + sizes := armedSizeSource.Load() |
| rows := map[string]status.RowLayout{} |
| for _, rt := range routes { |
| // Only instance-kind rows: a sidecar (Kind "sidecar") is outside |
| @@ -206,7 +207,10 @@ func layoutStatusReport(routes []registry.Route) *status.LayoutReport { |
| if why, held := pass.Held(rt.Host); held && word == activator.LayoutFlat { |
| word, reason = activator.LayoutFenced, "held down after a refused move to nested: "+why |
| } |
| - rows[rt.Host] = status.RowLayout{Layout: string(word), Reason: reason, Note: pass.Note(rt.Host)} |
| + // The size cell (#329, spec §5.6): the agent's own cgroupfs |
| + // read against the activator's state, no root call. |
| + rows[rt.Host] = status.RowLayout{Layout: string(word), Reason: reason, Note: pass.Note(rt.Host), |
| + Size: rowSizeCell(sizes, rt.Host, word)} |
| case rt.Socket != "" && !rt.Hibernate: |
| // ActivatorManaged's own doc: an unflagged socket route is run |
| // by another supervisor, nobody's to migrate or isolate. |
diff --git a/internal/host/sizestatus.go b/internal/host/sizestatus.go| new file mode 100644 |
| index 000000000..6d836632c |
| --- /dev/null |
| +++ b/internal/host/sizestatus.go |
| @@ -0,0 +1,144 @@ |
| +package host |
| + |
| +import ( |
| + "errors" |
| + "io/fs" |
| + "os" |
| + "path/filepath" |
| + "strconv" |
| + "strings" |
| + "sync/atomic" |
| + |
| + "github.com/carlosframework/platform/internal/activator" |
| + "github.com/carlosframework/platform/internal/cgroup" |
| + "github.com/carlosframework/platform/internal/instancectl" |
| + "github.com/carlosframework/platform/internal/registry" |
| +) |
| + |
| +// sizeStater is the activator's live-size view (#329, spec §5.4): |
| +// SizeState answers for an awake instance that is not a worker, with the |
| +// size its route and build run at now (activator.EffectiveSize through the |
| +// Service's own backend), and NoteSize says a row's size column may have |
| +// moved. Production's is the agent's *activator.Service. |
| +type sizeStater interface { |
| + SizeState(host string) (activator.SizeState, bool) |
| + NoteSize(host string) |
| +} |
| + |
| +var _ sizeStater = (*activator.Service)(nil) |
| + |
| +// sizeSource is what the agent's status tick and provisioning passes read |
| +// sizes through: the activator Service and the cgroup root to read the |
| +// size in force from. The Service's SizeState already computes the wanted |
| +// size through the Service's own backend (the *SplitBackend the agent |
| +// builds), so no second reference to that backend is kept here. |
| +type sizeSource struct { |
| + svc sizeStater |
| + cgroupRoot string |
| +} |
| + |
| +// armedSizeSource is the box's size source: nil until RunAgent builds the |
| +// activator Service, and on a box with none. |
| +var armedSizeSource atomic.Pointer[sizeSource] |
| + |
| +// armSizeSource publishes svc as the box's size source, reading the size |
| +// in force under cgroupRoot. |
| +func armSizeSource(svc *activator.Service, cgroupRoot string) { |
| + armedSizeSource.Store(&sizeSource{svc: svc, cgroupRoot: cgroupRoot}) |
| +} |
| + |
| +// noteSizeChanged is the provisioning passes' PolicyChanged: a converge |
| +// that moved a row's policy columns tells the activator, whose next sweep |
| +// compares the size column at once rather than at its backstop. An |
| +// egress-only change makes a compare and no write. Before the activator is |
| +// armed, and on a box with none, it does nothing. |
| +func noteSizeChanged(host string) { |
| + if src := armedSizeSource.Load(); src != nil { |
| + src.svc.NoteSize(host) |
| + } |
| +} |
| + |
| +// readSizeInForce is the size host's cgroup holds (spec §5.4 "Read-back"): |
| +// memory.max of generation gen's unit when gen > 0 and the unit's cgroup |
| +// exists, else of the host's slice, matched to a size row on memory alone. |
| +// It reads cgroupfs, what systemd wrote and the kernel holds, and asks |
| +// root nothing. No slice, an unreadable file, "max" or a value that is no |
| +// row: false. |
| +func readSizeInForce(cgroupRoot, host string, gen uint64) (cgroup.Size, bool) { |
| + dir := filepath.Join(cgroupRoot, instancectl.SliceControlGroup(host)) |
| + if gen > 0 { |
| + unit := filepath.Join(dir, instancectl.GenUnitName(host, gen)) |
| + switch _, err := os.Stat(unit); { |
| + case err == nil: |
| + dir = unit |
| + case !errors.Is(err, fs.ErrNotExist): |
| + return cgroup.Size{}, false |
| + } |
| + } |
| + b, err := os.ReadFile(filepath.Join(dir, "memory.max")) |
| + if err != nil { |
| + return cgroup.Size{}, false |
| + } |
| + n, err := strconv.ParseInt(strings.TrimSpace(string(b)), 10, 64) |
| + if err != nil { |
| + return cgroup.Size{}, false |
| + } |
| + return cgroup.SizeOf(cgroup.Limit{MemoryMax: n}) |
| +} |
| + |
| +// sizeCell is an awake nested row's size cell (spec §5.6): "swap" while a |
| +// swap holds the parent, "?" when the size in force could not be read, the |
| +// size's name when it is the one wanted, else in force ">" wanted. |
| +func sizeCell(inForce cgroup.Size, ok bool, st activator.SizeState) string { |
| + switch { |
| + case st.Raised: |
| + return "swap" |
| + case !ok: |
| + return "?" |
| + case inForce.Name == st.Want.Name: |
| + return inForce.Name |
| + } |
| + return inForce.Name + ">" + st.Want.Name |
| +} |
| + |
| +// rowSizeCell is the size cell of an activator-managed row the layout pass |
| +// calls word: "" with no source armed (the report is as it was before |
| +// sizes), "-" for a row that is not nested (no live size there) or not an |
| +// awake instance (asleep, or a worker), else sizeCell over the cgroup's |
| +// read-back. |
| +func rowSizeCell(src *sizeSource, host string, word activator.Layout) string { |
| + if src == nil { |
| + return "" |
| + } |
| + if word != activator.LayoutNested { |
| + return "-" |
| + } |
| + st, awake := src.svc.SizeState(host) |
| + if !awake { |
| + return "-" |
| + } |
| + inForce, ok := readSizeInForce(src.cgroupRoot, host, st.Gen) |
| + return sizeCell(inForce, ok, st) |
| +} |
| + |
| +// sizeCommittedMiB is the box's committed figure (spec §5.5): the sum, in |
| +// MiB, of the memory limit of the size each awake instance runs at, from |
| +// the activator's SizeState (whose Want is the effective size for the |
| +// entry's current build). Asleep rows and workers count nothing. nil with |
| +// no source armed. It reads the activator's memory and the builds' |
| +// manifests on disk, never the store. |
| +func sizeCommittedMiB(src *sizeSource, routes []registry.Route) *int64 { |
| + if src == nil { |
| + return nil |
| + } |
| + var mib int64 |
| + for _, rt := range routes { |
| + if rt.Kind != "instance" { |
| + continue |
| + } |
| + if st, awake := src.svc.SizeState(rt.Host); awake { |
| + mib += st.Want.Limit.MemoryMax >> 20 |
| + } |
| + } |
| + return &mib |
| +} |
diff --git a/internal/host/sizestatus_test.go b/internal/host/sizestatus_test.go| new file mode 100644 |
| index 000000000..f1e4339a6 |
| --- /dev/null |
| +++ b/internal/host/sizestatus_test.go |
| @@ -0,0 +1,258 @@ |
| +package host |
| + |
| +import ( |
| + "os" |
| + "path/filepath" |
| + "reflect" |
| + "strconv" |
| + "strings" |
| + "sync" |
| + "testing" |
| + |
| + "github.com/carlosframework/platform/internal/activator" |
| + "github.com/carlosframework/platform/internal/cgroup" |
| + "github.com/carlosframework/platform/internal/instancectl" |
| + "github.com/carlosframework/platform/internal/layout" |
| + "github.com/carlosframework/platform/internal/provision" |
| + "github.com/carlosframework/platform/internal/registry" |
| +) |
| + |
| +// fakeSizeStater is the activator's live-size view over a fixed table: |
| +// a host in states is awake with that state, any other host is not. It |
| +// records every NoteSize. |
| +type fakeSizeStater struct { |
| + states map[string]activator.SizeState |
| + |
| + mu sync.Mutex |
| + noted []string |
| +} |
| + |
| +func (f *fakeSizeStater) SizeState(host string) (activator.SizeState, bool) { |
| + st, ok := f.states[host] |
| + return st, ok |
| +} |
| + |
| +func (f *fakeSizeStater) NoteSize(host string) { |
| + f.mu.Lock() |
| + defer f.mu.Unlock() |
| + f.noted = append(f.noted, host) |
| +} |
| + |
| +func (f *fakeSizeStater) notes() []string { |
| + f.mu.Lock() |
| + defer f.mu.Unlock() |
| + return append([]string(nil), f.noted...) |
| +} |
| + |
| +func mustSizeNamed(t *testing.T, name string) cgroup.Size { |
| + t.Helper() |
| + s, ok := cgroup.SizeByName(name) |
| + if !ok { |
| + t.Fatalf("no size %q", name) |
| + } |
| + return s |
| +} |
| + |
| +// writeMemoryMax writes a memory.max file under dir, creating dir. |
| +func writeMemoryMax(t *testing.T, dir, value string) { |
| + t.Helper() |
| + if err := os.MkdirAll(dir, 0o755); err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := os.WriteFile(filepath.Join(dir, "memory.max"), []byte(value+"\n"), 0o644); err != nil { |
| + t.Fatal(err) |
| + } |
| +} |
| + |
| +func TestSizeCell(t *testing.T) { |
| + t.Parallel() |
| + small, standard, large, xlarge := mustSizeNamed(t, "small"), mustSizeNamed(t, "standard"), mustSizeNamed(t, "large"), mustSizeNamed(t, "xlarge") |
| + for _, c := range []struct { |
| + name string |
| + inForce cgroup.Size |
| + ok bool |
| + st activator.SizeState |
| + want string |
| + }{ |
| + {"raised", large, true, activator.SizeState{Raised: true, Want: large}, "swap"}, |
| + {"raised and unreadable", cgroup.Size{}, false, activator.SizeState{Raised: true, Want: large}, "swap"}, |
| + {"unreadable", cgroup.Size{}, false, activator.SizeState{Want: large}, "?"}, |
| + {"in force", large, true, activator.SizeState{Want: large}, "large"}, |
| + {"shrink pending", large, true, activator.SizeState{Want: small}, "large>small"}, |
| + {"growth pending", standard, true, activator.SizeState{Want: xlarge}, "standard>xlarge"}, |
| + } { |
| + if got := sizeCell(c.inForce, c.ok, c.st); got != c.want { |
| + t.Errorf("%s: sizeCell = %q, want %q", c.name, got, c.want) |
| + } |
| + } |
| +} |
| + |
| +func TestReadSizeInForcePrefersTheServingUnit(t *testing.T) { |
| + t.Parallel() |
| + root := t.TempDir() |
| + const host = "shop-a.example.com" |
| + slice := filepath.Join(root, instancectl.SliceControlGroup(host)) |
| + // A swap raised the slice to 2 GiB; generation 2's own unit holds 1 GiB. |
| + writeMemoryMax(t, slice, "2147483648") |
| + writeMemoryMax(t, filepath.Join(slice, instancectl.GenUnitName(host, 2)), "1073741824") |
| + |
| + for _, c := range []struct { |
| + name string |
| + gen uint64 |
| + want string |
| + ok bool |
| + }{ |
| + {"the serving unit", 2, "large", true}, |
| + {"no unit directory: the slice", 3, "xlarge", true}, |
| + {"no generation: the slice", 0, "xlarge", true}, |
| + } { |
| + got, ok := readSizeInForce(root, host, c.gen) |
| + if ok != c.ok || got.Name != c.want { |
| + t.Errorf("%s: readSizeInForce(gen %d) = %q, %v; want %q, %v", c.name, c.gen, got.Name, ok, c.want, c.ok) |
| + } |
| + } |
| + |
| + // "max" (no limit), a value that is no row, and no slice at all are |
| + // not a size in force. |
| + const unlimited, odd = "shop-b.example.com", "shop-c.example.com" |
| + writeMemoryMax(t, filepath.Join(root, instancectl.SliceControlGroup(unlimited)), "max") |
| + writeMemoryMax(t, filepath.Join(root, instancectl.SliceControlGroup(odd)), strconv.FormatInt(1536<<20, 10)) |
| + for _, h := range []string{unlimited, odd, "shop-d.example.com"} { |
| + if got, ok := readSizeInForce(root, h, 0); ok { |
| + t.Errorf("%s: readSizeInForce = %q, true; want false", h, got.Name) |
| + } |
| + } |
| +} |
| + |
| +// nestedRoute and flatRoute are activator-managed rows the layout pass |
| +// classifies nested and flat under dd and sd. |
| +func nestedRoute(dd, sd, host string) registry.Route { |
| + return registry.Route{Host: host, Kind: "instance", Hibernate: true, Status: "ready", |
| + DBPath: provision.NestedDBPath(dd, host), |
| + Socket: filepath.Join(sd, "instances", provision.InstanceID(host), "app.sock")} |
| +} |
| + |
| +func flatRoute(dd, sd, host string) registry.Route { |
| + return registry.Route{Host: host, Kind: "instance", Hibernate: true, Status: "ready", |
| + DBPath: provision.DefaultDBPath(dd, host), Socket: filepath.Join(sd, host+".sock")} |
| +} |
| + |
| +// TestLayoutReportCarriesSize: with a size source armed, every |
| +// activator-managed row carries a size cell read from cgroupfs against the |
| +// activator's SizeState; with none armed, no row carries one, so the report |
| +// is what it was before sizes. Not parallel: it arms the layout pass and |
| +// the size source. |
| +func TestLayoutReportCarriesSize(t *testing.T) { |
| + resetLayoutGlobals(t) |
| + prev := armedSizeSource.Load() |
| + t.Cleanup(func() { armedSizeSource.Store(prev) }) |
| + |
| + dd, sd, root := t.TempDir(), t.TempDir(), t.TempDir() |
| + armedLayoutPass.Store(&layout.Pass{DataDir: dd, SocketDir: sd}) |
| + const ( |
| + serving = "shop-a.example.com" // awake, generation 2, large in force |
| + growing = "shop-b.example.com" // awake, slice alone, standard in force, xlarge wanted |
| + asleep = "shop-c.example.com" |
| + flat = "shop-d.example.com" // awake but flat: no live size |
| + swapped = "shop-e.example.com" // a swap holds the parent |
| + ) |
| + writeMemoryMax(t, filepath.Join(root, instancectl.SliceControlGroup(serving)), "2147483648") |
| + writeMemoryMax(t, filepath.Join(root, instancectl.SliceControlGroup(serving), instancectl.GenUnitName(serving, 2)), "1073741824") |
| + writeMemoryMax(t, filepath.Join(root, instancectl.SliceControlGroup(growing)), "536870912") |
| + writeMemoryMax(t, filepath.Join(root, instancectl.SliceControlGroup(swapped)), "1610612736") |
| + large, xlarge, standard := mustSizeNamed(t, "large"), mustSizeNamed(t, "xlarge"), mustSizeNamed(t, "standard") |
| + svc := &fakeSizeStater{states: map[string]activator.SizeState{ |
| + serving: {Gen: 2, Want: large}, |
| + growing: {Want: xlarge}, |
| + flat: {Want: standard}, |
| + swapped: {Gen: 4, Raised: true, Want: standard}, |
| + }} |
| + routes := []registry.Route{ |
| + nestedRoute(dd, sd, serving), nestedRoute(dd, sd, growing), nestedRoute(dd, sd, asleep), |
| + flatRoute(dd, sd, flat), nestedRoute(dd, sd, swapped), |
| + {Host: "external.example.com", Kind: "instance", Socket: "/elsewhere/external.sock"}, |
| + } |
| + |
| + unarmed := layoutStatusReport(routes) |
| + for h, row := range unarmed.Rows { |
| + if row.Size != "" { |
| + t.Errorf("no source armed: %s carries size %q, want none", h, row.Size) |
| + } |
| + } |
| + |
| + armedSizeSource.Store(&sizeSource{svc: svc, cgroupRoot: root}) |
| + report := layoutStatusReport(routes) |
| + want := map[string]string{ |
| + serving: "large", growing: "standard>xlarge", asleep: "-", flat: "-", swapped: "swap", |
| + "external.example.com": "", |
| + } |
| + got := map[string]string{} |
| + for h, row := range report.Rows { |
| + got[h] = row.Size |
| + } |
| + if !reflect.DeepEqual(got, want) { |
| + t.Fatalf("size cells = %v, want %v", got, want) |
| + } |
| + if report.Rows[serving].Layout != string(activator.LayoutNested) || report.Rows[flat].Layout != string(activator.LayoutFlat) { |
| + t.Fatalf("fixture rows classify %+v, want nested and flat", report.Rows) |
| + } |
| +} |
| + |
| +func TestSizeCommittedSumsAwakeEffectiveSizes(t *testing.T) { |
| + t.Parallel() |
| + if got := sizeCommittedMiB(nil, nil); got != nil { |
| + t.Fatalf("no source armed: committed = %d, want nil", *got) |
| + } |
| + svc := &fakeSizeStater{states: map[string]activator.SizeState{ |
| + "shop-a.example.com": {Want: mustSizeNamed(t, "small")}, |
| + "shop-b.example.com": {Gen: 3, Want: mustSizeNamed(t, "xlarge")}, |
| + // An awake entry of a row that is not an instance is not counted. |
| + "side.example.com": {Want: mustSizeNamed(t, "large")}, |
| + }} |
| + src := &sizeSource{svc: svc, cgroupRoot: t.TempDir()} |
| + routes := []registry.Route{ |
| + {Host: "shop-a.example.com", Kind: "instance", Size: "small"}, |
| + {Host: "shop-b.example.com", Kind: "instance", Size: "xlarge"}, |
| + {Host: "shop-c.example.com", Kind: "instance", Size: "large"}, // asleep |
| + {Host: "side.example.com", Kind: "sidecar"}, |
| + } |
| + got := sizeCommittedMiB(src, routes) |
| + if got == nil || *got != 256+2048 { |
| + t.Fatalf("committed = %v, want 2304", got) |
| + } |
| + if got := sizeCommittedMiB(src, nil); got == nil || *got != 0 { |
| + t.Fatalf("nothing awake: committed = %v, want 0", got) |
| + } |
| +} |
| + |
| +// TestPolicyChangedNotesTheSize pins the hook both provisioning loops get |
| +// through boxProvisionConfig: a converge that moved a row's policy columns |
| +// tells the armed activator, and before the activator is armed the hook |
| +// does nothing. RunAgent arms the source where it builds the Service. Not |
| +// parallel: it swaps the armed source. |
| +func TestPolicyChangedNotesTheSize(t *testing.T) { |
| + prev := armedSizeSource.Load() |
| + t.Cleanup(func() { armedSizeSource.Store(prev) }) |
| + |
| + armedSizeSource.Store(nil) |
| + cfg := boxProvisionConfig(nil, nil) |
| + if cfg.PolicyChanged == nil { |
| + t.Fatal("boxProvisionConfig sets no PolicyChanged") |
| + } |
| + cfg.PolicyChanged("shop-a.example.com") // nothing armed: no panic, nothing to tell |
| + |
| + svc := &fakeSizeStater{} |
| + armedSizeSource.Store(&sizeSource{svc: svc, cgroupRoot: t.TempDir()}) |
| + boxProvisionConfig(nil, nil).PolicyChanged("shop-a.example.com") |
| + if got := svc.notes(); !reflect.DeepEqual(got, []string{"shop-a.example.com"}) { |
| + t.Fatalf("NoteSize calls = %v, want [shop-a.example.com]", got) |
| + } |
| + |
| + src, err := os.ReadFile("agent.go") |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if n := strings.Count(string(src), "armSizeSource(svc, "); n != 1 { |
| + t.Fatalf("agent.go arms the size source %d times, want once where it builds the Service", n) |
| + } |
| +} |
diff --git a/internal/status/contract_test.go b/internal/status/contract_test.go| index 23fba2709..e2686bfc9 100644 |
| --- a/internal/status/contract_test.go |
| +++ b/internal/status/contract_test.go |
| @@ -82,13 +82,13 @@ var allowedBoxKeys = map[string][]string{ |
| "": {"generated_at", "label", "name", "region", "routes", "load", "capacity", "replication", "adoption_running", "config_path_running", "restart_path_running", "expired_canaries", "metrics"}, |
| "routes": {"static", "resident", "hibernating", "awake", "asleep"}, |
| "replication": {"healthy", "lag_seconds"}, |
| - "metrics": {"mem_total_bytes", "mem_avail_bytes", "load1", "disk_free_bytes", "release", "tunnel", "route_versions", "upstreams", "layout", "config_refusals", "config_refusals_total", "release_refusals", "proof_waits", "config_guard", "build_states", "build_states_err", "update_settings", "updates", "egress"}, |
| + "metrics": {"mem_total_bytes", "mem_avail_bytes", "load1", "disk_free_bytes", "release", "tunnel", "route_versions", "upstreams", "layout", "config_refusals", "config_refusals_total", "release_refusals", "proof_waits", "config_guard", "build_states", "build_states_err", "update_settings", "updates", "egress", "size_committed_mib"}, |
| "metrics.route_versions": {wildcardAnyKey}, |
| "metrics.upstreams": {wildcardAnyKey}, |
| "metrics.upstreams.*[]": {"addr", "up", "since", "fails", "last_error"}, |
| "metrics.layout": {"mode", "rows", "default", "default_blocked"}, |
| "metrics.layout.rows": {wildcardAnyKey}, |
| - "metrics.layout.rows.*": {"layout", "reason", "note"}, |
| + "metrics.layout.rows.*": {"layout", "reason", "note", "size"}, |
| // config_refusals (amadan #213) names hosts and a closed reason word, in |
| // the private block only. Pinned to the field level so a future field on |
| // the refusal is a publication decision too. |
| @@ -303,6 +303,7 @@ func fixtureProbes() status.Probes { |
| memAvail := int64(3123456789) // distinct from dryrun.go's 4242424241 |
| diskFree := int64(1123456789) // distinct from dryrun.go's 4242424240 |
| load1 := 1.23 // distinct from dryrun.go's 42.42 |
| + sizeCommitted := int64(2304) |
| // Listening function returns true for hibernating routes, false otherwise. |
| listening := func(sock string) *bool { |
| @@ -333,6 +334,8 @@ func fixtureProbes() status.Probes { |
| Mode: "flat", |
| Rows: map[string]status.RowLayout{ |
| "contract-layout.internal": {Layout: "flat"}, |
| + // A size cell, so the row's "size" key is exercised too (#329). |
| + "contract-sized.internal": {Layout: "nested", Size: "standard>xlarge"}, |
| "contract-foreign.internal": {Layout: "foreign", |
| Reason: `db "x" socket "y" are neither the flat nor the nested defaults`}, |
| }, |
| @@ -377,6 +380,10 @@ func fixtureProbes() status.Probes { |
| Egress: map[string]status.HostEgress{ |
| "contract-egress.internal": {Allowed: []string{"10.0.5.20"}, Refused: []string{"10.0.0.0/8: too wide"}, State: "failing", Detail: "set-property failed"}, |
| }, |
| + // The committed figure, so metrics.size_committed_mib is exercised |
| + // by the allowlist walk too (#329). |
| + SizeCommittedMiB: &sizeCommitted, |
| + |
| ConfigGuard: "bypassed (CARLOS_NO_SEALED_CONFIG)", |
| MemFrac: &memFrac, |
| DiskFrac: &diskFrac, |
diff --git a/internal/status/snapshot.go b/internal/status/snapshot.go| index e8f805dc5..9d38c665b 100644 |
| --- a/internal/status/snapshot.go |
| +++ b/internal/status/snapshot.go |
| @@ -197,6 +197,9 @@ type Probes struct { |
| // with the agent's own policy state where root has none. nil or empty |
| // means no host reported. Private Metrics only: it names hosts. |
| Egress map[string]HostEgress |
| + // SizeCommittedMiB is the sum, in MiB, of the sizes this box's awake |
| + // instances run at (#329, spec §5.5), or nil with no activator armed. |
| + SizeCommittedMiB *int64 |
| } |
| // HostEgress is one instance's egress read-back (#328, spec §4.4): the |
| @@ -260,6 +263,12 @@ type RowLayout struct { |
| // a refusal: what a move quarantined out of the instance directory or |
| // kept aside, and when. Paths, so private like Reason. |
| Note string `json:"note,omitempty"` |
| + // Size is the row's size cell (#329, spec §5.6): the size its cgroup |
| + // holds ("large"), the size in force and the one wanted when they differ |
| + // ("standard>xlarge"), "swap" while a swap holds the parent, "?" when |
| + // the cgroup could not be read, and "-" for a row that is not awake, |
| + // not nested, or a worker. Absent on a box with no activator armed. |
| + Size string `json:"size,omitempty"` |
| } |
| // LayoutReport is one box's whole layout picture: Mode is the intent the |
| @@ -658,6 +667,11 @@ type BoxMetrics struct { |
| // RouteVersions. Omitted when empty, so a box with no egress policy |
| // publishes exactly what it did before the field existed. |
| Egress map[string]HostEgress `json:"egress,omitempty"` |
| + // SizeCommittedMiB is the sum, in MiB, of the memory limits of the sizes |
| + // this box's awake instances run at (#329, spec §5.5): what the box has |
| + // promised, beside MemTotalBytes and MemAvailBytes. Information for the |
| + // console's size door, never a gate. Omitted with no activator armed. |
| + SizeCommittedMiB *int64 `json:"size_committed_mib,omitempty"` |
| } |
| // UpdateSettingsProtocol is the BoxMetrics.UpdateSettings a binary reports |
| @@ -1081,7 +1095,7 @@ func CollectBox(routes []registry.Route, p Probes, now time.Time) Box { |
| len(routeVersions) > 0 || len(routeServing) > 0 || len(aliasReadings) > 0 || len(p.Upstreams) > 0 || |
| len(routeDBBytes) > 0 || p.Layout != nil || len(p.ConfigRefusals) > 0 || len(p.ReleaseRefusals) > 0 || len(p.ProofWaits) > 0 || p.Rollout != nil || p.ConfigGuard != "" || |
| p.Alerts != nil || p.GeoIP != nil || len(p.BuildStates) > 0 || p.BuildStatesErr != "" || |
| - p.UpdateSettings != 0 || len(p.Updates) > 0 || len(p.Egress) > 0 { |
| + p.UpdateSettings != 0 || len(p.Updates) > 0 || len(p.Egress) > 0 || p.SizeCommittedMiB != nil { |
| box.Metrics = &BoxMetrics{ |
| ConsoleProcesses: p.ConsoleProcesses, |
| ActivationID: p.ActivationID, ActivationComplete: p.ActivationComplete, |
| @@ -1125,6 +1139,8 @@ func CollectBox(routes []registry.Route, p Probes, now time.Time) Box { |
| UpdateSettings: p.UpdateSettings, |
| Updates: p.Updates, |
| Egress: p.Egress, |
| + |
| + SizeCommittedMiB: p.SizeCommittedMiB, |
| } |
| } |
diff --git a/internal/status/snapshot_test.go b/internal/status/snapshot_test.go| index b735044bf..919f15933 100644 |
| --- a/internal/status/snapshot_test.go |
| +++ b/internal/status/snapshot_test.go |
| @@ -262,3 +262,31 @@ func TestCollectBoxOmitsEmptyEgress(t *testing.T) { |
| } |
| } |
| } |
| + |
| +// TestCollectBoxCarriesSizeCommitted pins Probes.SizeCommittedMiB (#329): |
| +// the sum of the awake instances' sizes reaches the private Metrics block |
| +// as size_committed_mib and counts on its own toward "something is known"; |
| +// with no figure (nil) the snapshot is what it was before the field. |
| +func TestCollectBoxCarriesSizeCommitted(t *testing.T) { |
| + at := time.Date(2026, 10, 25, 9, 0, 0, 0, time.UTC) |
| + mib := int64(2304) |
| + b := CollectBox(nil, Probes{SizeCommittedMiB: &mib}, at) |
| + if b.Metrics == nil || b.Metrics.SizeCommittedMiB == nil || *b.Metrics.SizeCommittedMiB != 2304 { |
| + t.Fatalf("metrics = %+v, want size_committed_mib 2304", b.Metrics) |
| + } |
| + out, err := json.Marshal(b) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if !strings.Contains(string(out), `"size_committed_mib":2304`) { |
| + t.Fatalf("json lacks size_committed_mib: %s", out) |
| + } |
| + if b := CollectBox(nil, Probes{}, at); b.Metrics != nil { |
| + t.Fatalf("no figure and nothing else known must mean no metrics block: %+v", b.Metrics) |
| + } |
| + routes := []registry.Route{{Host: "shop-a.example.com", Kind: "instance", Version: "v1"}} |
| + got, _ := json.Marshal(CollectBox(routes, Probes{MachineID: "m", Release: "v1"}, at)) |
| + if strings.Contains(string(got), "size_committed") { |
| + t.Fatalf("snapshot with no figure carries the key: %s", got) |
| + } |
| +} |