featuregate

package
v0.4.0 Latest Latest
Warning

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

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

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var AggregatorAnnotations = Register("telegraf.aggregators",
	"Enable telegraf aggregator plugin configuration via pod annotations",
	false)

AggregatorAnnotations enables telegraf aggregator plugin configuration via pod annotations.

When enabled, pods can use the telegraf.influxdata.com/aggregators annotation to specify raw TOML configuration for aggregator plugins.

View Source
var NativeSidecars = Register("operator.nativesidecars",
	"Use Kubernetes 1.28+ native sidecar containers instead of regular containers",
	false)

NativeSidecars controls whether to inject Telegraf as native sidecar containers (Kubernetes 1.28+ feature) instead of regular containers.

Native sidecars provide better lifecycle management and startup ordering, but require Kubernetes 1.28+ with the SidecarContainers feature gate enabled.

View Source
var ProcessorAnnotations = Register("telegraf.processors",
	"Enable telegraf processor plugin configuration via pod annotations",
	false)

ProcessorAnnotations enables telegraf processor plugin configuration via pod annotations.

When enabled, pods can use the telegraf.influxdata.com/processors annotation to specify raw TOML configuration for processor plugins.

Functions

func RegisterFlags

func RegisterFlags(flagSet *flag.FlagSet)

RegisterFlags adds feature gate flags to the provided FlagSet using the global registry.

func Set

func Set(name string, enabled bool) error

Set enables or disables a gate by name in the global registry.

func VisitAll

func VisitAll(fn func(*Gate))

VisitAll calls the provided function for each Gate in the global registry.

Types

type Gate

type Gate struct {
	Name        string
	Description string
	// contains filtered or unexported fields
}

Gate represents a feature that can be enabled or disabled.

func Get

func Get(name string) *Gate

Get retrieves a Gate by name from the global registry.

func Register

func Register(name, description string, defaultEnabled bool) *Gate

Register creates and registers a new Gate in the global registry.

func (*Gate) IsEnabled

func (g *Gate) IsEnabled() bool

IsEnabled returns true if the feature gate is enabled.

type Registry

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

Registry manages feature gates in a thread-safe manner.

Example
// Create a new registry
registry := NewRegistry()

// Register some gates
featureA := registry.Register("feature.a", "Enable feature A", false)
featureB := registry.Register("feature.b", "Enable feature B", true)

// Check if features are enabled
fmt.Printf("Feature A enabled: %v\n", featureA.IsEnabled())
fmt.Printf("Feature B enabled: %v\n", featureB.IsEnabled())

// Enable feature A
_ = registry.Set("feature.a", true) // Ignore error in example
fmt.Printf("Feature A enabled after set: %v\n", featureA.IsEnabled())

// List all gates
registry.VisitAll(func(g *Gate) {
	status := "disabled"
	if g.IsEnabled() {
		status = "enabled"
	}
	fmt.Printf("Gate %s: %s (%s)\n", g.Name, status, g.Description)
})
Output:
Feature A enabled: false
Feature B enabled: true
Feature A enabled after set: true
Gate feature.a: enabled (Enable feature A)
Gate feature.b: enabled (Enable feature B)

func GlobalRegistry

func GlobalRegistry() *Registry

GlobalRegistry returns the global Registry instance.

func NewRegistry

func NewRegistry() *Registry

NewRegistry creates a new Registry.

func (*Registry) Get

func (r *Registry) Get(name string) *Gate

Get retrieves a Gate by name. Returns nil if the gate doesn't exist.

func (*Registry) Register

func (r *Registry) Register(name, description string, defaultEnabled bool) *Gate

Register creates and registers a new Gate. Panics if a gate with the same name is already registered.

func (*Registry) RegisterFlags

func (r *Registry) RegisterFlags(flagSet *flag.FlagSet)

RegisterFlags adds feature gate flags to the provided FlagSet.

func (*Registry) Set

func (r *Registry) Set(name string, enabled bool) error

Set enables or disables a gate by name. Returns an error if the gate doesn't exist.

func (*Registry) VisitAll

func (r *Registry) VisitAll(fn func(*Gate))

VisitAll calls the provided function for each registered Gate in lexicographical order.

Jump to

Keyboard shortcuts

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