canarypolicy

package
v1.0.2 Latest Latest
Warning

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

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

Documentation

Overview

Package canarypolicy holds the stage schedule, thresholds and env defaults of staged canary releases. It is a leaf so the app spec can import it.

Index

Constants

View Source
const (
	EnvStages       = "APP_CANARY_STAGES"
	EnvInterval     = "APP_CANARY_INTERVAL"
	EnvMaxErrorRate = "APP_CANARY_MAX_ERROR_RATE"
	EnvMaxP95Ratio  = "APP_CANARY_MAX_P95_RATIO"
	EnvMinRequests  = "APP_CANARY_MIN_REQUESTS"
	EnvP95FloorMS   = "APP_CANARY_P95_FLOOR_MS"
	EnvTick         = "APP_CANARY_TICK"
)

Env vars that tune the defaults a per-app policy or start request can override.

View Source
const (

	// MaxStages bounds a stage schedule.
	MaxStages = 10
	// MaxWeight is the largest share ingress gives a canary; 100 means promote.
	MaxWeight = 99
	// Full is the stage value that means "promote".
	Full = 100
)

Variables

This section is empty.

Functions

func OSEnv

func OSEnv(k string) string

OSEnv reads the process environment, the getenv the daemon passes in.

func ParseStages

func ParseStages(v string) ([]int, error)

ParseStages parses "10,25,50,100"; an empty string yields no stages.

func ValidateStages

func ValidateStages(stages []int) error

ValidateStages checks a schedule: ascending percents of 1 to 100, at least one below 100 so something is judged before promotion.

Types

type Limits

type Limits struct {
	// MinRequests is the canary request count a stage needs before it is judged.
	MinRequests uint64
	// P95FloorMS ignores latency ratios while the canary p95 is below it.
	P95FloorMS float64
	Tick       time.Duration
}

Limits are the judgement knobs that are global rather than per app.

func DefaultLimits

func DefaultLimits(getenv func(string) string) Limits

DefaultLimits returns the global limits overridden by APP_CANARY_* env vars.

type Policy

type Policy struct {
	Stages []int
	// Interval is how long each stage observes traffic before it may advance.
	Interval time.Duration
	// MaxErrorRate is how far (as a fraction, 0.02 is two points) the canary's
	// 5xx rate may exceed the stable release's before the canary is rolled back.
	MaxErrorRate float64
	// MaxP95Ratio is how many times the stable p95 the canary's p95 may reach.
	MaxP95Ratio float64
}

Policy is the stage schedule and breach thresholds of one staged canary.

func DefaultPolicy

func DefaultPolicy(getenv func(string) string) Policy

DefaultPolicy returns the built-in defaults overridden by APP_CANARY_* env vars.

func (Policy) Validate

func (p Policy) Validate() error

Validate checks p's thresholds and schedule.

func (Policy) Weight

func (p Policy) Weight(i int) int

Weight is the traffic percent ingress sends the canary at stage i.

Jump to

Keyboard shortcuts

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