splittest

package
v1.5.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 22, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package splittest holds the pure rules of app split testing: variant validation, sticky assignment and the env defaults. Ingress and the API both import it, so it stays free of store and HTTP types.

Index

Constants

View Source
const (
	EnvCookieName    = "APP_SPLIT_COOKIE_NAME"
	EnvCookieTTL     = "APP_SPLIT_COOKIE_TTL"
	EnvOverrideParam = "APP_SPLIT_OVERRIDE_PARAM"
	EnvFlushInterval = "APP_SPLIT_FLUSH_INTERVAL"
)

Env vars that tune the defaults a test can override per cookie.

View Source
const (

	// MaxVariants bounds a test so the variants table stays readable.
	MaxVariants = 5
	// TotalWeight is what the variant weights must add up to.
	TotalWeight = 100
)
View Source
const (
	KindProduction = "production"
	KindBranch     = "branch"
	KindRelease    = "release"
)

Variant kinds. Production is the app itself; the others are other deploys.

View Source
const (
	StatusRunning = "running"
	StatusStopped = "stopped"
)

Test statuses.

Variables

This section is empty.

Functions

func OSEnv

func OSEnv(k string) string

OSEnv reads the process environment.

func ParseStaticImageRef

func ParseStaticImageRef(ref string) (string, bool)

ParseStaticImageRef returns the deploy ID of a ref made by StaticImageRef.

func StaticImageRef

func StaticImageRef(deployID string) string

StaticImageRef encodes a static deploy ID as a promote target.

func ValidCookieName

func ValidCookieName(n string) bool

ValidCookieName reports whether n is safe as a cookie or query parameter name.

func Validate

func Validate(vs []Variant) error

Validate checks a variant set: 2 to MaxVariants arms, exactly one production arm, unique labels, non-negative weights summing to TotalWeight.

Types

type Assignment

type Assignment struct {
	Variant Variant
	// SetCookie is true when the visitor's cookie must be written: a fresh
	// draw or a QA override. A kept assignment leaves the cookie alone.
	SetCookie bool
}

Assignment is the outcome of Decide.

func Decide

func Decide(vs []Variant, forced, cookie string, rng *rand.Rand) Assignment

Decide picks the variant for one visitor. A forced key (the QA override) wins, then a still-valid cookie value, then a fresh weighted draw. A cookie naming a removed or zero-weight variant is treated as absent.

type Defaults

type Defaults struct {
	CookieName    string
	CookieTTL     time.Duration
	OverrideParam string
	FlushInterval time.Duration
}

Defaults are the process-wide fallbacks for a test's cookie settings.

func DefaultsFromEnv

func DefaultsFromEnv(getenv func(string) string) Defaults

DefaultsFromEnv reads the APP_SPLIT_* env vars over the built-in defaults.

type Variant

type Variant struct {
	ID     string `json:"id"`
	Label  string `json:"label"`
	Kind   string `json:"kind"`
	Ref    string `json:"ref,omitempty"`
	Weight int    `json:"weight"`
}

Variant is one arm of a split test. Ref is a branch name for a branch variant and a deploy URL service name for a release variant.

func Draw

func Draw(vs []Variant, rng *rand.Rand) Variant

Draw picks a variant by weight with rng.

func Find

func Find(vs []Variant, key string) (Variant, bool)

Find returns the variant whose ID or label (case-insensitive) matches key.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL