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
2 changes: 1 addition & 1 deletion .github/fork-fleet.md
Original file line number Diff line number Diff line change
Expand Up @@ -975,7 +975,7 @@ dispatcher keeps only pacing in memory, so a restart starts over cleanly.
| Dispatcher | Crash after `generate-jitconfig`, before `start` | An offline registration with no unit. The next pass deletes it, and the pass after starts the job's runner again (at most 3 tries per job, then it is left to the watch and the sweep). |
| Dispatcher | Crash after `start` | The unit is there. The next pass sees it and starts nothing twice. |
| Dispatcher | Launcher killed half-way through copying the template | No unit. The next pass deletes the registration, `prune` removes the half copy and any environment file, and the job's runner is started again. |
| Dispatcher | A pool's label changed: offline registrations under its old label | Deleted when the pool lists the old label in `retired` (and `retired_labels`); never online ones or another pool's. A label two pools retire, or a pool's label now, is refused. Without `retired` they stay (delete them by hand). |
| Dispatcher | A pool's label changed: offline registrations under its old label | Deleted when the pool lists the old label in `retired` (and `retired_labels`); never online ones or another pool's. An idle runner there is stopped like any other. A label two pools retire, or a pool's label in either list, is refused. Without `retired` they stay (delete them by hand). |
| Dispatcher | Restart, or a host reboot | It reads everything again from GitHub and systemd. The lock directory under `/run` is made again after a boot. After a reboot, a job that was running fails as a lost runner (`auto`: the sweep re-runs it GitHub-hosted). A job still queued has its offline registration deleted and gets a new runner. |
| Dispatcher | Two dispatchers for one pool | The second one fails on that pool's lock (`dispatch-<pool>.lock`). Two dispatchers for different pools both run. |
| Dispatcher | The job went away before its runner took it (cancelled) | The idle runner is stopped after 3 passes, or at once if another queued job asks for all of its labels. A re-run's job never can: its label names its own attempt. |
Expand Down
12 changes: 8 additions & 4 deletions .github/scripts/fork-fleet.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,11 @@ def check_retired(cfg, launched):
made under them, so each must be this pool's alone: in retired_labels, no pool's label now, in no other pool's."""
out, seen = [], set()
listed, current = cfg.get('retired_labels', []), {p.get('label') for p in launched}
# A label still retired is no pool's label now: a host still on the config that retired it deletes the offline
# registrations under it (another pool's runners, before they connect). Reuse it only after it left retired_labels.
if isinstance(listed, list):
out += [f'{x!r} is a dispatcher pool\'s label and in retired_labels: take it out of retired_labels (and every '
'retired) first' for x in listed if isinstance(x, str) and x in current]
for p in cfg.get('pools') or []:
if 'retired' not in p:
continue
Expand Down Expand Up @@ -1131,12 +1136,13 @@ def host(p, verb, *args):
ours[r['name']] = (p, r)
elif hosts[p['name']].made(r.get('name') or ''):
old[r['name']] = (p, r)
state['idle'] = {k: v for k, v in state['idle'].items() if k in ours}
state['idle'] = {k: v for k, v in state['idle'].items() if k in ours or k in old}

# Leftovers: a registration with no runner behind it, and a runner whose job went away before it started. Such a
# runner is stopped at once when a queued job of another run could be given it (the hook would refuse that job),
# else after idle_passes passes (a runner that is just taking its own job is not busy yet). A runner's labels name
# the run attempt it was made for, so no job of another attempt can be given it.
# the run attempt it was made for, so no job of another attempt can be given it. The same holds under a label the
# pool had before: such a runner counts toward the pool's slots (units()), so an idle one is stopped too.
for name, (p, r) in [*ours.items(), *old.items()]:
if p['name'] in down:
continue
Expand All @@ -1147,8 +1153,6 @@ def host(p, verb, *args):
if e.code != 404:
raise
say(f'{name}: deleted a registration with no runner behind it')
elif name in old:
continue # online under a label the pool had before: left to finish (or to be stopped by hand)
elif r.get('status') == 'online' and not r.get('busy') and int(name.rsplit('-', 1)[1]) not in queued_ids:
state['idle'][name] = state['idle'].get(name, 0) + 1
labels = [x.get('name') for x in r.get('labels') or [] if isinstance(x, dict)]
Expand Down
46 changes: 43 additions & 3 deletions .github/scripts/fork-fleet.test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4476,16 +4476,52 @@ def test_another_pools_retired_label_is_not_touched(self):
self.dispatch()
self.assertEqual(self.left(), ['fleet-old-b-50'])

def test_an_online_registration_under_a_retired_label_is_never_touched(self):
def test_an_online_registration_under_a_retired_label_is_never_deleted(self):
self.reg(40, 'fleet-old-a-40')
self.reg(42, 'fleet-old-a-42', status='online', busy=True)
self.reg(43, 'fleet-old-a-43', status='online') # idle, its job gone: still left alone (not stopped)
self.reg(43, 'fleet-old-a-43', status='online') # idle, its own job still queued: it is about to take it
self.fake[WAITING].units |= {'fleet-old-a-42', 'fleet-old-a-43'}
self.gh.add(a_run(6, actor='someone'), a_job(61, ['fleet-old-a'])) # a queued job that could take 43
self.gh.add(a_run(6, actor='someone'), a_job(43, ['fleet-old-a']))
self.dispatch(passes=CFG['dispatch']['idle_passes'] + 1)
self.assertEqual(self.left(), ['fleet-old-a-42', 'fleet-old-a-43'])
self.assertEqual(self.fake[WAITING].stopped, [])

