module std.ab
std.ab — A/B experiments (§18.5, D-6850..D-6862).
A test ab "name" { variant a = current; variant b = candidate; split by .User 50/50; … } declares an experiment. The code
that serves the experiment asks which variant the current request belongs to:
match ab.variant("search v2") {
"b" => newSearch(q)
_ => oldSearch(q)
}- under
oxl test --kind abthe recorded traffic is replayed and every request is put into a variant by the hash of its split key; - in a cluster
oxl ab start "name"creates the dynamic Flagoxl.ab.<name>(percent = share of the second variant,by= the split): the same key always lands in the same variant, and the handler's latency and outcome count for that variant; a violatedguardturns the flag off (audited); - without a running experiment every request gets the control (the first variant).
Intrinsic: runtime/src/ab/ab_live.cpp.
Example:
use std.ab { ab }
fn search(q: str) -> str io {
match ab.variant("search v2") {
"b" => "new engine for {q}"
_ => "old engine for {q}"
}
}
fn main() io {
// without a running experiment every request gets the control variant
print(search("shoes"))
}Output
old engine for shoes
Types
data ab | Namespace of the experiment functions. |