Skip to main content

ControlBuilder

Struct ControlBuilder 

Source
pub struct ControlBuilder<T: Clone + Send + Sync + 'static> { /* private fields */ }
Expand description

Construct a Control<T>. Every control needs an initial value, a name, and a rev allocator. Apply timeout and validator are optional.

Implementations§

Source§

impl<T: Clone + Send + Sync + 'static> ControlBuilder<T>

Source

pub fn new(name: &str, initial: T) -> Self

Source

pub fn rev_allocator(self, allocator: Arc<RevAllocator>) -> Self

Source

pub fn apply_timeout(self, d: Duration) -> Self

Source

pub fn validator<F>(self, f: F) -> Self
where F: Fn(&T) -> Result<(), String> + Send + Sync + 'static,

Register a pre-fanout validator. Bad values reject the write before any applier is called. Typical use: bounds checking (0 < concurrency <= 10_000), format parsing.

Source

pub fn reify_as_gauge<F>(self, to_f64: F) -> Self
where F: Fn(&T) -> Option<f64> + Send + Sync + 'static,

Publish the control’s current value as a numeric gauge. to_f64 converts each committed value to an f64 (or None to suppress that sample — useful for enum-valued controls where some variants don’t have a meaningful numeric projection). The reified gauge is captured alongside instrument-emitted metrics by the tree walk — consumers (SQLite, VictoriaMetrics push, summary report, TUI) pick it up without any extra wiring.

Metric name: control.<control_name>. Labels: the effective-labels of the component the control lives on.

Source

pub fn final_at_scope(self, scope_name: impl Into<String>) -> Self

Pin the control’s value at the declaring scope. The Launch-origin seed write still goes through so the initial value can be installed; every subsequent runtime write returns SetError::FinalViolation with scope_name so the operator can see where the pin lives.

Use when a workload (or a parent scope) needs to guarantee that a runtime writer cannot override a value this scope has chosen — e.g. a DDL phase that deliberately runs at concurrency=1 regardless of what the operator nudges the session-wide concurrency to.

Source

pub fn branch_scope(self, scope: BranchScope) -> Self

Declare the visibility of this control within the component tree. Defaults to BranchScope::Local.

BranchScope::Subtree means every descendant component resolves the control name through walk-up; descendants constructed after a successful write read the new committed value at construction time. See SRD 23 §“Branch-scoped and final controls”.

Source

pub fn from_f64<F>(self, f: F) -> Self
where F: Fn(f64) -> Result<T, String> + Send + Sync + 'static,

Register a converter that lets type-erased writers (GK control_set, web API JSON bodies) push f64 values into this control. Without a converter, f64 writes return SetError::ValidationFailed with a “no f64 setter” message.

For Control<f64> a trivial converter is |v| Ok(v); for Control<u32> a reasonable converter validates the range (if v < 0 || v > u32::MAX as f64 { Err(...) }) and casts. More complex types (e.g. a rate spec) can interpret f64 as ops/sec and synthesize a fresh domain value.

Source

pub fn build(self) -> Control<T>

Auto Trait Implementations§

§

impl<T> !RefUnwindSafe for ControlBuilder<T>

§

impl<T> !UnwindSafe for ControlBuilder<T>

§

impl<T> Freeze for ControlBuilder<T>
where T: Freeze, Option<Box<dyn Fn(&T) -> Result<(), String> + Send + Sync>>: Freeze, Option<Box<dyn Fn(&T) -> Option<f64> + Send + Sync>>: Freeze, Option<Box<dyn Fn(f64) -> Result<T, String> + Send + Sync>>: Freeze,

§

impl<T> Send for ControlBuilder<T>
where Option<Box<dyn Fn(&T) -> Result<(), String> + Send + Sync>>: Send, Option<Box<dyn Fn(&T) -> Option<f64> + Send + Sync>>: Send, Option<Box<dyn Fn(f64) -> Result<T, String> + Send + Sync>>: Send,

§

impl<T> Sync for ControlBuilder<T>
where Option<Box<dyn Fn(&T) -> Result<(), String> + Send + Sync>>: Sync, Option<Box<dyn Fn(&T) -> Option<f64> + Send + Sync>>: Sync, Option<Box<dyn Fn(f64) -> Result<T, String> + Send + Sync>>: Sync,

§

impl<T> Unpin for ControlBuilder<T>
where T: Unpin, Option<Box<dyn Fn(&T) -> Result<(), String> + Send + Sync>>: Unpin, Option<Box<dyn Fn(&T) -> Option<f64> + Send + Sync>>: Unpin, Option<Box<dyn Fn(f64) -> Result<T, String> + Send + Sync>>: Unpin,

§

impl<T> UnsafeUnpin for ControlBuilder<T>

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.