Skip to main content

RoutingLabels

Struct RoutingLabels 

Source
pub struct RoutingLabels { /* private fields */ }
Expand description

A policy’s routing label set: the token runs-on targets.

04-subsystem-contracts.md types this as Option<NonEmpty<Label>>. This type is the NonEmpty<Label> half, and it is deliberately stronger than a non-empty vector, because the contract has two separate requirements that a bare NonEmpty only covers one of:

  • Non-empty. Guaranteed by RoutingLabels::host_label always existing. generate-jitconfig rejects labels: [] with 422 (docs/spikes/d18-org-jit-verification.md, Point 3), so an empty set is not a case to handle downstream.
  • The derived host label may not be dropped. b1: “Optional descriptive labels may be added to the set; the derived host label may not be dropped from it.” A Vec<Label> cannot express that. Here the host label is a separate field with no removal path, so dropping it is not a rule anyone has to remember.

The Option half of Option<NonEmpty<Label>> is carried by PolicyMode: MonitorOnly has no routing labels because the variant has no field for them, not because the field happens to be None.

Why the default is host-scoped. With no AcquireJobs, nothing reserves a queued job for one host. Two hosts whose policies carry the same label will both start a runner for the same job, and the loser pays a capacity slot and a cold start (01-current-architecture.md, edge case 6). The host identity baked into the derived label is the only control that prevents that by default — the capacity ceilings only bound it once it happens.

Implementations§

Source§

impl RoutingLabels

Source

pub const PREFIX: &'static str = "rm"

The product prefix in a derived label.

Source

pub fn derive(host_label: &HostLabel, os: Os, arch: Arch) -> Self

Derive the host-scoped default label, rm-<host>-<os>-<arch>.

02-target-architecture.md: “The label set … encodes the product, host identity, and host OS — for example rm-home-win-x64.” Read against that sentence the four segments are product / host identity / OS / architecture, so --host-label home on a Windows x64 host derives rm-home-win-x64.

Note that the worked command in 03-control-flows.md step 3 passes --host-label home-win, which under this rule derives rm-home-win-win-x64. That is a redundant example rather than a different rule — b1’s Scope names the three inputs explicitly — but it is recorded here because it is the obvious thing for a reader to trip on.

Source

pub fn from_parts( host_label: Label, additional: impl IntoIterator<Item = Label>, ) -> Self

Build from an explicit host label, for the operator override f2 supports, and for b2 reloading a stored set.

This accepts any Label as the host label, including one that is not host-scoped at all. “Host-scoped by construction” is a property of Self::derive, not of this type: f2 deliberately supports an operator override, so a hard rejection here would break a supported workflow, and this is also the serde path, so b2 reaches it for every stored row. A hand-edited row can therefore set host_label to self-hosted, and Self::remove will then defend that as immovable while two hosts happily serve each other’s jobs. Ask Self::is_derived_shape before trusting the collision control.

Source

pub fn from_host_label(host_label: Label) -> Self

Build from an explicit host label with no optional labels.

Source

pub fn host_label(&self) -> &Label

The one label that carries host identity and cannot be removed.

Source

pub fn is_derived_shape(&self) -> bool

Whether the host label still has the shape Self::derive produces: rm-<host>-<os>-<arch>, with the OS and architecture segments being tokens this crate actually emits.

This is a warning predicate, not a validation rule. It is false for an operator override, and an override is supported — f2 offers one on purpose. What it detects is that the collision control has been turned off: the derived shape is what keeps two hosts from answering each other’s jobs, so a policy whose host label is self-hosted or ubuntu-latest will route work that belongs to another machine, and Self::remove will refuse to remove that label because it cannot tell the difference. f2 and g2 should say so rather than fail; nothing here rejects it.

Matching is structural rather than a check against a known host label, because the host label this was derived from is not stored — only the concatenation is.

The middle segments are not inspected, only counted. An earlier version also required every one of them to be non-empty, meaning to reject an empty host segment — but a HostLabel cannot be empty, so that condition never rejected anything Self::derive could produce and only ever produced false negatives: HostLabel::new("home--pc") is legal (only a leading or trailing - is refused), derives rm-home--pc-win-x64, and was reported as not derived. The consequence was f2/g2 warning an operator that their collision control was off when they had done nothing wrong, which is worse than the residual it leaves: a hand-edited rm--win-x64 now reads as derived. That row is still host-scoped in shape, so it does not mislead in the direction this predicate exists to catch.

Source

pub fn additional(&self) -> impl Iterator<Item = &Label>

The optional descriptive labels, in sorted order.

Source

pub fn add(&mut self, label: Label) -> bool

Add an optional descriptive label. Returns false if it was already in the set (including as the host label).

Source

pub fn remove(&mut self, label: &Label) -> Result<bool, PolicyError>

Remove an optional descriptive label.

§Errors

PolicyError::HostLabelNotRemovable when asked to remove the host label. There is deliberately no override: this is the routing identity that keeps two hosts from serving each other’s jobs.

Source

pub fn contains(&self, label: &Label) -> bool

Source

pub fn iter(&self) -> impl Iterator<Item = &Label>

Every label, host label first.

Source

pub fn count(&self) -> NonZeroUsize

Never zero.

Source

pub fn to_non_empty(&self) -> NonEmpty<Label>

The same set in the shape 04-subsystem-contracts.md names.

Source

pub fn as_registration_labels(&self) -> Vec<String>

The labels array for generate-jitconfig (04-subsystem-contracts.md, “Generate JIT configuration”).

c4 sends exactly this. It matters that it is exactly this: the v1 spike established that no labels are added implicitly — the 201 carries the requested labels and nothing else, so a runner registered from this array does not answer runs-on: self-hosted unless self-hosted is in it (docs/spikes/d18-org-jit-verification.md, Point 3, findings 1 and 2).

Source

pub fn matches(&self, runs_on: &RunsOn) -> RunsOnMatch

Decide whether this policy should serve a queued job.

GitHub assigns a job to a runner whose label set is a superset of the job’s required labels, so the predicate is subset-in-the-other-direction: the job’s required labels must all be present here.

Source

pub fn tally<'a>( &self, jobs: impl IntoIterator<Item = &'a RunsOn>, ) -> DemandTally

Tally a poll’s worth of queued jobs into a demand signal.

The three counts are kept apart on purpose. An unresolvable runs-on is neither counted as demand nor dropped: b1 requires it be “reported as unresolvable rather than silently counted or silently dropped”, because counting it would start a runner for a job that may not be ours and dropping it would hide a workflow this host can never serve.

Trait Implementations§

Source§

impl Clone for RoutingLabels

Source§

fn clone(&self) -> RoutingLabels

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for RoutingLabels

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for RoutingLabels

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for RoutingLabels

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for RoutingLabels

Source§

impl PartialEq for RoutingLabels

Source§

fn eq(&self, other: &RoutingLabels) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for RoutingLabels

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for RoutingLabels

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more