status: a demo box's room on /data and /run, and the disk alert
Demo disk bound, slice 1. Box status on a demo box gains demo_disk: /data and /run free and total bytes and inodes, and the demo builds root's retention record says it keeps, with the backlog and its start. Additive; absent on every other box. The disk alert on a demo box reads the higher of the data disk's blocks and the use of /data's inodes and /run's bytes and inodes, so inodes alone can fire it.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
11 files changed,
+400
−15
internal/host/agent.go+4 −1internal/host/demodisk_status.go+104 −0internal/host/demodisk_status_test.go+137 −0internal/host/demoretention.go+0 −3internal/host/metrics_loop.go+20 −2internal/host/statfs_unix.go+16 −1internal/host/statfs_windows.go+10 −1internal/status/contract_test.go+12 −1internal/status/demodisk.go+40 −0internal/status/demodisk_test.go+45 −0internal/status/snapshot.go+12 −6
diff --git a/internal/host/agent.go b/internal/host/agent.go| index d6c3aa485..a4907e4d7 100644 |
| --- a/internal/host/agent.go |
| +++ b/internal/host/agent.go |
| @@ -5240,7 +5240,10 @@ func statusLoop(reg *registry.Registry, svc *activator.Service, buildStates func |
| MemAvailBytes: memAvail, |
| Load1: readLoad1(), |
| DiskFreeBytes: readDiskFreeBytes(), |
| - Release: version.Build, |
| + // A demo box's room on /data and /run and its kept demo builds |
| + // (demo disk bound, slice 1); nil on any other box. |
| + DemoDisk: readDemoDisk(), |
| + Release: version.Build, |
| // carlos.prev's release, so the console can tell whether a |
| // failed apply here could restore a build below the |
| // stateless replicas floor (#511 R16). |
diff --git a/internal/host/demodisk_status.go b/internal/host/demodisk_status.go| new file mode 100644 |
| index 000000000..93f7f5291 |
| --- /dev/null |
| +++ b/internal/host/demodisk_status.go |
| @@ -0,0 +1,104 @@ |
| +// A demo box's disk numbers (demo disk bound plan, slice 1): box status |
| +// reports the room on /data and /run in bytes and inodes and the demo |
| +// builds root keeps, and the disk alert reads the highest use of any of |
| +// them, so a demo that fills the inodes or /run is warned about before the |
| +// box goes down. |
| +package host |
| + |
| +import ( |
| + "encoding/json" |
| + "os" |
| + |
| + "github.com/carlosframework/platform/internal/rootstate" |
| + "github.com/carlosframework/platform/internal/status" |
| +) |
| + |
| +// demoRunDir is the tmpfs demo run dirs live on today (/run/carlos/instances). |
| +const demoRunDir = "/run" |
| + |
| +// demoDiskProbe is the status tick's and the alert loop's reading on a demo |
| +// box (CARLOS_DEMO_BOX set, valid or not: a misconfigured demo box is still |
| +// one), nil on any other. room is a filesystem's statfs; builds is root's |
| +// retention record. A part that does not read is absent. |
| +func demoDiskProbe(getenv func(string) string, room func(string) (*status.FilesystemRoom, error), builds func() (*status.DemoBuilds, error)) func() *status.DemoDisk { |
| + if getenv("CARLOS_DEMO_BOX") == "" { |
| + return nil |
| + } |
| + return func() *status.DemoDisk { |
| + d := &status.DemoDisk{} |
| + if r, err := room(dataDir()); err == nil { |
| + d.Data = r |
| + } |
| + if r, err := room(demoRunDir); err == nil { |
| + d.Run = r |
| + } |
| + if b, err := builds(); err == nil { |
| + d.Builds = b |
| + } |
| + return d |
| + } |
| +} |
| + |
| +// productionDemoDiskProbe is demoDiskProbe on this box. |
| +func productionDemoDiskProbe() func() *status.DemoDisk { |
| + return demoDiskProbe(os.Getenv, filesystemRoom, func() (*status.DemoBuilds, error) { |
| + return readDemoBuilds(func() (rootstate.Store, error) { return rootstate.Open(demoRetentionDir, false, true) }) |
| + }) |
| +} |
| + |
| +// readDemoBuilds reads root's retention record (demoretention.go) as the |
| +// agent may: a root-owned public directory, by descriptor. |
| +func readDemoBuilds(open func() (rootstate.Store, error)) (*status.DemoBuilds, error) { |
| + s, err := open() |
| + if err != nil { |
| + return nil, err |
| + } |
| + defer s.Close() |
| + raw, err := s.Read(demoRetentionRecord) |
| + if err != nil { |
| + return nil, err |
| + } |
| + var rec demoRetentionStatus |
| + if err := json.Unmarshal(raw, &rec); err != nil { |
| + return nil, err |
| + } |
| + if rec.Schema != 1 { |
| + return nil, os.ErrInvalid |
| + } |
| + return &status.DemoBuilds{Outputs: rec.Outputs, OutputBytes: rec.OutputBytes, At: rec.At, Backlog: rec.Backlog, BacklogSince: rec.BacklogSince}, nil |
| +} |
| + |
| +// demoDiskFill is the highest fraction used of anything d read: /data's |
| +// inodes, /run's bytes and inodes, and /data's bytes, which the disk rule |
| +// already reads as DiskFrac. nil when d read nothing. |
| +func demoDiskFill(d *status.DemoDisk) *float64 { |
| + if d == nil { |
| + return nil |
| + } |
| + var fill *float64 |
| + higher := func(free, total int64) { |
| + if total <= 0 || free < 0 || free > total { |
| + return |
| + } |
| + f := 1 - float64(free)/float64(total) |
| + if fill == nil || f > *fill { |
| + fill = &f |
| + } |
| + } |
| + for _, r := range []*status.FilesystemRoom{d.Data, d.Run} { |
| + if r != nil { |
| + higher(r.FreeBytes, r.Bytes) |
| + higher(r.FreeInodes, r.Inodes) |
| + } |
| + } |
| + return fill |
| +} |
| + |
| +// readDemoDisk is the status tick's reading: nil on a box that is not a |
| +// demo box. |
| +func readDemoDisk() *status.DemoDisk { |
| + if p := productionDemoDiskProbe(); p != nil { |
| + return p() |
| + } |
| + return nil |
| +} |
diff --git a/internal/host/demodisk_status_test.go b/internal/host/demodisk_status_test.go| new file mode 100644 |
| index 000000000..ddd677ec2 |
| --- /dev/null |
| +++ b/internal/host/demodisk_status_test.go |
| @@ -0,0 +1,137 @@ |
| +package host |
| + |
| +import ( |
| + "context" |
| + "encoding/json" |
| + "errors" |
| + "math" |
| + "os" |
| + "path/filepath" |
| + "testing" |
| + "time" |
| + |
| + "github.com/carlosframework/platform/internal/metrics" |
| + "github.com/carlosframework/platform/internal/release" |
| + "github.com/carlosframework/platform/internal/rootstate" |
| + "github.com/carlosframework/platform/internal/status" |
| +) |
| + |
| +func demoBoxEnv(on bool) func(string) string { |
| + return func(k string) string { |
| + if on && k == "CARLOS_DEMO_BOX" { |
| + return "1" |
| + } |
| + return "" |
| + } |
| +} |
| + |
| +// The status numbers are read only on a demo box: /data and /run by statfs, |
| +// and the kept builds from root's retention record. |
| +func TestDemoDiskProbeReadsDataRunAndTheRecord(t *testing.T) { |
| + rooms := map[string]*status.FilesystemRoom{ |
| + dataDir(): {FreeBytes: 10, Bytes: 100, FreeInodes: 5, Inodes: 50}, |
| + "/run": {FreeBytes: 1, Bytes: 2, FreeInodes: 3, Inodes: 4}, |
| + } |
| + room := func(dir string) (*status.FilesystemRoom, error) { |
| + if r, ok := rooms[dir]; ok { |
| + return r, nil |
| + } |
| + return nil, os.ErrNotExist |
| + } |
| + since := time.Date(2026, 11, 29, 1, 0, 0, 0, time.UTC) |
| + builds := func() (*status.DemoBuilds, error) { |
| + return &status.DemoBuilds{Outputs: 2, OutputBytes: 64, Backlog: 1, BacklogSince: since}, nil |
| + } |
| + if p := demoDiskProbe(demoBoxEnv(false), room, builds); p != nil { |
| + t.Fatal("a box that is not a demo box has a demo disk probe") |
| + } |
| + got := demoDiskProbe(demoBoxEnv(true), room, builds)() |
| + if got == nil || *got.Data != *rooms[dataDir()] || *got.Run != *rooms["/run"] || got.Builds.Outputs != 2 || !got.Builds.BacklogSince.Equal(since) { |
| + t.Fatalf("probe = %+v", got) |
| + } |
| + // Each part that does not read is absent, never zero. |
| + none := demoDiskProbe(demoBoxEnv(true), func(string) (*status.FilesystemRoom, error) { return nil, os.ErrPermission }, |
| + func() (*status.DemoBuilds, error) { return nil, os.ErrNotExist })() |
| + if none == nil || none.Data != nil || none.Run != nil || none.Builds != nil { |
| + t.Fatalf("unread parts = %+v", none) |
| + } |
| +} |
| + |
| +// The record root writes is what the agent reads back, field for field. |
| +func TestDemoBuildsReadsRootsRecord(t *testing.T) { |
| + disk := &rollbackDisk{dir: t.TempDir()} |
| + since := time.Date(2026, 11, 29, 1, 0, 0, 0, time.UTC) |
| + r := &demoRetention{box: retentionDemo, record: func() (rootstate.Store, error) { return disk, nil }, now: func() time.Time { return since }, logf: t.Logf} |
| + r.writeRecord(demoRetentionResult{outputs: 3, outputBytes: 96, backlog: 2, err: errors.New("lock")}) |
| + got, err := readDemoBuilds(func() (rootstate.Store, error) { return disk, nil }) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + want := status.DemoBuilds{Outputs: 3, OutputBytes: 96, At: since, Backlog: 2, BacklogSince: since} |
| + if *got != want { |
| + t.Fatalf("read %+v, want %+v", *got, want) |
| + } |
| + if _, err := readDemoBuilds(func() (rootstate.Store, error) { return &rollbackDisk{dir: t.TempDir()}, nil }); err == nil { |
| + t.Fatal("no record read as a record") |
| + } |
| +} |
| + |
| +// The disk alert's reading on a demo box is the highest use of blocks and |
| +// inodes over /data and /run: inodes alone can carry it. |
| +func TestDemoDiskFillIsTheHighestUse(t *testing.T) { |
| + d := &status.DemoDisk{ |
| + Data: &status.FilesystemRoom{FreeBytes: 90, Bytes: 100, FreeInodes: 4, Inodes: 100}, |
| + Run: &status.FilesystemRoom{FreeBytes: 50, Bytes: 100, FreeInodes: 80, Inodes: 100}, |
| + } |
| + if got := demoDiskFill(d); got == nil || math.Abs(*got-0.96) > 1e-9 { |
| + t.Fatalf("fill = %v, want the /data inodes' 0.96", got) |
| + } |
| + d.Run.FreeBytes = 1 |
| + if got := demoDiskFill(d); got == nil || math.Abs(*got-0.99) > 1e-9 { |
| + t.Fatalf("fill = %v, want /run bytes' 0.99", got) |
| + } |
| + if demoDiskFill(nil) != nil || demoDiskFill(&status.DemoDisk{Data: &status.FilesystemRoom{}}) != nil { |
| + t.Fatal("no reading made a fill") |
| + } |
| +} |
| + |
| +// The disk incident on a demo box fires on inodes alone, and clears when |
| +// they are freed, through the alerts engine (alertTick) as the loop runs it. |
| +func TestAlertTickFiresDiskOnInodesAlone(t *testing.T) { |
| + ctx := context.Background() |
| + s := release.NewDirStore(t.TempDir()) |
| + statePath := filepath.Join(t.TempDir(), "alerts.json") |
| + st := metrics.AlertState{V: 1, Box: "box-1", Rules: map[string]metrics.RuleState{}} |
| + rules := metrics.DefaultRules() |
| + blocks := 0.10 |
| + at := time.Date(2026, 11, 29, 12, 0, 0, 0, time.UTC) |
| + tick := func(fill *float64) { |
| + t.Helper() |
| + at = at.Add(time.Minute) |
| + if err := alertTick(ctx, s, "box-1", rules, &st, metrics.Sample{At: at, Host: metrics.HostSample{DiskFrac: &blocks}}, alertReadings{demoFill: fill}, statePath, nil, nil, nil); err != nil { |
| + t.Fatal(err) |
| + } |
| + } |
| + tick(nil) |
| + if st.Rules["disk"].Firing { |
| + t.Fatal("disk fired at 10% blocks") |
| + } |
| + full := 0.97 |
| + tick(&full) |
| + if !st.Rules["disk"].Firing { |
| + t.Fatalf("disk did not fire with inodes 97%% used: %+v", st.Rules["disk"]) |
| + } |
| + freed := 0.30 |
| + tick(&freed) |
| + if st.Rules["disk"].Firing { |
| + t.Fatalf("disk still firing after the inodes were freed: %+v", st.Rules["disk"]) |
| + } |
| + raw, err := os.ReadFile(statePath) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + var persisted metrics.AlertState |
| + if err := json.Unmarshal(raw, &persisted); err != nil || persisted.Rules["disk"].Firing { |
| + t.Fatalf("persisted state: %s %v", raw, err) |
| + } |
| +} |
diff --git a/internal/host/demoretention.go b/internal/host/demoretention.go| index c622fbf8e..522a5acfc 100644 |
| --- a/internal/host/demoretention.go |
| +++ b/internal/host/demoretention.go |
| @@ -55,9 +55,6 @@ import ( |
| const ( |
| demoRetentionDir = "/var/lib/carlos-release/demo-retention" |
| demoRetentionRecord = "status" |
| - // demoBacklogStale is how old a retention backlog may get before box |
| - // status gives it a line of its own. |
| - demoBacklogStale = 24 * time.Hour |
| ) |
| // demoRetentionStatus is the record: what the last run left, and the |
diff --git a/internal/host/metrics_loop.go b/internal/host/metrics_loop.go| index 8d077a615..5874d3524 100644 |
| --- a/internal/host/metrics_loop.go |
| +++ b/internal/host/metrics_loop.go |
| @@ -44,7 +44,10 @@ type sampleProbes struct { |
| owners func() map[string]metrics.Vouch |
| // restarts is each platform unit's systemd restart counter (see |
| // restartWatch). A nil func, or a nil map from it, is "could not ask". |
| - restarts func() map[string]unitRestartState |
| + restarts func() map[string]unitRestartState |
| + // demoDisk is a demo box's disk numbers for the disk rule |
| + // (demoDiskProbe); nil on any other box. |
| + demoDisk func() *status.DemoDisk |
| now func() time.Time |
| departures func() *metrics.DepartureSample |
| } |
| @@ -536,11 +539,18 @@ func alertTick(ctx context.Context, s release.Store, box string, rules metrics.R |
| sinks *alertSinks, trend *diskTrend, beat *engineBeatWatch) error { |
| rules.DiskFrac = diskAlertFrac(rules.DiskFrac, extra.diskTotal, extra.staticTree) |
| + // A demo box's disk rule reads the higher of the data disk's blocks and |
| + // demoFill (/data's inodes, /run's bytes and inodes). Only on a tick |
| + // with host readings: a sample without them leaves the rule as it was. |
| + diskFrac := latest.Host.DiskFrac |
| + if diskFrac != nil && extra.demoFill != nil && *extra.demoFill > *diskFrac { |
| + diskFrac = extra.demoFill |
| + } |
| obs := metrics.Observation{ |
| At: latest.At, |
| CPUFrac: latest.Host.CPUFrac, |
| MemFrac: latest.Host.MemFrac, |
| - DiskFrac: latest.Host.DiskFrac, |
| + DiskFrac: diskFrac, |
| LagSecs: nil, // v1: no lag reading feeds the agent loop yet |
| GeoIP: geoIPAlertReading(latest.At), |
| Restarts: extra.restarts, |
| @@ -613,6 +623,10 @@ type alertReadings struct { |
| // verify is the restore drill's standing, read from its local copy |
| // each tick (verifyWatch); nil leaves the verify rules as they were. |
| verify *metrics.VerifyReading |
| + // demoFill is a demo box's highest use of /data's inodes and /run's |
| + // bytes and inodes (demoDiskFill); the disk rule reads the higher of it |
| + // and the data disk's blocks. nil on any other box. |
| + demoFill *float64 |
| } |
| // verifyWatch reads the restore drill's local copy of this box's record |
| @@ -780,6 +794,7 @@ func realSampleProbes(execRoot string, src unitSources, owners func() map[string |
| }, |
| owners: owners, |
| restarts: platformUnitRestarts, |
| + demoDisk: productionDemoDiskProbe(), |
| now: time.Now, |
| } |
| } |
| @@ -1004,6 +1019,9 @@ func metricsLoop(execRoot string, src unitSources, owners func() map[string]metr |
| } |
| restartTick := func(at time.Time) alertReadings { |
| extra := alertReadings{restarts: restarts.tick(at, probes.restarts()), verify: verify.read(at)} |
| + if probes.demoDisk != nil { |
| + extra.demoFill = demoDiskFill(probes.demoDisk()) |
| + } |
| if _, total, ok := probes.diskBytes(); ok { |
| extra.diskTotal, extra.staticTree = total, largestStaticTree() |
| } |
diff --git a/internal/host/statfs_unix.go b/internal/host/statfs_unix.go| index a57f9ceba..226b2e835 100644 |
| --- a/internal/host/statfs_unix.go |
| +++ b/internal/host/statfs_unix.go |
| @@ -2,7 +2,11 @@ |
| package host |
| -import "syscall" |
| +import ( |
| + "syscall" |
| + |
| + "github.com/carlosframework/platform/internal/status" |
| +) |
| // diskBytes reports the total and available bytes of the filesystem holding |
| // dir. |
| @@ -19,3 +23,14 @@ func diskBytes(dir string) (total, avail uint64, err error) { |
| } |
| return uint64(st.Blocks) * uint64(st.Bsize), uint64(st.Bavail) * uint64(st.Bsize), nil |
| } |
| + |
| +// filesystemRoom is dir's filesystem in bytes and inodes: free to an |
| +// unprivileged writer (Bavail), and the totals. |
| +func filesystemRoom(dir string) (*status.FilesystemRoom, error) { |
| + var st syscall.Statfs_t |
| + if err := syscall.Statfs(dir, &st); err != nil { |
| + return nil, err |
| + } |
| + return &status.FilesystemRoom{FreeBytes: int64(uint64(st.Bavail) * uint64(st.Bsize)), Bytes: int64(uint64(st.Blocks) * uint64(st.Bsize)), |
| + FreeInodes: int64(uint64(st.Ffree)), Inodes: int64(uint64(st.Files))}, nil |
| +} |
diff --git a/internal/host/statfs_windows.go b/internal/host/statfs_windows.go| index 00777bc67..c9849f3a1 100644 |
| --- a/internal/host/statfs_windows.go |
| +++ b/internal/host/statfs_windows.go |
| @@ -2,7 +2,11 @@ |
| package host |
| -import "errors" |
| +import ( |
| + "errors" |
| + |
| + "github.com/carlosframework/platform/internal/status" |
| +) |
| // diskBytes has no Windows implementation: this package's disk readings |
| // describe a CARLOS box's /data volume, and boxes are Linux. Windows builds |
| @@ -13,3 +17,8 @@ import "errors" |
| func diskBytes(dir string) (total, avail uint64, err error) { |
| return 0, 0, errors.New("disk readings are box-side (linux) only") |
| } |
| + |
| +// filesystemRoom has no Windows implementation, for the same reason. |
| +func filesystemRoom(dir string) (*status.FilesystemRoom, error) { |
| + return nil, errors.New("disk readings are box-side (linux) only") |
| +} |
diff --git a/internal/status/contract_test.go b/internal/status/contract_test.go| index cee5ea4f5..60631882d 100644 |
| --- a/internal/status/contract_test.go |
| +++ b/internal/status/contract_test.go |
| @@ -83,7 +83,7 @@ var allowedBoxKeys = map[string][]string{ |
| "routes": {"static", "resident", "hibernating", "awake", "asleep"}, |
| "replication": {"healthy", "lag_seconds"}, |
| // capabilities names supported protocols only, in the bucket-private metrics. |
| - "metrics": {"capabilities", "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", "offline_move"}, |
| + "metrics": {"capabilities", "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", "offline_move", "demo_disk"}, |
| "metrics.route_versions": {wildcardAnyKey}, |
| "metrics.upstreams": {wildcardAnyKey}, |
| "metrics.upstreams.*[]": {"addr", "up", "since", "fails", "last_error"}, |
| @@ -120,6 +120,13 @@ var allowedBoxKeys = map[string][]string{ |
| // read: the hosts this box keeps a stale live link for, bounded, and |
| // whether it holds more. Private block only, pinned to the field level. |
| "metrics.offline_move": {"stale_live_links", "stale_live_links_overflow"}, |
| + // demo_disk (demo disk bound, slice 1) is a demo box's room on /data and |
| + // /run and its kept demo builds, numbers only, in the private block; |
| + // pinned to the field level. |
| + "metrics.demo_disk": {"data", "run", "builds"}, |
| + "metrics.demo_disk.data": {"free_bytes", "bytes", "free_inodes", "inodes"}, |
| + "metrics.demo_disk.run": {"free_bytes", "bytes", "free_inodes", "inodes"}, |
| + "metrics.demo_disk.builds": {"outputs", "output_bytes", "at", "backlog", "backlog_since"}, |
| } |
| // allowedFleetKeys are THE schema for Fleet's JSON output. Same friction as |
| @@ -393,6 +400,10 @@ func fixtureProbes() status.Probes { |
| // The offline move facts, so metrics.offline_move is exercised by |
| // the allowlist walk too (#339). |
| OfflineMove: &status.OfflineMoveFacts{StaleLiveLinks: []string{"contract-left.internal"}, StaleLiveLinksOverflow: true}, |
| + // A demo box's disk numbers (demo disk bound, slice 1), so |
| + // metrics.demo_disk is exercised by the allowlist walk too. |
| + DemoDisk: &status.DemoDisk{Data: &status.FilesystemRoom{FreeBytes: 1, Bytes: 2, FreeInodes: 3, Inodes: 4}, Run: &status.FilesystemRoom{FreeBytes: 5, Bytes: 6, FreeInodes: 7, Inodes: 8}, |
| + Builds: &status.DemoBuilds{Outputs: 9, OutputBytes: 10, At: time.Unix(11, 0), Backlog: 12, BacklogSince: time.Unix(13, 0)}}, |
| ConfigGuard: "bypassed (CARLOS_NO_SEALED_CONFIG)", |
| MemFrac: &memFrac, |
diff --git a/internal/status/demodisk.go b/internal/status/demodisk.go| new file mode 100644 |
| index 000000000..3bd36749f |
| --- /dev/null |
| +++ b/internal/status/demodisk.go |
| @@ -0,0 +1,40 @@ |
| +package status |
| + |
| +import "time" |
| + |
| +// DemoDisk is a demo box's disk numbers (demo disk bound plan, slice 1): |
| +// the room left on /data and on /run, in bytes and inodes, and the demo |
| +// builds the box keeps. It rides in the bucket-private Metrics block only |
| +// on demo boxes; nil everywhere else and on boxes from before it. |
| +type DemoDisk struct { |
| + // Data and Run are /data and the /run tmpfs. nil: not read. |
| + Data *FilesystemRoom `json:"data,omitempty"` |
| + Run *FilesystemRoom `json:"run,omitempty"` |
| + // Builds is root's record of its last demo build retention run. nil: |
| + // no record read. |
| + Builds *DemoBuilds `json:"builds,omitempty"` |
| +} |
| + |
| +// FilesystemRoom is one filesystem's statfs numbers: what is free to an |
| +// unprivileged writer, and the totals. A zero is a reading, not unknown. |
| +type FilesystemRoom struct { |
| + FreeBytes int64 `json:"free_bytes"` |
| + Bytes int64 `json:"bytes"` |
| + FreeInodes int64 `json:"free_inodes"` |
| + Inodes int64 `json:"inodes"` |
| +} |
| + |
| +// DemoBacklogStale is how old a demo build retention backlog may get |
| +// before box status gives it a line of its own (plan slice 1). |
| +const DemoBacklogStale = 24 * time.Hour |
| + |
| +// DemoBuilds is the staged demo build outputs root's last retention run |
| +// left, and its backlog: outputs held beyond the bound because a run could |
| +// not delete them, with when that began (zero when there is none). |
| +type DemoBuilds struct { |
| + Outputs int `json:"outputs"` |
| + OutputBytes int64 `json:"output_bytes"` |
| + At time.Time `json:"at"` |
| + Backlog int `json:"backlog"` |
| + BacklogSince time.Time `json:"backlog_since,omitzero"` |
| +} |
diff --git a/internal/status/demodisk_test.go b/internal/status/demodisk_test.go| new file mode 100644 |
| index 000000000..0ef2dc8d6 |
| --- /dev/null |
| +++ b/internal/status/demodisk_test.go |
| @@ -0,0 +1,45 @@ |
| +package status_test |
| + |
| +import ( |
| + "encoding/json" |
| + "reflect" |
| + "testing" |
| + "time" |
| + |
| + "github.com/carlosframework/platform/internal/status" |
| +) |
| + |
| +// A demo box's disk numbers ride in the private metrics block as one new, |
| +// additive key: a box without them publishes exactly what it did before, |
| +// and the numbers round-trip. |
| +func TestDemoDiskIsAdditive(t *testing.T) { |
| + without := status.CollectBox(nil, status.Probes{MachineID: "m", Release: "r"}, time.Now()) |
| + raw, err := json.Marshal(without) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + var shape struct { |
| + Metrics map[string]any `json:"metrics"` |
| + } |
| + if err := json.Unmarshal(raw, &shape); err != nil { |
| + t.Fatal(err) |
| + } |
| + if _, ok := shape.Metrics["demo_disk"]; ok || shape.Metrics == nil { |
| + t.Fatalf("a box without demo disk numbers publishes demo_disk: %s", raw) |
| + } |
| + since := time.Date(2026, 11, 29, 1, 2, 3, 0, time.UTC) |
| + d := &status.DemoDisk{Data: &status.FilesystemRoom{FreeBytes: 1, Bytes: 2, FreeInodes: 3, Inodes: 4}, Run: &status.FilesystemRoom{FreeBytes: 5, Bytes: 6, FreeInodes: 7, Inodes: 8}, |
| + Builds: &status.DemoBuilds{Outputs: 9, OutputBytes: 10, At: since, Backlog: 12, BacklogSince: since}} |
| + with := status.CollectBox(nil, status.Probes{MachineID: "m", DemoDisk: d}, time.Now()) |
| + raw, err = json.Marshal(with) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + var back status.Box |
| + if err := json.Unmarshal(raw, &back); err != nil { |
| + t.Fatal(err) |
| + } |
| + if back.Metrics == nil || back.Metrics.DemoDisk == nil || !reflect.DeepEqual(back.Metrics.DemoDisk, d) { |
| + t.Fatalf("round trip: %s", raw) |
| + } |
| +} |
diff --git a/internal/status/snapshot.go b/internal/status/snapshot.go| index 0e2fcb727..19bd503b0 100644 |
| --- a/internal/status/snapshot.go |
| +++ b/internal/status/snapshot.go |
| @@ -125,6 +125,9 @@ type Probes struct { |
| MemAvailBytes *int64 |
| Load1 *float64 |
| DiskFreeBytes *int64 |
| + // DemoDisk is a demo box's disk numbers (BoxMetrics.DemoDisk); nil on |
| + // every other box. |
| + DemoDisk *DemoDisk |
| // Release is the running binary's version.Build (a short sha or similar), |
| // and Tunnel is one of ""|"connected"|"reconnecting" — both land in |
| // Box.Metrics unbanded, like the four numeric fields above. "" means |
| @@ -705,10 +708,13 @@ type BoxMetrics struct { |
| HostClaimEnabled bool `json:"host_claim_enabled,omitempty"` |
| RetirementReceiptSHA256 string `json:"retirement_receipt_sha256,omitempty"` |
| - MemTotalBytes *int64 `json:"mem_total_bytes,omitempty"` |
| - MemAvailBytes *int64 `json:"mem_avail_bytes,omitempty"` |
| - Load1 *float64 `json:"load1,omitempty"` |
| - DiskFreeBytes *int64 `json:"disk_free_bytes,omitempty"` |
| + MemTotalBytes *int64 `json:"mem_total_bytes,omitempty"` |
| + MemAvailBytes *int64 `json:"mem_avail_bytes,omitempty"` |
| + Load1 *float64 `json:"load1,omitempty"` |
| + DiskFreeBytes *int64 `json:"disk_free_bytes,omitempty"` |
| + // DemoDisk is a demo box's room on /data and /run and the demo builds it |
| + // keeps (demo disk bound plan, slice 1). Absent on any other box. |
| + DemoDisk *DemoDisk `json:"demo_disk,omitempty"` |
| Release string `json:"release,omitempty"` // running binary's version.Build |
| PrevRelease string `json:"prev_release,omitempty"` // carlos.prev's release; "none": no carlos.prev |
| ApplyFinished bool `json:"apply_finished,omitempty"` // no open system apply journal; absent: unfinished or unknown |
| @@ -1356,7 +1362,7 @@ func CollectBox(routes []registry.Route, p Probes, now time.Time) Box { |
| 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 || p.HeldStreams != nil || len(p.BuildStates) > 0 || p.BuildStatesErr != "" || |
| p.DemoClaimSeedReady || p.DemoMovedReady || p.UpdateSettings != 0 || len(p.Updates) > 0 || len(p.Egress) > 0 || p.SizeCommittedMiB != nil || |
| - p.MailerArmed || p.OfflineMove != nil || p.NamedUnits != nil || p.SeedsFloor != nil || p.ConsoleFleet != nil { |
| + p.MailerArmed || p.OfflineMove != nil || p.NamedUnits != nil || p.SeedsFloor != nil || p.ConsoleFleet != nil || p.DemoDisk != nil { |
| var capabilities []string |
| if p.DemoClaimSeedReady { |
| capabilities = append(capabilities, seeds.DemoClaimCapability) |
| @@ -1381,7 +1387,7 @@ func CollectBox(routes []registry.Route, p Probes, now time.Time) Box { |
| RetirementReceiptSHA256: p.RetirementReceiptSHA256, |
| MemTotalBytes: p.MemTotalBytes, MemAvailBytes: p.MemAvailBytes, |
| - Load1: p.Load1, DiskFreeBytes: p.DiskFreeBytes, DiskFullETAHours: p.DiskFullETAHours, |
| + Load1: p.Load1, DiskFreeBytes: p.DiskFreeBytes, DiskFullETAHours: p.DiskFullETAHours, DemoDisk: p.DemoDisk, |
| Release: p.Release, PrevRelease: p.PrevRelease, ApplyFinished: p.ApplyFinished, Tunnel: p.Tunnel, GeoIP: p.GeoIP, HeldStreams: p.HeldStreams, |
| Platform: p.Platform, SystemChannel: p.SystemChannel, System: p.System, |
| InstanceID: p.InstanceID, |