diff --git a/CHANGELOG.md b/CHANGELOG.md index 8871721..87c4dae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,6 +31,10 @@ has a matching GitHub release whose body comes from its section below. without anyone typing `needs_mib` or keeping it up to date. An engine not yet measured takes the whole card, and the grant line in `berth events` names the size it used ([#311](https://github.com/T-Crypt/berth/issues/311)). +- `berth status` has a SCHEDULE table and the harbor a SCHEDULES panel. Each lists every engine that has a + `window`, with its hours, whether they are open, and how long until they close or open. An engine shows before its + window opens, and a `berth run --window` lease shows its own hours. The status JSON carries the same rows as + `schedules`, and each lease carries its `window`. ### Fixed diff --git a/docs/leasing.md b/docs/leasing.md index 8e6da13..b45ff0c 100644 --- a/docs/leasing.md +++ b/docs/leasing.md @@ -187,8 +187,9 @@ maintenance or before a VM takes it. Name the card by its name or its PCI addres [Run an engine whenever the card is free](gateway.md#run-an-engine-whenever-the-card-is-free). - **A window puts either on the clock.** `window = "23:00-07:00"` on the entry, or `berth run --window 23:00-07:00`, holds the lease to those hours on the node's wall clock. It may cross midnight. A lease that asks outside them - waits for them with no deadline (unless `--wait` sets one) and holds up nobody behind it. `berth status` says when - the window opens, and a background engine is not started at all. When the window closes its holder drains at its usual boundary, so a slot or a job boundary comes first and a + waits for them with no deadline (unless `--wait` sets one) and holds up nobody behind it. A background engine is + not started at all outside its hours. `berth status` (SCHEDULE) and the harbor (SCHEDULES) list every engine that + has a window, whether or not it runs, with its hours and when it next opens or closes. When the window closes its holder drains at its usual boundary, so a slot or a job boundary comes first and a request in flight finishes. ```toml diff --git a/internal/broker/status.go b/internal/broker/status.go index 6103bd3..9a4e485 100644 --- a/internal/broker/status.go +++ b/internal/broker/status.go @@ -86,6 +86,7 @@ func (b *Broker) Status() proto.Status { GPUPIDs: pids, Used: l.used(), GTTUsed: l.gttUsed(), GTTContested: l.contestedGTT, Contested: l.contested, Age: now.Sub(since).Seconds(), Pinned: l.pinned, + Window: l.window.String(), Training: l.training, } if l.state == parked { diff --git a/internal/broker/window_test.go b/internal/broker/window_test.go index 2374637..74b04a4 100644 --- a/internal/broker/window_test.go +++ b/internal/broker/window_test.go @@ -197,3 +197,19 @@ func TestWindowWaiterOnSeveralCardsOutlastsTheDefaultWait(t *testing.T) { t.Fatal("nightly is not on both cards") } } + +// The status names the hours a lease is held to, waiting or granted, and +// leaves a lease with no window without one. +func TestStatusCarriesTheLeaseWindow(t *testing.T) { + b, clk := startTurnBroker(t, procs.Map{}) + clk.set(at2330) + must(t, acquire(b, Request{Engine: "nightly", Priority: Batch, Needs: 8 * GiB, Window: night})) + must(t, acquire(b, Request{Engine: "chat", Priority: Interactive, Needs: 4 * GiB})) + got := map[string]string{} + for _, l := range b.Status().Leases { + got[l.Engine] = l.Window + } + if got["nightly"] != "23:00-07:00" || got["chat"] != "" { + t.Errorf("lease windows = %v, want nightly 23:00-07:00 and chat none", got) + } +} diff --git a/internal/cli/daemon.go b/internal/cli/daemon.go index 16188dc..131f8d9 100644 --- a/internal/cli/daemon.go +++ b/internal/cli/daemon.go @@ -279,7 +279,11 @@ func runDaemon(c *Context) int { go samplerLoop(ctx, rec, hr, n, watcher, ev, &lastHost, &lastAlerts) x := server.Extras{Engines: watcher.Snapshot, Host: lastHost.Load, History: rec.Get, Insights: func() *proto.Insights { return watcher.Insights(time.Now()) }, - Requests: watcher.Requests, Alerts: lastAlerts.Load, Finished: watcher.Finished} + Requests: watcher.Requests, Alerts: lastAlerts.Load, Finished: watcher.Finished, + Windows: map[string]proto.Window{}} + for _, e := range cfg.Engine { + x.Windows[e.Name] = e.Window + } if *devicesFile != "" { x.Pair = &pair.Store{Path: *devicesFile} } diff --git a/internal/cli/status.go b/internal/cli/status.go index d248f4c..1b62235 100644 --- a/internal/cli/status.go +++ b/internal/cli/status.go @@ -137,6 +137,16 @@ func (v statusView) Human(c *Context, ok bool) error { } lease("LEASE", st.Leases, false) lease("WAITING", st.Waiting, true) + if len(st.Schedules) > 0 { + fmt.Fprint(tw, "\nSCHEDULE\tHOURS\tNOW\n") + for _, s := range st.Schedules { + now := c.Style.Warn("closed") + ", opens in " + age(s.ChangeS) + if s.Open { + now = c.Style.OK("open") + ", closes in " + age(s.ChangeS) + } + fmt.Fprintf(tw, "%s\t%s\t%s\n", s.Engine, s.Window, esc(now)) + } + } if len(st.Squatters) > 0 { fmt.Fprint(tw, "\n"+cardCol("SQUATTER", "CARD")+"\tPID\tHOLDS\tSEEN\tUNPROTECTED RUN\n") for _, s := range st.Squatters { diff --git a/internal/cli/status_test.go b/internal/cli/status_test.go index 1dcf5fd..0965163 100644 --- a/internal/cli/status_test.go +++ b/internal/cli/status_test.go @@ -442,3 +442,26 @@ func TestClaimsTablesSayHoldsAndNameCards(t *testing.T) { t.Errorf("one card claims table:\n%s", s) } } + +// berth status lists every engine held to hours and where the node's clock +// sits in them, so a window shows before its engine runs. +func TestStatusShowsTheSchedules(t *testing.T) { + var out, errOut bytes.Buffer + c := &Context{Out: &out, Err: &errOut, Format: FormatHuman, Style: newStyle(&out), errStyle: newStyle(&errOut)} + st := &proto.Status{ + API: proto.APIVersion, Version: "test", + Schedules: []proto.Schedule{ + {Engine: "nightly", Window: "23:00-07:00", Open: false, ChangeS: 3 * 3600}, + {Engine: "render", Window: "18:00-22:00", Open: true, ChangeS: 2*3600 + 15*60}, + }, + } + if err := (statusView{st: st}).Human(c, true); err != nil { + t.Fatal(err) + } + s := out.String() + for _, want := range []string{"SCHEDULE", "HOURS", "nightly", "23:00-07:00", "closed, opens in 3h", "render", "open, closes in 2h15m"} { + if !strings.Contains(s, want) { + t.Errorf("stdout lacks %q:\n%s", want, s) + } + } +} diff --git a/internal/harbor/web/demo.json b/internal/harbor/web/demo.json index 0e6951e..af73c4d 100644 --- a/internal/harbor/web/demo.json +++ b/internal/harbor/web/demo.json @@ -127,6 +127,10 @@ "age_seconds": 40 } ], + "schedules": [ + {"engine": "nightly-train", "window": "23:00-07:00", "open": false, "change_s": 10800}, + {"engine": "render", "window": "18:00-22:00", "open": true, "change_s": 8100} + ], "waiting": [ { "id": "LIT-0145", diff --git a/internal/harbor/web/harbor.css b/internal/harbor/web/harbor.css index 1a91cf0..58f4e13 100644 --- a/internal/harbor/web/harbor.css +++ b/internal/harbor/web/harbor.css @@ -1036,6 +1036,10 @@ body.ready #panel-engines > :nth-child(n+2) { animation-delay: 60ms; } .sq.sw-up { border-left-color: var(--green); } .sq.sw-waiting, .sq.sw-starting { border-left-color: var(--amber); } .sq.sw-failed { border-left-color: var(--magenta); } +/* A schedule row: green while its hours are open, dim while shut. */ +.sq.sched { border-left-color: var(--dim-2); } +.sq.sched .name { color: var(--ink-strong); } +.sq.sched-open { border-left-color: var(--green); } .sw-state { display: inline-flex; align-items: center; gap: var(--s1); white-space: nowrap; } .sw-chip { border: 1px solid var(--hair-2); border-radius: var(--r-pill); padding: 0 var(--s2); font-size: var(--fs-micro); color: var(--dim); } .sw-cordon, .sw-pinned { color: var(--amber); border-color: var(--amber-dim); } diff --git a/internal/harbor/web/harbor.js b/internal/harbor/web/harbor.js index b6aa942..4dc3110 100644 --- a/internal/harbor/web/harbor.js +++ b/internal/harbor/web/harbor.js @@ -133,7 +133,7 @@ let shortcutsDlg, railMenuDlg; let lastLogSig = null; // filter+query+pause signature: repaint only on change, append otherwise let clearLogFilter = null; // set by buildLogSearch: the page's Esc reaches it (R-07) let lastTick = 0; // the relative-time ticker's own 1 s cadence -let berthsRoot, claimsRoot, claimsMeta, stowRoot, notickRoot, machineRoot, machineCharts, machineMeta, socketLine; +let berthsRoot, schedulesRoot, schedulesMeta, claimsRoot, claimsMeta, stowRoot, notickRoot, machineRoot, machineCharts, machineMeta, socketLine; let kpiStripEl, tideEl, tideLegend, tideMeta; let boardMeta, berthsMeta, stowMeta, noticketMeta, enginesMeta; let throughputMeta, throughputDecode, throughputRpm; @@ -168,6 +168,8 @@ function main() { shortcutsDlg = $("shortcuts"); railMenuDlg = $("rail-menu"); berthsRoot = $("berths"); + schedulesRoot = $("schedules"); + schedulesMeta = $("schedules-meta"); claimsRoot = $("claims"); claimsMeta = $("claims-meta"); stowRoot = $("stowaways"); @@ -508,7 +510,7 @@ let pendingSection = null; const HARBOR_SECTIONS = [ ["sec-counter", "Counter"], ["sec-tide", "Tide"], ["sec-timeline", "Timeline"], ["sec-board", "Board"], ["sec-log", "Log"], ["sec-berths", "Berths"], - ["sec-machine", "Machine"], ["sec-claims", "Claims"], ["sec-stow", "Stowaways"], ["sec-noticket", "No ticket"], + ["sec-machine", "Machine"], ["sec-schedules", "Schedules"], ["sec-claims", "Claims"], ["sec-stow", "Stowaways"], ["sec-noticket", "No ticket"], ]; const ENGINES_SECTIONS = [ ["sec-engines", "Engines"], ["sec-library", "Library"], ["priority-panel", "Ranking"], ["sec-pool", "KV pool"], @@ -2097,6 +2099,22 @@ function claimLine(cl) { function memoryWord(cl) { return fmtGiB(cl.used || 0) + " GiB" + (cl.gtt_used ? " + " + fmtGiB(cl.gtt_used) + " GiB GTT" : ""); } +// renderSchedules lists the engines held to hours, by the node's clock, as +// berth status does: an engine shows here before its window opens. +function renderSchedules(s) { + const list = el("div", "squatter-list"); + const all = s.schedules || []; + const open = all.filter((sc) => sc.open); + schedulesMeta.textContent = all.length ? open.length + " open of " + all.length : "none"; + if (all.length === 0) list.append(el("div", "empty-note", "no engine is held to hours: set window = \"23:00-07:00\" on an [[engine]]")); + for (const sc of all) { + const row = el("div", "sq sched" + (sc.open ? " sched-open" : "")); + const now = sc.open ? "open, closes in " + fmtAge(sc.change_s) : "closed, opens in " + fmtAge(sc.change_s); + row.append(el("div", "top", el("span", "name", sc.engine), el("span", null, sc.window)), el("div", "meta", now)); + list.append(row); + } + schedulesRoot.replaceChildren(list); +} function renderClaims(s) { const list = el("div", "squatter-list"); const all = s.claims || []; @@ -2469,6 +2487,7 @@ function renderLight(s) { paintTabCounts(entries.length, (s.engines || []).length); renderBerths(s); paintAlerts(s); + renderSchedules(s); renderClaims(s); renderStowaways(s); renderNoTicket(s); diff --git a/internal/harbor/web/index.html b/internal/harbor/web/index.html index f70a875..8cf1682 100644 --- a/internal/harbor/web/index.html +++ b/internal/harbor/web/index.html @@ -168,6 +168,13 @@