remote-metrics-nested: no CPU delta across a changed unit set; nested tests Linux-only (round 1)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
11 files changed,
+425
−310
docs/superpowers/notes/census-proposal-remote-metrics-nested.md+2 −2docs/superpowers/notes/remote-instance-metrics.md+19 −1docs/superpowers/reviews/CODEX-FINDINGS-remote-metrics-nested-r1.md+31 −0docs/superpowers/reviews/CODEX-REVIEW-BRIEF-remote-metrics-nested.md+13 −1internal/host/metrics_loop.go+6 −1internal/host/metrics_nested.go+8 −1internal/host/metrics_nested_linux_test.go+334 −0internal/host/metrics_nested_test.go+1 −298internal/host/metrics_probes.go+5 −0internal/provision/testdata/plan14-root-reads-chain.tsv+1 −1internal/provision/testdata/plan14-root-reads-remote-metrics-nested.tsv+5 −5
CI passed — run details
diff --git a/docs/superpowers/notes/census-proposal-remote-metrics-nested.md b/docs/superpowers/notes/census-proposal-remote-metrics-nested.md| index 9ff20c415..ffeb27ffc 100644 |
| --- a/docs/superpowers/notes/census-proposal-remote-metrics-nested.md |
| +++ b/docs/superpowers/notes/census-proposal-remote-metrics-nested.md |
| @@ -5,7 +5,7 @@ Ruling `census-ruling-remote-metrics-nested`. The independent reviewer approves |
| | unit | change | read sites | what changed | |
| |---|---|---|---| |
| | `internal/host/agent.go` `runAgent` | body | unchanged (5) | snapshots the nested layout (snapshotNestedUnits over /sys/fs/cgroup/carlos.slice/carlos-instances.slice) once at start, before the activator, and hands the metrics loop a unitSources struct (stamped units, routeHostNames, that root and the snapshot); reads nothing new itself | |
| -| `internal/host/metrics_loop.go` `sampler.tick` | body | unchanged (1) | clears the tenant tag of a reading marked leftover (a nested unit present at agent start) before CarryTags; no read added | |
| +| `internal/host/metrics_loop.go` `sampler.tick` | body | unchanged (1) | clears the tenant tag of a reading marked leftover (a nested unit present at agent start) before CarryTags, and takes no CPU delta when a nested reading's set of cgroups changed since the previous tick; no read added | |
| Envelopes re-pinned: `internal/host`. |
| @@ -23,6 +23,6 @@ New dispositions, which census-propose wrote and the reviewer checks against the |
| - new `internal/host/metrics_nested.go:snapshotNestedUnits`: reads +file:ReadDir ×2; written legacy, accepted-legacy, frozen |
| - new `internal/host/metrics_nested_linux.go:cgroupID`: reads +file:Stat; written legacy, accepted-legacy, frozen |
| -Seal: `ed0d770a827bdb37a87d21e5c8efb259ca0de88457b0cb3202ebb006fc0cd032` → `5a1cc50b9465ed19098fb9b0557324acb622bd84e1621157788af63a702ce4a3`. |
| +Seal: `ed0d770a827bdb37a87d21e5c8efb259ca0de88457b0cb3202ebb006fc0cd032` → `3543f05491efe4c861c1d208672e52c5241671494859205822d4047ab2c94784`. |
| Overlay: `internal/provision/testdata/plan14-root-reads-remote-metrics-nested.tsv`, appended to `internal/provision/testdata/plan14-root-reads-chain.tsv`. |
diff --git a/docs/superpowers/notes/remote-instance-metrics.md b/docs/superpowers/notes/remote-instance-metrics.md| index f7ad52580..8925eba28 100644 |
| --- a/docs/superpowers/notes/remote-instance-metrics.md |
| +++ b/docs/superpowers/notes/remote-instance-metrics.md |
| @@ -316,7 +316,10 @@ the unit cgroups in its nested slice (`nestedUnitReadings`), sums them |
| publishes the sum as `carlos-exec@<host>`, the name a flat host reports |
| under, so the console's per-host match and tenant filter need no change. |
| A host with both a flat cgroup and a slice (a layout change in flight) is |
| -summed. Unit cgroups, never the slice: systemd makes a unit's cgroup new |
| +summed. The reading names the cgroups it summed (unit and cgroup id), and |
| +the sampler takes no CPU delta between two readings of different sets: a |
| +unit that went or came makes the difference of two sums wrong. Unit |
| +cgroups, never the slice: systemd makes a unit's cgroup new |
| at each start, while the slice keeps the charges of units that stopped, |
| an earlier tenant's included. |
| @@ -352,3 +355,18 @@ id. Passed in run 20261026T194200-02064e. Mutations: 8, all killed. |
| **Still not sampled.** Unit-backed `carlos-app@` tenants (systemd starts |
| them, including by socket activation, and they can outlive the agent) and |
| instances that never sleep (no activator entry vouches for them). |
| + |
| +### Nested branch review rounds |
| + |
| +Round 1 (Astra, 139e04ca): NOT READY. |
| + |
| +- P1 (platform-specific test expectations, not the tenant family): the |
| + nested tests needed Linux cgroup ids and would fail on a Mac. They are |
| + now `metrics_nested_linux_test.go`; the pure sum test stays everywhere. |
| +- P2 (CPU counter continuity): a CPU delta between two sums over |
| + different unit sets was wrong (a command unit that went made the run |
| + unit's 50% read 17%). Fixed: readings name their cgroups and no delta is |
| + taken across a change (`TestNestedCPUDeltaOverTheSameUnits`, exact |
| + values; mutant killed). |
| +- Census: the reviewer approved all six units and the `internal/host` |
| + envelope. |
diff --git a/docs/superpowers/reviews/CODEX-FINDINGS-remote-metrics-nested-r1.md b/docs/superpowers/reviews/CODEX-FINDINGS-remote-metrics-nested-r1.md| new file mode 100644 |
| index 000000000..01a9208f7 |
| --- /dev/null |
| +++ b/docs/superpowers/reviews/CODEX-FINDINGS-remote-metrics-nested-r1.md |
| @@ -0,0 +1,31 @@ |
| +Reviewed round **1 of 3**, commit `139e04ca70384a6bb637278415d723f69b063284`, against merge base `4dc5902d4f244a3de346b258660950472df9b07a`. |
| + |
| +1. **P1 — Section 4: the new tests fail on non-Linux platforms.** |
| + **Fault family: platform-specific test expectations.** |
| + [metrics_nested_test.go:197](/home/paulca/amadan.net/carlos/platform-remote-metrics-nested/internal/host/metrics_nested_test.go:197) has no Linux build constraint or platform skip, but requires a tagged reading at line 207. On Darwin, [metrics_nested_other.go:7](/home/paulca/amadan.net/carlos/platform-remote-metrics-nested/internal/host/metrics_nested_other.go:7) always returns `ok=false`; `nestedUnitReadings` consequently marks every reading leftover, and the sampler removes its owner. `TestNestedReusedHostname` fails for the same reason; the clean-start assertion in `TestNestedSnapshotUnreadable` also contradicts the non-Linux implementation. |
| + |
| + **Failure scenario:** running these tests on a Mac fails despite the production stub behaving as intended. **Fix:** restrict the cgroup-identity integration tests to Linux, retaining the pure `sumUnitRaw` test across platforms. |
| + |
| +2. **P2 — Section 2: CPU deltas subtract counters from different sets of cgroups.** |
| + **Fault family: CPU counter continuity.** |
| + [metrics_nested.go:101](/home/paulca/amadan.net/carlos/platform-remote-metrics-nested/internal/host/metrics_nested.go:101) collapses currently present units into one cumulative counter; [metrics_loop.go:109](/home/paulca/amadan.net/carlos/platform-remote-metrics-nested/internal/host/metrics_loop.go:109) subtracts the previous host total without retaining the contributing cgroup identities. |
| + |
| + **Failure scenario:** one tick reads a run unit at 100 CPU-seconds and a command unit at 20. Sixty seconds later, the command’s cgroup has disappeared and the run unit reads 130. The sampler reports `(130−120)/60 = 16.7%`, although the surviving run unit alone consumed 50%. The aggregate remains increasing, so the existing counter-reset check does not catch it. Generation retirement and unit recreation have the same problem. |
| + |
| + **Fix:** retain the contributing cgroup IDs and invalidate/rebaseline CPU whenever that set changes, or calculate deltas per cgroup lifetime before aggregation. Add an exact-value test where a disappearing unit’s counter is smaller than the surviving unit’s increase. Memory can remain an instantaneous sum. |
| + |
| +Census verdicts below concern the recorded authority and read boundaries; they do not clear the functional findings above. |
| + |
| +| Unit or envelope | Verdict and evidence | |
| +|---|---| |
| +| `runAgent` | **APPROVE.** [agent.go:282](/home/paulca/amadan.net/carlos/platform-remote-metrics-nested/internal/host/agent.go:282) snapshots the fixed cgroup root before activator construction; the metrics wiring preserves its existing authority disposition. | |
| +| `sampler.tick` | **APPROVE.** [metrics_loop.go:117](/home/paulca/amadan.net/carlos/platform-remote-metrics-nested/internal/host/metrics_loop.go:117) removes leftover tags before `CarryTags`; no new privileged read or authority. | |
| +| `routeHostNames` | **APPROVE.** [agent.go:3939](/home/paulca/amadan.net/carlos/platform-remote-metrics-nested/internal/host/agent.go:3939) reads the agent’s registry and returns hostnames. `legacy/accepted-legacy` fits. | |
| +| `nestedUnitReadings` | **APPROVE.** [metrics_nested.go:78](/home/paulca/amadan.net/carlos/platform-remote-metrics-nested/internal/host/metrics_nested.go:78) reads host-derived paths beneath the fixed cgroup root through the agent’s sampler. No root authority is added. | |
| +| `snapshotNestedUnits` | **APPROVE.** [metrics_nested.go:36](/home/paulca/amadan.net/carlos/platform-remote-metrics-nested/internal/host/metrics_nested.go:36) performs read-only enumeration and refuses vouching after enumeration or identity failures. | |
| +| `cgroupID` | **APPROVE.** [metrics_nested_linux.go:13](/home/paulca/amadan.net/carlos/platform-remote-metrics-nested/internal/host/metrics_nested_linux.go:13) performs a read-only stat; failures return no identity. | |
| +| `internal/host` envelope | **APPROVE.** Reviewed the changed wiring, readers, aggregation and non-Linux stub, including [metrics_loop.go:878](/home/paulca/amadan.net/carlos/platform-remote-metrics-nested/internal/host/metrics_loop.go:878). No added root execution, write authority or store request. | |
| + |
| +`git diff --check` passed. Targeted Go tests could not start because the sandbox refused creation of Go’s work directory. The non-Linux failure is established by source inspection, not execution. Root-runner and mutation results were not independently rerun. No files changed. |
| + |
| +**NOT READY** |
| \ No newline at end of file |
diff --git a/docs/superpowers/reviews/CODEX-REVIEW-BRIEF-remote-metrics-nested.md b/docs/superpowers/reviews/CODEX-REVIEW-BRIEF-remote-metrics-nested.md| index 072fb0a4c..4cf9d1439 100644 |
| --- a/docs/superpowers/reviews/CODEX-REVIEW-BRIEF-remote-metrics-nested.md |
| +++ b/docs/superpowers/reviews/CODEX-REVIEW-BRIEF-remote-metrics-nested.md |
| @@ -1,4 +1,4 @@ |
| -# Review brief: branch remote-metrics-nested, round 1 of 3 |
| +# Review brief: branch remote-metrics-nested, round 2 of 3 |
| Repo carlos/platform, branch `remote-metrics-nested`, commit named in the |
| reviewer's prompt. |
| @@ -59,6 +59,18 @@ finding in that family. |
| the `internal/host` envelope, per AGENTS.md "The census: the reviewer |
| decides". |
| +## Round 2 |
| + |
| +Earlier round: round 1, |
| +`docs/superpowers/reviews/CODEX-FINDINGS-remote-metrics-nested-r1.md` (a |
| +P1 on non-Linux test expectations, a P2 on CPU deltas across changing |
| +unit sets). First give one line per P1 and P2 from round 1: resolved, |
| +partly, or not. Carry every unresolved or partly resolved finding forward |
| +at its current severity, then add new findings. The verdict covers |
| +everything outstanding. Give census verdicts again only for units the |
| +fixes changed (`nestedUnitReadings`, `sampler.tick`, the `internal/host` |
| +envelope); round 1's others stand. |
| + |
| ## Severity |
| - **P1**: unsafe, would not compile, a test fails, or it would not work. |
diff --git a/internal/host/metrics_loop.go b/internal/host/metrics_loop.go| index 0363f4369..a9ec19365 100644 |
| --- a/internal/host/metrics_loop.go |
| +++ b/internal/host/metrics_loop.go |
| @@ -63,6 +63,7 @@ type sampler struct { |
| prevCPU *metrics.CPUCounters |
| prevUnit map[string]*int64 // unit -> cpu usec at previous tick |
| prevOwner map[string]*metrics.Owner // unit -> owner vouched at previous tick (nil: none) |
| + prevMembers map[string]string // unit -> the cgroups its previous reading summed (unitRaw.members) |
| prevAt time.Time |
| buf []metrics.Sample |
| writtenHours map[string]bool // hour -> this process has written/merged it at least once |
| @@ -97,12 +98,14 @@ func (sm *sampler) tick(p sampleProbes) { |
| var unitSamples map[string]metrics.UnitSample |
| var newPrevUnit map[string]*int64 |
| + var newPrevMembers map[string]string |
| if units != nil { |
| unitSamples = make(map[string]metrics.UnitSample, len(units)) |
| newPrevUnit = make(map[string]*int64, len(units)) |
| + newPrevMembers = make(map[string]string, len(units)) |
| for name, u := range units { |
| var prevUsec *int64 |
| - if sm.prevUnit != nil { |
| + if sm.prevUnit != nil && sm.prevMembers[name] == u.members { |
| prevUsec = sm.prevUnit[name] |
| } |
| unitSamples[name] = metrics.UnitSample{ |
| @@ -113,6 +116,7 @@ func (sm *sampler) tick(p sampleProbes) { |
| WriteBytes: u.writeBytes, |
| } |
| newPrevUnit[name] = u.cpuUsec |
| + newPrevMembers[name] = u.members |
| } |
| metrics.TagUnits(unitSamples, before, after) |
| // A nested reading that includes a unit this agent did not start |
| @@ -150,6 +154,7 @@ func (sm *sampler) tick(p sampleProbes) { |
| sm.prevCPU = curCPU |
| sm.prevUnit = newPrevUnit |
| + sm.prevMembers = newPrevMembers |
| sm.prevAt = now |
| } |
diff --git a/internal/host/metrics_nested.go b/internal/host/metrics_nested.go| index 78f53ae3c..03005c835 100644 |
| --- a/internal/host/metrics_nested.go |
| +++ b/internal/host/metrics_nested.go |
| @@ -5,6 +5,8 @@ import ( |
| "io/fs" |
| "os" |
| "path/filepath" |
| + "sort" |
| + "strconv" |
| "strings" |
| "github.com/carlosframework/platform/internal/cgroup" |
| @@ -84,15 +86,18 @@ func nestedUnitReadings(root string, hosts []string, start nestedStart) map[stri |
| continue |
| } |
| var parts []unitRaw |
| + var members []string |
| leftover := start.unswept |
| for _, u := range units { |
| if !u.IsDir() || !strings.HasSuffix(u.Name(), ".service") { |
| continue |
| } |
| ud := filepath.Join(dir, u.Name()) |
| - if id, ok := cgroupID(ud); !ok || start.ids[id] { |
| + id, ok := cgroupID(ud) |
| + if !ok || start.ids[id] { |
| leftover = true |
| } |
| + members = append(members, u.Name()+"#"+strconv.FormatUint(id, 10)) |
| parts = append(parts, readUnitRaw(ud)) |
| } |
| if len(parts) == 0 { |
| @@ -100,6 +105,8 @@ func nestedUnitReadings(root string, hosts []string, start nestedStart) map[stri |
| } |
| sum := sumUnitRaw(parts) |
| sum.leftover = leftover |
| + sort.Strings(members) |
| + sum.members = strings.Join(members, ",") |
| out[cgroup.ExecName(host)] = sum |
| } |
| return out |
diff --git a/internal/host/metrics_nested_linux_test.go b/internal/host/metrics_nested_linux_test.go| new file mode 100644 |
| index 000000000..af2c58e73 |
| --- /dev/null |
| +++ b/internal/host/metrics_nested_linux_test.go |
| @@ -0,0 +1,334 @@ |
| +//go:build linux |
| + |
| +package host |
| + |
| +// Nested (isolated exec) instances in the metrics sweep, end to end on one |
| +// box: a real registry, a real activator waking and stopping through a |
| +// stand-in backend, the nested layout's cgroup tree as instance-control |
| +// lays it out (carlos-instances-<id>.slice/<unit>, written here into a temp |
| +// root), the sampler's tick and flush, and the chunk the console reads. |
| +// The real tree under systemd is TestRootRunnerNestedUnitsAreSampled. |
| + |
| +import ( |
| + "context" |
| + "encoding/json" |
| + "errors" |
| + "net/http" |
| + "net/http/httptest" |
| + "os" |
| + "path/filepath" |
| + "strconv" |
| + "testing" |
| + "time" |
| + |
| + "github.com/carlosframework/platform/internal/activator" |
| + "github.com/carlosframework/platform/internal/cgroup" |
| + "github.com/carlosframework/platform/internal/instancectl" |
| + "github.com/carlosframework/platform/internal/metrics" |
| + "github.com/carlosframework/platform/internal/registry" |
| + "github.com/carlosframework/platform/internal/release" |
| +) |
| + |
| +// nestedBackend starts nothing real: the wake's process is a plannedProc, |
| +// and its units are whatever the test writes into the cgroup tree. |
| +type nestedBackend struct{} |
| + |
| +func (nestedBackend) Acquire(context.Context, registry.Route) (activator.Lease, error) { |
| + return plannedLease{}, nil |
| +} |
| +func (nestedBackend) Restore(context.Context, registry.Route) (bool, error) { return false, nil } |
| +func (nestedBackend) Seed(context.Context, registry.Route) error { return nil } |
| +func (nestedBackend) Start(context.Context, registry.Route) (activator.Proc, string, error) { |
| + return &plannedProc{}, "v1", nil |
| +} |
| +func (nestedBackend) NextDue(context.Context, registry.Route) (int64, error) { return 0, nil } |
| +func (nestedBackend) HasSidecar(registry.Route) bool { return false } |
| +func (nestedBackend) StartSidecar(context.Context, registry.Route) (activator.Proc, error) { |
| + return nil, errors.New("no sidecar") |
| +} |
| +func (nestedBackend) StartWorker(context.Context, registry.Route, map[string]string) (activator.Proc, string, error) { |
| + return nil, "", errors.New("no worker") |
| +} |
| + |
| +const nestedHost = "eu.shop.example.com" |
| + |
| +// nestedBox is one box: its registry, its activator and its nested root. |
| +type nestedBox struct { |
| + reg *registry.Registry |
| + svc *activator.Service |
| + root string |
| + socket string |
| + start nestedStart |
| + sm *sampler |
| + at time.Time |
| +} |
| + |
| +func newNestedBox(t *testing.T) *nestedBox { |
| + t.Helper() |
| + reg, err := registry.Open(filepath.Join(t.TempDir(), "registry.db")) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + t.Cleanup(func() { reg.Close() }) |
| + b := &nestedBox{reg: reg, root: t.TempDir(), socket: healthySocket(t), sm: &sampler{}, |
| + at: time.Date(2026, 10, 26, 20, 0, 0, 0, time.UTC)} |
| + b.restartAgent(t) |
| + return b |
| +} |
| + |
| +// restartAgent is a new agent on the box: a fresh activator, and the |
| +// nested layout snapshotted before it can start anything (runAgent's |
| +// order). |
| +func (b *nestedBox) restartAgent(t *testing.T) { |
| + t.Helper() |
| + b.start = snapshotNestedUnits(b.root) |
| + b.svc = activator.New(activator.Config{Bucket: "hib", Idle: time.Hour}, nestedBackend{}, b.reg) |
| + b.svc.Routes = b.reg |
| + svc := b.svc |
| + t.Cleanup(func() { svc.Shutdown(context.Background()) }) |
| + b.sm = &sampler{} |
| +} |
| + |
| +// mint is the provision pass minting host for acct's app on this box. |
| +func (b *nestedBox) mint(t *testing.T, acct string) { |
| + t.Helper() |
| + if err := b.reg.Upsert(registry.Route{Host: nestedHost, Kind: "instance", Account: acct, App: "shop", |
| + Socket: b.socket, Hibernate: true, Provisioned: true, Status: "ready"}); err != nil { |
| + t.Fatal(err) |
| + } |
| +} |
| + |
| +// wake serves one request: the activator wakes the host for its row. |
| +func (b *nestedBox) wake(t *testing.T) { |
| + t.Helper() |
| + rt, err := b.reg.Get(nestedHost) |
| + if err != nil || rt == nil { |
| + t.Fatalf("route: %+v %v", rt, err) |
| + } |
| + rec := httptest.NewRecorder() |
| + req := httptest.NewRequest(http.MethodGet, "http://"+nestedHost+"/", nil) |
| + if !b.svc.ServeHTTP(rec, req, *rt, http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {})) || rec.Code != http.StatusOK { |
| + t.Fatalf("wake = %d %s", rec.Code, rec.Body) |
| + } |
| +} |
| + |
| +// stop puts every entry down, as a retirement or an idle sleep does. |
| +func (b *nestedBox) stop(t *testing.T) { |
| + t.Helper() |
| + b.svc.RetireExcept(map[string]bool{}) |
| + deadline := time.Now().Add(5 * time.Second) |
| + for !b.svc.Quiesced(nestedHost) { |
| + if time.Now().After(deadline) { |
| + t.Fatal("the entry did not stop") |
| + } |
| + time.Sleep(10 * time.Millisecond) |
| + } |
| +} |
| + |
| +// unit writes (or rewrites) one unit cgroup of host's slice, as systemd |
| +// does for a unit instance-control starts. |
| +func (b *nestedBox) unit(t *testing.T, unit string, usec, mem int64) string { |
| + t.Helper() |
| + dir := filepath.Join(b.root, instancectl.SliceName(nestedHost), unit) |
| + if err := os.MkdirAll(dir, 0o755); err != nil { |
| + t.Fatal(err) |
| + } |
| + for name, body := range map[string]string{ |
| + "cpu.stat": "usage_usec " + strconv.FormatInt(usec, 10) + "\n", |
| + "memory.current": strconv.FormatInt(mem, 10) + "\n", |
| + } { |
| + if err := os.WriteFile(filepath.Join(dir, name), []byte(body), 0o644); err != nil { |
| + t.Fatal(err) |
| + } |
| + } |
| + return dir |
| +} |
| + |
| +// tick is one sampler tick and flush through production code; it returns |
| +// the host's reading as the chunk carries it. |
| +func (b *nestedBox) tick(t *testing.T) metrics.UnitSample { |
| + t.Helper() |
| + b.at = b.at.Add(time.Minute) |
| + f := 0.4 |
| + src := unitSources{nestedHosts: func() []string { return routeHostNames(b.reg) }, nestedRoot: b.root, nestedAtStart: b.start} |
| + p := realSampleProbes("", src, func() map[string]metrics.Vouch { return metricsOwners(b.reg, b.svc, nil) }) |
| + p.procStat = func() *metrics.CPUCounters { return nil } |
| + p.loadavg = func() (*float64, *float64, *float64) { return nil, nil, nil } |
| + p.memFrac = func() *float64 { return &f } |
| + p.diskFrac = func() *float64 { return &f } |
| + at := b.at |
| + p.now = func() time.Time { return at } |
| + // The real probe also scans the box's own system.slice; only the |
| + // nested tree under test is read here. |
| + units := p.units |
| + p.units = func() map[string]unitRaw { |
| + out := map[string]unitRaw{} |
| + for k, v := range units() { |
| + if k == cgroup.ExecName(nestedHost) { |
| + out[k] = v |
| + } |
| + } |
| + return out |
| + } |
| + b.sm.tick(p) |
| + store := release.NewDirStore(t.TempDir()) |
| + if err := metricsFlush(context.Background(), store, "box-b", b.sm, at); err != nil { |
| + t.Fatal(err) |
| + } |
| + body, _, err := store.Get(context.Background(), metrics.RawKey("box-b", metrics.HourOf(at))) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + var chunk metrics.RawChunk |
| + if err := json.Unmarshal(body, &chunk); err != nil { |
| + t.Fatal(err) |
| + } |
| + return chunk.Samples[len(chunk.Samples)-1].Units[cgroup.ExecName(nestedHost)] |
| +} |
| + |
| +func owner(u metrics.UnitSample) string { |
| + if u.Owner == nil { |
| + return "" |
| + } |
| + return u.Owner.Account + "/" + u.Owner.App |
| +} |
| + |
| +// TestNestedInstanceIsSampledAndTagged: a nested instance's units are |
| +// read from its slice, summed into one reading under carlos-exec@<host>, |
| +// and tagged with its tenant once two ticks of the same entry agree. |
| +func TestNestedInstanceIsSampledAndTagged(t *testing.T) { |
| + b := newNestedBox(t) |
| + b.mint(t, "bdn") |
| + b.wake(t) |
| + b.unit(t, instancectl.UnitName(instancectl.RoleRun, nestedHost), 1_000_000, 3<<20) |
| + b.unit(t, instancectl.UnitName(instancectl.RoleSidecar, nestedHost), 500_000, 1<<20) |
| + first := b.tick(t) |
| + if first.MemBytes == nil || *first.MemBytes != 4<<20 { |
| + t.Fatalf("nested reading = %+v, want the two units' memory summed (4 MB)", first) |
| + } |
| + if owner(first) != "bdn/shop" { |
| + t.Fatalf("first reading owner = %q, want bdn/shop", owner(first)) |
| + } |
| + b.unit(t, instancectl.UnitName(instancectl.RoleRun, nestedHost), 4_000_000, 3<<20) |
| + second := b.tick(t) |
| + if second.CPUFrac == nil || owner(second) != "bdn/shop" { |
| + t.Fatalf("second reading = cpu %v owner %q, want a CPU fraction tagged bdn/shop", second.CPUFrac, owner(second)) |
| + } |
| +} |
| + |
| +// TestNestedReusedHostname: the hostname was the rival's on this box, then |
| +// this account's. Its units are new cgroups, but the host has had two |
| +// tenants in this agent's life, so nothing is vouched until the agent |
| +// restarts; after a restart, a unit still there from before the restart is |
| +// a leftover, and only a reading wholly of units this agent started is |
| +// tagged. |
| +func TestNestedReusedHostname(t *testing.T) { |
| + b := newNestedBox(t) |
| + b.mint(t, "rival") |
| + b.wake(t) |
| + old := b.unit(t, instancectl.UnitName(instancectl.RoleRun, nestedHost), 9_000_000, 11<<20) |
| + if u := b.tick(t); owner(u) != "rival/shop" { |
| + t.Fatalf("predecessor's reading owner = %q, want rival/shop", owner(u)) |
| + } |
| + b.stop(t) |
| + if err := os.RemoveAll(old); err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := b.reg.Delete(nestedHost); err != nil { |
| + t.Fatal(err) |
| + } |
| + b.mint(t, "bdn") |
| + b.wake(t) |
| + b.unit(t, instancectl.UnitName(instancectl.RoleRun, nestedHost), 200_000, 2<<20) |
| + for i := 0; i < 2; i++ { |
| + if u := b.tick(t); u.Owner != nil { |
| + t.Fatalf("tick %d after the hostname changed tenant: owner %q, want none", i, owner(u)) |
| + } |
| + } |
| + |
| + // The agent restarts while the unit is still there (its stop in |
| + // flight): a leftover until it goes. |
| + b.restartAgent(t) |
| + b.wake(t) |
| + if u := b.tick(t); u.Owner != nil || u.MemBytes == nil { |
| + t.Fatalf("reading with a unit from before the restart = owner %q mem %v, want a reading, untagged", owner(u), u.MemBytes) |
| + } |
| + // The new generation's unit starts, then the old one goes. (Created |
| + // first because a temp filesystem may hand a removed dir's inode to the |
| + // next one; cgroupfs never reuses a cgroup id.) |
| + b.unit(t, instancectl.GenUnitName(nestedHost, 1), 100_000, 2<<20) |
| + if err := os.RemoveAll(filepath.Join(b.root, instancectl.SliceName(nestedHost), instancectl.UnitName(instancectl.RoleRun, nestedHost))); err != nil { |
| + t.Fatal(err) |
| + } |
| + // Its first reading's CPU delta starts from the leftover's counter |
| + // (CarryTags); the next is wholly this agent's units. |
| + if u := b.tick(t); u.Owner != nil { |
| + t.Fatalf("first reading after the leftover went = owner %q, want none", owner(u)) |
| + } |
| + if u := b.tick(t); owner(u) != "bdn/shop" { |
| + t.Fatalf("reading of a unit this agent started = owner %q, want bdn/shop", owner(u)) |
| + } |
| +} |
| + |
| +// TestNestedSnapshotUnreadable: when the nested layout cannot be listed at |
| +// agent start, nothing in it is known to be this agent's. |
| +func TestNestedSnapshotUnreadable(t *testing.T) { |
| + if st := snapshotNestedUnits(filepath.Join(t.TempDir(), "absent")); st.unswept || len(st.ids) != 0 { |
| + t.Fatalf("a box with no nested layout = %+v, want clean", st) |
| + } |
| + root := t.TempDir() |
| + if err := os.MkdirAll(filepath.Join(root, "carlos-instances-x.slice"), 0o755); err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := os.Chmod(root, 0o300); err != nil { |
| + t.Fatal(err) |
| + } |
| + defer os.Chmod(root, 0o755) //nolint:errcheck |
| + if _, err := os.ReadDir(root); err == nil { |
| + t.Skip("listable without read permission (running as root?)") |
| + } |
| + if st := snapshotNestedUnits(root); !st.unswept { |
| + t.Fatal("an unlistable nested layout counted as swept") |
| + } |
| + b := &nestedBox{root: t.TempDir()} |
| + b.unit(t, instancectl.UnitName(instancectl.RoleRun, nestedHost), 1, 1) |
| + got := nestedUnitReadings(b.root, []string{nestedHost}, nestedStart{unswept: true}) |
| + if r, ok := got[cgroup.ExecName(nestedHost)]; !ok || !r.leftover { |
| + t.Fatalf("a reading after an unswept start = %+v, want a leftover", got) |
| + } |
| + if r := nestedUnitReadings(b.root, []string{nestedHost}, nestedStart{})[cgroup.ExecName(nestedHost)]; r.leftover { |
| + t.Fatal("a reading after a clean start is a leftover") |
| + } |
| +} |
| + |
| +// TestNestedCPUDeltaOverTheSameUnits (Astra, nested branch round 1, P2): |
| +// a nested reading is a sum over the host's unit cgroups, so a delta |
| +// between two sums is right only when both read the same cgroups. Tick 1 |
| +// reads the run unit at 100 s and a command unit at 20 s; by tick 2 the |
| +// command's cgroup is gone and the run unit reads 130 s. (130-120)/60 would |
| +// say 17%; the run unit alone used 50%. No delta is taken across the |
| +// change, and the next tick's is the run unit's own. |
| +func TestNestedCPUDeltaOverTheSameUnits(t *testing.T) { |
| + b := newNestedBox(t) |
| + b.mint(t, "bdn") |
| + b.wake(t) |
| + run := instancectl.UnitName(instancectl.RoleRun, nestedHost) |
| + b.unit(t, run, 100_000_000, 1<<20) |
| + cmd := b.unit(t, instancectl.UnitName(instancectl.RoleCmd, nestedHost), 20_000_000, 1<<20) |
| + b.tick(t) |
| + if err := os.RemoveAll(cmd); err != nil { |
| + t.Fatal(err) |
| + } |
| + b.unit(t, run, 130_000_000, 1<<20) |
| + if u := b.tick(t); u.CPUFrac != nil { |
| + t.Fatalf("CPU across a unit that went = %v, want none", *u.CPUFrac) |
| + } |
| + b.unit(t, run, 160_000_000, 1<<20) |
| + u := b.tick(t) |
| + if u.CPUFrac == nil || *u.CPUFrac < 0.499 || *u.CPUFrac > 0.501 { |
| + t.Fatalf("CPU over the same unit = %v, want 0.5", u.CPUFrac) |
| + } |
| + if owner(u) != "bdn/shop" { |
| + t.Fatalf("owner = %q", owner(u)) |
| + } |
| +} |
diff --git a/internal/host/metrics_nested_test.go b/internal/host/metrics_nested_test.go| index 9bef267e9..7d34a9165 100644 |
| --- a/internal/host/metrics_nested_test.go |
| +++ b/internal/host/metrics_nested_test.go |
| @@ -1,303 +1,6 @@ |
| package host |
| -// Nested (isolated exec) instances in the metrics sweep, end to end on one |
| -// box: a real registry, a real activator waking and stopping through a |
| -// stand-in backend, the nested layout's cgroup tree as instance-control |
| -// lays it out (carlos-instances-<id>.slice/<unit>, written here into a temp |
| -// root), the sampler's tick and flush, and the chunk the console reads. |
| -// The real tree under systemd is TestRootRunnerNestedUnitsAreSampled. |
| - |
| -import ( |
| - "context" |
| - "encoding/json" |
| - "errors" |
| - "net/http" |
| - "net/http/httptest" |
| - "os" |
| - "path/filepath" |
| - "strconv" |
| - "testing" |
| - "time" |
| - |
| - "github.com/carlosframework/platform/internal/activator" |
| - "github.com/carlosframework/platform/internal/cgroup" |
| - "github.com/carlosframework/platform/internal/instancectl" |
| - "github.com/carlosframework/platform/internal/metrics" |
| - "github.com/carlosframework/platform/internal/registry" |
| - "github.com/carlosframework/platform/internal/release" |
| -) |
| - |
| -// nestedBackend starts nothing real: the wake's process is a plannedProc, |
| -// and its units are whatever the test writes into the cgroup tree. |
| -type nestedBackend struct{} |
| - |
| -func (nestedBackend) Acquire(context.Context, registry.Route) (activator.Lease, error) { |
| - return plannedLease{}, nil |
| -} |
| -func (nestedBackend) Restore(context.Context, registry.Route) (bool, error) { return false, nil } |
| -func (nestedBackend) Seed(context.Context, registry.Route) error { return nil } |
| -func (nestedBackend) Start(context.Context, registry.Route) (activator.Proc, string, error) { |
| - return &plannedProc{}, "v1", nil |
| -} |
| -func (nestedBackend) NextDue(context.Context, registry.Route) (int64, error) { return 0, nil } |
| -func (nestedBackend) HasSidecar(registry.Route) bool { return false } |
| -func (nestedBackend) StartSidecar(context.Context, registry.Route) (activator.Proc, error) { |
| - return nil, errors.New("no sidecar") |
| -} |
| -func (nestedBackend) StartWorker(context.Context, registry.Route, map[string]string) (activator.Proc, string, error) { |
| - return nil, "", errors.New("no worker") |
| -} |
| - |
| -const nestedHost = "eu.shop.example.com" |
| - |
| -// nestedBox is one box: its registry, its activator and its nested root. |
| -type nestedBox struct { |
| - reg *registry.Registry |
| - svc *activator.Service |
| - root string |
| - socket string |
| - start nestedStart |
| - sm *sampler |
| - at time.Time |
| -} |
| - |
| -func newNestedBox(t *testing.T) *nestedBox { |
| - t.Helper() |
| - reg, err := registry.Open(filepath.Join(t.TempDir(), "registry.db")) |
| - if err != nil { |
| - t.Fatal(err) |
| - } |
| - t.Cleanup(func() { reg.Close() }) |
| - b := &nestedBox{reg: reg, root: t.TempDir(), socket: healthySocket(t), sm: &sampler{}, |
| - at: time.Date(2026, 10, 26, 20, 0, 0, 0, time.UTC)} |
| - b.restartAgent(t) |
| - return b |
| -} |
| - |
| -// restartAgent is a new agent on the box: a fresh activator, and the |
| -// nested layout snapshotted before it can start anything (runAgent's |
| -// order). |
| -func (b *nestedBox) restartAgent(t *testing.T) { |
| - t.Helper() |
| - b.start = snapshotNestedUnits(b.root) |
| - b.svc = activator.New(activator.Config{Bucket: "hib", Idle: time.Hour}, nestedBackend{}, b.reg) |
| - b.svc.Routes = b.reg |
| - svc := b.svc |
| - t.Cleanup(func() { svc.Shutdown(context.Background()) }) |
| - b.sm = &sampler{} |
| -} |
| - |
| -// mint is the provision pass minting host for acct's app on this box. |
| -func (b *nestedBox) mint(t *testing.T, acct string) { |
| - t.Helper() |
| - if err := b.reg.Upsert(registry.Route{Host: nestedHost, Kind: "instance", Account: acct, App: "shop", |
| - Socket: b.socket, Hibernate: true, Provisioned: true, Status: "ready"}); err != nil { |
| - t.Fatal(err) |
| - } |
| -} |
| - |
| -// wake serves one request: the activator wakes the host for its row. |
| -func (b *nestedBox) wake(t *testing.T) { |
| - t.Helper() |
| - rt, err := b.reg.Get(nestedHost) |
| - if err != nil || rt == nil { |
| - t.Fatalf("route: %+v %v", rt, err) |
| - } |
| - rec := httptest.NewRecorder() |
| - req := httptest.NewRequest(http.MethodGet, "http://"+nestedHost+"/", nil) |
| - if !b.svc.ServeHTTP(rec, req, *rt, http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {})) || rec.Code != http.StatusOK { |
| - t.Fatalf("wake = %d %s", rec.Code, rec.Body) |
| - } |
| -} |
| - |
| -// stop puts every entry down, as a retirement or an idle sleep does. |
| -func (b *nestedBox) stop(t *testing.T) { |
| - t.Helper() |
| - b.svc.RetireExcept(map[string]bool{}) |
| - deadline := time.Now().Add(5 * time.Second) |
| - for !b.svc.Quiesced(nestedHost) { |
| - if time.Now().After(deadline) { |
| - t.Fatal("the entry did not stop") |
| - } |
| - time.Sleep(10 * time.Millisecond) |
| - } |
| -} |
| - |
| -// unit writes (or rewrites) one unit cgroup of host's slice, as systemd |
| -// does for a unit instance-control starts. |
| -func (b *nestedBox) unit(t *testing.T, unit string, usec, mem int64) string { |
| - t.Helper() |
| - dir := filepath.Join(b.root, instancectl.SliceName(nestedHost), unit) |
| - if err := os.MkdirAll(dir, 0o755); err != nil { |
| - t.Fatal(err) |
| - } |
| - for name, body := range map[string]string{ |
| - "cpu.stat": "usage_usec " + strconv.FormatInt(usec, 10) + "\n", |
| - "memory.current": strconv.FormatInt(mem, 10) + "\n", |
| - } { |
| - if err := os.WriteFile(filepath.Join(dir, name), []byte(body), 0o644); err != nil { |
| - t.Fatal(err) |
| - } |
| - } |
| - return dir |
| -} |
| - |
| -// tick is one sampler tick and flush through production code; it returns |
| -// the host's reading as the chunk carries it. |
| -func (b *nestedBox) tick(t *testing.T) metrics.UnitSample { |
| - t.Helper() |
| - b.at = b.at.Add(time.Minute) |
| - f := 0.4 |
| - src := unitSources{nestedHosts: func() []string { return routeHostNames(b.reg) }, nestedRoot: b.root, nestedAtStart: b.start} |
| - p := realSampleProbes("", src, func() map[string]metrics.Vouch { return metricsOwners(b.reg, b.svc, nil) }) |
| - p.procStat = func() *metrics.CPUCounters { return nil } |
| - p.loadavg = func() (*float64, *float64, *float64) { return nil, nil, nil } |
| - p.memFrac = func() *float64 { return &f } |
| - p.diskFrac = func() *float64 { return &f } |
| - at := b.at |
| - p.now = func() time.Time { return at } |
| - // The real probe also scans the box's own system.slice; only the |
| - // nested tree under test is read here. |
| - units := p.units |
| - p.units = func() map[string]unitRaw { |
| - out := map[string]unitRaw{} |
| - for k, v := range units() { |
| - if k == cgroup.ExecName(nestedHost) { |
| - out[k] = v |
| - } |
| - } |
| - return out |
| - } |
| - b.sm.tick(p) |
| - store := release.NewDirStore(t.TempDir()) |
| - if err := metricsFlush(context.Background(), store, "box-b", b.sm, at); err != nil { |
| - t.Fatal(err) |
| - } |
| - body, _, err := store.Get(context.Background(), metrics.RawKey("box-b", metrics.HourOf(at))) |
| - if err != nil { |
| - t.Fatal(err) |
| - } |
| - var chunk metrics.RawChunk |
| - if err := json.Unmarshal(body, &chunk); err != nil { |
| - t.Fatal(err) |
| - } |
| - return chunk.Samples[len(chunk.Samples)-1].Units[cgroup.ExecName(nestedHost)] |
| -} |
| - |
| -func owner(u metrics.UnitSample) string { |
| - if u.Owner == nil { |
| - return "" |
| - } |
| - return u.Owner.Account + "/" + u.Owner.App |
| -} |
| - |
| -// TestNestedInstanceIsSampledAndTagged: a nested instance's units are |
| -// read from its slice, summed into one reading under carlos-exec@<host>, |
| -// and tagged with its tenant once two ticks of the same entry agree. |
| -func TestNestedInstanceIsSampledAndTagged(t *testing.T) { |
| - b := newNestedBox(t) |
| - b.mint(t, "bdn") |
| - b.wake(t) |
| - b.unit(t, instancectl.UnitName(instancectl.RoleRun, nestedHost), 1_000_000, 3<<20) |
| - b.unit(t, instancectl.UnitName(instancectl.RoleSidecar, nestedHost), 500_000, 1<<20) |
| - first := b.tick(t) |
| - if first.MemBytes == nil || *first.MemBytes != 4<<20 { |
| - t.Fatalf("nested reading = %+v, want the two units' memory summed (4 MB)", first) |
| - } |
| - if owner(first) != "bdn/shop" { |
| - t.Fatalf("first reading owner = %q, want bdn/shop", owner(first)) |
| - } |
| - b.unit(t, instancectl.UnitName(instancectl.RoleRun, nestedHost), 4_000_000, 3<<20) |
| - second := b.tick(t) |
| - if second.CPUFrac == nil || owner(second) != "bdn/shop" { |
| - t.Fatalf("second reading = cpu %v owner %q, want a CPU fraction tagged bdn/shop", second.CPUFrac, owner(second)) |
| - } |
| -} |
| - |
| -// TestNestedReusedHostname: the hostname was the rival's on this box, then |
| -// this account's. Its units are new cgroups, but the host has had two |
| -// tenants in this agent's life, so nothing is vouched until the agent |
| -// restarts; after a restart, a unit still there from before the restart is |
| -// a leftover, and only a reading wholly of units this agent started is |
| -// tagged. |
| -func TestNestedReusedHostname(t *testing.T) { |
| - b := newNestedBox(t) |
| - b.mint(t, "rival") |
| - b.wake(t) |
| - old := b.unit(t, instancectl.UnitName(instancectl.RoleRun, nestedHost), 9_000_000, 11<<20) |
| - if u := b.tick(t); owner(u) != "rival/shop" { |
| - t.Fatalf("predecessor's reading owner = %q, want rival/shop", owner(u)) |
| - } |
| - b.stop(t) |
| - if err := os.RemoveAll(old); err != nil { |
| - t.Fatal(err) |
| - } |
| - if err := b.reg.Delete(nestedHost); err != nil { |
| - t.Fatal(err) |
| - } |
| - b.mint(t, "bdn") |
| - b.wake(t) |
| - b.unit(t, instancectl.UnitName(instancectl.RoleRun, nestedHost), 200_000, 2<<20) |
| - for i := 0; i < 2; i++ { |
| - if u := b.tick(t); u.Owner != nil { |
| - t.Fatalf("tick %d after the hostname changed tenant: owner %q, want none", i, owner(u)) |
| - } |
| - } |
| - |
| - // The agent restarts while the unit is still there (its stop in |
| - // flight): a leftover until it goes. |
| - b.restartAgent(t) |
| - b.wake(t) |
| - if u := b.tick(t); u.Owner != nil || u.MemBytes == nil { |
| - t.Fatalf("reading with a unit from before the restart = owner %q mem %v, want a reading, untagged", owner(u), u.MemBytes) |
| - } |
| - // The new generation's unit starts, then the old one goes. (Created |
| - // first because a temp filesystem may hand a removed dir's inode to the |
| - // next one; cgroupfs never reuses a cgroup id.) |
| - b.unit(t, instancectl.GenUnitName(nestedHost, 1), 100_000, 2<<20) |
| - if err := os.RemoveAll(filepath.Join(b.root, instancectl.SliceName(nestedHost), instancectl.UnitName(instancectl.RoleRun, nestedHost))); err != nil { |
| - t.Fatal(err) |
| - } |
| - // Its first reading's CPU delta starts from the leftover's counter |
| - // (CarryTags); the next is wholly this agent's units. |
| - if u := b.tick(t); u.Owner != nil { |
| - t.Fatalf("first reading after the leftover went = owner %q, want none", owner(u)) |
| - } |
| - if u := b.tick(t); owner(u) != "bdn/shop" { |
| - t.Fatalf("reading of a unit this agent started = owner %q, want bdn/shop", owner(u)) |
| - } |
| -} |
| - |
| -// TestNestedSnapshotUnreadable: when the nested layout cannot be listed at |
| -// agent start, nothing in it is known to be this agent's. |
| -func TestNestedSnapshotUnreadable(t *testing.T) { |
| - if st := snapshotNestedUnits(filepath.Join(t.TempDir(), "absent")); st.unswept || len(st.ids) != 0 { |
| - t.Fatalf("a box with no nested layout = %+v, want clean", st) |
| - } |
| - root := t.TempDir() |
| - if err := os.MkdirAll(filepath.Join(root, "carlos-instances-x.slice"), 0o755); err != nil { |
| - t.Fatal(err) |
| - } |
| - if err := os.Chmod(root, 0o300); err != nil { |
| - t.Fatal(err) |
| - } |
| - defer os.Chmod(root, 0o755) //nolint:errcheck |
| - if _, err := os.ReadDir(root); err == nil { |
| - t.Skip("listable without read permission (running as root?)") |
| - } |
| - if st := snapshotNestedUnits(root); !st.unswept { |
| - t.Fatal("an unlistable nested layout counted as swept") |
| - } |
| - b := &nestedBox{root: t.TempDir()} |
| - b.unit(t, instancectl.UnitName(instancectl.RoleRun, nestedHost), 1, 1) |
| - got := nestedUnitReadings(b.root, []string{nestedHost}, nestedStart{unswept: true}) |
| - if r, ok := got[cgroup.ExecName(nestedHost)]; !ok || !r.leftover { |
| - t.Fatalf("a reading after an unswept start = %+v, want a leftover", got) |
| - } |
| - if r := nestedUnitReadings(b.root, []string{nestedHost}, nestedStart{})[cgroup.ExecName(nestedHost)]; r.leftover { |
| - t.Fatal("a reading after a clean start is a leftover") |
| - } |
| -} |
| +import "testing" |
| // TestSumUnitRaw: a field is summed only when every unit has it. |
| func TestSumUnitRaw(t *testing.T) { |
diff --git a/internal/host/metrics_probes.go b/internal/host/metrics_probes.go| index cf7ad3c70..0cbe5101e 100644 |
| --- a/internal/host/metrics_probes.go |
| +++ b/internal/host/metrics_probes.go |
| @@ -208,6 +208,11 @@ type unitRaw struct { |
| // leftover marks a nested host's reading that includes a unit this |
| // agent did not start (nestedUnitReadings): never vouched. |
| leftover bool |
| + // members names the cgroups a summed nested reading was read from |
| + // (unit and cgroup id each), "" for a single cgroup. The sampler takes |
| + // no CPU delta across two readings of different members: a unit that |
| + // went or came would make the difference of two sums wrong. |
| + members string |
| } |
| // readUnitRaw reads a unit's resource usage from the cgroup v2 files in |
diff --git a/internal/provision/testdata/plan14-root-reads-chain.tsv b/internal/provision/testdata/plan14-root-reads-chain.tsv| index 8075f29b2..3b3f13147 100644 |
| --- a/internal/provision/testdata/plan14-root-reads-chain.tsv |
| +++ b/internal/provision/testdata/plan14-root-reads-chain.tsv |
| @@ -3,4 +3,4 @@ |
| plan14-root-reads-c2-root-exec-inputs.tsv 0ef813eebfb1a2e2812d897c4f0b5fd7f75e3e39c7602cf64d1634e8374327af |
| plan14-root-reads-label-case-running-tile.tsv 0ef813eebfb1a2e2812d897c4f0b5fd7f75e3e39c7602cf64d1634e8374327af |
| plan14-root-reads-remote-instance-metrics.tsv ed0d770a827bdb37a87d21e5c8efb259ca0de88457b0cb3202ebb006fc0cd032 |
| -plan14-root-reads-remote-metrics-nested.tsv 5a1cc50b9465ed19098fb9b0557324acb622bd84e1621157788af63a702ce4a3 |
| +plan14-root-reads-remote-metrics-nested.tsv 3543f05491efe4c861c1d208672e52c5241671494859205822d4047ab2c94784 |
diff --git a/internal/provision/testdata/plan14-root-reads-remote-metrics-nested.tsv b/internal/provision/testdata/plan14-root-reads-remote-metrics-nested.tsv| index cba38bc19..fee9d8493 100644 |
| --- a/internal/provision/testdata/plan14-root-reads-remote-metrics-nested.tsv |
| +++ b/internal/provision/testdata/plan14-root-reads-remote-metrics-nested.tsv |
| @@ -1,15 +1,15 @@ |
| # Census overlay remote-metrics-nested, written by census-propose (#369). census-ruling-remote-metrics-nested, approved on #280 before the merge; the approval card is docs/superpowers/notes/census-proposal-remote-metrics-nested.md. |
| # 2 body, 0 sites, 1 envelope: each changed unit re-frozen at its existing disposition with its claim appended. |
| # 4 new dispositions: 0 reads re-frozen at their disposition with the claim, 4 new units frozen accepted-legacy, 0 quiet units retired while they read nothing, 0 other. |
| -@legacy 99d191aa6dd304aa060b5c321552431c4d6b2c4d030920bface2ea34fbf07154 internal/host/metrics_loop.go sampler.tick legacy accepted-legacy accepted-legacy;rev3=J4;basis=root-input;rev3=census-ruling-remote-instance-metrics;basis=calls the owners probe before and after the unit read and tags readings with metrics.TagUnits and metrics.CarryTags; no read added;rev3=census-ruling-remote-metrics-nested;basis=clears the tenant tag of a reading marked leftover (a nested unit present at agent start) before CarryTags; no read added file:ReadBytes@963 4789ff4d04c00a2c5ac99fd868e64a794eed38b36db818fe488f669e0c1e2add |
| +@legacy eb93ad3343e07652959273596a2366e438e70284b79cc6d7f96d26f8da0ca45a internal/host/metrics_loop.go sampler.tick legacy accepted-legacy accepted-legacy;rev3=J4;basis=root-input;rev3=census-ruling-remote-instance-metrics;basis=calls the owners probe before and after the unit read and tags readings with metrics.TagUnits and metrics.CarryTags; no read added;rev3=census-ruling-remote-metrics-nested;basis=clears the tenant tag of a reading marked leftover (a nested unit present at agent start) before CarryTags, and takes no CPU delta when a nested reading's set of cgroups changed since the previous tick; no read added file:ReadBytes@1093 1263e19712bffa735063f32113ff378d9b8ba59b7568cdbb550d29ac0880ec4b |
| @legacy 4732421e39880404f16930726c01362c30d092a4869c8ee7e9a9b963fc9be0f5 internal/host/agent.go routeHostNames legacy accepted-legacy accepted-legacy;rev3=census-ruling-remote-metrics-nested;basis=new: lists the agent's own registry for its route hosts (as stampedUnitNames does each tick) for the nested slice reads; no file path, nothing written registry:Host@261,whole:Route@203,whole:Route@232 9d2f7f2de05da66145e8e229b5dca737593b3ebfd6455fa83791fe1bb869c711 |
| -@legacy e46e9eb10dcb71ada6f9ea5ff88eba98c93559eafc0ea5f1be991662ac7162e4 internal/host/metrics_nested.go nestedUnitReadings legacy accepted-legacy accepted-legacy;rev3=census-ruling-remote-metrics-nested;basis=new: as the agent (user carlos), lists each route host's nested slice dir under the fixed cgroupfs root (path from instancectl.SliceName of a registry host, which escapes everything but [A-Za-z0-9:_.]) and reads its unit cgroups' cpu.stat, memory.current, memory.peak and io.stat through readUnitRaw, as the sampler already does for other units; read-only, world-readable cgroupfs files; root never calls it file:ReadDir@226 333995b2c499b6535e7db9104248fa2540d2fc6b1f8c86606459421f7b8cb99a |
| +@legacy acfac81e4b52ab4b08a326c9f9da947939ef4192b0ce0680a3d52c3abf509f06 internal/host/metrics_nested.go nestedUnitReadings legacy accepted-legacy accepted-legacy;rev3=census-ruling-remote-metrics-nested;basis=new: as the agent (user carlos), lists each route host's nested slice dir under the fixed cgroupfs root (path from instancectl.SliceName of a registry host, which escapes everything but [A-Za-z0-9:_.]) and reads its unit cgroups' cpu.stat, memory.current, memory.peak and io.stat through readUnitRaw, as the sampler already does for other units, and names the cgroups it summed (unit and cgroup id); read-only, world-readable cgroupfs files; root never calls it file:ReadDir@226 442f0e537ceb7cf207dba4d22f36c72b25f84057ee78a191d0eef0928e179605 |
| @legacy fdba9404918aa1ff51552f42cb6c917393981f78dbdba238bec34ce19e1e1387 internal/host/metrics_nested.go snapshotNestedUnits legacy accepted-legacy accepted-legacy;rev3=census-ruling-remote-metrics-nested;basis=new: as the agent, once at start, lists the fixed nested layout root and its slices and records each unit cgroup's inode; read-only; root never calls it file:ReadDir@370,file:ReadDir@68 19a49124d843519691de7b4dce2adb0e727cc637974c2c9f375e35d10ea6430e |
| @legacy cb395998f3fc6f6bd8660c377171c199bf5282bfa4c8401729983a5b170926cf internal/host/metrics_nested_linux.go cgroupID legacy accepted-legacy accepted-legacy;rev3=census-ruling-remote-metrics-nested;basis=new: stats a cgroup dir for its inode (the cgroup id); read-only; root never calls it file:Stat@55 a42cbf096d2fc142026a764ddb19788e500fee5f197eec5cfd88e158735b8b4b |
| internal/host/agent.go runAgent authority B,C,D,F rev3=census-ruling-self-serve-moves-1;basis=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos): builds the box's lifetime judge once (newBoxJudge, nil with host claims on) and hands it to the seed placement, the moves and runs workers and every loop it starts; read sites unchanged, offsets moved; B,C,D,F authority retained; self-serve moves 1 Task 8: derives the box's lifetimes switch from the judge once (lifetimes := boxJudge != nil) and hands it to the edges file loop; read sites unchanged, offsets moved;rev3=census-ruling-plans-4d-lapse;basis=arms two more plans hooks from the same snapshot: e.SetPlanDisabledFor(planDisabledFor) beside SetPlanGovernedFor, and svc.SetDisabledFor(planDisabledRoute) beside SetMaxRunFor (plans 4d); the reads live in those units (plans-4d-units decision); read sites unchanged, offsets moved;rev3=census-ruling-rootfs-apps-2;basis=main's body as of the merge of origin/main 9b81d97b (with main's plan rate ceiling, edge request records, regional box names, self-serve moves plan 1, plans 4d-1 lapse and its other later changes under main's own census rulings) plus the rootfs placement wiring in the activator start: an agentRootfs built from eb.NestedOK, CARLOS_DEPLOYMENT_SINGLE_TENANT, CARLOS_POOLS, the claim flag, swapArming's answer, the control client's /ready/rootfs and, on a fleet box whose identity resolved, fleetOwnerCheck over the deploy store main already opens for the fleet label (fleetStore), then arm and armedRootfs.Store; this body reads nothing new itself; the closures it wires read later, at a rootfs wake and each status tick: GET /ready/rootfs over the control socket, NestedOK's checks, and release.FleetOwnerKey for the judged row's own account and this box's fleet from the deploy store;rev3=census-ruling-instance-egress-sizes-328-329;basis=#328 plan 2 Tasks 7 and 11, #329 plan 3 Task 7 and plan 1 Task 7's policy cache: the control client is built once and handed to eb.Control, to the status tick (egressStatus) and to a new egressNudgeLoop goroutine; armSizeSource(svc, "/sys/fs/cgroup") after the activator Service; armPolicyCache() after armChangeIndex; statusLoop takes egressStatus. The reads are those units' own (decision rows); this body reads nothing new: the same five sites, offsets moved, in the agent; B,C,D,F authority retained.;rev3=census-ruling-remote-instance-metrics;basis=builds the metrics loop's owners closure (metricsOwners over the agent's registry, the activator and cgm.Leftover) when an activator exists and hands it to metricsLoop; reads nothing new itself;rev3=census-ruling-remote-metrics-nested;basis=snapshots the nested layout (snapshotNestedUnits over /sys/fs/cgroup/carlos.slice/carlos-instances.slice) once at start, before the activator, and hands the metrics loop a unitSources struct (stamped units, routeHostNames, that root and the snapshot); reads nothing new itself file:Exec@15646,file:Open@1150,registry:App@10927,whole:Route@10919,whole:Route@25822 76515f7210520c335e157c9dd72181eace54ba1c4ffcd005e516e12404bc54df |
| -internal/host/metrics_loop.go sampler.tick legacy accepted-legacy accepted-legacy;rev3=J4;basis=root-input;rev3=census-ruling-remote-instance-metrics;basis=calls the owners probe before and after the unit read and tags readings with metrics.TagUnits and metrics.CarryTags; no read added;rev3=census-ruling-remote-metrics-nested;basis=clears the tenant tag of a reading marked leftover (a nested unit present at agent start) before CarryTags; no read added file:ReadBytes@963 4789ff4d04c00a2c5ac99fd868e64a794eed38b36db818fe488f669e0c1e2add |
| +internal/host/metrics_loop.go sampler.tick legacy accepted-legacy accepted-legacy;rev3=J4;basis=root-input;rev3=census-ruling-remote-instance-metrics;basis=calls the owners probe before and after the unit read and tags readings with metrics.TagUnits and metrics.CarryTags; no read added;rev3=census-ruling-remote-metrics-nested;basis=clears the tenant tag of a reading marked leftover (a nested unit present at agent start) before CarryTags, and takes no CPU delta when a nested reading's set of cgroups changed since the previous tick; no read added file:ReadBytes@1093 1263e19712bffa735063f32113ff378d9b8ba59b7568cdbb550d29ac0880ec4b |
| internal/host/agent.go routeHostNames legacy accepted-legacy accepted-legacy;rev3=census-ruling-remote-metrics-nested;basis=new: lists the agent's own registry for its route hosts (as stampedUnitNames does each tick) for the nested slice reads; no file path, nothing written registry:Host@261,whole:Route@203,whole:Route@232 9d2f7f2de05da66145e8e229b5dca737593b3ebfd6455fa83791fe1bb869c711 |
| -internal/host/metrics_nested.go nestedUnitReadings legacy accepted-legacy accepted-legacy;rev3=census-ruling-remote-metrics-nested;basis=new: as the agent (user carlos), lists each route host's nested slice dir under the fixed cgroupfs root (path from instancectl.SliceName of a registry host, which escapes everything but [A-Za-z0-9:_.]) and reads its unit cgroups' cpu.stat, memory.current, memory.peak and io.stat through readUnitRaw, as the sampler already does for other units; read-only, world-readable cgroupfs files; root never calls it file:ReadDir@226 333995b2c499b6535e7db9104248fa2540d2fc6b1f8c86606459421f7b8cb99a |
| +internal/host/metrics_nested.go nestedUnitReadings legacy accepted-legacy accepted-legacy;rev3=census-ruling-remote-metrics-nested;basis=new: as the agent (user carlos), lists each route host's nested slice dir under the fixed cgroupfs root (path from instancectl.SliceName of a registry host, which escapes everything but [A-Za-z0-9:_.]) and reads its unit cgroups' cpu.stat, memory.current, memory.peak and io.stat through readUnitRaw, as the sampler already does for other units, and names the cgroups it summed (unit and cgroup id); read-only, world-readable cgroupfs files; root never calls it file:ReadDir@226 442f0e537ceb7cf207dba4d22f36c72b25f84057ee78a191d0eef0928e179605 |
| internal/host/metrics_nested.go snapshotNestedUnits legacy accepted-legacy accepted-legacy;rev3=census-ruling-remote-metrics-nested;basis=new: as the agent, once at start, lists the fixed nested layout root and its slices and records each unit cgroup's inode; read-only; root never calls it file:ReadDir@370,file:ReadDir@68 19a49124d843519691de7b4dce2adb0e727cc637974c2c9f375e35d10ea6430e |
| internal/host/metrics_nested_linux.go cgroupID legacy accepted-legacy accepted-legacy;rev3=census-ruling-remote-metrics-nested;basis=new: stats a cgroup dir for its inode (the cgroup id); read-only; root never calls it file:Stat@55 a42cbf096d2fc142026a764ddb19788e500fee5f197eec5cfd88e158735b8b4b |
| -@coverage internal/host 023493f7c44f91162122fe7ec8eadcfec730d9777bfc0c69c3f0627ce6ce70b2 |
| +@coverage internal/host 3476df1ecdefdb3bf472740f058464c8e360187ef9547cf8dd255f82545d5034 |