Documentation ¶
Overview ¶
Package choices provides a library for simple a/b and multivariate testing.
choices uses hashing to uniquely assign users to experiments and decide the values the user is assigned. This allows us to quickly assign a user to an experiment with out having to look up what they were assigned previously. Most of the ideas in this package are based off of Facebook's Planout.
In choices there are three main concepts. Namespaces, Experiments, and Params. Namespaces split traffic between the experiments they contain. Experiments are the element you are testing. Experiments are made up of one or more Params. Params are a key value pair. The value can be either a Uniform Choice value or a Weighted Choice value.
In most cases you will want to create one namespace per experiment. If you have experiments that might have interactions you can use namespaces to split the traffic between them. For example, if you are running a test on a banner and another test that takes over the whole page, you will want to split the traffic between these two tests. Another example, is if you want to run a test on a small percent of traffic. Namespaces contain a list of TeamID's. These TeamID's are used to deterime which Experiments to return to the caller.
Experiments contain the Params for a running experiment. When a caller queries Namespaces, Namespaces will hash the user into a segment, It will then check if the segment is contained in an Experiment. If the segment is contained in the experiment then the experiment will be evaluated. An experiment will in turn evaluate each of it's Params.
Params are key-value pairs. They Options for value are Uniform choice or Weighted choice. Uniform choices will be selected in a uniform fashion. Weighted choices will be selected based on the proportions supplied in the weights.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var SegmentsAll = segments{255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}
Functions ¶
func GlobalSalt ¶
func GlobalSalt(salt string) func(*ElwinConfig) error
WithGlobalSalt sets the salt used in hashing users.
func UpdateInterval ¶
func UpdateInterval(dur time.Duration) func(*ElwinConfig) error
UpdateInterval changes the update interval for Storage. Must call SetStorage after this or cancel context of the current Storage and call SetStorage again.
Types ¶
type ElwinConfig ¶
type ElwinConfig struct { Storage Storage ErrChan chan error // contains filtered or unexported fields }
func NewElwin ¶
func NewElwin(ctx context.Context, opts ...func(*ElwinConfig) error) (*ElwinConfig, error)
NewElwin sets the storage engine. It starts a ticker that will call s.Update() until the context is cancelled. To change the tick interval call SetUpdateInterval(d time.Duration). Must cancel the context before calling NewElwin again otherwise you will leak go routines.
func (*ElwinConfig) Namespaces ¶
func (ec *ElwinConfig) Namespaces(teamID, userID string) ([]ExperimentResponse, error)
Namespaces determines the assignments for the a given users units based on the current set of namespaces and experiments. It returns a Response object if it is successful or an error if something went wrong.
type Experiment ¶
Experiment is a structure that represents a single experiment in elwin. It can contain multiple parameters. Experiments are evaluated through the call to Namespaces.
type ExperimentResponse ¶
type ExperimentResponse struct { Name string Params []ParamValue }
ExperimentResponse holds the data for an evaluated expeiment.
type Namespace ¶
type Namespace struct { Name string Segments segments TeamID []string Experiments []Experiment }
Namespace is a container for experiments. Segments in the namespace divide traffic. Units are the keys that will hash experiments.
func NewNamespace ¶
NewNamespace creates a new namespace with all segments available. It returns an error if no units are given.
func TeamNamespaces ¶
TeamNamespaces filters the namespaces from storage based on teamID.
func (*Namespace) AddExperiment ¶
AddExperiment adds an experiment to the namespace. It takes the the given number of segments from the namespace. It returns an error if the number of segments is larger than the number of available segments in the namespace.
type Param ¶
Param is a struct that represents a single parameter in an experiment. Param is evaluated through the call to Namespaces.
type ParamValue ¶
ParamValue is a key value pair returned from an evalated experiment parameter.
type Storage ¶
Storage is an interface for the storage of experiments. Storage has two functions. Update, which checks for new data from the data store, and Read which returns the current slice of Namespaces. Clients using the storage interface should never write data to the slice returned by Namespaces. Storage should be read only the values should never be overwritten.
type Uniform ¶
type Uniform struct {
Choices []string
}
Uniform is a way to select from a list of Choices with uniform probability.
type Value ¶
Value is the interface Param Values must implement. They take a hash value and return the string that represents the value or an error.