OxL Reference

data Flag

A feature flag with rules (§14.2): a percentage of users / nodes / tenants, allow and deny lists. on(for: p) is deterministic for one principal: the answer depends on the flag's name and the principal only, never on time or chance.

oxl
newSearch: Flag = Flag.off                       // everybody off
live: Flag = Flag.percent(10, by: .Tenant)      // 10 % of the tenants
beta: Flag = Flag.on                             // everybody on

At run time the rules change with oxl config set Limits.newSearch 25% (also on, off, percent=25,by=tenant,allow=a;b,deny=c or the JSON object), per layer like any other value.

Example:

oxl✓ checked in CI
dynamic Features {
  newSearch: Flag = Flag.percent(30)
  legacy: Flag = Flag.off
}

fn main() io {
  let f = Features.get()
  let ann = Principal.User("ann", [], Map.new(), false, none)
  // the same principal always gets the same answer
  print("{f.newSearch.on(r#for: ann) == f.newSearch.on(r#for: ann)} {f.legacy.on(r#for: ann)}")
}
Output
true false
pub(api) data Flag

Thread safety. a handle may be shared by tasks; the answer for a principal does not change while the rules do not.

Since. 1.0.0-beta

Methods

percent(p: f64, by: FlagBy, allow: List<str>, deny: List<str>) -> Flag
On for p percent (0..100) of the users (by), plus the allow list, minus the deny list.
open(cfg: str, key: str, default: Flag, gate: DynGate) -> Flag
Declares the flag (once per process) and returns it bound to the cluster value; called by the generated Config.get().
on(r#for: &Principal) -> bool
Is the flag on for p?
current() -> str
The rules in force (JSON).
set(text: str, layer: DynScope) -> () | DynError
Replaces the rules of layer ("on", "off", "25%", "percent=25,by=tenant" or JSON).
setAs(p: &Principal, text: str, layer: DynScope) -> () | DynError
set on behalf of p.

Defined in: std/core/dynconf.oxl:719

See also