Documentation
¶
Overview ¶
Package flagdata is the consumer side of the change source seam (see package flagsource): it reacts to the events of a change source and turns them into generations of flag data for the pipeline that builds and swaps the runtime.
One goroutine (Consumer.Run) owns all the state. For each flag set file it keeps the version that the latest event described and the last good version. It validates what an event carries with the code that validates flag files and flag set documents, applies the claim rules (a flag set name, an API key and a public flag key belong to the file that comes first: the earlier source, then the smaller object key), and at the end of a pass coalesces what changed into the next generation. Unchanged content never raises the generation; generations only go up.
The consumer knows nothing about stores, listings, ETags or polling: its whole input is events, so a source can be swapped for another one, and the consumer can be tested with a fake source.
The manifest of a generation (the objects with names, sizes and checksums) is an internal form: it is how the objects of a generation are named for the engine, and it is never read from or written to a store.
Index ¶
- Constants
- Variables
- type Applier
- type Config
- type Consumer
- func (c *Consumer) Await(ctx context.Context, passes uint64) error
- func (c *Consumer) Handle(ctx context.Context, event *flagsource.Event)
- func (c *Consumer) Ready() <-chan struct{}
- func (c *Consumer) Run(ctx context.Context, events <-chan flagsource.Event) error
- func (c *Consumer) Seed(restored *Restored)
- func (c *Consumer) Status() Status
- type Generation
- type GenerationObject
- type IncompleteSource
- type Problem
- type Restored
- type Status
Constants ¶
const ( // VirtualConnection is the connection name of the objects that exist only in memory (the flag set documents the // consumer builds from flag set files). It cannot clash with a connection of the bootstrap file: their names start // with a letter. VirtualConnection = "$flagsets" // Channel is the channel of every generation. Channel = "computed" )
Names of the virtual connection and of the channel of the objects of a generation.
Variables ¶
var ErrGeneration = errors.New("flagdata: the generation cannot be built")
ErrGeneration is the cause of a pass that could not be turned into a generation: the previous generation stays.
var ErrRunning = errors.New("flagdata: the consumer runs already")
ErrRunning is returned by a Consumer.Run while another one runs.
Functions ¶
This section is empty.
Types ¶
type Applier ¶
type Applier interface {
Submit(content *flagruntime.Content)
}
Applier is the pipeline that builds and swaps the runtime: *flagruntime.Engine implements it. Submit does not block (the newest content wins).
type Config ¶
type Config struct {
Applier Applier
Logger *slog.Logger
Now func() time.Time
OnGeneration func(*Generation)
// Expected are the places that a first look has to list: what a relay that is not ready yet is waiting for before the
// first look has ended.
Expected []flagsource.Scope
// MaxObjects and MaxTotalBytes are the ceiling of one generation, all the sources together.
MaxObjects int
MaxTotalBytes int64
// StartTimeout is how long a start with no state waits for every source to be listed once; zero waits for ever.
StartTimeout time.Duration
}
Config configures a Consumer.
type Consumer ¶
type Consumer struct {
// contains filtered or unexported fields
}
Consumer holds the flag data. Its state belongs to the goroutine of Consumer.Run.
func (*Consumer) Await ¶
Await waits until the consumer has handled the end of the given number of passes of its source, applied or not, and returns the error of ctx if that ends first. A caller that asked its source for a pass (a refresh) waits for the pass that it caused with it.
func (*Consumer) Handle ¶
func (c *Consumer) Handle(ctx context.Context, event *flagsource.Event)
Handle reacts to one event. It is what Run calls for each event; it must not be called while Run runs.
func (*Consumer) Ready ¶
func (c *Consumer) Ready() <-chan struct{}
Ready returns a channel that is closed when the first full pass was applied.
func (*Consumer) Run ¶
Run reacts to the events until ctx is done or in is closed, and returns nil then. It is the one goroutine that touches the state: it starts none. A second Run while one runs returns ErrRunning.
func (*Consumer) Seed ¶
Seed tells the consumer what a restored state holds, before the first event: the generation and content checksum, so that unchanged content keeps the generation and changed content goes above it, and the last good version of each flag set file. The content is handed to the pipeline at once, so a start while the store is down serves the last generation. It does not restore who owns a flag set name, API key or public flag key: no rule of correctness or security depends on what is stored on disk, so the first pass decides the claims as a start without a cache does. Seed must be called before Run, and once.
type Generation ¶
type Generation struct {
Objects map[string]GenerationObject
ETag string
Manifest []byte
Number uint64
Revision uint64
}
Generation is a generation of flag data as the cache directory keeps it: the computed manifest with its generation, and the objects it names. It is read-only.
type GenerationObject ¶
type GenerationObject struct {
Kind string
Format string
Checksum controlplane.Checksum
Bytes []byte
}
GenerationObject is one object of a Generation.
type IncompleteSource ¶
type IncompleteSource struct {
// Source is the connection and prefix.
Source string `json:"source"`
// Reason is one of the reasons of the change source: unavailable, refused, unresolved.
Reason string `json:"reason"`
// Detail is bounded text about the failure.
Detail string `json:"detail"`
}
IncompleteSource is a place that the last pass could not list: its flag sets stay exactly as they were.
type Problem ¶
type Problem struct {
// File is the connection and key of the flag set file.
File string `json:"file"`
// Reason names what is wrong, never a value or an API key.
Reason string `json:"reason"`
// KeptPrevious tells that the flag set still serves its last good version.
KeptPrevious bool `json:"keptPrevious"`
}
Problem is a flag set file that cannot be served as it is now.
type Restored ¶
type Restored struct {
// ETag is the ETag of the restored generation.
ETag string
// Manifest is the restored manifest, encoded.
Manifest []byte
// Objects are the bytes of the restored objects.
Objects [][]byte
}
Restored is the state a restart brings back from the cache directory: the generation the last run served and the objects it held.
type Status ¶
type Status struct {
LastApplied time.Time `json:"lastApplied,omitzero"`
LastErrorAt time.Time `json:"lastErrorAt,omitzero"`
ContentChecksum string `json:"contentChecksum"`
LastError string `json:"lastError,omitempty"`
Invalid []Problem `json:"invalid,omitempty"`
Incomplete []IncompleteSource `json:"incompleteSources,omitempty"`
Waiting []string `json:"waitingFor,omitempty"`
Objects []controlplane.ManifestObject `json:"objects,omitempty"`
Passes uint64 `json:"passes"`
Failures uint64 `json:"failures"`
Generation uint64 `json:"generation"`
ObjectCount int `json:"objectCount"`
FlagSets int `json:"flagSets"`
Flags int `json:"flags"`
Revision uint64 `json:"revision"`
PassesSeen uint64 `json:"passesSeen"`
Ready bool `json:"ready"`
StartTimedOut bool `json:"startTimedOut,omitempty"`
}
Status is what the consumer knows. It holds no API key and no object content. It is a copy: it never changes.