Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,10 @@ first `start` with this recipe, kill the old process groups (`kill -s TERM -- -<
- **Runners column.** Every runner the forges report, plus any seen in job data, and a line for this
device's gitlab-runner when `runner_metrics` is set.
- **Phone health.** Battery, plugged state, temperature, CPU (Termux's own processes on a phone, the whole system on a Linux host) and memory, plus a 24 h
battery and temperature chart. A new failure on main or staging vibrates the phone once.
chart: battery, CPU and memory on a 0-100% scale, temperature on its own scale, and a band for each job
this device ran (a red tick on top for a failed one, dashed edges for a GitLab busy span, which is only
known to the poll interval). A host without a battery gets the same chart as "This host", without battery
and temperature. A new failure on main or staging vibrates the phone once.

| Waiting, stalled queue | On hold (manual) |
|---|---|
Expand Down
133 changes: 113 additions & 20 deletions board/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@
--queue: #f29a3a;
--hold: #7cb7e8;
--off: #3a3f46;
/* 24 h chart series: three line hues validated as a set on --board-deep (lightness band, CVD and
normal-vision separation, 3:1 contrast); battery is an area wash, so its form tells it apart */
--s-temp: #d28e05;
--s-cpu: #338ced;
--s-mem: #e24d8b;
--s-batt: #0aac23;
--sans: "Roboto Condensed", sans-serif-condensed, "Arial Narrow", sans-serif;
--mono: "Roboto Mono", "Droid Sans Mono", "DejaVu Sans Mono", monospace;
}
Expand Down Expand Up @@ -129,12 +135,29 @@
.side > .chart { flex: 1 1 auto; display: flex; flex-direction: column; }
.chart .plot { position: relative; flex: 1 1 0; min-height: 14vh; }
.chart svg { position: absolute; inset: 0; display: block; width: 100%; height: 100%; }
/* scale marks: battery on the left edge, temperature on the right; both scales share the three lines */
.chart .tick { position: absolute; font-size: 1.7vh; line-height: 1; color: var(--dim); opacity: .8; padding: .3vh .4vw; pointer-events: none; }
/* scale marks: 0-100 % (battery, CPU, memory) on the left edge, temperature on the right; the scales share
the three lines */
/* a halo in the surface colour keeps them readable where a line or a band passes under them (14vh minimum) */
.chart .tick { position: absolute; font-size: 1.7vh; line-height: 1; color: var(--dim); padding: .3vh .4vw; pointer-events: none;
text-shadow: 0 0 .3vh var(--board-deep), 0 0 .3vh var(--board-deep), 0 0 .3vh var(--board-deep), 0 0 .6vh var(--board-deep); }
.chart .tick.l { left: 0; } .chart .tick.r { right: 0; }
.chart .tick.y0 { top: 0; } .chart .tick.y1 { top: 50%; transform: translateY(-100%); } .chart .tick.y2 { bottom: 0; }
.legend { display: flex; gap: 1.4vw; font-size: 2.2vh; color: var(--dim); margin-top: .5vh; }
.legend i { display: inline-block; width: 1.8vh; height: .5vh; vertical-align: middle; margin-right: .3vw; }
/* the jobs this device ran, behind the series: neutral bands; a failed job adds a red tick along the top,
an approximate span (busy between two polls) is fainter with dashed edges */
.chart .run rect { fill: var(--text); fill-opacity: .11; }
.chart .run.fail rect { fill: var(--fail); fill-opacity: .2; }
.chart .run.approx rect { fill-opacity: .06; }
.chart .run .cap { stroke: var(--fail); stroke-width: 6px; }
.chart .run .edge { stroke: var(--dim); stroke-width: 1px; stroke-dasharray: 3 3; stroke-opacity: .8; }
.chart .series { fill: none; stroke-width: 2px; stroke-linejoin: round; stroke-linecap: round; }
.legend { display: flex; flex-wrap: wrap; column-gap: 1.4vw; row-gap: .3vh; font-size: 2.2vh; color: var(--dim); margin-top: .5vh; }
.legend span { white-space: nowrap; }
.legend i { display: inline-block; width: 1.8vh; height: .5vh; vertical-align: middle; margin-right: .3vw; background: var(--k); }
.legend i.dash { height: 0; background: none; border-top: .3vh dashed var(--k); }
.legend i.area { height: 1.4vh; opacity: .45; }
.legend i.band { width: 1.4vh; height: 1.4vh; background: color-mix(in srgb, var(--text) 16%, transparent); }
.legend i.band.fail { background: color-mix(in srgb, var(--fail) 26%, transparent); border-top: .4vh solid var(--fail); }
.legend i.band.approx { background: color-mix(in srgb, var(--text) 8%, transparent); border: 1px dashed var(--dim); border-top: 0; border-bottom: 0; }

footer { grid-column: 1 / -1; display: flex; gap: 2vw; padding: .9vh 2.4vw; font-size: 2.2vh; color: var(--dim); background: var(--board-deep); }
footer .err { color: var(--fail); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
Expand Down Expand Up @@ -456,26 +479,96 @@
};
$("fleet").innerHTML = fleet.length || lr ? `<h2>Runners</h2>` + local + fleet.map(f =>
`<div class="row ${cls(f.status)} ${sig(f)}"><i class="sig"></i>${name(f.name)}<span class="w" style="min-width:${Math.min([...what(f)].length, 7)}ch">${esc(what(f))}</span></div>`).join("") : "";
renderChart(st.device_history || []);
renderChart(st.device_history || [], st.device_runs || [], st.device || {});
}

function renderChart(h) {
if (h.length < 2) { $("chart").innerHTML = `<h2>Phone, last 24 h</h2><p class="legend">The chart shows up after 10 minutes of samples.</p>`; return; }
const W = 400, H = 100, now = Date.now() / 1000, x = t => W * (1 - (now - t) / 86400);
// The 24 h chart. Left scale 0-100 %: battery (area wash), CPU and memory (lines); right scale 20-50°:
// temperature, with the 40° warning line. Behind them, one band per job this device ran (device_runs), from
// start to end (to now while it runs): a failed job adds a tick along the top, an approximate span (a busy
// count seen between two polls, without project, job or result) is fainter with dashed edges. A series with
// no data is left out with its scale, line and legend entry: a host without a battery shows CPU, memory and
// its runs under "This host". A missing value or a gap in the samples breaks a line instead of bridging it.
const hhmm = t => new Date(t * 1000).toLocaleTimeString("en-GB", {hour: "2-digit", minute: "2-digit"});
function chartPaths(h, key, x, y, area, H) {
// consecutive samples with a value, split where one is missing or the gap is over 2.5 sample spacings
// (never under 15 min); a lone sample still draws as a dot (round cap)
const gaps = h.slice(1).map((s, i) => s.t - h[i].t).sort((p, q) => p - q);
const maxGap = Math.max(900, 2.5 * (gaps[gaps.length >> 1] || 0));
const segs = [];
let cur = null, prev = null;
for (const s of h) {
const v = s[key];
if (typeof v !== "number" || !Number.isFinite(v)) { cur = null; continue; }
if (!cur || s.t - prev > maxGap) segs.push(cur = []);
cur.push([x(s.t).toFixed(1), y(v).toFixed(1)]);
prev = s.t;
}
return segs.map(g => area
? `M${g[0][0]},${H} ${g.map(([px, py]) => `L${px},${py}`).join(" ")} L${g.at(-1)[0]},${H}Z`
: `M${g[0][0]},${g[0][1]} ${(g.length > 1 ? g.slice(1) : g).map(([px, py]) => `L${px},${py}`).join(" ")}`).join(" ");
}
function runBands(runs, now, x, W, H) {
const from = now - 86400;
const unit = W / Math.max(1, $("chart").clientWidth); // viewBox units per CSS pixel
const shown = runs.filter(r => Number.isFinite(r.start) && r.start <= now && (r.end ?? now) >= from);
const svg = shown.map(r => {
let a = x(Math.max(r.start, from)), b = x(Math.min(r.end ?? now, now));
const fail = r.result === "failed", min = (fail ? 4 : 2) * unit; // a short job stays 2 px wide, a failed one 4 px
if (b - a < min) { const m = (a + b) / 2; a = m - min / 2; b = m + min / 2; }
const when = `${hhmm(r.start)}–${r.end == null ? "now" : hhmm(r.end)}`;
const what = r.approx ? `${r.forge || "runner"} busy (approximate)` : [short(r.project), r.job, r.result || (r.end == null ? "running" : "")].filter(Boolean).join(" · ");
const [x0, w] = [a.toFixed(2), (b - a).toFixed(2)];
return `<g class="run${fail ? " fail" : ""}${r.approx ? " approx" : ""}"><title>${esc(`${what}, ${when}`)}</title><rect x="${x0}" y="0" width="${w}" height="${H}"/>${
fail ? `<line class="cap" x1="${x0}" x2="${b.toFixed(2)}" y1="0" y2="0" vector-effect="non-scaling-stroke"/>` : ""}${
r.approx ? [a, b].map(e => `<line class="edge" x1="${e.toFixed(2)}" x2="${e.toFixed(2)}" y1="0" y2="${H}" vector-effect="non-scaling-stroke"/>`).join("") : ""}</g>`;
}).join("");
return {svg, n: shown.length, failed: shown.filter(r => r.result === "failed").length,
approx: shown.filter(r => r.approx).length, open: shown.filter(r => r.end == null).length};
}
function renderChart(h, runs, device) {
const has = k => h.some(s => typeof s[k] === "number");
const battery = has("battery") || device.battery != null;
const title = `<h2>${battery ? "Phone" : "This host"}, last 24 h</h2>`;
const now = Date.now() / 1000;
if (h.length < 2 && !runs.some(r => (r.end ?? now) >= now - 86400)) {
$("chart").innerHTML = `${title}<p class="legend">The chart shows up after 10 minutes of samples.</p>`; return;
}
const W = 400, H = 100, x = t => W * (1 - (now - t) / 86400);
const yT = v => H - H * Math.min(1, Math.max(0, (v - 20) / 30)); // 20° to 50°
const yB = v => H - H * v / 100;
const temp = h.filter(s => s.temp != null).map(s => `${x(s.t).toFixed(1)},${yT(s.temp).toFixed(1)}`).join(" ");
const bat = h.filter(s => s.battery != null);
const area = bat.length ? `M${x(bat[0].t).toFixed(1)},${H} ` + bat.map(s => `L${x(s.t).toFixed(1)},${yB(s.battery).toFixed(1)}`).join(" ") + ` L${x(bat.at(-1).t).toFixed(1)},${H}Z` : "";
$("chart").innerHTML = `<h2>Phone, last 24 h</h2>
<div class="plot"><svg viewBox="0 0 ${W} ${H}" preserveAspectRatio="none" role="img" aria-label="Temperature and battery over the last 24 hours">
const yP = v => H - H * Math.min(100, Math.max(0, v)) / 100; // 0 to 100 %
const temp = has("temp"), bands = runBands(runs, now, x, W, H);
const series = [ // [key, label, colour, legend key style, scale]
["battery", "battery", "--s-batt", "area", yP],
["cpu", "CPU", "--s-cpu", "", yP],
["mem", "memory", "--s-mem", "", yP],
["temp", "temperature", "--s-temp", "", yT],
].filter(([k]) => has(k));
const pct = series.filter(([k]) => k !== "temp").map(([, l]) => l);
const lines = series.map(([k, , c, st, y]) => st === "area"
? `<path d="${chartPaths(h, k, x, y, true, H)}" fill="var(${c})" fill-opacity=".1"/>`
: `<path class="series" d="${chartPaths(h, k, x, y, false, H)}" stroke="var(${c})" vector-effect="non-scaling-stroke"/>`).join("");
const jobs = bands.n ? `Shaded bands: ${bands.n} ${bands.n === 1 ? "job" : "jobs"} this device ran${
[bands.failed && `${bands.failed} failed (red tick on top)`, bands.approx && `${bands.approx} approximate busy ${bands.approx === 1 ? "span" : "spans"} (dashed edges)`,
bands.open && `${bands.open} still running`].filter(Boolean).map(t => `, ${t}`).join("")}.` : "No jobs ran on this device in the last 24 hours.";
const label = [`${battery ? "Phone" : "This host"}, last 24 hours.`,
pct.length ? `Left scale 0 to 100%: ${pct.join(", ")}.` : "",
temp ? "Right scale 20 to 50°: temperature, with a dashed line at 40°." : "", jobs].filter(Boolean).join(" ");
const legend = [
...series.map(([, l, c, st]) => [l, c, st]),
...(temp ? [["40°", "--queue", "dash"]] : []),
...(bands.n ? [["job", "", "band"]] : []),
...(bands.failed ? [["failed", "", "band fail"]] : []),
...(bands.approx ? [["approx.", "", "band approx"]] : []),
].map(([l, c, st]) => `<span><i class="${st}"${c ? ` style="--k:var(${c})"` : ""}></i>${esc(l)}</span>`).join("");
$("chart").innerHTML = `${title}
<div class="plot"><svg viewBox="0 0 ${W} ${H}" preserveAspectRatio="none" role="img" aria-label="${esc(label)}">
${bands.svg}
${[0, H / 2, H].map(y => `<line x1="0" x2="${W}" y1="${y}" y2="${y}" stroke="var(--dim)" stroke-opacity=".28" stroke-width="1" vector-effect="non-scaling-stroke"/>`).join("")}
<line x1="0" x2="${W}" y1="${yT(40)}" y2="${yT(40)}" stroke="var(--queue)" stroke-width="1" stroke-dasharray="4 4" vector-effect="non-scaling-stroke"/>
<path d="${area}" fill="var(--ok)" opacity=".16"/>
<polyline points="${temp}" fill="none" stroke="var(--flap)" stroke-width="2" vector-effect="non-scaling-stroke"/>
</svg>${[["100%", "50°"], ["50%", "35°"], ["0%", "20°"]].map(([b, t], i) =>
`<span class="tick l y${i}">${b}</span><span class="tick r y${i}">${t}</span>`).join("")}</div>
<div class="legend"><span><i style="background:var(--flap)"></i>temperature</span><span><i style="background:var(--ok);opacity:.5"></i>battery</span><span><i style="background:var(--queue)"></i>40°</span></div>`;
${temp ? `<line x1="0" x2="${W}" y1="${yT(40)}" y2="${yT(40)}" stroke="var(--queue)" stroke-width="1" stroke-dasharray="4 4" vector-effect="non-scaling-stroke"/>` : ""}
${lines}
</svg>${[["100%", "50°"], ["50%", "35°"], ["0%", "20°"]].map(([p, t], i) =>
`<span class="tick l y${i}">${p}</span>${temp ? `<span class="tick r y${i}">${t}</span>` : ""}`).join("")}</div>
<div class="legend">${legend}</div>`;
}

function fitSide() {
Expand Down
14 changes: 14 additions & 0 deletions board/tests/test_fixes.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,20 @@ def test_local_runner_line(self):
])



class DeviceChart(unittest.TestCase):
@unittest.skipUnless(shutil.which("node"), "node not installed")
def test_chart_line_breaks_on_missing_values_and_gaps(self):
# a null or absent value (macOS cpu, samples older than cpu/mem) and a gap of over 15 min break the line
# instead of drawing it to zero or bridging it; a lone sample stays a dot
html = (HERE / "index.html").read_text()
fn = re.search(r"function chartPaths\(.*?\n\}", html, re.S).group(0)
h = [{"t": 0, "cpu": 10}, {"t": 300, "cpu": 20}, {"t": 600, "cpu": None}, {"t": 900, "cpu": 30},
{"t": 1200}, {"t": 1500, "cpu": 40}, {"t": 1800, "cpu": 50}, {"t": 4800, "cpu": 60}]
js = f"{fn}\nconsole.log(chartPaths({json.dumps(h)}, 'cpu', t => t / 100, v => v, false, 100))"
out = subprocess.run(["node", "-e", js], capture_output=True, text=True, check=True).stdout.strip()
self.assertEqual(out, "M0.0,10.0 L3.0,20.0 M9.0,30.0 L9.0,30.0 M15.0,40.0 L18.0,50.0 M48.0,60.0 L48.0,60.0")

class NeutralDefaults(unittest.TestCase):
def test_no_local_runner_logs_by_default(self):
self.assertFalse(hasattr(server, "GH_LOGS"))
Expand Down
Binary file modified docs/screenshots/board-failure-1920x1080.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/screenshots/board-failure-915x412-2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/screenshots/board-idle-1920x1080.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/screenshots/board-idle-915x412-2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/screenshots/board-on-hold-1920x1080.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/screenshots/board-on-hold-915x412-2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/screenshots/board-running-1920x1080.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/screenshots/board-running-915x412-2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/screenshots/board-waiting-1920x1080.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/screenshots/board-waiting-915x412-2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
51 changes: 46 additions & 5 deletions docs/screenshots/make_screenshots.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,32 +137,73 @@ def raw_state(pipelines, runners=RUNNERS, device=DEVICE, running=0, errors=()):
"device": dict(device), "runner": {"configured": True, "up": True, "running": running, "name": "phone-runner"}}


def history(temp_peak=36.0, low_batt=False):
def gh_run(project, name, ago, secs, result):
"""One exact job from a local GitHub runner log: started `ago` seconds before NOW, ran `secs`."""
return {"forge": "github", "project": project, "job": name, "start": NOW - ago,
"end": NOW - ago + secs if secs is not None else None, "result": result if secs is not None else None,
"approx": False}


def gl_span(ago, secs):
"""One approximate busy span from gitlab-runner metrics: no project, job or result."""
return {"forge": "gitlab", "project": None, "job": None, "start": NOW - ago,
"end": NOW - ago + secs if secs is not None else None, "result": None, "approx": True}


# the jobs this device ran over the last 24 h (device_runs), oldest first: exact GitHub jobs (one failed, one
# canceled) and approximate GitLab busy spans
RUNS = [
gh_run("acme/mobile", "android", 84000, 540, "success"),
gl_span(80000, 1500),
gh_run("lib/utils", "ci", 60000, 95, "success"),
gh_run("lib/parser", "ci", 50000, 900, "failed"),
gl_span(43000, 900),
gl_span(30000, 2400),
gh_run("acme/mobile", "android", 21600, 610, "success"),
gl_span(14400, 600),
gh_run("acme/mobile", "android", 9000, 590, "canceled"),
gh_run("acme/docs-site", "pages", 3600, 140, "success"),
]


def history(temp_peak=36.0, low_batt=False, runs=RUNS):
"""Device samples every 5 min; CPU and memory rise while a job runs. The board was stopped for 45 min
around 06:00 (no samples there), so every line breaks instead of bridging the gap."""
out = []
for i in range(0, 86400, 300):
h = i / 3600
if 15.5 <= h < 16.25:
continue
t = NOW - 86400 + i
busy = any(r["start"] <= t <= (r["end"] if r["end"] is not None else NOW) for r in runs)
bump = math.exp(-((h - 15) / 2.2) ** 2) # afternoon usage peak
temp = 31 + (temp_peak - 31) * bump + 0.6 * math.sin(h * 1.3)
batt = max(20, 80 - (h - 9) * 3.6) if low_batt and h > 9 else 80 + 1.5 * math.sin(h * 0.8)
out.append({"t": NOW - 86400 + i, "temp": round(temp, 1), "battery": round(batt)})
cpu = (56 + 6 * math.sin(h * 3)) if busy else 4 + 2 * abs(math.sin(h * 2.1))
mem = (64 + 3 * math.sin(h)) if busy else 41 + 3 * math.sin(h * 0.7)
out.append({"t": t, "temp": round(temp, 1), "battery": round(batt), "cpu": round(cpu), "mem": round(mem)})
return out


def finish(raw, hist=None):
def finish(raw, hist=None, runs=RUNS):
"""raw poller output -> /api/state, through the board's own build_state (throwaway store, no vibration)."""
store = Store(Path(tempfile.gettempdir()) / "mini-runner-screenshots-unused.json") # never saved
st = server.build_state(json.loads(json.dumps(raw)), store, NOW, lambda: None)
st["updated"] = NOW - 4
st["device_history"] = hist or history()
st["device_history"] = hist or history(runs=runs)
st["device_runs"] = runs
return st


RUNS_OPEN = RUNS + [gl_span(1500, None)] # still running: the band reaches now


def scenes():
hot = {**DEVICE, "battery": 78, "temp": 38.6, "cpu_pct": 61, "mem_used_pct": 67}
return {
# a job running on the phone, another on a build box; the rest of the board finished
"running": finish(raw_state([web_app(2, 128), mobile_running(), *DONE], device=hot, running=1),
history(temp_peak=39)),
history(temp_peak=39, runs=RUNS_OPEN), RUNS_OPEN),
# jobs ready for a runner for 7 min while every runner idles: the stalled-queue alert
"waiting": finish(raw_state([
pipe("acme/api", "staging", "queued", 30, [
Expand Down
Binary file modified docs/screenshots/queue-moving.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading