flags

package
v0.1.0-rc.1 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package flags is gridctl's experimental feature-flag registry. A flag is born experimental and off by default, is enabled per stack through the top-level `experimental:` map in stack.yaml (or per process through a GRIDCTL_EXPERIMENTAL_<NAME> environment variable), and graduates by having its behavior promoted to a real config block. Registry entries are never deleted: a graduated or removed flag keeps its entry so a stale stack.yaml gets a specific migration message instead of a generic unknown-key warning.

Stage semantics follow the OpenTelemetry Collector featuregate model. Setting an unknown or concluded flag name is always a warning, never an error: a stack.yaml written against a newer gridctl must still start on an older one (Article IX).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Flag

type Flag struct {
	// Name is the snake_case flag key, spelled identically to the stable
	// config key the feature will graduate to.
	Name string
	// Description is the one-line summary shown in docs and the UI.
	Description string
	// Stage is the lifecycle position.
	Stage Stage
	// Since is the release that introduced the flag (bare semver, e.g. "0.1.0").
	Since string
	// GraduatesBy is the release by which an experimental flag must
	// graduate or have its deadline deliberately extended. Required for
	// experimental flags; the enforcement test fails past it.
	GraduatesBy string
	// Message is the migration text for graduated and removed flags, e.g.
	// "graduated in 0.2.0; remove the entry, the feature is now always on".
	Message string
}

Flag is one registry entry.

func Overdue

func Overdue(reg *Registry, currentVersion string) []Flag

Overdue returns the experimental flags whose GraduatesBy deadline is at or before currentVersion. An empty, "dev", or unparseable currentVersion returns nil: development builds never enforce the graduation clock. Pre-release suffixes are ignored — the clock compares major.minor.patch only, so 0.3.0-beta.1 already counts as 0.3.0.

func (Flag) EnvVar

func (f Flag) EnvVar() string

EnvVar returns the environment variable that overrides this flag.

type Registry

type Registry struct {
	// contains filtered or unexported fields
}

Registry is an ordered, indexed set of flags.

func Default

func Default() *Registry

Default returns the built-in registry. The entries are compile-time constants validated by TestBuiltinRegistryValid; if construction ever fails at runtime an empty registry is returned so no flag resolves on.

func NewRegistry

func NewRegistry(entries ...Flag) (*Registry, error)

NewRegistry validates and indexes a set of flags. It returns an error for duplicate or empty names, a missing Since, an experimental flag without a GraduatesBy, or a concluded flag without a migration Message.

func (*Registry) All

func (r *Registry) All() []Flag

All returns every entry in registration order.

func (*Registry) Lookup

func (r *Registry) Lookup(name string) (Flag, bool)

Lookup returns the flag with the given name.

type Resolved

type Resolved struct {
	// Enabled maps every known experimental flag name that resolved to true.
	// Flags resolving to false are absent. Nil when nothing is enabled.
	Enabled map[string]bool
	// Warnings lists unknown names, concluded names, and malformed env
	// overrides encountered during resolution.
	Warnings []Warning
}

Resolved is the outcome of resolving a stack's experimental map against a registry and the process environment.

func Resolve

func Resolve(reg *Registry, experimental map[string]bool) Resolved

Resolve computes the effective flag set from the stack.yaml `experimental:` map and per-flag GRIDCTL_EXPERIMENTAL_<NAME> env overrides. An env override beats the YAML value; an unset env var defers to YAML; a malformed env value warns and defers to YAML (never silently false). Unknown YAML names warn listing the valid flags; graduated and removed names warn with their migration message and contribute nothing.

type Stage

type Stage string

Stage is a flag's lifecycle position.

const (
	// StageExperimental flags are off by default and settable via the
	// `experimental:` map or env override.
	StageExperimental Stage = "experimental"
	// StageGraduated flags have been promoted to a real config block.
	// Setting one warns with its migration message; the value is ignored.
	StageGraduated Stage = "graduated"
	// StageRemoved flags no longer exist in any form. Setting one warns
	// with its migration message; the value is ignored.
	StageRemoved Stage = "removed"
)

type Warning

type Warning struct {
	// Name is the flag key the warning is about ("" for none).
	Name string
	// Message is the full human-readable warning text.
	Message string
}

Warning is one advisory finding from resolution or name validation. Warnings never block an apply.

func CheckNames

func CheckNames(reg *Registry, experimental map[string]bool) []Warning

CheckNames validates the names of a stack's experimental map against a registry without consulting the environment. It backs both apply-time console warnings and the design-time ValidateWithIssues channel.

Jump to

Keyboard shortcuts

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