def test_an_idle_runner_under_a_retired_label_is_stopped_and_frees_its_slot(self):
"""#319: idle runners under the old label count toward the pool's slots, so they are stopped like any other
(after idle_passes) and a queued job for the pool starts then, not when their units time out."""
slots, passes = RET_POOLS[WAITING]['slots'], CFG['dispatch']['idle_passes']
old = [f'fleet-old-a-{40 + i}' for i in range(slots)]
for i, name in enumerate(old):
self.reg(40 + i, name, status='online') # its job went away (cancelled): idle
self.fake[WAITING].units |= set(old)
self.gh.add(a_run(), a_job(11, job_labels(WAITING, 'lint'))) # no runner of the old label could take it
self.dispatch(passes=passes - 1)
self.assertEqual((self.fake[WAITING].stopped, self.fake[WAITING].started), ([], []))
self.dispatch()
self.assertEqual(sorted(self.fake[WAITING].stopped), old)
self.dispatch()
self.assertEqual([n for n, _ in self.fake[WAITING].started], [f'{RET_POOLS[WAITING]["label"]}-11'])

def test_an_idle_runner_under_a_retired_label_another_job_could_take_is_stopped_at_once(self):
self.reg(43, 'fleet-old-a-43', status='online')
self.fake[WAITING].units.add('fleet-old-a-43')
self.gh.add(a_run(6, actor='someone'), a_job(61, ['fleet-old-a'])) # the hook would refuse it on 43
self.dispatch()
self.assertEqual(self.fake[WAITING].stopped, ['fleet-old-a-43'])

def test_only_a_job_id_after_the_label_matches(self):
"""#319: near-miss names under the pool's labels (now and retired) are no runner it made: never deleted."""
a = RET_POOLS[WAITING]['label']
near = [f'{x}{tail}' for x in ('fleet-old-a', a)
for tail in ('-40-1', '-abc', '-40\n', '-40 ', '-\u0664\u0660', '-', '--40', '-' + '9' * 21)]
near += ['fleet-old-a2-40', 'fleet-old-ab-40', 'xfleet-old-a-40', 'FLEET-OLD-A-40', f'{a}2-40', f'x{a}-40']
for i, name in enumerate(near):
self.reg(100 + i, name)
self.reg(40, 'fleet-old-a-40') # the one name it made: deleted
self.dispatch()
self.assertEqual(self.deletes(), ['actions/runners/40'])
self.assertEqual(self.left(), sorted(near))

def test_two_dispatchers_with_different_pools_side_by_side(self):
a, b = RET_POOLS[WAITING]['label'], RET_POOLS[OTHER]['label']
self.reg(40, 'fleet-old-a-40') # A's leftover under its old label
Expand Down Expand Up @@ -4530,6 +4566,10 @@ def test_a_retired_label_no_pool_may_claim_is_refused(self):
'two pools claim one': lambda c: c['pools'][self.at(OTHER)].update(retired=['fleet-old-a']),
'not in retired_labels': lambda c: c['pools'][self.at(WAITING)].update(retired=['fleet-old-z']),
'not a list': lambda c: c['pools'][self.at(WAITING)].update(retired='fleet-old-a'),
# #319: a label reused while it is still retired; a host on the older config still deletes its
# registrations as that pool's leftovers
'a pool\'s label still in retired_labels': lambda c: c.update(
retired_labels=['fleet-old-a', 'fleet-old-b', b]),
}
for name, change in cases.items():
with self.subTest(name):
Expand Down
10 changes: 7 additions & 3 deletions fork-ci/actions/fleet-route/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ for pull requests ready for review.
| `pools` | yes | tried in order; see below |
| `jobs` | yes | routed jobs, heaviest first: `job` (id), `memory_mb`, optional `shards` (1-999), `gates` and `avoid` (below) |
| `reruns` | no | a dispatcher pool where a trusted person's re-run of failed jobs may go (below) |
| `retired_labels` | no | old pool labels (keep a label here for a week after changing it): never `hosted` or a static pool's label |
| `retired_labels` | no | old pool labels (keep a label here for a week after changing it): never `hosted` or a pool's label now (below) |
| `stuck_seconds` | yes | auto: how long a fleet job may wait before the watch cancels its run (the sweep re-runs it) |
| `fleet_stuck_seconds` | yes | the same in fleet mode (cancelled with an error; the sweep re-runs nothing, fleet-watch re-runs it once on `fallback`) |
| `beacon_fresh_seconds` | with a dispatcher pool | a heartbeat older than this counts no free slot, with an `::error::` |
Expand Down Expand Up @@ -256,8 +256,12 @@ that uses only the action has neither. So:
- **Old runner labels:** keep the old label on its runners, and in `retired_labels`, for a week after a pool's label
changes. Runs routed before the change queue on it and still find a runner.
- **Old registrations:** list the old label in that pool's `retired` too. Its dispatcher then deletes the offline
registrations it made under the old label (`<old label>-<job id>`), as it does under the new one. It never touches
an online one, nor one under another pool's label. Without `retired`, delete them by hand.
registrations it made under the old label (`<old label>-<job id>`), as it does under the new one, and stops an idle
runner there after `idle_passes` (it holds one of the pool's `slots`). It never deletes an online one, nor touches one
under another pool's label. Without `retired`, delete them by hand.
- **Reusing a label:** a pool's label may not be in `retired_labels` (the config is refused). To give a retired label
to a pool again, first take it out of `retired_labels` and every `retired`, and wait until every host runs that
config: a host still on the older one deletes the new pool's registrations under it before their runners connect.
- **Removing a pool:** take it out of every job's `avoid` too (a config that still names it is refused, and the error
names the pool).
- **Queued runs on a removed label** wait until GitHub drops them (24 hours). Cancel such a run by hand and re-run
Expand Down
Loading