feat(webhook): use priority field as tiebreaker in matcher dispatch - #5133
feat(webhook): use priority field as tiebreaker in matcher dispatch#5133vegardx wants to merge 1 commit into
Conversation
When multiple runner pools match the same job labels (subset match via exactMatch: true), sort by ascending priority so the lowest-priority pool (cheapest) is selected first. The Terraform variable already supports priority (optional, default 999) and pre-sorts the config before writing to SSM. However the Lambda re-sorted only by exactMatch, losing the priority ordering. This commit adds priority as a secondary sort key in the Lambda. Refs: github-aws-runners#5128
|
Closing this one — I was wrong about the premise, and main has moved past it.
Worse, the comparator here predates What was worth salvaging is in #5214: declaring |
Problem
When multiple runner pools match the same job labels via
exactMatch: true(subset matching), dispatch order is non-deterministic. A workflow requesting[self-hosted, linux, x64]can land on any pool whose labels contain that subset — including an expensive 16 vCPU on-demand pool when a cheap 2 vCPU spot pool would suffice.See #5128 for the full discussion and concrete examples.
Fix
The Terraform variable
runner_matcher_configalready supports an optionalpriorityfield (default 999) and pre-sorts the config before writing to SSM. However the Lambda re-sorts only byexactMatch, discarding the priority ordering. This PR addspriorityas a secondary sort key:The assumption is that when a workflow omits specific labels (e.g. uses just
[self-hosted, linux, x64]instead of[self-hosted, linux, x64, large, ondemand]), the omission is intentional — the requester does not care which specific pool handles the job. Thepriorityfield lets the operator decide which pool should be preferred for these ambiguous requests.Changes
lambdas/functions/webhook/src/sqs/index.ts— add optionalpriorityfield toMatcherConfiglambdas/functions/webhook/src/runners/dispatch.ts— sort by priority as tiebreakerlambdas/functions/webhook/src/runners/dispatch.test.ts— test: multiple pools match common subset, lowest priority winsBackwards compatible
priorityis optional, defaults to 999priority = optional(number, 999)— no Terraform changes neededRefs: #5128