feat(webhook): use priority field as tiebreaker in matcher dispatch#5133
Draft
vegardx wants to merge 1 commit into
Draft
feat(webhook): use priority field as tiebreaker in matcher dispatch#5133vegardx wants to merge 1 commit into
vegardx 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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