Documentation
¶
Overview ¶
Package flags implements Console's feature-flag evaluation engine. It wraps a store.FlagStore for persistence and resolves a flag to an Evaluation for a given subject deterministically: the same (flag, subject) pair always yields the same result, so a rollout is stable across calls and processes.
Index ¶
- Constants
- type Engine
- func (e *Engine) Create(ctx context.Context, f core.Flag) error
- func (e *Engine) Delete(ctx context.Context, key string) error
- func (e *Engine) Evaluate(ctx context.Context, key string, subj core.Subject) (core.Evaluation, error)
- func (e *Engine) Get(ctx context.Context, key string) (core.Flag, error)
- func (e *Engine) List(ctx context.Context) ([]core.Flag, error)
- func (e *Engine) SetEmitter(fn func(core.Event))
- func (e *Engine) SetRecorder(r obs.Recorder)
- func (e *Engine) Update(ctx context.Context, f core.Flag) error
Constants ¶
const ( // ResultOn: the flag evaluated to an enabled Evaluation (rolled in). ResultOn = "on" // ResultOff: the flag evaluated to a disabled Evaluation (flag disabled, // out of scope, or excluded by rollout). ResultOff = "off" // ResultNotFound: no flag exists for the requested key. ResultNotFound = "not_found" // ResultError: evaluation failed for any other reason (e.g. store error). ResultError = "error" )
Result label values for console_flag_evaluations_total{result}.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine evaluates feature flags and provides CRUD passthrough to its store.
func New ¶
New returns an Engine backed by the given store. Evaluation metrics are discarded until SetRecorder is called.
func (*Engine) Evaluate ¶
func (e *Engine) Evaluate(ctx context.Context, key string, subj core.Subject) (core.Evaluation, error)
Evaluate resolves key for subj. The result is deterministic per (flag, subject): bucketing is derived from a stable hash, never from randomness, so repeated calls are identical.
The pipeline is: load → enabled gate → scope gate → rollout gate → variant selection. The first gate that fails returns a disabled "off" Evaluation with a Reason naming the gate.
Each call is recorded in console_flag_evaluations_total{result} (see the Result* constants) and console_flag_eval_duration_seconds; recording never affects the returned Evaluation.
func (*Engine) SetEmitter ¶
SetEmitter installs an event sink (e.g. a notify.Dispatcher's Emit). Passing nil disables emission.
func (*Engine) SetRecorder ¶ added in v0.8.0
SetRecorder installs the instrumentation Recorder and resolves the console_flag_evaluations_total{result} counters and the console_flag_eval_duration_seconds histogram once. Labels are the bounded result set only; flag and subject keys are never used as labels. A nil Recorder is treated as obs.Nop. Call before the engine is shared between goroutines (the composition root does so at construction).