Documentation
¶
Overview ¶
Package service manages the flagsets and the feature flag clients used by the relay proxy.
Index ¶
- Variables
- func NewAdminKeyError(msg string) error
- type APIKeys
- type ConfigVersioned
- type EvaluationIdentity
- type EvaluationTagger
- type EventAcceptor
- type FlagChanger
- type FlagSet
- type FlagSetResolver
- type KeySource
- type Monitoring
- type OrderedEvaluator
- type Probes
- type PublicScope
- type RefreshOutcome
- type RefreshUnsupported
- type Refresher
- type SegmentUser
- type Services
- type StateVisitor
Constants ¶
This section is empty.
Variables ¶
var ErrAdminKey = errors.New("the key is an admin key")
ErrAdminKey is what an error of FlagSetResolver.FlagSet wraps (errors.Is) when the key is an admin key: it authenticates, and it is linked to no flag set.
var ErrNotPolling = errors.New("the relay is not polling its control plane")
ErrNotPolling is the error of Refresher.Refresh when the relay does not poll (not started, or stopped).
Functions ¶
func NewAdminKeyError ¶ added in v0.2.0
NewAdminKeyError returns the error of a resolver for an admin key, with the message of the answer: it wraps ErrAdminKey.
Types ¶
type APIKeys ¶ added in v0.2.0
type APIKeys struct {
// contains filtered or unexported fields
}
APIKeys answers which API keys the relay proxy accepts. The keys change at reload: APIKeys asks its source on every call, so the HTTP layer observes the change without owning the keys. It is a value that wraps the source, copying it shares the same live keys. Without a source (the zero value) it behaves like an empty configuration: no key is accepted and the authentication is disabled.
func NewAPIKeysFrom ¶ added in v0.2.0
NewAPIKeysFrom returns the accessor of the API keys of a source.
func (APIKeys) AdminKeyExists ¶ added in v0.2.0
AdminKeyExists reports whether the key is an admin key.
func (APIKeys) AuthenticationEnabled ¶ added in v0.2.0
AuthenticationEnabled reports whether the evaluation requests must carry an accepted key.
type ConfigVersioned ¶ added in v0.2.0
type ConfigVersioned interface {
// ConfigETag is the identity of the configuration of the flag set, the one the change notification carries.
ConfigETag() string
// ConfigModified is the date of the configuration of the flag set (the createdAt of its manifest, the same on every
// replica), zero when it has none.
ConfigModified() time.Time
}
ConfigVersioned is a FlagSet that knows which configuration it serves: the OFREP bulk evaluation compares it with the configuration a client was notified of.
type EvaluationIdentity ¶ added in v0.2.0
type EvaluationIdentity struct {
// Name is the name of the flag set.
Name string
// State is the state of the flag set.
State string
// Content is the hash of the flags of the flag set and of the segments they use.
Content uint64
// Enrichment is the hash of the enrichment merged into every evaluation of the flag set.
Enrichment uint64
// Flags is the number of flags of the flag set.
Flags int
}
EvaluationIdentity is what makes the answer of a bulk evaluation: the flag set and the evaluation environment its flags are evaluated in. Two flag sets with the same identity answer the same request with the same states, as long as the flags of the request are pre-taggable (see EvaluationTagger).
type EvaluationTagger ¶ added in v0.2.0
type EvaluationTagger interface {
// EvaluationIdentity returns the identity of the bulk evaluation of flagsToEvaluate (every flag when empty), and
// whether it can be tagged: every flag that it evaluates has an answer that is a function of the identity and of the
// request context alone (no scheduled rollout, experimentation, progressive rollout or dynamic segment).
EvaluationIdentity(flagsToEvaluate []string) (EvaluationIdentity, bool)
}
EvaluationTagger is a FlagSet that tells, before a bulk evaluation runs, whether its answer is decided by the flag set and the request alone: the OFREP bulk evaluation then keeps the tag of the answers it sent, by the hash of their inputs, and answers a request that carries the tag with a 304, without evaluating a flag.
type EventAcceptor ¶ added in v0.2.0
type EventAcceptor interface {
// AcceptEventData hands a feature event to the exporters and reports whether it was accepted.
AcceptEventData(event *exporter.FeatureEvent) bool
}
EventAcceptor is a FlagSet that tells whether it accepted a feature event: its queue to the exporters is bounded and a full queue drops the event. The collector then counts only the accepted events as ingested. A flag set that does not implement it accepts every event.
type FlagChanger ¶ added in v0.2.0
type FlagChanger interface {
// FlagChange returns the hash of every flag and the hash of the whole table.
FlagChange() (flags map[string]uint32, hash uint32, err error)
}
FlagChanger is a FlagSet that keeps the hashes of its flags: the flag change endpoint answers with them instead of encoding every flag again. The returned map is shared: the caller only reads it.
type FlagSet ¶ added in v0.2.0
type FlagSet interface {
// RawVariation evaluates one flag without a type.
RawVariation(
ctx context.Context,
flagKey string,
evalCtx ffcontext.Context,
defaultValue any,
) (model.RawVarResult, error)
// GetFlagStates evaluates the listed flags.
GetFlagStates(ctx context.Context, evalCtx ffcontext.Context, flagsToEvaluate []string) flagstate.AllFlags
// AllFlagsState evaluates every flag.
AllFlagsState(ctx context.Context, evalCtx ffcontext.Context) flagstate.AllFlags
// GetFlagsFromCache returns the flags of the flag set.
GetFlagsFromCache() (map[string]flagdef.Flag, error)
// GetFlagsFromCacheWithContext is GetFlagsFromCache with the context of the request.
GetFlagsFromCacheWithContext(ctx context.Context) (map[string]flagdef.Flag, error)
// GetCacheRefreshDate is the date the flags were last refreshed.
GetCacheRefreshDate() time.Time
// GetEvaluationContextEnrichment is the enrichment that every evaluation of the flag set gets.
GetEvaluationContextEnrichment() map[string]any
// CollectEventData hands a feature event to the exporters.
CollectEventData(event *exporter.FeatureEvent)
// CollectTrackingEventData hands a tracking event to the exporters.
CollectTrackingEventData(event *exporter.TrackingEvent)
// ForceRefresh asks the flag source for the latest flags and reports whether it did.
ForceRefresh() bool
}
FlagSet is what the HTTP handlers use of one flag set: the evaluation, the flag configuration, the collection of events and the refresh. The config v2 core satisfies it (corehttp.Adapter). The evaluations take the context of the request: the lookups of the dynamic segments end with it. A value that an evaluation returns is shared: the handlers only read it, and never change it.
type FlagSetResolver ¶ added in v0.2.0
type FlagSetResolver interface {
// FlagSet returns the flag set linked to the API Key
FlagSet(apiKey string) (FlagSet, error)
// FlagSetName returns the name of the flagset linked to the API Key.
// In default mode it returns the default flagset name, with flagsets it returns an
// error if the API Key is empty or not linked to a flagset.
FlagSetName(apiKey string) (string, error)
// IsDefaultFlagSet returns true if the manager is in default mode (no flagsets configured)
IsDefaultFlagSet() bool
}
FlagSetResolver finds the flag set of an API key. It is the seam of the HTTP layer: the config v2 core implements it, the tests of the handlers implement it on engine clients.
type KeySource ¶ added in v0.2.0
type KeySource interface {
// AuthenticationEnabled reports whether the evaluation requests must carry an accepted key.
AuthenticationEnabled() bool
// KeyExists reports whether the key is accepted, whatever its kind.
KeyExists(apiKey string) bool
// AdminKeyExists reports whether the key is an admin key.
AdminKeyExists(apiKey string) bool
}
KeySource is the source of the API keys: the config v2 core, whose routing changes at reload. Its methods are called for every request and must not allocate.
type Monitoring ¶
type Monitoring interface {
Health() model.HealthResponse
Info() (model.InfoResponse, error)
}
Monitoring is the interface of the monitoring service.
type OrderedEvaluator ¶ added in v0.2.0
type OrderedEvaluator interface {
// EachFlagState evaluates flagsToEvaluate (every flag when empty), each flag once, and hands each state to visit in
// ascending key order. A name that the flag set does not hold is left out. The states are READ-ONLY, as the ones of
// GetFlagStates are.
EachFlagState(ctx context.Context, evalCtx ffcontext.Context, flagsToEvaluate []string, visit StateVisitor)
}
OrderedEvaluator is a FlagSet that evaluates a bulk request in ascending key order, without building the table of the states.
type Probes ¶ added in v0.2.0
type Probes interface {
// Ready answers /readyz: the status code and the body.
Ready() (int, model.ReadyResponse)
// Started answers /startupz: the status code and the body.
Started() (int, model.ReadyResponse)
}
Probes is implemented by a monitoring service that serves the probe endpoints /readyz and /startupz. A service that does not implement it does not serve the endpoints.
type PublicScope ¶ added in v0.2.0
type PublicScope interface {
// IsPublic reports that the flag set is the public one.
IsPublic() bool
// HasFlag reports whether the flag is one of the flag set.
HasFlag(key string) bool
// DropNotPublic counts events that were refused because their flag is not public.
DropNotPublic(count int)
}
PublicScope is a FlagSet that is the public flag set: a caller without an API key is a caller of the public flags only, so the events it sends are accepted for these flags and no other.
type RefreshOutcome ¶ added in v0.2.0
type RefreshOutcome struct {
Result string
Reason string
Rejection string
Generation uint64
AppliedGeneration uint64
Changed bool
Applied bool
}
RefreshOutcome is what a refresh on request found.
type RefreshUnsupported ¶ added in v0.2.0
type RefreshUnsupported interface {
// RefreshUnsupported is the reason, sent to the client.
RefreshUnsupported() string
}
RefreshUnsupported is a FlagSetResolver whose flag sets can not be refreshed on request: the refresh endpoint answers 501 with the reason.
type Refresher ¶ added in v0.2.0
type Refresher interface {
// Refresh polls now and returns what the poll found.
Refresh(ctx context.Context) (RefreshOutcome, error)
}
Refresher is a FlagSetResolver that polls its control plane on request, through the poll of the schedule: calls that arrive together share one poll, and ctx bounds the wait for it.
type SegmentUser ¶ added in v0.2.0
type SegmentUser interface {
// FlagSegments returns the sorted names of the segments that the rules of the flag use, nil for a flag that uses
// none, and whether one of them is dynamic (its members live in a store, so the flag needs the server to be
// evaluated).
FlagSegments(flagKey string) (names []string, requiresServerEvaluation bool)
}
SegmentUser is a FlagSet that knows which segments the rules of its flags use: the flag configuration endpoint lists them next to the flag. A flag set that does not implement it lists none.
type Services ¶
type Services struct {
// MonitoringService is the service in charge of managing the monitoring
MonitoringService Monitoring
// WebsocketBroadcasterService is the service in charge to manage the websockets in the relay proxy
WebsocketService stream.WebsocketService
// SSEService is the service in charge of managing SSE connections in the relay proxy
SSEService stream.SSEService
// Metrics is the service containing all the prometheus metrics
Metrics *metric.Metrics
}
Services holds the services used by the relay proxy.
type StateVisitor ¶ added in v0.2.0
type StateVisitor interface {
// Expect is called once, before the first Visit, with the most states that will be visited.
Expect(count int)
// Visit receives the state of one flag. The state is valid during the call only (the next flag reuses it): the
// visitor copies what it keeps. The metadata map of the state belongs to the visitor.
Visit(key string, state *flagstate.FlagState)
}
StateVisitor receives the states of a bulk evaluation.