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>
impl<T: Clone + Send + Sync + 'static> ControlBuilder<T>
pub fn new(name: &str, initial: T) -> Self
pub fn rev_allocator(self, allocator: Arc<RevAllocator>) -> Self
pub fn apply_timeout(self, d: Duration) -> Self
Sourcepub fn validator<F>(self, f: F) -> Self
pub fn validator<F>(self, f: F) -> Self
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.
Sourcepub fn reify_as_gauge<F>(self, to_f64: F) -> Self
pub fn reify_as_gauge<F>(self, to_f64: F) -> Self
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.
Sourcepub fn final_at_scope(self, scope_name: impl Into<String>) -> Self
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.
Sourcepub fn branch_scope(self, scope: BranchScope) -> Self
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”.
Sourcepub fn from_f64<F>(self, f: F) -> Self
pub fn from_f64<F>(self, f: F) -> Self
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.