chadtmiller.com/knotless
git that lives in your Atmosphere account
1
10
knotless-run: a queue pass that runs long says where it is
.changeset/runner-pass-logging.mdnew+7−0
| @@ -0,0 +1,7 @@ | ||
--- | ||
default: patch | ||
--- | ||
| ||
# A runner's pass that runs long says where it is | ||
| ||
`knotless-run` logs each pass over a repository as `pass ended`, with how long it took, and one still going after 5 minutes as `pass running long`, with the stage it is at, every 5 minutes. A git command slower than `KNOTLESS_SLOW_MS` is logged at warn, as `git`. The same failure of a repository is logged once a minute while it goes on, with a count, rather than every time. | ||
crates/knotless/src/git.rs+5−0
| @@ -70,7 +70,10 @@ impl Git { | ||
cmd | ||
} | ||
| ||
/// Runs git, logged as [`crate::telemetry::git`] logs it: one that is | ||
/// slow is said, though never cut short. | ||
async fn output(&self, args: &[&str], input: Option<&[u8]>) -> Result<std::process::Output> { | ||
let began = std::time::Instant::now(); | ||
let mut child = self | ||
.command(args) | ||
.spawn() | ||
| @@ -85,6 +88,8 @@ impl Git { | ||
}); | ||
let out = child.wait_with_output().await?; | ||
writer.await?; | ||
let command = args.first().copied().unwrap_or_default(); | ||
crate::telemetry::git(command, &self.dir, began.elapsed()); | ||
Ok(out) | ||
} | ||
| ||
crates/knotless/src/telemetry.rs+50−3
| @@ -33,6 +33,8 @@ pub struct Fields<'a> { | ||
pub pull: Option<&'a str>, | ||
pub status: Option<&'a str>, | ||
pub step: Option<&'a str>, | ||
/// Where a long piece of work is, as a merge queue's pass. | ||
pub stage: Option<&'a str>, | ||
pub container: Option<&'a str>, | ||
pub feed: Option<&'a str>, | ||
pub cache: Option<&'a str>, | ||
| @@ -71,6 +73,7 @@ macro_rules! event { | ||
pull = $f.pull, | ||
status = $f.status, | ||
step = $f.step, | ||
stage = $f.stage, | ||
container = $f.container, | ||
feed = $f.feed, | ||
cache = $f.cache, | ||
| @@ -116,11 +119,12 @@ pub fn millis(d: Duration) -> u64 { | ||
u64::try_from(d.as_millis()).unwrap_or(u64::MAX) | ||
} | ||
| ||
/// The slowest an HTTP call is before it is logged at warn: | ||
/// `KNOTLESS_SLOW_MS`, else a second. | ||
/// The slowest an HTTP call or a git command is before it is logged at | ||
/// warn: `KNOTLESS_SLOW_MS`, else a second. | ||
static SLOW_MS: AtomicU64 = AtomicU64::new(1000); | ||
| ||
fn slow(took: Duration) -> bool { | ||
/// Whether what took `took` was slow: past `KNOTLESS_SLOW_MS`. | ||
pub fn slow(took: Duration) -> bool { | ||
millis(took) >= SLOW_MS.load(Ordering::Relaxed) | ||
} | ||
| ||
| @@ -301,6 +305,32 @@ impl Call { | ||
} | ||
} | ||
| ||
/// Logs the git command `command` (its subcommand, as `pack-objects`) run | ||
/// in the repository at `dir`, which took `took`: at debug, or warn if it | ||
/// was slow, as an HTTP call is. Its other arguments are not logged. | ||
pub fn git(command: &str, dir: &std::path::Path, took: Duration) { | ||
let ms = millis(took); | ||
let dir = dir.to_string_lossy(); | ||
let trace = trace_id(); | ||
macro_rules! line { | ||
($level:expr) => { | ||
tracing::event!( | ||
target: "knotless::git", | ||
$level, | ||
command = command, | ||
path = dir.as_ref(), | ||
duration_ms = ms, | ||
trace_id = trace.as_deref(), | ||
"git" | ||
) | ||
}; | ||
} | ||
match slow(took) { | ||
true => line!(Level::WARN), | ||
false => line!(Level::DEBUG), | ||
} | ||
} | ||
| ||
/// What kind of failure `err` is, and why, without the URL it names. | ||
fn error_type(err: &reqwest::Error) -> String { | ||
let kind = match () { | ||
| @@ -667,6 +697,23 @@ mod tests { | ||
assert!(lines[0]["error"].as_str().unwrap().contains("on fire")); | ||
} | ||
| ||
#[test] | ||
fn git_commands() { | ||
let dir = std::path::Path::new("/srv/mirror.git"); | ||
let lines = logged(|| { | ||
git("rev-parse", dir, Duration::ZERO); | ||
git("pack-objects", dir, Duration::from_secs(5)); | ||
}); | ||
let ran: Vec<&serde_json::Value> = lines.iter().filter(|l| l["message"] == "git").collect(); | ||
assert_eq!(ran.len(), 2); | ||
assert_eq!(ran[0]["level"], "DEBUG"); | ||
assert_eq!(ran[0]["command"], "rev-parse"); | ||
assert_eq!(ran[1]["level"], "WARN"); | ||
assert_eq!(ran[1]["command"], "pack-objects"); | ||
assert_eq!(ran[1]["path"], "/srv/mirror.git"); | ||
assert_eq!(ran[1]["duration_ms"], 5000); | ||
} | ||
| ||
#[test] | ||
fn traces() { | ||
let id = "4bf92f3577b34da6a3ce929d0e0e4736"; | ||
crates/knotless-run/src/lib.rs+65−3
| @@ -209,6 +209,9 @@ pub struct Options { | ||
pub prune_grace: Duration, | ||
/// How often a repository's checks are pruned. | ||
pub prune_every: Duration, | ||
/// How long a pass over a repository runs before it is logged at | ||
/// warn, saying where it is, and again each time as long after. | ||
pub watchdog: Duration, | ||
} | ||
| ||
impl Options { | ||
| @@ -245,6 +248,7 @@ impl Options { | ||
keep_checks: Some(Duration::from_secs(30 * DAY)), | ||
prune_grace: Duration::from_secs(DAY), | ||
prune_every: Duration::from_secs(60 * 60), | ||
watchdog: Duration::from_secs(5 * 60), | ||
} | ||
} | ||
| ||
| @@ -800,13 +804,23 @@ pub struct Watch { | ||
/// Set once it is no longer watched, as left or found again under | ||
/// another name: the loops that ring and answer it then end. | ||
gone: Arc<AtomicBool>, | ||
/// Where the pass over it going is, for [`watched`] to say. | ||
stage: Stage, | ||
} | ||
| ||
/// Where a pass over a repository is: what it is waiting on. | ||
type Stage = Arc<Mutex<&'static str>>; | ||
| ||
impl Watch { | ||
fn id(&self) -> String { | ||
format!("{}/{}", self.remote.did(), self.key) | ||
} | ||
| ||
/// Says the pass over it is now at `stage`. | ||
fn at(&self, stage: &'static str) { | ||
*self.stage.lock().unwrap() = stage; | ||
} | ||
| ||
/// Whether it is still watched. | ||
fn watched(&self) -> bool { | ||
!self.gone.load(Ordering::SeqCst) | ||
| @@ -1016,6 +1030,7 @@ impl Runner { | ||
discovered: false, | ||
pulls_only, | ||
gone: Arc::default(), | ||
stage: Arc::default(), | ||
}) | ||
} | ||
| ||
| @@ -1095,10 +1110,12 @@ impl Runner { | ||
/// Runs every ref of `watch` that has moved since it last ran, and with | ||
/// `--pulls` every open pull into it whose head has. | ||
pub async fn reconcile(self: &Arc<Self>, watch: &Watch) -> Result<()> { | ||
watch.at("waiting for a stop"); | ||
let _reading = self.reconciling.read().await; | ||
if *self.stopping.borrow() { | ||
return Ok(()); | ||
} | ||
watch.at("reading the repository"); | ||
let snap = watch.remote.snapshot(&self.ctx).await?; | ||
let me = &self.reporter.identity.did; | ||
if watch.discovered && !names(snap.repo.as_ref(), &watch.key, me) { | ||
| @@ -1110,17 +1127,22 @@ impl Runner { | ||
let repo = snap | ||
.reference(watch.remote.did()) | ||
.context("a snapshot with a key has a repository")?; | ||
watch.at("reading reruns"); | ||
self.reruns(watch).await?; | ||
let moved = self.moved(watch, &snap)?; | ||
if !moved.is_empty() && !watch.pulls_only { | ||
watch.at("running refs"); | ||
self.refs(watch, &repo, &snap, moved).await?; | ||
} | ||
if self.opts.pulls { | ||
watch.at("running pulls"); | ||
self.pulls(watch, &repo, &snap).await?; | ||
} | ||
if self.opts.queue && !watch.pulls_only { | ||
watch.at("reading the queue"); | ||
self.queues(watch, &repo, &snap).await?; | ||
} | ||
watch.at("pruning checks"); | ||
self.prune(watch, &snap).await | ||
} | ||
| ||
| @@ -2266,6 +2288,7 @@ impl Runner { | ||
discovered: true, | ||
pulls_only: false, | ||
gone: Arc::default(), | ||
stage: Arc::default(), | ||
}; | ||
// Watched by its old name until now, that one's loops end. | ||
let old = self.named.lock().unwrap().insert(id, watch.clone()); | ||
| @@ -3030,7 +3053,10 @@ async fn queue(runner: Arc<Runner>, watch: Watch, door: Arc<Notify>) { | ||
if !watch.watched() { | ||
return; | ||
} | ||
let done = runner.reconcile(&watch).await; | ||
let began = std::time::Instant::now(); | ||
let every = runner.opts.watchdog; | ||
let done = watched(&watch.label, &watch.stage, every, runner.reconcile(&watch)).await; | ||
telemetry::pass(&watch.label, began.elapsed(), done.is_ok()); | ||
if done.is_err() { | ||
let (door, after) = (door.clone(), runner.opts.sweep.min(RETRY_MAX)); | ||
tokio::spawn(async move { | ||
| @@ -3042,6 +3068,28 @@ async fn queue(runner: Arc<Runner>, watch: Watch, door: Arc<Notify>) { | ||
} | ||
} | ||
| ||
/// Awaits `pass` over `label`, saying each `every` it goes on how long it | ||
/// has and at what `stage` it is: one hung for a quarter of an hour once, | ||
/// with nothing to say where. | ||
async fn watched<T>( | ||
label: &str, | ||
stage: &Stage, | ||
every: Duration, | ||
pass: impl Future<Output = T>, | ||
) -> T { | ||
let began = std::time::Instant::now(); | ||
let mut pass = std::pin::pin!(pass); | ||
loop { | ||
tokio::select! { | ||
done = &mut pass => return done, | ||
() = tokio::time::sleep(every) => { | ||
let at = *stage.lock().unwrap(); | ||
telemetry::long_pass(label, at, began.elapsed()); | ||
} | ||
} | ||
} | ||
} | ||
| ||
/// Rings the door of each private repository whose space the appview | ||
/// says was written to, as soon as it says so; every one's, when it may | ||
/// have missed some. One that cannot be asked is asked again a while after, | ||
| @@ -3180,8 +3228,9 @@ fn report(watch: &Watch, done: Result<()>) { | ||
| ||
/// Says what went wrong with the work of `label`, if anything did. | ||
fn noted(label: &str, done: Result<()>) { | ||
if let Err(err) = done { | ||
telemetry::failed(label, &err); | ||
match done { | ||
Ok(()) => telemetry::succeeded(label), | ||
Err(err) => telemetry::failed(label, &err), | ||
} | ||
} | ||
| ||
| @@ -3454,6 +3503,19 @@ fn kept_apart(subject: &Subject, wf: &Workflow) -> bool { | ||
mod tests { | ||
use super::*; | ||
| ||
#[tokio::test] | ||
async fn a_long_pass_is_watched() { | ||
let stage = Stage::default(); | ||
*stage.lock().unwrap() = "landing a batch"; | ||
let pass = tokio::time::sleep(Duration::from_millis(30)); | ||
watched("a/b", &stage, Duration::from_millis(5), pass).await; | ||
let quick = async { 7 }; | ||
assert_eq!( | ||
watched("a/b", &stage, Duration::from_secs(60), quick).await, | ||
7 | ||
); | ||
} | ||
| ||
#[test] | ||
fn cancels_once_moved() { | ||
// A newer commit's cancel replaces one for a newer commit, but never | ||
crates/knotless-run/src/queue.rs+6−0
| @@ -241,6 +241,7 @@ impl Runner { | ||
if branches.is_empty() { | ||
return Ok(()); | ||
} | ||
watch.at("syncing the mirror"); | ||
let mirror = Mirror::open(&self.ctx, watch.remote.did(), &watch.key).await?; | ||
mirror.sync(&watch.remote, snap).await?; | ||
let none = Vec::new(); | ||
| @@ -315,6 +316,7 @@ impl Runner { | ||
.collect(); | ||
let checks = self.failed_checks(on, &flight, &ended); | ||
if failed.is_empty() { | ||
on.watch.at("landing a batch"); | ||
if let Err(err) = self.land(on, &flight).await { | ||
let refused = refused(&err); | ||
let (label, branch) = (&on.watch.label, on.branch); | ||
| @@ -391,6 +393,7 @@ impl Runner { | ||
.filter(|i| !line.done.contains_key(&i.uri) && !going.contains(i.uri.as_str())) | ||
.cloned() | ||
.collect(); | ||
on.watch.at("checking pre-flights"); | ||
let ready = self.preflown(on, line, &tip, outside).await?; | ||
while line.flights.len() < self.opts.depth { | ||
// Halving is not run ahead of. | ||
| @@ -428,6 +431,7 @@ impl Runner { | ||
Err(why) => self.eject(on, line, &item, None, &why, &[]).await?, | ||
} | ||
} | ||
on.watch.at("stacking a batch"); | ||
let stack = queue::stack(on.git, &on_tip, &pulls, on.me).await?; | ||
// Ahead of a batch that may yet fail, a conflict may not stand: | ||
// the pull waits to be built on the branch itself. | ||
| @@ -442,6 +446,7 @@ impl Runner { | ||
} | ||
continue; | ||
} | ||
on.watch.at("launching a batch"); | ||
let flight = self.launch(on, stack, generation, ahead).await?; | ||
line.flights.push(flight); | ||
} | ||
| @@ -707,6 +712,7 @@ impl Runner { | ||
head, | ||
checks, | ||
}; | ||
on.watch.at("ejecting a pull"); | ||
queue::eject(&self.ctx, on.target, &item.uri, ejected).await?; | ||
telemetry::ejected(&on.watch.label, &item.uri, why); | ||
let at = queued_at(item).to_string(); | ||
crates/knotless-run/src/telemetry.rs+104−3
| @@ -4,7 +4,9 @@ | ||
| ||
use crate::{Subject, Watch}; | ||
use knotless::telemetry::{self, Fields, Level, millis}; | ||
use std::time::Duration; | ||
use std::collections::HashMap; | ||
use std::sync::{LazyLock, Mutex}; | ||
use std::time::{Duration, Instant}; | ||
| ||
/// Logs `message` about the run of `workflow` at `subject`: its ref, | ||
/// commit and pull, and how it ended and how long it took, if it has. | ||
| @@ -62,16 +64,90 @@ pub(crate) fn container(message: &str, id: &str, image: Option<&str>) { | ||
telemetry::note(Level::INFO, message, &fields); | ||
} | ||
| ||
/// Logs, at warn, what went wrong with `label`'s work. | ||
/// How often a failure going on is logged again, as `failed` with a count. | ||
const REPEAT_EVERY: Duration = Duration::from_secs(60); | ||
| ||
/// How long a failure not seen again is remembered: past it, it is logged | ||
/// at once, as a new one. | ||
const FORGET: Duration = Duration::from_secs(60 * 60); | ||
| ||
/// The failures logged, by label and error: when last, and how many | ||
/// times seen since without being logged. | ||
type Failing = HashMap<(String, String), (Instant, u64)>; | ||
| ||
static FAILING: LazyLock<Mutex<Failing>> = LazyLock::new(Mutex::default); | ||
| ||
/// Logs, at warn, what went wrong with `label`'s work: the first time it | ||
/// goes wrong so, then once each [`REPEAT_EVERY`] while it goes on, with | ||
/// how many times it went wrong so meanwhile. Another error is logged at | ||
/// once, and the same again once a success of `label`'s cleared it. | ||
pub(crate) fn failed(label: &str, err: &anyhow::Error) { | ||
let error = format!("{err:#}"); | ||
let seen = repeat(&mut FAILING.lock().unwrap(), label, &error, Instant::now()); | ||
let Some(repeats) = seen else { | ||
return; | ||
}; | ||
let fields = Fields { | ||
repo: Some(label), | ||
error: Some(format!("{err:#}")), | ||
error: Some(error), | ||
count: (repeats > 0).then_some(repeats), | ||
..Fields::default() | ||
}; | ||
telemetry::note(Level::WARN, "failed", &fields); | ||
} | ||
| ||
/// Forgets what went wrong with `label`'s work, which went right since. | ||
pub(crate) fn succeeded(label: &str) { | ||
FAILING.lock().unwrap().retain(|(l, _), _| l != label); | ||
} | ||
| ||
/// Whether `error` of `label`, at `now`, is to be logged, with how many | ||
/// times it was seen since last it was; or `None`, counting it. | ||
fn repeat(seen: &mut Failing, label: &str, error: &str, now: Instant) -> Option<u64> { | ||
seen.retain(|_, (at, _)| now.duration_since(*at) < FORGET); | ||
let key = (label.to_string(), error.to_string()); | ||
match seen.get_mut(&key) { | ||
Some((at, skipped)) if now.duration_since(*at) < REPEAT_EVERY => { | ||
*skipped += 1; | ||
None | ||
} | ||
Some((at, skipped)) => { | ||
let repeats = *skipped; | ||
(*at, *skipped) = (now, 0); | ||
Some(repeats) | ||
} | ||
None => { | ||
seen.insert(key, (now, 0)); | ||
Some(0) | ||
} | ||
} | ||
} | ||
| ||
/// Logs that a pass over `label`, reconciling it, ended after `took`: at | ||
/// debug, or info if it was slow, past `KNOTLESS_SLOW_MS`. | ||
pub(crate) fn pass(label: &str, took: Duration, ok: bool) { | ||
let fields = Fields { | ||
repo: Some(label), | ||
status: Some(["failed", "ok"][usize::from(ok)]), | ||
duration_ms: Some(millis(took)), | ||
..Fields::default() | ||
}; | ||
let level = [Level::DEBUG, Level::INFO][usize::from(telemetry::slow(took))]; | ||
telemetry::note(level, "pass ended", &fields); | ||
} | ||
| ||
/// Logs, at warn, that a pass over `label` has gone on for `took`, and is | ||
/// at `stage`. | ||
pub(crate) fn long_pass(label: &str, stage: &str, took: Duration) { | ||
let fields = Fields { | ||
repo: Some(label), | ||
stage: Some(stage), | ||
duration_ms: Some(millis(took)), | ||
..Fields::default() | ||
}; | ||
telemetry::note(Level::WARN, "pass running long", &fields); | ||
} | ||
| ||
/// Logs `message` about a batch of `pulls` pulls into `branch` of | ||
/// `label`, at `tip`, and why, if said. | ||
pub(crate) fn batch( | ||
| @@ -197,6 +273,11 @@ mod tests { | ||
container("container started", "0123456789abcdef", Some("rust")); | ||
container("container stopped", "short", None); | ||
failed("a/b", &anyhow::anyhow!("no PDS")); | ||
failed("a/b", &anyhow::anyhow!("no PDS")); | ||
succeeded("a/b"); | ||
pass("a/b", Duration::ZERO, true); | ||
pass("a/b", Duration::from_secs(5), false); | ||
long_pass("a/b", "landing", Duration::from_secs(300)); | ||
batch("batch started", "a/b", "main", "abc", 2, None); | ||
ejected("a/b", "at://did:plc:x/dev.knotless.pull/1", "conflicts"); | ||
noticed("a/b", Duration::ZERO, true); | ||
| @@ -207,4 +288,24 @@ mod tests { | ||
found("did:plc:x/b"); | ||
left("did:plc:x/b"); | ||
} | ||
| ||
#[test] | ||
fn failures_going_on_are_logged_now_and_then() { | ||
let mut seen = Failing::new(); | ||
let start = Instant::now(); | ||
let at = |secs| start + Duration::from_secs(secs); | ||
// The first time, at once; the same again only each minute, with | ||
// how often it was seen meanwhile. | ||
assert_eq!(repeat(&mut seen, "a/b", "gone", at(0)), Some(0)); | ||
assert_eq!(repeat(&mut seen, "a/b", "gone", at(5)), None); | ||
assert_eq!(repeat(&mut seen, "a/b", "gone", at(10)), None); | ||
assert_eq!(repeat(&mut seen, "a/b", "gone", at(60)), Some(2)); | ||
assert_eq!(repeat(&mut seen, "a/b", "gone", at(61)), None); | ||
// Another error, or another repository's, is logged at once. | ||
assert_eq!(repeat(&mut seen, "a/b", "refused", at(62)), Some(0)); | ||
assert_eq!(repeat(&mut seen, "c/d", "gone", at(62)), Some(0)); | ||
// One not seen for an hour is new again. | ||
assert_eq!(repeat(&mut seen, "a/b", "gone", at(2 * 60 * 60)), Some(0)); | ||
assert_eq!(seen.len(), 1); | ||
} | ||
} | ||
crates/knotless-run/tests/run.rs+12−4
| @@ -178,6 +178,7 @@ fn runner_opts(runner: &Sandbox, owner: &Sandbox, js: &Jetstream) -> knotless_ru | ||
keep_checks: None, | ||
prune_grace: Duration::ZERO, | ||
prune_every: Duration::ZERO, | ||
watchdog: Duration::from_secs(300), | ||
} | ||
} | ||
| ||
| @@ -753,6 +754,7 @@ fn what_goes_wrong_is_reported() { | ||
keep_checks: None, | ||
prune_grace: Duration::ZERO, | ||
prune_every: Duration::ZERO, | ||
watchdog: Duration::from_secs(300), | ||
}; | ||
let rt = tokio::runtime::Runtime::new().unwrap(); | ||
let (run, watches) = rt | ||
| @@ -929,6 +931,7 @@ fn a_deploy_is_never_cut_off() { | ||
keep_checks: None, | ||
prune_grace: Duration::ZERO, | ||
prune_every: Duration::ZERO, | ||
watchdog: Duration::from_secs(300), | ||
}; | ||
let rt = tokio::runtime::Runtime::new().unwrap(); | ||
let (run, watches) = rt | ||
| @@ -1058,6 +1061,7 @@ fn a_stop_drops_what_has_not_started() { | ||
keep_checks: None, | ||
prune_grace: Duration::ZERO, | ||
prune_every: Duration::ZERO, | ||
watchdog: Duration::from_secs(300), | ||
}; | ||
let start = || { | ||
let started = knotless_run::Runner::start(opts.clone(), common::ctx(&runner)); | ||
| @@ -1305,6 +1309,7 @@ fn a_failing_pds_wedges_nothing() { | ||
keep_checks: None, | ||
prune_grace: Duration::ZERO, | ||
prune_every: Duration::ZERO, | ||
watchdog: Duration::from_secs(300), | ||
}; | ||
let pds = flaky(&rt); | ||
let ctx = common::ctx(&runner); | ||
| @@ -2022,6 +2027,7 @@ fn a_merged_pull_passes_its_push() { | ||
keep_checks: None, | ||
prune_grace: Duration::ZERO, | ||
prune_every: Duration::ZERO, | ||
watchdog: Duration::from_secs(300), | ||
}; | ||
let (run, watches) = rt | ||
.block_on(knotless_run::Runner::start(opts, common::ctx(&runner))) | ||
| @@ -3310,10 +3316,10 @@ fn a_merge_queue_goes_on_by_itself() { | ||
let q = Line::new(&rt); | ||
let z = q.pull("z", "z", "z\n"); | ||
q.queue(&[&z]); | ||
rt.spawn(knotless_run::run( | ||
q.opts("state.json"), | ||
common::ctx(&q.owner), | ||
)); | ||
// Each pass over it that runs past a few milliseconds says where it is. | ||
let mut opts = q.opts("state.json"); | ||
opts.watchdog = Duration::from_millis(5); | ||
rt.spawn(knotless_run::run(opts, common::ctx(&q.owner))); | ||
q.shows(&z, "merged pull"); | ||
assert_eq!(q.log(1), ["z"]); | ||
} | ||
| @@ -3416,6 +3422,7 @@ fn a_workflow_asked_for_by_name() { | ||
keep_checks: None, | ||
prune_grace: Duration::ZERO, | ||
prune_every: Duration::ZERO, | ||
watchdog: Duration::from_secs(300), | ||
}; | ||
let start = || { | ||
let started = knotless_run::Runner::start(opts.clone(), common::ctx(&runner)); | ||
| @@ -3681,6 +3688,7 @@ fn a_private_repository_runs_in_its_space() { | ||
keep_checks: None, | ||
prune_grace: Duration::ZERO, | ||
prune_every: Duration::ZERO, | ||
watchdog: Duration::from_secs(300), | ||
..runner_opts(&runner, &owner, &js) | ||
}; | ||
rt.spawn(knotless_run::run(opts, common::ctx(&runner))); | ||
docs/design/runner.md+6−0
| @@ -128,6 +128,12 @@ flowchart TD | ||
steps --> ended[file the check as ended] | ||
``` | ||
| ||
A pass is logged as it ends, with how long it took. One that hung for 13 | ||
minutes once said nothing of where, so a pass still going after 5 minutes | ||
logs the stage it is at, and again every 5 minutes, and a slow git command | ||
is logged as a slow HTTP call is ([What a pass | ||
logs](../reference/runner-internals.md#what-a-pass-logs)). | ||
| ||
### Repositories that name it | ||
| ||
With `--discover`, the runner watches, besides those its arguments name, | ||
docs/reference/cli.md+6−3
| @@ -387,7 +387,10 @@ start: `<label>: no repository by that name this runner can read`. | ||
A usage error exits 2 and prints the usage; an error at run time exits 1, | ||
as `knotless-run: <error>`. Once started, the runner logs `knotless-run: | ||
watching <repositories> as <did>` to standard error, and an error in one | ||
repository as `knotless-run: <label>: <error>`, and goes on. A pass that | ||
repository as `knotless-run: <label>: <error>`, and goes on: the same | ||
error again only once a minute, with how many times it was seen. Each pass | ||
logs how long it took, and one going 5 minutes says where it is, every 5 | ||
minutes ([What a pass logs](runner-internals.md#what-a-pass-logs)). A pass that | ||
finds a repository's key changed fails with `<label> no longer names the | ||
repository it did`. | ||
| ||
| @@ -490,8 +493,8 @@ record written has it read that repository's, to find one that names it. | ||
| `KNOTLESS_MODERATOR` | the appview's | the DID of the moderation service reports go to, by its `#atproto_labeler` service | | ||
| `KNOTLESS_ADMIN_DIDS` | | on `knotless-serve`, the accounts that operate it, comma-separated: the admin methods take their service tokens, for the `admin` commands | | ||
| `KNOTLESS_BOT_DIDS` | | on `knotless-serve` with `--bots`, the accounts that may log in at `/oauth/bot`, comma-separated | | ||
| `RUST_LOG` | `info` | what `knotless-serve` and `knotless-run` log, as JSON lines on stderr: `debug`, or `info,knotless::outgoing=debug` for each call made | | ||
| `KNOTLESS_SLOW_MS` | 1000 | on `knotless-serve` and `knotless-run`, how slow a request served or made is before it is logged at warn | | ||
| `RUST_LOG` | `info` | what `knotless-serve` and `knotless-run` log, as JSON lines on stderr: `debug`, or `info,knotless::outgoing=debug` for each call made, `knotless::git=debug` for each git command | | ||
| `KNOTLESS_SLOW_MS` | 1000 | on `knotless-serve` and `knotless-run`, how slow a request served or made, or a git command, is before it is logged at warn; on `knotless-run`, a pass taking this long logs `pass ended` at info rather than debug | | ||
| ||
### Storage | ||
| ||
docs/reference/runner-internals.md+40−0
| @@ -58,3 +58,43 @@ and while any are, no old base is removed. Half-made `*.new` bases, and | ||
kept directories not wanted or broken, are removed, and the newest | ||
generation of each cache is the current one. Marks of a base no longer | ||
current are let go. | ||
| ||
## What a pass logs | ||
| ||
Each pass over a repository, as its door rings, logs `pass ended` with | ||
`repo`, `status` (`ok` or `failed`) and `duration_ms`: at debug, or at | ||
info when it took `KNOTLESS_SLOW_MS` (1000) or longer. | ||
| ||
A pass still going after 5 minutes logs `pass running long` at warn, with | ||
`repo`, `duration_ms` and `stage`, where the pass last said it was, and | ||
again every 5 minutes while it goes on. The stages, in the order a pass | ||
meets them: | ||
| ||
| Stage | | | ||
| --- | --- | | ||
| `waiting for a stop` | waiting for a stop under way, which holds every pass back | | ||
| `reading the repository` | reading the repository's record and refs | | ||
| `reading reruns` | reading the reruns asked for | | ||
| `running refs` | filing and starting the runs of refs that moved | | ||
| `running pulls` | with `--pulls`, reading open pulls and starting their runs | | ||
| `reading the queue` | with `--queue`, reading the merge queue's records | | ||
| `syncing the mirror` | bringing the mirror the queue builds batches in up to date | | ||
| `landing a batch` | landing a batch whose checks passed | | ||
| `ejecting a pull` | writing a pull's ejection | | ||
| `checking pre-flights` | reading and starting the pre-flights of pulls waiting | | ||
| `stacking a batch` | merging a batch's pulls onto the branch, in the mirror | | ||
| `launching a batch` | filing and starting a batch's runs | | ||
| `pruning checks` | deleting checks of no more use | | ||
| ||
Each git command logs `git` (target `knotless::git`), with `command`, its | ||
subcommand (`pack-objects`), `path`, the repository's directory, and | ||
`duration_ms`: at debug, or at warn when it took `KNOTLESS_SLOW_MS` or | ||
longer, as a slow HTTP call logs `outgoing` at warn. A git command is never | ||
cut short. | ||
| ||
A failure of a repository's work logs `failed` at warn, with `repo` and | ||
`error`, the first time that error is seen for that repository. The same | ||
error again is logged only once a minute while it goes on, with `count`, | ||
the times it was seen since last logged. Another error is logged at once, | ||
and so is the same one after any of the repository's work succeeds, or | ||
once it has not been seen for an hour. | ||