[projects/pld-builder.new] queue.html: show the last good build of a package
arekm
arekm at pld-linux.org
Fri Nov 13 11:26:49 CET 2026
commit 3ee02bef4218fd68c1905b7ef38afeb6fe69a59e
Author: Arkadiusz Miśkiewicz <arekm at maven.pl>
Date: Fri Nov 13 09:16:54 2026 +0100
queue.html: show the last good build of a package
A finished request leaves the queue 4 days after it came, too soon to find
the previous build of a package. The src builder now keeps finished builds in
spool/builder.sqlite, and the page shows the last good one on each builder
in the tooltip; with no other build done in the row, it decides what is slow.
PLD_Builder/db.py | 69 ++++++++++++++++++++++++++++++++++++++++++
PLD_Builder/path.py | 1 +
PLD_Builder/queue_html.py | 38 ++++++++++++++---------
PLD_Builder/request_handler.py | 6 ++++
PLD_Builder/script.js | 24 +++++++++------
5 files changed, 115 insertions(+), 23 deletions(-)
---
diff --git a/PLD_Builder/db.py b/PLD_Builder/db.py
new file mode 100644
index 0000000..59ca518
--- /dev/null
+++ b/PLD_Builder/db.py
@@ -0,0 +1,69 @@
+# vi: ts=8 sts=4 sw=4 et
+"""The src builder's own database, spool/builder.sqlite: what it keeps longer than the queue does.
+
+ builds the builds the bin builders finished: what, where, how it ended and when it ran
+"""
+
+import contextlib
+import sqlite3
+
+import path
+from request import is_final
+
+SCHEMA = """
+CREATE TABLE IF NOT EXISTS builds (
+ batch_id TEXT NOT NULL,
+ builder TEXT NOT NULL,
+ request_id TEXT NOT NULL,
+ request_no INTEGER NOT NULL,
+ spec TEXT NOT NULL,
+ branch TEXT NOT NULL,
+ src_rpm TEXT NOT NULL,
+ status TEXT NOT NULL,
+ started REAL NOT NULL,
+ ended REAL NOT NULL,
+ PRIMARY KEY (batch_id, builder)
+);
+CREATE INDEX IF NOT EXISTS builds_by_spec ON builds (spec, builder, ended);
+"""
+
+
+# the version of SCHEMA, kept in the file: a later one migrates from the version it finds
+VERSION = 1
+
+
+ at contextlib.contextmanager
+def connect():
+ """The database, created on first use; changes are committed when the block ends without an error"""
+ with contextlib.closing(sqlite3.connect(path.builder_db_file, timeout=60)) as db:
+ if db.execute("PRAGMA user_version").fetchone()[0] < VERSION:
+ db.executescript(SCHEMA + f"PRAGMA user_version = {VERSION};")
+ with db:
+ yield db
+
+
+def record_builds(requests, builder, batch_ids):
+ """Keep the builds of the batches a notification from builder finished, with their times"""
+ rows = [(b.b_id, builder, r.id, r.no, b.spec, b.branch, b.src_rpm, b.builders_status[builder],
+ b.builders_build_start[builder], b.builders_build_end[builder])
+ for r in requests for b in r.batches
+ if b.b_id in batch_ids and not b.is_command() and is_final(b.builders_status.get(builder, "?"))
+ and b.builders_build_start.get(builder) and b.builders_build_end.get(builder)]
+ if rows:
+ with connect() as db:
+ # a notification sent again replaces what the first one wrote
+ db.executemany("INSERT OR REPLACE INTO builds VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", rows)
+
+
+def ok_builds(specs):
+ """The successful builds of the specs, newest first: {(spec, builder): [(batch_id, started, ended)]}"""
+ found = {}
+ if not specs:
+ return found
+ with connect() as db:
+ for spec, builder, batch_id, started, ended in db.execute(
+ "SELECT spec, builder, batch_id, started, ended FROM builds"
+ f" WHERE status LIKE 'OK%' AND spec IN ({', '.join('?' * len(specs))}) ORDER BY ended DESC",
+ list(specs)):
+ found.setdefault((spec, builder), []).append((batch_id, started, ended))
+ return found
diff --git a/PLD_Builder/path.py b/PLD_Builder/path.py
index 07c8d57..2d1a9bc 100644
--- a/PLD_Builder/path.py
+++ b/PLD_Builder/path.py
@@ -26,6 +26,7 @@ build_dir = spool_dir + "/builds"
last_req_no_file = spool_dir + "/last_req_no"
got_lock_file = spool_dir + "/got_lock"
log_file = spool_dir + "/log"
+builder_db_file = spool_dir + "/builder.sqlite"
# www/
srpms_dir = www_dir + "/srpms"
diff --git a/PLD_Builder/queue_html.py b/PLD_Builder/queue_html.py
index 9242bee..b671681 100644
--- a/PLD_Builder/queue_html.py
+++ b/PLD_Builder/queue_html.py
@@ -15,6 +15,7 @@ import time
import urllib.parse
from datetime import datetime
+import db
from config import config
from request import escape, is_final
@@ -38,6 +39,7 @@ def write(f, requests):
def page(requests):
newest_first = sorted(requests, key=lambda r: r.no, reverse=True)
+ history = db.ok_builds({b.spec for r in requests for b in r.batches if not b.is_command()})
return (
'<!DOCTYPE html>\n'
'<html lang="en">\n'
@@ -58,7 +60,7 @@ def page(requests):
'</header>\n'
+ builders_line(requests)
+ f'<main style="--builders: {len(config.binary_builders)}">\n'
- + requests_by_day(newest_first)
+ + requests_by_day(newest_first, history)
+ LEGEND.format(zone=time.strftime("%Z"))
+ '</main>\n'
+ f'<script>\n{SCRIPT}</script>\n'
@@ -149,7 +151,7 @@ def builder_now(name, requests):
# -- requests
-def requests_by_day(requests):
+def requests_by_day(requests, history):
out = []
day = None
for r in requests:
@@ -157,7 +159,7 @@ def requests_by_day(requests):
if queued != day:
day = queued
out.append(f'<h2>{day}</h2>\n')
- out.append(request_html(r))
+ out.append(request_html(r, history))
return "".join(out)
@@ -169,7 +171,7 @@ def request_state(r):
return "done" if all(is_final(s) for s in statuses) else "open"
-def request_html(r):
+def request_html(r, history):
flags = "".join(f' <span class="flag {escape(flag)}">{escape(flag)}</span>' for flag in r.flags)
jobs = f", jobs {r.max_jobs}" if r.max_jobs else ""
return (
@@ -177,7 +179,7 @@ def request_html(r):
f'<header class="{escape(" ".join(r.flags))}"><a class=no href="#{r.no}">{r.no}</a> <b class=from>{escape(r.requester)}</b>{flags}'
f' <span class=rid>priority {r.priority}{jobs}, <a href="srpms/{escape(r.id)}">{escape(r.id)}</a></span>'
f' <span class=sent>queued {clock_zone(r.time)}, <time class=ago datetime="{iso(r.time)}"></time></span></header>\n'
- + "".join(batch_html(batch, r.id) for batch in r.batches)
+ + "".join(batch_html(batch, r.id, history) for batch in r.batches)
+ '</section>\n'
)
@@ -186,7 +188,7 @@ def batch_name(batch):
return "command" if batch.is_command() else batch.src_rpm.removesuffix(".src.rpm")
-def batch_html(batch, request_id):
+def batch_html(batch, request_id, history):
if batch.is_command():
flags = f" [{escape(' '.join(batch.command_flags))}]" if batch.command_flags else ""
what = f'<b>command</b>{flags}<pre>{escape(batch.command.strip())}</pre>'
@@ -200,24 +202,23 @@ def batch_html(batch, request_id):
f'{escape(options)}</span>')
return (
f'<div class="batch{" command" if batch.is_command() else ""}">\n<div class=what>{what}</div>\n<div class=builders>\n'
- + "".join(builder_html(batch, name, request_id) for name in batch.builders)
+ + "".join(builder_html(batch, name, request_id, history) for name in batch.builders)
+ '</div>\n</div>\n'
)
-def builder_html(batch, name, request_id):
+def builder_html(batch, name, request_id, history):
"""What one builder made of a batch: status, start and end, duration and log, each in a column of its own"""
status = batch.builders_status[name]
start = batch.builders_build_start.get(name)
end = batch.builders_build_end.get(name)
- span = took = log = about = ""
- seconds = ""
+ span = took = log = about = data = ""
if start and end:
span, took = f'{clock(start)} → {clock(end)}', duration(end - start)
# what script.js compares the other builders with; a failed build may stop at any point
if status.startswith("OK") or status == "UPLOADING":
- seconds = f" data-s={int(end - start)}"
+ data = f" data-s={int(end - start)}"
about = f"build {exact(start)} → {exact(end)}, sending to ftp not counted"
elif start:
span, took = f'{clock(start)} → …', running_since(start)
@@ -227,11 +228,19 @@ def builder_html(batch, name, request_id):
span = clock(batch.builders_status_time[name])
about = f"{status} since {exact(batch.builders_status_time[name])}"
+ # the build of the spec on this builder that last went well before this one: how long this may take
+ before = start or time.time()
+ last = next(((s, e) for batch_id, s, e in history.get((batch.spec, name), [])
+ if batch_id != batch.b_id and e <= before), None)
+ if last:
+ about = "\n".join(filter(None, [about, f"last OK build: {duration(last[1] - last[0])}, {exact(last[0])}"]))
+ data += f" data-last={int(last[1] - last[0])}"
+
# a skipped batch was not built, so it has no log
if is_final(status) and not status.startswith("SKIP"):
log = f'<a class=log href="{escape(build_log(batch, name, status, request_id))}">log</a>'
# right after the status: "OK (2m 12s, log)"
- more = ", ".join(([f"<b class=took{seconds}>{took}</b>"] if took else []) + ([log] if log else []))
+ more = ", ".join(([f"<b class=took{data}>{took}</b>"] if took else []) + ([log] if log else []))
more = f" ({more})" if more else ""
title = f' title="{escape(about)}"' if about else ""
# each bin builder in its own column, empty in rows not sent to it; the src builder goes elsewhere
@@ -283,8 +292,9 @@ LEGEND = """<h2>How to read a request</h2>
</div>
</div>
<p class=note>Start and end: from the builder taking the package (fetching the src.rpm, installing
-BuildRequires, rpmbuild) to its result; sending the rpms to ftp is not counted. A tooltip gives them to the second.
-A duration <b class="took slow">on orange</b> is a fifth longer than on the other builders, <b class="took slower">on dark orange</b>
+BuildRequires, rpmbuild) to its result; sending the rpms to ftp is not counted. A tooltip gives them to the second,
+with the last good build of the package on that builder. A duration <b class="took slow">on orange</b> is a fifth longer than on the
+other builders (or than that last good build, while none of them is done), <b class="took slower">on dark orange</b>
twice as long, and at least a minute either way. The stripe on the left is red when anything failed, yellow while something waits or builds, green when
all is done. Times are in {zone}.</p>
</section>
diff --git a/PLD_Builder/request_handler.py b/PLD_Builder/request_handler.py
index 7bf04a5..c0250a8 100644
--- a/PLD_Builder/request_handler.py
+++ b/PLD_Builder/request_handler.py
@@ -7,8 +7,10 @@ import time
from http import HTTPStatus
from xml.parsers.expat import ExpatError
+import db
import gpg
import log
+import mailer
import path
import request
import status
@@ -145,6 +147,8 @@ def handle_notification(r, user):
q.read()
not_fin = list(filter(lambda r: not r.is_done(), q.requests))
r.apply_to(q)
+ # a request done just now may leave the queue below, but its builds go into the history
+ applied = q.requests
for req in not_fin:
if req.is_done():
util.clean_tmp(path.srpms_dir + '/' + req.id)
@@ -162,6 +166,8 @@ def handle_notification(r, user):
q.write()
# what the bin builders take their work from; what only shows the queue comes after
q.write_signed(path.req_queue_signed_file)
+ with mailer.reported("history", "recording finished builds in spool/builder.sqlite"):
+ db.record_builds(applied, r.builder, r.batches)
q.write_pages()
q.unlock()
return HTTPStatus.OK
diff --git a/PLD_Builder/script.js b/PLD_Builder/script.js
index 089efce..0e6f93d 100644
--- a/PLD_Builder/script.js
+++ b/PLD_Builder/script.js
@@ -1,3 +1,8 @@
+function median(values) {
+ var v = values.slice().sort(function(x, y) { return x - y; }), mid = v.length / 2;
+ return v.length % 2 ? v[Math.floor(mid)] : (v[mid - 1] + v[mid]) / 2;
+}
+
// "<1m", "5m", "2h 10m", "3d": short, like the durations the page is written with
function span(seconds) {
var min = Math.floor(seconds / 60);
@@ -25,21 +30,22 @@ document.querySelectorAll('.builders').forEach(function(row) {
// the src builder runs a command on another machine
row.querySelectorAll('.builder:not(.src) .took').forEach(function(el) {
var since = el.querySelector('time.since');
- if (since) builds.push({el: el, s: (Date.now() - new Date(since.getAttribute('datetime'))) / 1000});
- else if (el.dataset.s) builds.push({el: el, s: Number(el.dataset.s), done: true});
+ var last = Number(el.dataset.last);
+ if (since) builds.push({el: el, s: (Date.now() - new Date(since.getAttribute('datetime'))) / 1000, last: last});
+ else if (el.dataset.s) builds.push({el: el, s: Number(el.dataset.s), last: last, done: true});
});
- // the median of the builds done: of three, two slow ones make the fast one the odd one out
- var done = builds.filter(function(b) { return b.done; }).map(function(b) { return b.s; }).sort(function(x, y) { return x - y; });
- if (!done.length) return;
- var mid = done.length / 2;
- var usual = done.length % 2 ? done[Math.floor(mid)] : (done[mid - 1] + done[mid]) / 2;
+ var done = builds.filter(function(b) { return b.done; });
builds.forEach(function(b) {
+ var others = done.filter(function(o) { return o != b; });
+ // the other builds done; of three the median counts the build itself, as two slow ones make the
+ // fast one the odd one out; with none, the last good build of the spec on the same builder
+ var usual = others.length > 1 ? median(done.map(function(o) { return o.s; })) : others.length ? others[0].s : b.last;
// short builds differ by seconds, which says nothing
- if (b.s - usual < 60) return;
+ if (!usual || b.s - usual < 60) return;
var ratio = Number((b.s / usual).toFixed(1));
if (ratio < 1.2) return;
b.el.classList.add(ratio < 2 ? 'slow' : 'slower');
- b.el.title = ratio + '\u00d7 the median of the builders, ' + span(usual);
+ b.el.title = ratio + '\u00d7 ' + (others.length ? 'the other builders, ' : 'the last OK build, ') + span(usual);
});
});
================================================================
---- gitweb:
http://git.pld-linux.org/gitweb.cgi/projects/pld-builder.new.git/commitdiff/3ee02bef4218fd68c1905b7ef38afeb6fe69a59e
More information about the pld-cvs-commit
mailing list