featuregate

package
Version: v0.37.0 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2021 License: Apache-2.0 Imports: 2 Imported by: 7

README

Collector Feature Gates

This package provides a mechanism that allows operators to enable and disable experimental or transitional features at deployment time. These flags should be able to govern the behavior of the application starting as early as possible and should be available to every component such that decisions may be made based on flags at the component level.

Usage

Feature gates must be defined and registered with the global registry in an init() function. This makes the Gate available to be configured and queried with a default value of its Enabled property.

const myFeatureGateID = "namespaced.uniqueIdentifier"

func init() {
	featuregate.Register(featuregate.Gate{
		ID:          fancyNewFeatureGate,
		Description: "A brief description of what the gate controls",
		Enabled:     false,
	})
}

The status of the gate may later be checked by interrogating the global feature gate registry:

if featuregate.IsEnabled(myFeatureGateID) {
	setupNewFeature()
}

Note that querying the registry takes a read lock and accesses a map, so it should be done once and the result cached for local use if repeated checks are required. Avoid querying the registry in a loop.

Controlling Gates

N.B.: This feature has not yet been implemented and is subject to change.

Feature gates can be enabled or disabled via the CLI, with the --feature-gates flag. When using the CLI flag, gate identifiers must be presented as a comma-delimited list. Gate identifiers prefixed with - will disable the gate and prefixing with + or with no prefix will enable the gate.

otelcol --config=config.yaml --feature-gates=gate1,-gate2,+gate3

This will enable gate1 and gate3 and disable gate2.

Feature Lifecycle

Features controlled by a Gate should follow a three-stage lifecycle, modeled after the system used by Kubernetes:

  1. An alpha stage where the feature is disabled by default and must be enabled through a Gate.
  2. A beta stage where the feature has been well tested and is enabled by default but can be disabled through a Gate.
  3. A generally available stage where the feature is permanently enabled and the Gate is no longer operative.

Features that prove unworkable in the alpha stage may be discontinued without proceeding to the beta stage. Features that make it to the beta stage will not be dropped and will eventually reach general availability where the Gate that allowed them to be disabled during the beta stage will be removed.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Apply

func Apply(cfg map[string]bool)

Apply a configuration in the form of a map of Gate identifiers to boolean values. Sets only those values provided in the map, other gate values are not changed.

func IsEnabled

func IsEnabled(id string) bool

IsEnabled returns true if a registered feature gate is enabled and false otherwise.

func Register

func Register(g Gate)

Register a Gate. May only be called in an init() function. Will panic() if a Gate with the same ID is already registered.

Types

type Gate

type Gate struct {
	ID          string
	Description string
	Enabled     bool
}

Gate represents an individual feature that may be enabled or disabled based on the lifecycle state of the feature and CLI flags specified by the user.

func List

func List() []Gate

List returns a slice of copies of all registered Gates.

Source Files

Jump to

Keyboard shortcuts

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