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
- Variables
- func Bootstrap(connection, manifestKey, channel string) string
- func Bucket(flagKey, targetingKey string, mod uint32) uint32
- func FlagsObject(set string) string
- type Config
- type Context
- type Def
- type Expectation
- type Flag
- type Fleet
- type Kind
- type Object
- type Pred
- type Ramp
- type Rule
- type Set
- type Shape
- type Size
- type Step
- type Variation
- type Window
Constants ¶
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).
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.
const ( NameSmall = "small" NameFull = "full" )
The names of the sizes.
const SetsObject = "sets"
SetsObject is the name of the object that lists the flag sets.
Variables ¶
var ErrInvalidConfig = errors.New("invalid fleet configuration")
ErrInvalidConfig is returned when the configuration cannot produce a fleet.
var ErrUnknownSize = errors.New("unknown fleet size")
ErrUnknownSize is returned for a size name that is neither small nor full.
Functions ¶
func Bootstrap ¶
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 ¶
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 ¶
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
}
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.
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.
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 (*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.
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 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.
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
}
Set is one flag set: its key, its flags and the contexts it is evaluated with.
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.