canarypolicy

package
v1.5.13 Latest Latest
Warning

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

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

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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"
	EnvSticky       = "APP_CANARY_STICKY"

	EnvMaxHealthFailures = "APP_CANARY_MAX_HEALTH_FAILURES"
	EnvAlertRuleID       = "APP_CANARY_ALERT_RULE_ID"
)

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 asks the live settings first, then the process environment.

func ParseStages

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

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

func SetLiveEnv

func SetLiveEnv(f func(string) string)

SetLiveEnv points the defaults at the runtime settings so a change applies to the next stage or release. nil goes back to the process environment alone.

func StickyEnabled

func StickyEnabled(getenv func(string) string) bool

StickyEnabled reports whether ingress pins a visitor to one release by cookie. It is on unless the setting says otherwise.

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
	// MaxHealthFailures rolls the canary back once its liveness probe has failed this many
	// times in a row; 0 turns the check off.
	MaxHealthFailures uint64
	// AlertRuleID names an alert rule whose firing state also rolls the canary back; empty is off.
	AlertRuleID string
}

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