Documentation
¶
Overview ¶
Package flagsource is the contract between the side of the relay that knows where flag data lives (a change source) and the side that knows what the flag data means (the flag data consumer, package flagdata).
A change source finds changes in a store and tells the consumer about them as plain data, through the port Source. It knows the store: listings, version markers, conditional reads, request limits, paging. It knows nothing about flag set names, API keys, generations or the engine.
The consumer reacts to the events. It validates, applies the claim rules, keeps the last good version of each flag set file, and hands generations to the pipeline that builds and swaps the runtime. It knows nothing about stores, listings, ETags or polling. A change source can therefore be replaced (a notification based one, say) without a change in the consumer.
The contract of a source:
- An Event carries the content: a flag set file arrives with the bytes of every flag file and segments file it names, so the consumer never reads a store. Modification times are plain times that the store reported.
- Events of one object arrive in order. Delivery is at least once: an event is idempotent, the version marker of the object tells a repeat.
- A source blocks on a full channel (under its context) and never drops an event.
- KindPass says that the source has a complete listing of every place it looks at. It is the only event after which the consumer decides claims and builds a generation. A polling source sends one after each look; a push source sends KindSet, KindUnreadable and KindGone as notifications arrive, and a KindPass with the complete list after its first full listing and then at an interval.
- A flag set file claims its name, its API keys and whether it is public by its own bytes. A source that read the bytes of a flag set file sends them with KindUnreadable when a file that it names cannot be used: the file keeps holding what it claims, and it blocks nothing. A flag set file whose own bytes could not be read for a reason that a retry may fix (the network, a 5xx, a limit of requests, a read that changed under the reader) is KindUnreadable with a Reason.Transient reason and no bytes when the consumer knows its claims already: the consumer keeps them and the last good version, and the file affects itself alone. When the source never sent its claims (a first read), the source sends no event for it and puts its place in Event.Incomplete for that pass. One that could not be read for a reason that no retry fixes (gone, access denied, too large, empty) is KindUnreadable with no bytes and a definitive reason: it claims nothing.
- Event.Rank says which source a flag set file belongs to: 0 for the flag set of the bootstrap file, then the position of the source in the bootstrap file, counted from 1. A file that several sources contain belongs to the earliest. The consumer gives a claim (an API key, a public flag key, a name) to the first file in the order of the rank, then of the object key, always: the order comes from the trusted bootstrap file and the keys, never from what a store holds or from who held the claim before. This follows GO Feature Flag: API keys are unique, and a tie is broken by a fixed order. The claims are those of the files now: a last good version supplies content under the current name and keys, never a claim against a file that claims it now. Only a file whose flag set file does not parse now keeps its old claims, and only those that no file claims.
- Event.Present lists every flag set file of the places that were listed. A file that is in a listed place and not in it is gone.
- Event.Incomplete lists the places that could not be listed (Scope: a connection and a key prefix). The consumer leaves their flag sets exactly as they are, and applies the other places. A start with no restored state is ready after the first pass with no incomplete place.
- An event never holds a value of a flag, an API key or the text of a file in a message: Event.Detail is bounded text about the problem, never content, and every text that comes from an object goes through Shown or Label.
Index ¶
Constants ¶
const ( // MaxShown is the length of a text that [Shown] repeats. MaxShown = 40 // MaxLabel is the length of a name that [Label] repeats. MaxLabel = 200 )
Limits of the text of an object that a message repeats.
const BootstrapConnection = "$bootstrap"
BootstrapConnection is the connection of the Ref of the flag set that the bootstrap file defines itself (the `flags` section): it is no object of a store, so a source sends it without reading anything for the flag set itself.
const DefaultFlagSetName = "default"
DefaultFlagSetName is the name of the flag set that the `flags` section of the bootstrap file defines. A flag set file may not take it.
const KindSetFile = "setFile"
KindSetFile is the kind that FormatOf takes for a flag set file.
const MaxIgnored = 20
MaxIgnored is the number of keys that Event.Ignored lists.
Variables ¶
This section is empty.
Functions ¶
func FormatOf ¶
FormatOf maps a key to a format by its extension, and reports whether the extension is one the kind reads: flag set files and segments files are yaml or json, flag files may be toml too.
Types ¶
type Entry ¶
type Entry struct {
// Connection is the name of a connection of the bootstrap file; empty means the connection of the flag set file.
Connection string `json:"connection,omitempty" yaml:"connection"`
// Key is the key of one object (a file name below the root of the connection).
Key string `json:"key,omitempty" yaml:"key"`
// Prefix names a directory: every object below it is used.
Prefix string `json:"prefix,omitempty" yaml:"prefix"`
}
Entry is one line of the flags or segments list of a flag set file: one object (Key) or every object below a directory (Prefix). Exactly one of Key and Prefix is set.
type Event ¶
type Event struct {
// Modified is the modification time that the store reports for the flag set file ([KindSet]); zero when it does
// not say.
Modified time.Time
// Detail is bounded text about a problem, for the log and the status. It never holds the content of an object.
Detail string
// Reason is the typed reason of [KindUnreadable].
Reason Reason
// Marker is the version marker of the flag set file ([KindSet]).
Marker string
// Set is the flag set file ([KindSet], [KindGone], [KindUnreadable]).
Set Ref
// Bytes is the content of the flag set file ([KindSet]); for [KindUnreadable], the content of the flag set file when
// it was read and the problem is one of the files it names.
Bytes []byte
// Files are the flag files and segments files the flag set file names, with their content ([KindSet]). A flag set
// file that cannot be decoded has none: the consumer reports the problem it finds.
Files []File
// Present lists every flag set file the source found in the places of the pass that it completed ([KindPass]),
// unreadable ones included. A flag set file that is not in it, and is in no place of Incomplete, is gone.
Present []Ref
// Incomplete lists the places of the pass that the source could not list ([KindPass]). The consumer leaves the
// flag set files of such a place exactly as they are: they are not gone, no claim of them is released and their last
// good version stays.
Incomplete []Incomplete
// Ignored lists some keys of the pass that are not flag set files, at most [MaxIgnored] ([KindPass]).
Ignored []string
// IgnoredCount is the number of keys that were ignored ([KindPass]).
IgnoredCount int
// Rank is the precedence of the source the flag set file belongs to ([KindSet], [KindUnreadable]): 0 for the flag set
// of the bootstrap file, then 1 for the first source of flagSets.sources, 2 for the second, and so on. A file found
// under several sources belongs to the earliest. The consumer decides a claim between files of different ranks by it:
// the lower rank wins, always. It comes from the trusted bootstrap file and never from the content of a store.
Rank int
// Kind says what happened.
Kind Kind
}
Event is a change that a source tells the consumer. It is plain data. Which fields are set depends on Kind.
type File ¶
type File struct {
// Modified is the modification time that the store reports for the object; zero when it does not say. It is the
// same for every reader of the store.
Modified time.Time
// Ref is where the file is.
Ref Ref
// Kind is [FileFlags] or [FileSegments].
Kind FileKind
// Marker is the version marker of the object: equal markers of the same object mean equal content.
Marker string
// Bytes is the content of the file. The consumer treats it as immutable, and so must the source after it sent it.
Bytes []byte
}
File is one flag file or segments file with its content.
type Incomplete ¶
type Incomplete struct {
// Detail is bounded text about the failure, never content.
Detail string
// Scope is the place.
Scope Scope
// Reason says why in the closed set of [Reason].
Reason Reason
}
Incomplete is a place of a pass that could not be listed.
type Kind ¶
type Kind uint8
Kind is the kind of an Event.
const ( // KindSet: a flag set file is as in the event now. Set, Marker, Bytes and Files are set. KindSet Kind = iota + 1 // KindGone: the flag set file does not exist any more. Set is set. KindGone // KindUnreadable: the flag set file could not be used. Set, Reason and Detail are set. The consumer keeps the last // good version of the flag set file. When the bytes of the flag set file itself were read and the problem is one of // the files it names (missing, unreadable, invalid, a connection that is down, a prefix that cannot be listed), // Bytes holds them: the file then claims its name and API keys, whatever happens to the files it names. Without // Bytes and with a definitive reason (the file is gone from the store, refused, too large, empty) it claims nothing; // with a reason that is [Reason.Transient] the claims that the consumer knows of the file stay. KindUnreadable // KindPass: the source finished a full pass. Pass and Present are set. KindPass )
The kinds of event.
type ProblemError ¶
type ProblemError struct {
// contains filtered or unexported fields
}
ProblemError is a fact about the content of an object, worded for a log: it holds a line and a kind of problem, never a value of the object.
func Problemf ¶
func Problemf(format string, args ...any) *ProblemError
Problemf returns a ProblemError.
type Reason ¶
type Reason string
Reason says in a closed set why a flag set file could not be read or resolved.
const ( // ReasonNotFound: the object does not exist (a flag file that the flag set file names, for example). ReasonNotFound Reason = "not-found" // ReasonTooLarge: the object is over its size limit. ReasonTooLarge Reason = "too-large" // ReasonEmpty: the object has no content. ReasonEmpty Reason = "empty" // ReasonUnstable: the object changed while it was read. ReasonUnstable Reason = "unstable" // ReasonRefused: the store refuses the object or the listing, and a retry will not help. ReasonRefused Reason = "refused" ReasonUnavailable Reason = "unavailable" // ReasonUnresolved: what the flag set file names cannot be resolved (an unknown connection, a bad key, a prefix // with too many files). ReasonUnresolved Reason = "unresolved" // ReasonOverBudget: a source passed its budget of objects or bytes in the pass. ReasonOverBudget Reason = "over-budget" )
The reasons of a KindUnreadable event.
type Ref ¶
Ref names one object of a store: a connection of the bootstrap file and a key in it.
func BootstrapRef ¶
func BootstrapRef() Ref
BootstrapRef is the Ref of the flag set of the `flags` section.
type Scope ¶
type Scope struct {
// Connection is the connection of the bootstrap file.
Connection string
// Prefix is the key prefix, empty for the whole connection. A prefix ends with a slash.
Prefix string
}
Scope is a place a source lists: the flag set files of a connection whose key starts with Prefix.
type SetFile ¶
type SetFile struct {
// Name is the name of the flag set; it defaults to the file name without its extension.
Name string `json:"name,omitempty" yaml:"name"`
// APIKeys are the keys of the clients of the flag set; with none the flag set is public.
APIKeys []string `json:"apiKeys,omitempty" yaml:"apiKeys"`
// Flags are the flag files of the flag set; a later file wins on a duplicate flag key.
Flags []Entry `json:"flags,omitempty" yaml:"flags"`
// Segments are the segments files of the flag set.
Segments []Entry `json:"segments,omitempty" yaml:"segments"`
}
SetFile is the document of a flag set file: one flag set, by the keys of the flag files and segments files it is made of.
func DecodeSetFile ¶
DecodeSetFile reads a flag set file strictly: one document, no unknown field. An error holds the line and the kind of the problem, never the text of the file.
type Source ¶
type Source interface {
// Run delivers events on out, in order for each object, until ctx is done. It blocks while out is full and never
// drops an event. It returns nil when ctx ended, and an error only for a failure it cannot go on from. It does not
// close out.
Run(ctx context.Context, out chan<- Event) error
// Refresh looks for changes now, and returns when the pass that it caused has ended: nil when it succeeded, the
// failure of the pass otherwise. Calls that arrive together may share a pass, and a pass that was already running
// when the call arrived does not count. A source that is told about changes has nothing to run: it returns nil
// when it has delivered what it knows.
Refresh(ctx context.Context) error
// Nudge asks the source to look for changes now instead of at its next time. It never blocks. It reports whether
// the request was taken: false when the source is waiting after failed passes (a notification never makes it
// ask a store that is failing). A source that is told about changes may treat it as a hint.
Nudge() bool
// Stats is what the source did, without blocking it.
Stats() Stats
}
Source is the port of a change source. Its whole capability set is here: a caller never looks for more with a type assertion.
type Stats ¶
type Stats struct {
// LastPass is the end of the last finished pass; zero when there was none.
LastPass time.Time `json:"lastPass,omitzero"`
// LastErrorAt is the time of LastError; zero when the last pass succeeded.
LastErrorAt time.Time `json:"lastErrorAt,omitzero"`
// LastError is why the last pass failed; empty when it succeeded. It names objects, never values.
LastError string `json:"lastError,omitempty"`
// Passes counts the passes that finished, Failures the ones that did not.
Passes uint64 `json:"passes"`
Failures uint64 `json:"failures"`
}
Stats is the work of a source. It holds no API key and no content.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package objectstore is the read port of the flag source that polls object stores: the small ObjectStore interface through which the relay reads flag set files and flag files, and the errors and types of its answers.
|
Package objectstore is the read port of the flag source that polls object stores: the small ObjectStore interface through which the relay reads flag set files and flag files, and the errors and types of its answers. |
|
azurestore
Package azurestore is the objectstore.ObjectStore on Azure Blob Storage, over the Get Blob request.
|
Package azurestore is the objectstore.ObjectStore on Azure Blob Storage, over the Get Blob request. |
|
filestore
Package filestore is the objectstore.ObjectStore and objectstore.Lister on a directory of the local file system (a volume mount, a ConfigMap).
|
Package filestore is the objectstore.ObjectStore and objectstore.Lister on a directory of the local file system (a volume mount, a ConfigMap). |
|
gcsstore
Package gcsstore is the objectstore.ObjectStore on Google Cloud Storage, over the JSON API and the media download of one object.
|
Package gcsstore is the objectstore.ObjectStore on Google Cloud Storage, over the JSON API and the media download of one object. |
|
httpstore
Package httpstore is the objectstore.ObjectStore on a plain HTTP server (static hosting, a CDN).
|
Package httpstore is the objectstore.ObjectStore on a plain HTTP server (static hosting, a CDN). |
|
ratelimit
Package ratelimit caps the requests the relay makes through one connection.
|
Package ratelimit caps the requests the relay makes through one connection. |
|
s3store
Package s3store is the objectstore.ObjectStore and objectstore.Lister on the S3 client of a named connection of the connection factory: GetObject for reads, ListObjectsV2 for listings and HeadObject for the description of one key.
|
Package s3store is the objectstore.ObjectStore and objectstore.Lister on the S3 client of a named connection of the connection factory: GetObject for reads, ListObjectsV2 for listings and HeadObject for the description of one key. |
|
storekit
Package storekit holds what several object stores share and that names no cloud SDK: the rules of a key, the bounded read of a body, the whole-second time rule of S3, and the rules and the transport of the HTTP and the cloud stores (settings limits, redirect policy, Retry-After, the mapping of a status to a result).
|
Package storekit holds what several object stores share and that names no cloud SDK: the rules of a key, the bounded read of a body, the whole-second time rule of S3, and the rules and the transport of the HTTP and the cloud stores (settings limits, redirect policy, Retry-After, the mapping of a status to a result). |
|
storekit/internal/bodyread
Package bodyread reads the body of an object store's answer into one buffer, within the limit of the call.
|
Package bodyread reads the body of an object store's answer into one buffer, within the limit of the call. |
|
storetest
Package storetest is the conformance suite of objectstore.ObjectStore: the contract of a store as executable cases.
|
Package storetest is the conformance suite of objectstore.ObjectStore: the contract of a store as executable cases. |
|
Package polling is the change source that polls a store: it lists the places that hold flag set files, reads the objects whose version marker moved, and delivers what it found as flagsource.Event values.
|
Package polling is the change source that polls a store: it lists the places that hold flag set files, reads the objects whose version marker moved, and delivers what it found as flagsource.Event values. |