pub struct AbTest {
pub id: String,
pub variants: Vec<Variant>,
pub assignments: RwLock<HashMap<String, String>>,
pub metrics: HashMap<String, Arc<VariantMetrics>>,
pub start_time: Instant,
pub traffic_pct: f64,
}Expand description
An active A/B test comparing two or more variants.
Fields§
§id: StringUnique test identifier.
variants: Vec<Variant>All variants in this test.
assignments: RwLock<HashMap<String, String>>Map of session_id → variant_id for all assigned sessions.
metrics: HashMap<String, Arc<VariantMetrics>>Per-variant metrics (Arc so VariantMetrics with atomics can live behind shared refs).
start_time: InstantWhen the test was started.
traffic_pct: f64Fraction of traffic routed into this test (0.0–1.0).
Implementations§
Source§impl AbTest
impl AbTest
Sourcepub fn new(
id: impl Into<String>,
variants: Vec<Variant>,
traffic_pct: f64,
) -> Self
pub fn new( id: impl Into<String>, variants: Vec<Variant>, traffic_pct: f64, ) -> Self
Create a new A/B test.
id— unique test namevariants— must be non-empty; weights are normalised internallytraffic_pct— fraction of sessions to route into this test (0.0–1.0)
Sourcepub fn assign(&self, session_id: &str) -> Option<&Variant>
pub fn assign(&self, session_id: &str) -> Option<&Variant>
Deterministically assign a session to a variant using consistent hashing.
Returns None if traffic sampling excludes this session or there are no
variants.
Sourcepub fn record_result(
&self,
session_id: &str,
latency_ms: u64,
tokens: u64,
success: bool,
)
pub fn record_result( &self, session_id: &str, latency_ms: u64, tokens: u64, success: bool, )
Record the outcome of a request for the session’s assigned variant.
Auto Trait Implementations§
impl !Freeze for AbTest
impl RefUnwindSafe for AbTest
impl Send for AbTest
impl Sync for AbTest
impl Unpin for AbTest
impl UnsafeUnpin for AbTest
impl UnwindSafe for AbTest
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::Request