flags

package
v0.8.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 30, 2026 License: AGPL-3.0 Imports: 8 Imported by: 0

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

View Source
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

func New(s store.FlagStore) *Engine

New returns an Engine backed by the given store. Evaluation metrics are discarded until SetRecorder is called.

func (*Engine) Create

func (e *Engine) Create(ctx context.Context, f core.Flag) error

Create persists a new flag.

func (*Engine) Delete

func (e *Engine) Delete(ctx context.Context, key string) error

Delete removes a flag by key.

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) Get

func (e *Engine) Get(ctx context.Context, key string) (core.Flag, error)

Get loads a flag by key.

func (*Engine) List

func (e *Engine) List(ctx context.Context) ([]core.Flag, error)

List returns all flags.

func (*Engine) SetEmitter

func (e *Engine) SetEmitter(fn func(core.Event))

SetEmitter installs an event sink (e.g. a notify.Dispatcher's Emit). Passing nil disables emission.

func (*Engine) SetRecorder added in v0.8.0

func (e *Engine) SetRecorder(r obs.Recorder)

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).

func (*Engine) Update

func (e *Engine) Update(ctx context.Context, f core.Flag) error

Update persists changes to an existing flag.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL