fleet

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2026 License: MIT Imports: 10 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 fleet generates a seeded deployment of many flag sets for the fleet end-to-end test (issue #84): the bootstrap file, the documents to publish (flag sets and flags) and the manifest, a list of evaluation contexts per flag set, and the result that each evaluation must give.

The expected results are derived by construction, never by running the engine: every flag comes from a small template whose outcome for a context follows from how the context was built (a rule that names a plan expects its variation for a context of that plan), and the time shapes (progressive, scheduled, experimentation) are placed before, inside or after their window relative to the instant that the caller gives. A percentage split cannot be predicted for one key without the hash: the generator computes the documented bucketing (Bucket, FNV-1a from the standard library) itself, so a split is as exact as any other expectation.

The same seed, size and instant give the same bytes. A Fleet holds two generations: the first, and a reload in which a known subset of the flags changed.

Index

Constants

View Source
const (
	ReasonStatic              = "STATIC"
	ReasonDefault             = "DEFAULT"
	ReasonSplit               = "SPLIT"
	ReasonTargetingMatch      = "TARGETING_MATCH"
	ReasonTargetingMatchSplit = "TARGETING_MATCH_SPLIT"
	ReasonDisabled            = "DISABLED"
)

The reasons of the engine, as a flag evaluation reports them (the OFREP endpoints collapse some of them, see Expectation.OFREPReason).

View Source
const (
	// First is the generation that the relay starts on.
	First = 1
	// Reload is the generation that is published in the middle of a run.
	Reload = 2
)

The two generations of a fleet.

View Source
const (
	NameSmall = "small"
	NameFull  = "full"
)

The names of the sizes.

View Source
const SetsObject = "sets"

SetsObject is the name of the object that lists the flag sets.

Variables

View Source
var ErrInvalidConfig = errors.New("invalid fleet configuration")

ErrInvalidConfig is returned when the configuration cannot produce a fleet.

View Source
var ErrUnknownSize = errors.New("unknown fleet size")

ErrUnknownSize is returned for a size name that is neither small nor full.

Functions

func Bootstrap

func Bootstrap(connection, manifestKey, channel string) string

Bootstrap returns the version 2 bootstrap file of the relay: the connection (the YAML mapping of the connection named "control", for example `{type: file, path: "/dir"}`) and the control plane that reads the manifest at key.

func Bucket

func Bucket(flagKey, targetingKey string, mod uint32) uint32

Bucket is the bucket of a key in a percentage rollout: the FNV-1a (32 bit) hash of the flag key followed by the targeting key, modulo the sum of the weights times 1000. This is the documented bucketing of a rollout; the generator computes it here with the standard library so that the expectation of a split is exact and does not come from the engine.

func FlagsObject

func FlagsObject(set string) string

FlagsObject is the name of the flags object of a set.

Types

type Config

type Config struct {
	// Now is the instant the time shapes are placed around: the value of clock.Now during the run.
	Now time.Time
	// Size is the number of flag sets, flags and contexts.
	Size Size
	// Seed selects the fleet: the same seed gives the same bytes.
	Seed uint64
	// TrackEvents makes every flag collect its evaluation events (the exporters get one event per evaluation).
	TrackEvents bool
}

Config is the input of New.

type Context

type Context struct {
	// Key is the targeting key.
	Key string
	// Plan and Country are the attributes that the queries of the rules test.
	Plan, Country string
}

Context is an evaluation context of a flag set.

func (*Context) Attrs

func (c *Context) Attrs() map[string]any

Attrs returns the attributes of the context without the key.

type Def

type Def struct {
	Window     *Window
	Ramp       *Ramp
	Split      map[string]float64
	Default    string
	Shape      Shape
	Variations []Variation
	Rules      []Rule
	Steps      []Step
}

Def is the definition of a flag in one generation.

type Expectation

type Expectation struct {
	// Value is the value of an exact result.
	Value any
	// Variant is the variation of an exact result.
	Variant string
	// Reason is the reason of the result: the rule that matched, a split, the default rule of a flag with rules, or a
	// static answer.
	Reason string
	// Kind says how the result is reported.
	Kind Kind
}

Expectation is the result that an evaluation of a flag for a context must give.

func (*Expectation) OFREPReason

func (e *Expectation) OFREPReason() string

OFREPReason is the reason that the OFREP endpoints report: they have no DEFAULT (STATIC) and no TARGETING_MATCH_SPLIT (SPLIT).

type Flag

type Flag struct {
	// Key is the key of the flag.
	Key string
	// contains filtered or unexported fields
}

Flag is a flag of a set with its definition in both generations.

func (*Flag) Changes

func (f *Flag) Changes() bool

Changes reports whether the reload changes the definition of the flag.

func (*Flag) Def

func (f *Flag) Def(gen int) *Def

Def returns the definition of the flag in generation gen (First or Reload).

func (*Flag) Expect

func (f *Flag) Expect(gen int, ctx *Context, now time.Time) Expectation

Expect returns the result of the flag for the context in generation gen. now is the instant of the run.

type Fleet

type Fleet struct {
	// Sets are the flag sets, in name order.
	Sets []*Set
	// contains filtered or unexported fields
}

Fleet is a generated deployment with its two generations.

func New

func New(cfg *Config) (*Fleet, error)

New generates the fleet of cfg.

func (*Fleet) Flags

func (f *Fleet) Flags() int

Flags returns the number of flags of the fleet.

func (*Fleet) Manifest

func (f *Fleet) Manifest(
	gen int, channel, connection, prefix string, number uint64, created *time.Time,
) ([]byte, error)

Manifest returns the manifest of generation gen as a publisher writes it: one entry per object of Objects, stored under its content-addressed key below prefix on the connection, as the manifest generation number.

func (*Fleet) Now

func (f *Fleet) Now() time.Time

Now returns the instant the time shapes are placed around.

func (*Fleet) Objects

func (f *Fleet) Objects(gen int) ([]Object, error)

Objects returns the documents of generation gen: the flag sets and the flags of each set, in name order.

func (*Fleet) Size

func (f *Fleet) Size() Size

Size returns the size of the fleet.

type Kind

type Kind int

Kind says how a result is reported.

const (
	// KindExact is one variation, with its value and reason.
	KindExact Kind = iota
	// KindInactive is a flag outside its experimentation window: the caller's default value is served.
	KindInactive
)

The kinds of expectation.

type Object

type Object struct {
	// Name is the name of the object in the manifest.
	Name string
	// Kind is controlplane.KindFlags or controlplane.KindFlagSets.
	Kind string
	// Body is the YAML document.
	Body []byte
}

Object is a document to publish.

type Pred

type Pred struct {
	Attr   string
	Values []string
}

Pred matches the contexts whose attribute has one of the values.

type Ramp

type Ramp struct {
	InitialAt, EndAt   time.Time
	Initial, End       string
	InitialPct, EndPct float64
}

Ramp is a progressive rollout between two variations.

type Rule

type Rule struct {
	// Split, when not nil, is served in place of Variation: weights by variation name.
	Split     map[string]float64
	Name      string
	Variation string
	Preds     []Pred
}

Rule is a targeting rule: all its predicates must match; it then serves a variation or a split.

func (*Rule) Query

func (r *Rule) Query() string

Query is the query of the rule in the query language of the relay: its predicates joined with and.

type Set

type Set struct {
	// Name is the name of the flag set (its flags object is "flags-" and the name).
	Name string
	// APIKey is the plain key of the flag set. The first set has a key shaped like a UUID.
	APIKey string
	// Flags are the flags of the set, in key order.
	Flags []*Flag
	// Contexts are the evaluation contexts of the set.
	Contexts []Context
	// contains filtered or unexported fields
}

Set is one flag set: its key, its flags and the contexts it is evaluated with.

func (*Set) Changed

func (s *Set) Changed() []string

Changed returns the keys of the flags of the set whose definition differs between the two generations.

type Shape

type Shape string

Shape is the template a flag was generated from.

const (
	// ShapeStatic serves one variation to everyone (boolean, string, number or object values).
	ShapeStatic Shape = "static"
	// ShapeRule has one targeting rule with a query; the default rule serves another variation.
	ShapeRule Shape = "rule"
	// ShapeRuleOrder has two rules that can both match: the first one wins.
	ShapeRuleOrder Shape = "rule-order"
	// ShapeAll is a percentage rollout at 100% of one variation: every key gets it.
	ShapeAll Shape = "percent-all"
	// ShapeSplit is a 50/50 percentage rollout: a key gets one of two variations.
	ShapeSplit Shape = "percent-split"
	// ShapeRuleSplit serves a 50/50 split to the contexts that match a rule and one variation to the others.
	ShapeRuleSplit Shape = "rule-split"
	// ShapeRampBefore is a progressive rollout that has not started: its initial variation.
	ShapeRampBefore Shape = "progressive-before"
	// ShapeRampInside is a progressive rollout inside its window, a quarter of the way from 0% to 100% of its end
	// variation: a key whose bucket is below 25% has the end variation.
	ShapeRampInside Shape = "progressive-inside"
	// ShapeRampAfter is a progressive rollout that has ended: its end variation.
	ShapeRampAfter Shape = "progressive-after"
	// ShapeStepApplied is a scheduled rollout with a step in the past (applied) and one in the future.
	ShapeStepApplied Shape = "scheduled-applied"
	// ShapeStepPending is a scheduled rollout whose only step is in the future.
	ShapeStepPending Shape = "scheduled-pending"
	// ShapeWindowIn is an experimentation whose window contains the instant: it evaluates normally.
	ShapeWindowIn Shape = "experiment-in"
	// ShapeWindowOut is an experimentation whose window is over: the flag is inactive.
	ShapeWindowOut Shape = "experiment-out"
)

The shapes of the generated flags.

type Size

type Size struct {
	// Name is "small" or "full".
	Name string
	// FlagSets is the number of flag sets.
	FlagSets int
	// FlagsPerSet is the number of flags of each flag set.
	FlagsPerSet int
	// Contexts is the number of evaluation contexts of each flag set.
	Contexts int
}

Size is how big a fleet is.

func SizeFull

func SizeFull() Size

SizeFull is the size of the scheduled run: hundreds of flag sets, tens of thousands of flags.

func SizeNamed

func SizeNamed(name string) (Size, error)

SizeNamed returns the size with the given name.

func SizeSmall

func SizeSmall() Size

SizeSmall is the size of the pull request run.

type Step

type Step struct {
	At      time.Time
	Default string
}

Step is a scheduled change of the default rule.

type Variation

type Variation struct {
	// Value is a JSON value as a decoded JSON document has it (float64 for every number).
	Value any
	// Name is the name of the variation, which OFREP reports as the variant.
	Name string
}

Variation is a named value of a flag.

type Window

type Window struct{ Start, End time.Time }

Window is the experimentation window of a flag.

Jump to

Keyboard shortcuts

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